MATLAB Answers

How to make sure that function is entirely run on GPU?

2 ビュー (過去 30 日間)
Florian 2020 年 5 月 30 日
回答済み: Edric Ellis 2020 年 6 月 1 日
I want to implement an algorithm, which performs operations on very large arrays (up to 10 million entries each), on the GPU. I have already achieved, that it runs on the GPU and even gives a speed up of up to factor 10, but I am not entirely sure, whether all operations and functions of the algorithm are running on the GPU, or whether there is still CPU-GPU transfers required. Specifically, I wonder whether Matlab offers an intuitive way of showing such unnecessary transfers.
So my question is whether the following operation b leads to such transfers:
If I define two variables amplitude and period on the CPU - let's say
and create an gpu array
and calculate b by using the function
b = @(u) b_st+amplitude*sin(u*2*pi/period);
will then
be calculated entirely on the GPU? Or do I have to also define period and amplitude on the GPU via gpuarray()?
Thank you in advance!

  0 件のコメント


回答 (1 件)

Edric Ellis
Edric Ellis 2020 年 6 月 1 日
Operations on gpuArray data automatically take place on the GPU. When you operate on mixed GPU and CPU data, generally the operation takes place on the GPU - the only time this is not the case is when the gpuArray inputs are considered to be "parameters" (such as sizes or dimensions) rather than "data". For example:
sum(magic(3), gpuArray(1))
In this case, the "data" argument to sum is on the CPU, and the dimension "parameter" happens to be on the GPU. Because the data is on the CPU, the GPU-ness of the summation dimension is ignored, and the compuation takes place on the CPU.

  0 件のコメント






Community Treasure Hunt

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

Start Hunting!

Translated by