이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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.'
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/678088/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/678578/image.png)
2. bbdbn.rbm (consists of 3 inner struct)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/678583/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/678588/image.png)
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 (한국어)