fmincon running on GPU

조회 수: 44 (최근 30일)
CSCh
CSCh 2021년 12월 7일
댓글: Walter Roberson 2024년 7월 22일
Hi
I implemented a modified copy of this example.
I tried to run it on GPU
but if I try to convert the inputs (dlR,..) from alarrays to gpuarray's, I got the error
objFun = @(parameters) objectiveFunction(parameters,dlR,dlTheta,dlT,dlR0,dlTheta0,dlT0,dlUr0,parameterNames,parameterSizes);
"FMINCON requires all values returned by functions to be of data type double."
So how can I run this example with GPU power?
Best regards,
Chris

채택된 답변

Walter Roberson
Walter Roberson 2022년 2월 2일
objFun = @(parameters) objectiveFunction(parameters,dlR,dlTheta,dlT,dlR0,dlTheta0,dlT0,dlUr0,parameterNames,parameterSizes);
That is fine in itself, and if you want, any or all of the values such as dl* variables can be gpuArray --- however, the value passed by fmincon, received here as parameters will never be gpuArray .
Inside objectiveFunction you can unpack parameters as needed into individual variables, potentially constructing gpuArray objects as needed.
Then you can do whatever calculation is appropriate.
When you get an appropriate place in the calculation, gather() the gpuArray calculations. The resulting output will not be gpuArray.
The final output from objectiveFunction must not be gpuArray .
If your logic is suitable, it would be perfectly fine to code something like
cost = gather(cost);
at the end of your code -- though it would be more efficient to use different variable names so that you are not changing the type of the variable
cost_non_gpu = gather(cost); %with the function having been defined as returning cost_non_gpu
  댓글 수: 9
CSCh
CSCh 2022년 2월 3일
Thank you for you explanation. It would be really helpfull if you could give an example how I can use the vectorization together with Fmincon.
Thank you.
Walter Roberson
Walter Roberson 2022년 2월 3일
Unfortunately at present fmincon() does not support vectorization; my point about vectorization is that if Mathwrks were looking to improve performance for fmincon, it would make more sense for Mathworks to start with permitting vectorization than it would for Mathworks to start by trying to permit the selection logic (of whether the location improved the fit) to be executed on the GPU. A GPU-improved fmincon would call for a redesign of the fmincon internals rather than for simply adding gpuArray to the list of types the code permits to be returned.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Shivam Singh
Shivam Singh 2022년 2월 2일
Hello Chris,
This error message indicates that the type of input arguments to fmincom is different than the expected. You may refer the fmincom function to know more about it.
Also, currently “fmincom” function doesn't have GPU support.
  댓글 수: 2
CSCh
CSCh 2024년 7월 22일
Is there any progress made by Mathworks in terms of the discussed issue "fmincon & using GPU"
Best regards,
Chris
Walter Roberson
Walter Roberson 2024년 7월 22일

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by