필터 지우기
필터 지우기

subs a value from gpu to a symbolic function

조회 수: 4 (최근 30일)
Tuan Hua
Tuan Hua 2023년 8월 22일
편집: Infinite_king 2024년 3월 27일
I am trying to substitute some symbolic variables in a symbolic function with some values from GPU. However, the subs function recognise these values as 0s as shown in the code below:
syms q1 q2
test = q1^2;
q1_value = gpuArray(1);
subs(test, q1, q1_value)
ans =
0
When I substitute a normal value, it show the right value:
subs(test, q1, 1)
ans =
1
What causes the problem? In addition, can I perform subs function with a gpu? I tried to use matlabfunction to speed up the subs function, but it was slower than using the subs function directly.

답변 (1개)

Infinite_king
Infinite_king 2024년 3월 27일
편집: Infinite_king 2024년 3월 27일
Hi Tuan Hua,
The 'subs' function expects one of the following data types as input inplace of 'q1_value'.
Data Types: sym | symfun | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | struct | cell
However, 'gpuArray' function will return a 'gpuArray object' which was not same as anyone of the aforementioned types. To resolve this issue, you can use the 'gather' function as follows,
q1_value = gather(q1_value) % transfer the data to cpu memory
'gather' function will transfer the data from GPU memory to CPU memory, so the resultant variable can be used as usual.
As per the documentation, 'subs' function will not support gpuArray. This means the computational load of 'subs' function cannot be transfered to GPU.
For more information, refer the following resources,
Hope this is helpful.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by