# Where is the device to store a copy of memory in MATLAB

I am new to MATLAB gpu computing. In the following code, I have used multiple gpu arrays that are created in the device directly. However, NVidia Visual Profiler shows that there is a large number of copies of memory per device (D2H). Could you please teach me how to detect and remove them. My code looks like this:

``````function [x]=myFunction()
C = rand(1024,2,'gpuArray');
D = rand(1024,2,'gpuArray');
b = rand(1024,1,'gpuArray');

DT = transpose(D);

[n,m]=size(C);

%define variables of algorithm
x=zeros(n,1,'gpuArray');
F=zeros(n,m,'gpuArray');
y=ones(n,1,'gpuArray');

gpuZero = zeros(1,1,'gpuArray');

z=C(1,:) * DT(:,1);
x(1)=b(1)/z;
F(1,:)=C(1,:)/z;
v=DT(:,2);
y(1)=-F(1,:)*v;

si = tril(reshape(cumsum(reshape(C(2:end,:)*DT,n,n-1),2),n-1,n)); // completely on GPU memory

for i=2:n-1
i_1 = i-1;

t=C(i,:)-si(i_1,1:i_1)*F(1:i_1,:);
z=z+t*v;
w=b(i)-si(i_1,1:i_1)*x(1:i_1);
x(1:i)=x(1:i)+w/z*y(1:i);

F(1:i,:)=F(1:i,:)+y(1:i)*(t/z);
v=DT(:,2:i+1)*y(1:i);
y(1:i)=[gpuZero;y(1:i_1)]-F(1:i,:)*v;
end
%i=n

z=z+(C(n,1:m)-si(n-1,1:n-1)*F(1:n-1,:))*v;
w=b(n)-si(n-1,:)*x;
x=x+w/z*y;
//exit;    // for visual profiler
end
```