本帖最后由 蓝云风翼 于 2013-12-18 17:28 编辑

注:

利用gpu加速有一下工具

1.JACKET 可从帖子中寻找

2.MATLAB a.并行计算工具箱 gpuArray,查看支持gpuArray的函数methods('gpuArray')

b.已经支持GPU的一些工具箱

c.使用mex方式 http://www.matlabsky.com/thread-33511-1-1.html

d.使用产生ptx方法编写cuda kernel

这些都可以通过help gpuArray查看,建议使用最新版本2013a

查看GPU是否支持gpuDevice命令

3.GPUMAT帖子中找

4. nvmex方式即cudawhitepaper可从帖子中直接下载

http://www.matlabsky.com/thread-20597-1-1.html

http://www.matlabsky.com/thread-25951-1-1.html

SIMULINK  :http://www.matlabsky.com/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)

FunctionsCreate array on GPU

Transfer distributed array data or gpuArray to local workspace

Determine if gpuArray or CUDAKernel is available on GPU

Query or select GPU device

Number of GPU devices present

Time required to run function on GPU

Reset GPU device and clear its memory

Wait for job to change state or for GPU calculation to complete

Apply function to each element of array on GPU

Binary singleton expansion function for gpuArray

Apply function to each page of array on GPU

Create GPU CUDA kernel object from PTX and CU code

Evaluate kernel on GPU

Set some constant memory on GPU

ClassesArray of data stored on GPU

Graphics processing unit (GPU)

Kernel executable on GPU

1.使用GPU

首先在命令行窗口输入 gpuDevice 查看当前计算机上是否已经正确安装了GPU设备(硬件+驱动)。

查看所有支持的GPU:

for ii = 1:gpuDeviceCount

g = gpuDevice(ii);

fprintf(1, 'Device %i has ComputeCapability %s \n', ...

g.Index, g.ComputeCapability)

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:

X = rand( 10, 'single' );

G = gpuArray( X );

isequal( gather( G ), X )  % returns true

classUnderlying( G )       % returns 'single'

G2 = G .* G                % use "times" method defined for gpuArray objects复制代码

See also gather

Reference page in Help browser

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.通过gather将GPU计算结果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

利用神经网络工具箱

使用gpuDeviceCount 查看当前系统可利用的GPU数目,使用gpuDevice 查看及使用GPU。

gpuDeviceCountgpuDevicegpuDevice(2) % Select device 2, if available复制代码

设置train的参数'useGPU' 选项'yes',单GPU上执行。

net2 = train(net1,x,t,'useGPU','yes');

y = net2(x,'useGPU','yes');复制代码

Multiple GPU/CPU Computing

可以在并行级上使用多GPUs.设置'useParallel'和 'useGPU' 为 'yes'在单机上来使用 所有GPUs 和CPU cores。每个worker 与使用特定的GPU的CPU相连。

net2 = train(net1,x,t,'useParallel','yes','useGPU','yes');

y = net2(x,'useParallel','yes','useGPU','yes');复制代码

查看使用资源情况

net2 = train(net1,x,t,'useGPU','yes','showResources','yes')

y = net2(x,'useGPU','yes','showResources','yes')复制代码

Computing Resources:

GPU device 1, Telsa K20C

出于一些原因,使用多GPUs和多CPUs可能会带来更高的性能,但是出于另外一些原因,CPUs资源有可能会拖GPUs的后腿,所以单独使用GPUs会更快,设置 'useGPU'为'only', 来限制workers使用特定的GPUs。

net2 = train(net1,x,t,'useParallel','yes','useGPU','only');

y = net2(x,'useParallel','yes','useGPU','only');复制代码

Cluster Computing with MATLAB Distributed Computing Server

MATLAB? Distributed Computing Server? 提供了在集群计算机网络上使用 CPUs 和 GPUs资源。使用cluster,打开并行cluster的pool 。设置 'useParallel' 和'useGPU' 选项。

net2 = train(net1,x,t,'useParallel','yes');

y = net2(x,'useParallel','yes');

net2 = train(net1,x,t,'useParallel','yes');

y = net2(x,'useParallel','yes');

