matlab nvcc,matlab实现Cuda编译器

NVCC cuda compiler wraper

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');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值