float gpu 加速_(总结篇)使用 MATLAB GPU 加速计算|MATLAB 并行计算与分布式服务器|MATLAB技术论坛...
本帖最后由 藍(lán)云風(fēng)翼 于 2013-12-18 17:28 編輯
注:
利用gpu加速有一下工具
1.JACKET 可從帖子中尋找
2.MATLAB a.并行計(jì)算工具箱 gpuArray,查看支持gpuArray的函數(shù)methods('gpuArray')
b.已經(jīng)支持GPU的一些工具箱
c.使用mex方式 http://www.matlabsky.com/thread-33511-1-1.html
d.使用產(chǎn)生ptx方法編寫cuda kernel
這些都可以通過(guò)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在通用數(shù)值計(jì)算領(lǐng)域的應(yīng)用已經(jīng)越來(lái)越廣泛,MATLAB通過(guò)以下幾種方式支持GPU。
一、MATLAB內(nèi)嵌GPU函數(shù)fft, filter,及l(fā)inear algebra operations等。
二、內(nèi)嵌工具箱支持GPU的函數(shù): Communications System Toolbox, Neural Network Toolbox, Phased Array Systems Toolbox, and Signal Processing Toolbox (GPU support for signal processing algorithms)
三、在MATLAB中接入CUDA kernel,通過(guò)PTX方式或者M(jìn)EX方式。
Multiple GPUs在單機(jī)和計(jì)算集群上的使用通過(guò)MATLAB 的并行計(jì)算工具箱(PCT)及MATLAB分布式計(jì)算工具箱(MDCS)(matlab worker)
一、PCT??GPUArray
Parallel Computing Toolbox 提供 GPUArray,這是一個(gè)具有多個(gè)關(guān)聯(lián)函數(shù)的特殊數(shù)組類型,可讓您直接從 MATLAB 在啟用 CUDA 的 NVIDIA GPU 上執(zhí)行計(jì)算。這些函數(shù)包括 fft、元素級(jí)運(yùn)算和幾種線性代數(shù)運(yùn)算,如 lu 和 mldivide(也稱作反斜杠運(yùn)算符 (\))。該工具箱還提供一種機(jī)制,可讓您直接從 MATLAB 使用現(xiàn)有的基于 CUDA 的 GPU 內(nèi)核。
使用 MATLAB 進(jìn)行 GPU 計(jì)算。使用 GPUArrays 和 啟用 GPU 的 MATLAB 函數(shù),有助于加速 MATLAB 運(yùn)算,而無(wú)需進(jìn)行低級(jí)的 CUDA 編程。
PCT工具箱支持NVIDIA CUDA GPUs(計(jì)算能力大于1.3,K20C 計(jì)算能力為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 查看當(dāng)前計(jì)算機(jī)上是否已經(jīng)正確安裝了GPU設(shè)備(硬件+驅(qū)動(dòng))。
查看所有支持的GPU:
for ii = 1:gpuDeviceCount
g = gpuDevice(ii);
fprintf(1, 'Device %i has ComputeCapability %s \n', ...
g.Index, g.ComputeCapability)
end復(fù)制代碼
查看gpuArray支持的函數(shù)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復(fù)制代碼
See also gather
Reference page in Help browser
doc gpuArray復(fù)制代碼
下面的例子介紹了GPU的基本流程
%1.將數(shù)據(jù)從CPU傳輸至GPU(也可以通過(guò)GPU直接生成數(shù)據(jù))
Ga = gpuArray(rand(1000, 'single'));
%2.對(duì)GPU數(shù)據(jù)執(zhí)行GPU操作,此時(shí)的fft操作對(duì)象是gpuArray
Gfft = fft(Ga);
Gb = (real(Gfft) + Ga) * 6;
%3.通過(guò)gather將GPU計(jì)算結(jié)果Gb回傳到CPU中以便后續(xù)操作。
G = gather(Gb);
使用whos查看數(shù)據(jù)存儲(chǔ)
Name? ?? ? Size? ?? ?? ?Bytes??Class
G? ?? ? 1000x1000? ???4000000??single
Ga? ?? ?1000x1000? ?? ?? ?108??gpuArray
Gb? ?? ?1000x1000? ?? ?? ?108??gpuArray
Gfft? ? 1000x1000? ?? ?? ?108??gpuArray
二、工具箱使用
GPU Computing
利用神經(jīng)網(wǎng)絡(luò)工具箱
使用gpuDeviceCount 查看當(dāng)前系統(tǒng)可利用的GPU數(shù)目,使用gpuDevice 查看及使用GPU。
gpuDeviceCountgpuDevicegpuDevice(2) % Select device 2, if available復(fù)制代碼
設(shè)置train的參數(shù)'useGPU' 選項(xiàng)'yes',單GPU上執(zhí)行。
net2 = train(net1,x,t,'useGPU','yes');
y = net2(x,'useGPU','yes');復(fù)制代碼
Multiple GPU/CPU Computing
可以在并行級(jí)上使用多GPUs.設(shè)置'useParallel'和 'useGPU' 為 'yes'在單機(jī)上來(lái)使用 所有GPUs 和CPU cores。每個(gè)worker 與使用特定的GPU的CPU相連。
net2 = train(net1,x,t,'useParallel','yes','useGPU','yes');
y = net2(x,'useParallel','yes','useGPU','yes');復(fù)制代碼
查看使用資源情況
net2 = train(net1,x,t,'useGPU','yes','showResources','yes')
y = net2(x,'useGPU','yes','showResources','yes')復(fù)制代碼
Computing Resources:
GPU device 1, Telsa K20C
出于一些原因,使用多GPUs和多CPUs可能會(huì)帶來(lái)更高的性能,但是出于另外一些原因,CPUs資源有可能會(huì)拖GPUs的后腿,所以單獨(dú)使用GPUs會(huì)更快,設(shè)置 'useGPU'為'only', 來(lái)限制workers使用特定的GPUs。
net2 = train(net1,x,t,'useParallel','yes','useGPU','only');
y = net2(x,'useParallel','yes','useGPU','only');復(fù)制代碼
Cluster Computing with MATLAB Distributed Computing Server
MATLAB? Distributed Computing Server? 提供了在集群計(jì)算機(jī)網(wǎng)絡(luò)上使用 CPUs 和 GPUs資源。使用cluster,打開并行cluster的pool 。設(shè)置 'useParallel' 和'useGPU' 選項(xiàng)。
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');復(fù)制代碼
在當(dāng)前主機(jī)上查看所有可使用的GPU:
gpuCount = gpuDeviceCount
for i=1:gpuCount
gpuDevice(i)
end復(fù)制代碼
查看當(dāng)前使用的pool:
poolSize = pool.NumWorkers復(fù)制代碼
使用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復(fù)制代碼
Execute MEX-Functions Containing CUDA Code
內(nèi)容
· 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 只能用的時(shí)候創(chuàng)建)
附:
內(nèi)嵌的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
>>復(fù)制代碼
總結(jié)
以上是生活随笔為你收集整理的float gpu 加速_(总结篇)使用 MATLAB GPU 加速计算|MATLAB 并行计算与分布式服务器|MATLAB技术论坛...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: office2016和Visio2016
- 下一篇: [OfficeExcel] Word+E