net2 = train(net1,x,t,'useParallel','yes','useGPU','only');

y = net2(x,'useParallel','yes','useGPU','only');复制代码

在当前主机上查看所有可使用的GPU:

gpuCount = gpuDeviceCount

for i=1:gpuCount

gpuDevice(i)

end复制代码

查看当前使用的pool:

poolSize = pool.NumWorkers复制代码

使用MATLAB Distributed Computing Server查看集群上所有可使用的GPU:

spmd  worker.index = labindex;

worker.name = system('hostname');

worker.gpuCount = gpuDeviceCount;

try

worker.gpuInfo = gpuDevice;

catch

worker.gpuInfo = [];

end

worker

end复制代码

Execute MEX-Functions Containing CUDA Code

内容

· Write a MEX-File Containing CUDA Code

· Set Up for MEX-File Compilation

· Compile a GPU MEX-File

· Run the Resulting MEX-Functions

· Comparison to a CUDA Kernel

· Access Complex Data

· Call Host-Side Libraries

Write a MEX-File Containing CUDA Code

C FunctionsInitialize MATLAB GPU library on currently selected deviceCopy mxArray to mxGPUArray

Duplicate (deep copy) mxGPUArray object

Copy imaginary part of mxGPUArray

Copy real part of mxGPUArray

Create complex GPU array from two real gpuArrays

Create read-only mxGPUArray object from input mxArray

Create mxGPUArray object, allocating memory on GPU

Create mxArray for returning CPU data to MATLAB with data from GPU

Create mxArray for returning GPU data to MATLAB

Delete mxGPUArray object

mxClassID associated with data on GPU

Complexity of data on GPU

Raw pointer to underlying data

Read-only raw pointer to underlying data

mxGPUArray dimensions

Size of dimension array for mxGPUArray

Number of elements on GPU for array

Determine if two mxGPUArrays refer to same GPU data

Determine if mxArray is pointer to valid GPU data

Determine if mxArray contains GPU data

C ClassesType for MATLAB gpuArray

PTX方式

k = parallel.gpu.CUDAKernel('myfun.ptx','myfun.cu');详见:

http://www.mathworks.cn/cn/help/distcomp/run-cuda-or-ptx-code-on-gpu.html

(不能SAVE 和load 只能用的时候创建)

附:

内嵌的GPU工具箱:

Communications System ToolboxGPU support for a select list of System objects. These System objects execute on GPU (graphics processing unit) to improve performance by reducing simulation time and are among the most commonly used functionality in the product:

comm.gpu.LDPCDecoder

comm.gpu.ConvolutionalEncoder

comm.gpu.TurboDecoder

comm.gpu.ViterbiDecoder

comm.gpu.BlockDeinterleaver

comm.gpu.BlockInterleaver

comm.gpu.ConvolutionalDeinterleaver

comm.gpu.ConvolutionalInterleaver

comm.gpu.PSKDemodulator

comm.gpu.PSKModulator

comm.gpu.AWGNChannel

MATLAB Compiler Support for GPU System Objects

Image Processing ToolboxOption in blockproc function to improve performance of block processing tasks. Set the ‘UseParallel’ argument to true to use this option. GPU acceleration for popular image processing functions such as bwmorph, edge, imfilter, imdilate, imerode, imopen, imclose, imtophat, imbothat, and imshow.Documentation: Image Processing Toolbox

See GPU Computing section for a complete list of GPU-enabled functions

Neural Network ToolboxParallel computing support for training and simulation

GPU support for training and simulation

Phased Array System ToolboxAcceleration of clutter model simulation with parfor or GPU

Signal Processing ToolboxGPU acceleration for xcorr, xcorr2, fftfilt, xcov, and cconv

>>methods('gpuArray')  (matlab2013b)

Methods for class gpuArray:

abs                   fill                  ndgrid

acos                  fill3                 ndims

acosh                 filter                ne

acot                  filter2               nnz

acoth                 find                  norm

acsc                  fix                   normest

acsch                 flip                  not

all                   flipdim               num2str

and                   fliplr                numel

any                   flipud                or

applylut              floor                 padarray

area                  fplot                 pagefun

arrayfun              fprintf               pareto

asec                  full                  pcolor

