(总结篇)使用MATLABGPU加速计算MATLAB并行计算与分布式服务器MATLAB技术论坛
本帖最后由 蓝云风翼 于 2013-12-18 17:28 编辑
注:
利用gpu加速有一下工具
1.JACKET 可从帖子中寻
2.MATLAB a.并行计算工具箱 gpuArray,查看支持gpuArray的函数methods('gpuArray')
b.已经支持GPU的一些工具箱
c.使用mex方式 /thread-33511-1-1.html
d.使用产生ptx方法编写cuda kernel
这些都可以通过help gpuArray查看,建议使用最新版本2013a
查看GPU是否支持gpuDevice命令
3.GPUMAT帖子中
4. nvmex方式即cudawhitepaper可从帖子中直接下载
/thread-20597-1-1.html
/thread-25951-1-1.html
SIMULINK  :/forum.php?mod=viewthread&tid=27230
目前,GPU在通用数值计算领域的应用已经越来越广泛,MATLAB通过以下几种方式支持GPU。
一、MATLAB内嵌GPU函数fft, filter,及linear algebra operations等。
二、内嵌工具箱支持GPU的函数: Communications System Toolbox, Neural Network Toolbox, Phased Array Systems Toolbox, and Signal Processing Toolbox (GPU support for signal processing algorithms)
三、在MATLAB中接入CUDA kernel,通过PTX方式或者MEX方式。
Multiple GPUs在单机和计算集上的使用通过MATLAB 的并行计算工具箱(PCT)及MATLAB分布式计算工具箱(MDCS)(matlab worker)
一、PCT  GPUArray
Parallel Computing Toolbox 提供 GPUArray,这是一个具有多个关联函数的特殊数组类型,可让您直接从 MATLAB 在启用 CUDA 的 NVIDIA GPU 上执行计算。这些函数包括 fft、元素级运算和几种线性代数运算,如 lu 和 mldivide(也称作反斜杠运算符 (\))。该工具箱还提供一种机制,可让您直接从 MATLAB 使用现有的基于 CUDA 的 GPU 内核。
使用 MATLAB 进行 GPU 计算。使用 GPUArrays 和 启用 GPU 的 MATLAB 函数,有助于加速 MATLAB 运算,而无需进行低级的 CUDA 编程。
PCT工具箱支持NVIDIA CUDA GPUs(计算能力大于1.3,K20C 计算能力为3.5)
Functions
gpuArray
Create array on GPU
gather
Transfer distributed array data or gpuArray to local workspace
existsOnGPU
Determine if gpuArray or CUDAKernel is available on GPU
gpuDevice
Query or select GPU device
gpuDeviceCount
Number of GPU devices present
gputimeit
Time required to run function on GPU
reset
Reset GPU device and clear its memory
wait
Wait for job to change state or for GPU calculation to complete
arrayfun
Apply function to each element of array on GPU
bsxfun
Binary singleton expansion function for gpuArray
pagefun
Apply function to each page of array on GPU
parallel.gpu.CUDAKernel
Create GPU CUDA kernel object from PTX and CU code
feval
Evaluate kernel on GPU
setConstantMemory
Set some constant memory on GPU
Classes
gpuArray
Array of data stored on GPU
GPUDevice
Graphics processing unit (GPU)
CUDAKernel
Kernel executable on GPU
1.使用GPU
首先在命令行窗口输入 gpuDevice 查看当前计算机上是否已经正确安装了GPU设备(硬件+驱动)。
查看所有支持的GPU:
1.for ii = 1:gpuDeviceCount   
2.g = gpuDevice(ii);   
3.fprintf(1, 'Device %i has ComputeCapability %s \n', ...           
4.g.Index, g.ComputeCapability)
5.end
复制代码
查看gpuArray支持的函数methods('gpuArray')
>> help gpuArray
gpuArray create data on the GPU
G = gpuArray( X ) copies the numeric data X to the GPU. This data can be
operated on by passing it to the FEVAL method of parallel.gpu.CUDAKernel
objects, or by using one of the methods defined for gpuArray objects.  See
the Parallel Computing Toolbox documentation for a
list of methods supported by gpuArray. 
The MATLAB data X must be numeric (for example: single, double, int8 etc.)
or logical, and the GPU device must have sufficient free memory to store the
data. X must be full.
Example:
1.X = rand( 10, 'single' ); 
2.G = gpuArray( X );   
3.isequal( gather( G ), X )  % returns true   
4.classUnderlying( G )      % returns 'single'   
5.G2 = G .* G                % use "times" method defined for gpuArray objects
复制代码
See also gather
Reference page in Help browser
1.doc gpuArray
复制代码
下面的例子介绍了GPU的基本流程
%1.将数据从CPU传输至GPU(也可以通过GPU直接生成数据)
Ga = gpuArray(rand(1000, 'single'));
%2.对GPU数据执行GPU操作,此时的fft操作对象是gpuArray
Gfft = fft(Ga);
Gb = (real(Gfft) + Ga) * 6;
%3.通过gatherGPU计算结果Gb回传到CPU中以便后续操作。
G = gather(Gb);
使用whos查看数据存储
Name      Size         Bytes  Class
G      1000x1000     4000000  single
Ga      1000x1000         108  gpuArray
Gb      1000x1000         108  gpuArray
Gfft    1000x1000         108  gpuArray
二、工具箱使用
GPU Computing马自达mx5论坛
利用神经网络工具箱
使用gpuDeviceCount 查看当前系统可利用的GPU数目,使用gpuDevice 查看及使用GPU。