Strange gpu arrayfun behavior
이전 댓글 표시
I have existing code that works but I'd like to accelerate using the GPU version of arrayfun. However the behavior of GPU arrayfun is difficult to understand. According to the documentation the code within the helper function performs scalar operations on the input gpuArray values. However if I try to write my own scalar values the result is unpredictable. To demonstrate, if I have a helper function that look like:
function outArray = simpleTest(inArray)
outArray = inArray * 3.14159;
end
x = gpuArray(1:4);
y = arrayfun(@simpleTest, x);
y = gather(y)
y =
Columns 1 through 2
0.0000 + 0.0000i 0.0000 + 0.0000i
Columns 3 through 4
0.0000 + 0.0000i 0.0000 + 0.0000i
If I pass the scalar value to the helper function, as shown in the second helper function, it does seem to work:
function outArray = simpleTest2(inArray, scalarValue)
outArray = inArray * scalarValue;
end
y = arrayfun(@simpleTest2, x, 3.14159);
y = gather(y)
y =
3.1416 6.2832 9.4248 12.5664
Reading the documentation, I know that the scalar values in the calling function are expanded (similar to bsxfun) however I have been unable to get that function, or any other function, to work within the helper function. I know I'm missing something here, I would appreciate the help.
I have Matlab R2018a with Parallel Computing Toolbox and Cuda version 9.0 installed.
댓글 수: 5
Joss Knight
2018년 7월 22일
Well, that behaviour you appear to be getting is just incredibly weird and it doesn't reproduce for me. I can't think of any good reason why it would happen. It would be best to start by eliminating coding issues. To start, copy the code above into a new script, but move the function to the end, then run the script. This will ensure that you are running exactly what you wrote:
x = gpuArray(1:4);
y = arrayfun(@simpleTest, x);
y = gather(y)
function outArray = simpleTest(inArray)
outArray = inArray * 3.14159;
end
OCDER
2018년 7월 24일
Just curious, what does the following return?
which simpleTest
which simpleTest2
Joss Knight
2018년 7월 24일
Okay, so the next thing to do is to check and upgrade your driver. What is your device? What is your driver version?
gpuDevice
parallel.internal.gpu.CUDADriverVersion
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!