asech                 gamma                 permute

asin                  gammaln               pie

asinh                 gather                pie3

atan                  ge                    plot

atan2                 gpuArray              plot3

atanh                 gt                    plotmatrix

bar                   hist                  plotyy

bar3                  histeq                plus

bar3h                 horzcat               polar

barh                  hypot                 pow2

beta                  ifft                  power

betaln                ifft2                 prod

bitand                ifftn                 qr

bitcmp                im2double             quiver

bitget                im2int16              quiver3

bitor                 im2single             rdivide

bitset                im2uint16             real

bitshift              im2uint8              reallog

bitxor                imabsdiff             realpow

bsxfun                imadjust              realsqrt

bwlookup              imag                  reducepatch

bwmorph               image                 reducevolume

cast                  imagesc               rem

cat                   imbothat              repmat

cconv                 imclose               reshape

ceil                  imdilate              rgb2gray

chol                  imerode               rgb2ycbcr

circshift             imfilter              ribbon

clabel                imgradient            rose

classUnderlying       imgradientxy          rot90

colon                 imhist                round

comet                 imlincomb             scatter3

comet3                imnoise               sec

compass               imopen                sech

complex               imresize              semilogx

cond                  imrotate              semilogy

coneplot              imshow                shiftdim

conj                  imtophat              shrinkfaces

contour               ind2sub               sign

contour3              int16                 sin

contourc              int2str               single

contourf              int32                 sinh

contourslice          int64                 size

conv                  int8                  slice

conv2                 interp1               smooth3

convn                 interp2               sort

corr2                 interpstreamspeed     sprintf

cos                   inv                   spy

cosh                  ipermute              sqrt

cot                   isa                   stairs

coth                  isempty               std2

cov                   isequal               stdfilt

csc                   isequaln              stem

csch                  isequalwithequalnans  stem3

ctranspose            isfinite              stream2

cumprod               isfloat               stream3

cumsum                isinf                 streamline

curl                  isinteger             streamparticles

det                   islogical             streamribbon

diag                  ismember              streamslice

diff                  isnan                 streamtube

disp                  isnumeric             sub2ind

display               isocaps               subsasgn

divergence            isocolors             subsindex

dot                   isonormals            subsref

double                isosurface            subvolume

edge                  isreal                sum

eig                   issorted              surf

end                   issparse              surfc

eps                   ldivide               surfl

eq                    le                    svd

erf                   length                tan

erfc                  log                   tanh

erfcinv               log10                 times

erfcx                 log1p                 transpose

erfinv                log2                  tril

errorbar              logical               trimesh

existsOnGPU           loglog                trisurf

exp                   lt                    triu

expm1                 lu                    uint16

ezcontour             mat2gray              uint32

ezcontourf            mat2str               uint64

ezgraph3              max                   uint8

ezmesh                medfilt2              uminus

ezmeshc               mesh                  uplus

ezplot                meshc                 var

ezplot3               meshgrid              vertcat

ezpolar               meshz                 vissuite

ezsurf                min                   volumebounds

ezsurfc               minus                 voronoi

feather               mldivide              waterfall

fft                   mod                   xcorr

fft2                  mpower                xor

fftfilt               mrdivide              ycbcr2rgb

fftn                  mtimes

Static methods:

eye                   nan                   true

false                 ones                  zeros

inf                   rand

linspace              randi

logspace              randn

>>复制代码

