現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Use GPU for the matlab code
2 ビュー (過去 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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)