Cannot convert from gpuArray to double

The following error occurs when converting data from gpuArray to double in MATLAB: Cannot convert from gpuArray to double. Solution:

Add a gather in front of the converted variable.

give a simple example

A=gpuArray.linspace(4,12,25);
B=[];
i=1
while i <=25
    B(i)=A(i)
    i=i+1
end

The following error will appear:

从 gpuArray 转换为 double 时出现以下错误:
无法从 gpuArray 转换为 double。

Add A=gather(A)

A=gpuArray.linspace(4,12,25);
B=[];
i=1
A=gather(A)
while i <=25
    B(i)=A(i)
    i=i+1
end

The code will run normally.

Guess you like

Origin blog.csdn.net/weixin_48266700/article/details/126189870