Concurrent write to gpuArray

조회 수: 12 (최근 30일)
Zheng Gu
Zheng Gu 2015년 8월 8일
답변: Joss Knight 2015년 9월 2일
Is there a way for multiple threads of an arrayfun or other structure to write to the same gpuArray matrix, if I do not care about the order of writes (it is a array of falses and i only ever write trues) and will not read the array by gather until all threads are finished? Doing this by local output and reduction will consume too much memory.
Application: a monochrome 2d rasterizer that processes multiple polygons onto the frame buffer simultaneously

답변 (2개)

Matt J
Matt J 2015년 8월 8일
편집: Matt J 2015년 8월 8일
Even if there's a way, I think it will be very slow. GPUs are not designed to share large data across threads. However, one strategy might be to use gpuArray.arrayfun to prepare a table of the values to be written and their matrix coordinates (I,J,S). Then later, on the CPU, do
A_new=A_old+sparse(I,J,S)
Or, use accumarray instead of sparse(), if the resulting matrix is not sparse. Each GPU thread could compute a single triplet I(k),J(k), S(k) effectively assuming these computations are small, parallel, and don't share large data
  댓글 수: 1
Zheng Gu
Zheng Gu 2015년 8월 8일
Thanks for the answer. However my comment about local output and reduction really was meant to say that the framebuffer itself is small (several hundred KB) but having a copy of it per polygon is absolutely huge, not to mention then needing to reduce them into each other via a bitwise OR. The goal is not to share among threads but just to have all threads able to write to it without reading. Again the frame buffer itself is relatively small, but the number of polys is enormous.
Your suggestion is however an improvement on the above since it would use less space per poly.

댓글을 달려면 로그인하십시오.


Joss Knight
Joss Knight 2015년 9월 2일
In short, no, not in MATLAB code. arrayfun has to write one value per thread to a separate output address. Write a CUDAKernel or MEX function in C++.

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by