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 Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by