Why does the dot product operation on complex numbers not return an expected real value on gpuArray?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 23 de Ag. de 2018
Editada: MathWorks Support Team
el 12 de Jul. de 2022
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
Respuesta aceptada
MathWorks Support Team
el 12 de Jul. de 2022
Editada: MathWorks Support Team
el 12 de Jul. de 2022
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre GPU Computing in MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!