float gpu 加速_(总结篇)使用 MATLAB GPU 加速计算|MATLAB 并行计算与分布式服务器|MATLAB技术论坛...
本帖最后由 藍云風翼 于 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技术论坛...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: office2016和Visio2016
- 下一篇: [OfficeExcel] Word+E