Why does the dot product operation on complex numbers not return an expected real value on gpuArray?
8 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2018 年 8 月 23 日
編集済み: MathWorks Support Team
2022 年 7 月 12 日
I am performing a dot product using "dot" function on complex numbers and expecting a real value. When I do dot product on a CPU it gives me the expected output by returning a real value. However, when I do the same operation on a GPU, it gives me a complex number with imaginary part equal to 0. Is this expected behavior?
Please see the following code snippet and it's output:
>> a=1+i;
dot(a,a)
ans =
2
>> a=gpuArray(a);
>> dot(a,a)
ans =
2.0000 + 0.0000i
採用された回答
MathWorks Support Team
2022 年 7 月 12 日
編集済み: MathWorks Support Team
2022 年 7 月 12 日
This is an expected behavior with the GPU and it is based on the differences in how memory is assigned by MATLAB. On a GPU, we use an interleaved format for complex numbers. Hence, real and complex parts are stored together. On a CPU, we store the real and complex parts separately.
In the case of a CPU, it is easy to detect when all the complex parts are zero and to drop that section of the memory. However, this is an expensive operation in the interleaved format, so the 0 value complex part is maintained on the GPU. Testing the two outputs with “isequal” will confirm that they are the same despite the slight difference in the data type.
GPU also maintains the complexity of an output for functions which might return a complex output.
So that, if they are then used in another downstream operation which might return a complex output then the data type continues.
For more information, please visit the below documentation page:
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で GPU Computing in MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!