float gpu 加速_(总结篇)使用 MATLAB GPU 加速计算|MATLAB 并行计算与分布式服务器|MATLAB技术论坛...相关推荐

  1. android 系统gpu 调试_基于Android系统的GPU动态调频方案 | Imagination中文技术社区

    针对移动终端上GPU的高功耗问题,提出一种基于Android系统的GPU动态调频方案.方案根据各种应用对GPU的性能需求,引入了GPU的频率一性能模型,包括选择工作频率和测量相对性能的方法.动态调频算 ...

  2. python for循环加速_干货总结,24招加速你的Python代码,值得收藏

    一,分析代码运行时间 第1式,测算代码运行时间 平凡方法 快捷方法(jupyter环境) 第2式,测算代码多次运行平均时间 平凡方法 快捷方法(jupyter环境) 第3式,按调用函数分析代码运行时间 ...

  3. python 怎么用gpu运算_使用Python玩转GPU

    问题 随着机器学习对模型运算速度的需求越来越强烈, 一直想进行GPU编程,但一直以来这些都是c++的专利 一想到c++里的各种坑,就提不起劲来,毕竟这样来来回回填坑的投入产出,生产效率就会大打折扣 解 ...

  4. 图神经网络代码_第一篇:图神经网络(GNN)计算框架绪论

    写在开头: 这个专栏是为了总结我本科毕业设计中所设计的题目<基于GPU的图神经网络算法库的设计钰实现>.这半年来一直在这个方向上啃代码,读论文,真的学到了很多东西.尤其是阅读了大佬团队写的 ...

  5. 安卓禁用硬件加速_[转]Android如何关闭硬件加速

    硬件加速 Android 3.0 (API level 11), 开始支持 所有的View 的canvas都会使用GPU,但是硬件的加速会占有一定的RAM. 在API >= 14上,默认是开启的 ...

  6. python加速_使用numba对Python运算加速的方法

    有时候需要比较大的计算量,这个时候Python的效率就很让人捉急了,此时可以考虑使用numba 进行加速,效果提升明显~ (numba 安装貌似很是繁琐,建议安装Anaconda,里面自带安装好各种常 ...

  7. gpu驱动程序_如何从错误的GPU驱动程序更新中恢复

    gpu驱动程序 NVIDIA and AMD send out new drivers for their current graphics cards at roughly monthly inte ...

  8. matlab里怎么计算期望,§7.4.2 利用MATLAB计算随机变量的期望和方差.pdf

    §§7.4.27.4.2 利用利用MATLABMATLAB 计算随机变量的期望和方差 一一....用用用用MATLABMATLABMATLABMATLAB计算离散型随机计算离散型随机计算离散型随机计算 ...

  9. matlab由频率响应计算差分方程,现代线性系统:使用MATLAB

    中译本出版者的话 译者的话 出版者的话 符号一览表 全书内容简介 前    言 第1章  信号与序列 概述 基本概念与解说题 信号. 序列和系统 IP1. 1  描述连续时间信号 IP1. 2  序列 ...

最新文章

  1. memcached 系列2:memcached实例(转载)
  2. Java中通过NetworkInterface获取主机地址和物理地址等
  3. HDU 2544 Floyd算法
  4. python自定义切片_自定义Python切片,请指教
  5. promise then返回值
  6. 打印工资条怎么做到每个人都有表头明细_抖音百万点赞!2018年最火的5个Excel骚操作,你都会吗?...
  7. 编译报错程序集版本高于所引用的程序集的版本
  8. jquery选择器之过滤选择器
  9. OPC UA 统一架构学习4
  10. iOS 开发之 GCD 不同场景使用
  11. 远程连接redis,并设置字符集
  12. 三电系统集成技术杂谈
  13. 用于预测的神经网络模型,神经网络模型可解释性
  14. 如何查看微信小程序服务器域名并且修改
  15. 哼唱搜索软件测试,不知道歌名只哼唱也能识别歌名的音乐APP到底谁更好
  16. 微软关闭Win7所有服务器,微软公布Win7彻底退役时间 将于2020年终止所有支持
  17. 不积跬步无以至千里(C语言笔记)
  18. iMac一体机安装苹果和Win7双系统
  19. Java 序列化对象为json字符串,属性首字母大写,并按照属性首字母排序
  20. vps系统和云服务器搭建,vps系统和云服务器搭建

热门文章

  1. 链路追踪译文学习记录(Dapper!!!非原创!!!学习记录)
  2. DevOps: Mountain Duck - 多网盘挂载本地工具
  3. 智能(语音)对话系统架构研究
  4. 寒门能出贵子的关键在哪里
  5. Java8 通过foreach 遍历List,同时输出下标
  6. 求薪水最高的第6到第10个人
  7. 一个简单的格式化信函生成器
  8. 五子棋网络对战 java实现
  9. mpvue 搭配 minui
  10. 微信小程序wepy框架+minui踩坑之路