Evaluating fucntion by GPU.
Mostrar comentarios más antiguos
Hello, Is that possible to evaluate function written by myself on every element of array at once? Best regards, M. Pydych.
Respuestas (2)
Walter Roberson
el 9 de Mayo de 2017
0 votos
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 comentarios
Mateusz Pydych
el 9 de Mayo de 2017
Walter Roberson
el 9 de Mayo de 2017
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
el 13 de Mayo de 2017
Editada: Joss Knight
el 13 de Mayo de 2017
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
el 13 de Mayo de 2017
Editada: Joss Knight
el 13 de Mayo de 2017
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.
Categorías
Más información sobre GPU Computing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!