Why does the dot product operation on complex numbers not return an expected real value on gpuArray?

8 ビュー (過去 30 日間)
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
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 件)

カテゴリ

Help Center および File ExchangeGPU Computing in MATLAB についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by