MATLAB PARALLEL COMPUTING TOOLBOX - S Guide de l'utilisateur Page 291

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 656
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 290
Run MEX-Functions Containing CUDA Code
9-33
Compile a GPU MEX-File
When you have set up the options file, use the mex command in MATLAB to compile
a MEX-file containing the CUDA code. You can compile the example file using the
command:
mex -largeArrayDims mexGPUExample.cu
The -largeArrayDims option is required to ensure that 64-bit values for array
dimensions are passed to the MEX API.
Run the Resulting MEX-Functions
The MEX-function in this example multiplies every element in the input array by 2 to get
the values in the output array. To test it, start with a gpuArray in which every element is
1:
x = ones(4,4,'gpuArray');
y = mexGPUExample(x)
y =
2 2 2 2
2 2 2 2
2 2 2 2
2 2 2 2
Both the input and output arrays are gpuArray objects:
disp(['class(x) = ',class(x),', class(y) = ',class(y)])
class(x) = gpuArray, class(y) = gpuArray
Comparison to a CUDA Kernel
Parallel Computing Toolbox also supports CUDAKernel objects that can be used to
integrate CUDA code with MATLAB. Consider the following when choosing the MEX-file
approach versus the CUDAKernel approach:
MEX-files can interact with host-side libraries, such as the NVIDIA Performance
Primitives (NPP) or CUFFT libraries, and can also contain calls from the host to
functions in the CUDA runtime library.
Vue de la page 290
1 2 ... 286 287 288 289 290 291 292 293 294 295 296 ... 655 656

Commentaires sur ces manuels

Pas de commentaire