NVCC cuda compiler wraper

版本 1.1.0.0 (3.6 KB) 作者: Dirk-Jan Kroon
Compile cuda kernels in Matlab, like nvcc('example.cu')
2.3K 次下载
更新时间 2010/12/6

查看许可证

This function NVCC is a wraper for the NVIDIA Cuda compiler NVCC.exe
in combination with a Visual Studio compiler. After this Cuda
files can be compiled into kernels

If you call the code the first time, or with "nvcc -config":
1) It will try to locate the "The NVIDIA GPU Computing Toolkit", which
can be downloaded from www.nvidia.com/object/cuda_get.html
Typical Location :
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\bin
2) It will try to locate the visual studio compiler
Typical Location :
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\
3) It creates a file nvccbat.bat with the compiler information.

After this configuration procedure, you can compile files with:

nvcc(filename);

or

nvcc(options,filename)

filename : A string with the filename, for example 'example.cu'
options : NVCC Compiler options for example,
nvcc(option1, option2, option3,filename)

For help on NVCC config options type, "nvcc --help"

Note!
If the NVCC fails to locate the compiler you can try to
write your own "nvccbat.bat" file in a text-editor, for example:
echo off
set PATH=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\;PATH
set PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\bin;PATH
call vcvars32.bat
nvcc 1 2 3 4 5 6 7 8 9

1 Example, Configuration
Locate Cuda and VS compiler
nvcc -config

Show the NVCC compiler options
nvcc --help

Test some input options
nvcc --dryrun -ptx example.cu

2 Example,

Locate Cuda and VS compiler
nvcc -config
Compile the code
nvcc('example.cu');
It the same as :
nvcc -ptx example.cu

Make the kernel
Kernel = parallel.gpu.CUDAKernel('example.ptx', 'example.cu');

We want to execute this kernel 100 times
Kernel.ThreadBlockSize=100;

We make an array with 100 random files
Data=rand(100, 1, 'single');
DataCuda= gpuArray(Data);

We will add the value 1
OneCuda = parallel.gpu.GPUArray.ones(1,1);

Execute the kernel
DataOneCuda = feval(Kernel, DataCuda, OneCuda);

Get the data back
DataOne=gather(DataOneCuda);

Show the result
figure, hold on;
plot(Data,'b');
plot(DataOne,'r');

引用格式

Dirk-Jan Kroon (2024). NVCC cuda compiler wraper (https://www.mathworks.com/matlabcentral/fileexchange/29611-nvcc-cuda-compiler-wraper), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2010b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.1.0.0

Now allows NVCC.EXE extra configuration options. And will store the main .bat file with the configuration always in the same folder.

1.0.0.0