Contents

mThrust demo 02

Illustration of basic mThrust command
clear all
dx=Thrust.linspace(0,2*pi,9)
dx = 

 thrust::device_vector<double>[9]
 0  0.785398  1.5708  2.35619  3.14159  
3.92699  4.71239  5.49779  6.28319  

Computation on device

dy=cos(dx)
dy = 

 thrust::device_vector<double>[9]
 1  0.707107  6.12323e-17  -0.707107  -1  
-0.707107  -1.83697e-16  0.707107  1  
dy=dx.*dy.^2-1
dy = 

 thrust::device_vector<double>[9]
 -1  -0.607301  -1  0.178097  2.14159  
0.963495  -1  1.74889  5.28319  

Transfert from GPU device to Matlab

y=gather(dy);
whos
  Name      Size            Bytes  Class      Attributes

  dx        1x9                 8  mThrust              
  dy        1x9                 8  mThrust              
  y         9x1                72  double