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 ExchangeGPU 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