Use GPU for the matlab code
1 次查看(过去 30 天)
显示 更早的评论
I have computations on structs in my code with a label identifier and other numerical values. What I could understand is I can use gpuArray only for numerical computations but whenever it encounter a logical operation, it doesnt work. Is there a way out of this problem?
I am trying to run code available at: https://in.mathworks.com/matlabcentral/fileexchange/42853-deep-neural-network
Can anyone please help?
10 个评论
Walter Roberson
2021-7-8
Please expand on "whenever it encounters a local operation" and "it does not work"?
Virtualkeeda
2021-7-8
Sorry for the typo mistake..
So whenever the gpuArray encounters logical operation... As in the operations are mostly performing on a struct with two fields. 1st one with some label, like 'bbdbn', or 'dbn' and 2nd field with 3x1 cell on which all the major computation takes place. Please see the screenshot of the struct.
gpuArray gives an error 'GPU arrays support only fundamental numeric or logical data types.'
Joss Knight
2021-7-8
Can you post the actual output from the MATLAB command window so we can see the error and the call stack?
For what it's worth, there are no gpuArrays in that struct, and neither of the fields are numeric or logical data. Maybe you tried to construct a gpuArray using one of those things, or perhaps you passed the whole struct to gpuArray?
Virtualkeeda
2021-7-8
Thanks @Joss Knight for the response. I will get back to you with detailed explanation with example within 24 hours. Please hold on to this.
Virtualkeeda
2021-7-8
编辑:Virtualkeeda
2021-7-8
So, here is the whole structure of the struct:
- bbdn (consists of a type and a struct named rbm)
2. bbdbn.rbm (consists of 3 inner struct)
3. bbdbn.rbm{1,1}: consists of a type and 3 internal matrics W,b, & c (i have used gpuArray so they are showing like that now)
The opertaions are performing on these W,b, and c. You were right, earlier I was passing the whole struct to gpuArray, which was wrong and hence I was getitng the error. Now, I used gpuArray on the matrix operations such as:
dbn.rbm{nrbm}.W = gpuArray(linearMapping( Hall{nrbm-1}, OUT ));
H = gpuArray(sigmoid( bsxfun(@plus, V * dnn.W, dnn.b ) ));
There were many such operations.
But still the code is running as same as previous. Also, after using gpuArray I can see 0% GPU utilization. Am I missing something to install for matlab or for the gpu? Here is my gpuDevice details:
Name: 'Quadro T2000'
Index: 1
ComputeCapability: '7.5'
SupportsDouble: 1
DriverVersion: 11
ToolkitVersion: 10.1000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 4.2950e+09
AvailableMemory: 3.1927e+09
MultiprocessorCount: 16
ClockRateKHz: 1785000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
Walter Roberson
2021-7-8
dbn.rbm{nrbm}.W = gpuArray(linearMapping( Hall{nrbm-1}, OUT ));
H = gpuArray(sigmoid( bsxfun(@plus, V * dnn.W, dnn.b ) ));
I would have expected you to gpuArray() the data at an earlier step ? You would then not gupArray() around the calculation -- any calculation done on data that is gpuArray will automatically become gpuArray itself.
Virtualkeeda
2021-7-8
Yes Ok.
So, this is what I did now. At the starting initialization, I used gpuArray as:
rbm.W = gpuArray(randn(dimV, dimH) * 0.1);
rbm.b = gpuArray(zeros(1, dimH));
rbm.c = gpuArray(zeros(1, dimV));
I tested on 1 epoch and few layer. Still, gpu Utlilization 0 % and same old time consumption.
Joss Knight
2021-7-9
Isn't your input data in variables like dnn.b, dnn.W, Hall{i} and others? Plus all you seem to have done in the above is to move one set of network parameters to the GPU, rather than all of them. Isn't rbm a struct array containing many variables, all of which need to be gpuArray objects?
It's probably best to start with the documentation: https://www.mathworks.com/help/parallel-computing/run-matlab-functions-on-a-gpu.html
The basic principle is that if the data at the input to a function is a gpuArray object, that function will run on the GPU. Use the MATLAB debugger to check the datatype of the data about to be used on each line of your code, and make sure it is a gpuArray. You can use the isgpuarray() function.
You should also make sure your data is declared as single precision, so for instance replace
gpuArray(randn(dimV, dimH) * 0.1);
with
randn(dimV, dimH, 'single', 'gpuArray') * 0.1;
Note how I also create the data directly on the GPU rather than on the CPU and then moving it, as well as performing the scalar multiply on the GPU rather than the host.
Virtualkeeda
2021-7-9
Yes, the actual input data is in dnn.W,dnn.b etc.
Also, yes rbm is an struct containing a struct and a identifier type with labels like 'DNN', 'BBDBN' etc... But I think I cannot pass this rbm struct to gpuArray.
I guess, I will again have to go through the documentation on gpuArray.
Virtualkeeda
2021-7-10
Hello @Joss Knight, I could now use the gpuArray successfully. Thanks for your help and suggestions.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Big Data Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)