subs a value from gpu to a symbolic function
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Infinite_king
on 27 Mar 2024
Edited: Infinite_king
on 27 Mar 2024
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.
0 Comments
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!