subs a value from gpu to a symbolic function

4 次查看(过去 30 天)
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 中查找有关 Assumptions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by