MATLAB使用GPU

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MATLAB使用GPU相关的知识,希望对你有一定的参考价值。

参考技术A 在matlab中使用GPU,一般步骤如下:

1) 在mobaXterm中查看GPU使用情况: nvidia-smi ;指定使用哪个GPU(选空闲的): gpuDevice(x);

http://f.dataguru.cn/forum.php?mod=viewthread&ordertype=1&tid=873381

2)把变量 、数据存在GPU中 : gpuArray(网址中两种生成变量的方法都可用);把GPU中的数据取回CPU中: gather;

http://blog.sina.com.cn/s/blog 6f062c360102v9ic.html

matlab采用GPU运算

>>help gpu
There are several options available for using your computer‘s graphics
processing unit (gpu) for matrix operations.

- Transfer data between the MATLAB workspace and the gpu
- Evaluate individual MATLAB functions that have been
overloaded for execution on the gpu
- Execute MATLAB code containing multiple functions using ARRAYFUN.
(Not all MATLAB functions are supported.)
- Create kernels from CU files for execution on the gpu

The gpu Computing section of the Parallel Computing Toolbox User‘s Guide
provides more information on these use cases and lists supported devices
and device drivers.

Data Transfer Operations
gpuArray - Transfer an array from the MATLAB workspace to the gpu
gather - Transfer an array from the gpu to the MATLAB workspace

MATLAB Overloads

MATLAB functions that have been made available for
execution on the gpu can be viewed using the command

methods(‘gpuArray‘)

Certain other MATLAB functions that support gpuArray inputs are
listed in the Parallel Computing Toolbox documentation.

Examples:
% FFT
A = gpuArray( rand( 2^16, 100 ) );
F = fft(A)

% MLDIVIDE
A = gpuArray( rand(1024) ); B = gpuArray( rand(1024,1) );
X = AB

% MTIMES
A = gpuArray( rand(1024) ); B = gpuArray( rand(1024) );
C = A*B

Execute MATLAB code on the gpu
gpuArray/arrayfun - Apply a function to each element of an array on
the gpu

The function to evaluate on the gpu must exist on the path. Only a
subset of the MATLAB language is supported by ARRAYFUN on the gpu.
The restrictions are listed in the User‘s Guide.

Example:
% The file xycrull.m is one example of an existing MATLAB file
% that can be automatically executed on the gpu.
%
% Execute ‘type xycrull‘ at the MATLAB prompt to view the contents
% of the file.
%
gt = gpuArray(rand(400));
[o1, o2] = arrayfun(@xycrull, gt)

CUDA Kernel Operations
parallel.gpu.CUDAKernel - Create a kernel object that corresponds
to a particular kernel in a CU file
parallel.gpu.CUDAKernel/feval - Evaluate a kernel on the gpu

Device Information
gpuDeviceCount - Return the number of gpu devices available
gpuDevice - Query or select a gpu device

Timing gpu Operations
gputimeit - Measure time required to run function on gpu







































































以上是关于MATLAB使用GPU的主要内容,如果未能解决你的问题,请参考以下文章

matlab如何创建数组

Matlab中使用LaTeX

使用 MATLAB 编码器将 MATLAB 转换为 C++

如何在没有matlab的labview中使用matlab源代码?

如何在从 Matlab 调用的 mex 函数中使用 Matlab 引擎

Matlab、Simulink、导入的使用