MATLAB PARALLEL COMPUTING TOOLBOX - S Guida Utente Pagina 290

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
Vedere la pagina 289
9 GPU Computing
9-32
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < N)
B[i] = 2.0 * A[i];
}
It contains the following lines to determine the array size and launch a grid of the proper
size:
N = (int)(mxGPUGetNumberOfElements(A));
blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
TimesTwo<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, N);
Set Up for MEX-File Compilation
Your MEX source file that includes CUDA code must have a name with the extension
.cu, not .c nor .cpp.
Before you compile your MEX-file, copy the provided mex_CUDA_platform.xml file
for your platform and compiler from the specified location, into the same folder as
your MEX source file.
For Linux
®
platforms:
matlabroot/toolbox/distcomp/gpu/extern/src/mex/glnxa64/gcc/mex_CUDA_glnxa64.xml
For Macintosh platforms:
matlabroot/toolbox/distcomp/gpu/extern/src/mex/maci64/clang/mex_CUDA_maci64.xml
For Windows platforms with Visual Studio
®
2012:
matlabroot\toolbox\distcomp\gpu\extern\src\mex\win64\msvc2012\mex_CUDA_win64.xml
For Windows platforms with Visual Studio 2013:
matlabroot\toolbox\distcomp\gpu\extern\src\mex\win64\msvc2013\mex_CUDA_win64.xml
You must use the version of the NVIDIA compiler (nvcc) consistent with the
ToolkitVersion property of the GPUDevice object.
Before compiling, make sure either that the location of the folder containing nvcc
is on your search path, or that the path to this folder is encoded in the environment
variable MW_NVCC_PATH. You can set this variable using the MATLAB setenv
command. For example:
setenv('MW_NVCC_PATH','/usr/local/CUDA/bin')
Vedere la pagina 289
1 2 ... 285 286 287 288 289 290 291 292 293 294 295 ... 655 656

Commenti su questo manuale

Nessun commento