%% Transfer Data to and from the GPU
% To transfer data from the CPU to the GPU, use the gpuArray function.
% Create an array X.

X = [1,2,3];

%  Transfer X to the GPU.

G = gpuArray(X);

% Check that the data is on the GPU.

isgpuarray(G)

% Calculate the element-wise square of the array G.

GSq = G.^2;

% Transfer the result GSq back to the CPU.

XSq = gather(GSq)

% Check that the data is not on the GPU.

isgpuarray(XSq)

% Copyright 2021 The MathWorks, Inc.