How to make sure that function is entirely run on GPU?
4 次查看(过去 30 天)
显示 更早的评论
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
amplitude=300;
period=3;
and create an gpu array
u=rand(10000000,1);
and calculate b by using the function
b = @(u) b_st+amplitude*sin(u*2*pi/period);
will then
x=b(u);
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
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!