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

5 vues (au cours des 30 derniers jours)
Florian
Florian le 30 Mai 2020
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!

Réponses (1)

Edric Ellis
Edric Ellis le 1 Juin 2020
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.

Catégories

En savoir plus sur GPU Computing dans Help Center et File Exchange

Tags

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by