Hello, Is that possible to evaluate function written by myself on every element of array at once? Best regards, M. Pydych.

답변 (2개)

Walter Roberson
Walter Roberson 2017년 5월 9일

0 개 추천

You can use https://www.mathworks.com/help/distcomp/parallel.gpu.cudakernel.html to invoke relatively arbitrary GPU code .
However, you cannot simply create your own function and call it on a gpu array object . gpuarray methods are only available to the particular functions Mathworks has specially coded for gpuarray: see https://www.mathworks.com/help/distcomp/run-built-in-functions-on-a-gpu.html and note that Mathworks had to enable each of those individually.

댓글 수: 3

Mateusz Pydych
Mateusz Pydych 2017년 5월 9일
So there is no way that I can evaluate my function on multiple elements of array at once? I trought about GPU because computations using CPU are too time consuming,due to ammount of points on which this function have to be evaluated.
Walter Roberson
Walter Roberson 2017년 5월 9일
If your function involves only the calls listed in the link above, then it will (if I understand correctly) be compiled to work in parallel on the GPU. Otherwise, to get it to work on the GPU in parallel, you would have to rewrite your code as a .cu and compile it with the CUDA toolkit in order to be able to call it.
Joss Knight
Joss Knight 2017년 5월 13일
편집: Joss Knight 2017년 5월 13일
Hmm. You can write any gpuArray function you like just by adding it to a directory called @gpuArray that you've put on the MATLAB path. But you only need to do that if you need it to do something special for gpuArrays. If not, you just write a function like normal and pass it a gpuArray.

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

Joss Knight
Joss Knight 2017년 5월 13일
편집: Joss Knight 2017년 5월 13일

0 개 추천

Your question is extremely confusing. Every function can act on every element of its inputs at once. So if I write a function
function A = myFunc(A)
A = A.^2;
end
then I can pass it any array and it will act on the whole array
A = gpuArray.rand(1000, 1);
Asquared = myFunc(A);
In fact, the only way to write a function and get it to act on each element of the input independently is to use gpuArray/arrayfun.

카테고리

도움말 센터File Exchange에서 GPU Computing에 대해 자세히 알아보기

질문:

2017년 5월 9일

편집:

2017년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by