MATLAB PARALLEL COMPUTING TOOLBOX - S User's Guide Page 278

  • Download
  • Add to my manuals
  • Print
  • Page
    / 656
  • Table of contents
  • TROUBLESHOOTING
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 277
9 GPU Computing
9-20
Run CUDA or PTX Code on GPU
In this section...
“Overview” on page 9-20
“Create a CUDAKernel Object” on page 9-21
“Run a CUDAKernel” on page 9-26
“Complete Kernel Workflow” on page 9-28
Overview
This topic explains how to create an executable kernel from CU or PTX (parallel thread
execution) files, and run that kernel on a GPU from MATLAB. The kernel is represented
in MATLAB by a CUDAKernel object, which can operate on MATLAB array or gpuArray
variables.
The following steps describe the CUDAKernel general workflow:
1
Use compiled PTX code to create a CUDAKernel object, which contains the GPU
executable code.
2
Set properties on the CUDAKernel object to control its execution on the GPU.
3
Call feval on the CUDAKernel with the required inputs, to run the kernel on the
GPU.
MATLAB code that follows these steps might look something like this:
% 1. Create CUDAKernel object.
k = parallel.gpu.CUDAKernel('myfun.ptx','myfun.cu','entryPt1');
% 2. Set object properties.
k.GridSize = [8 1];
k.ThreadBlockSize = [16 1];
% 3. Call feval with defined inputs.
g1 = gpuArray(in1); % Input gpuArray.
g2 = gpuArray(in2); % Input gpuArray.
result = feval(k,g1,g2);
Page view 277
1 2 ... 273 274 275 276 277 278 279 280 281 282 283 ... 655 656

Comments to this Manuals

No comments