User`s guide
R2012a
7-12
g = gpuDevice(idx)
.
.
.
g = gpuDevice(idx) % Resets GPU device, clears data
To deselect the current device, use gpuDevice([ ]) with an empty argument (as
opposed to no argument). This clears the GPU of all arrays and kernels, and invalidates
variables in the workspace that point to such data.
Asynchronous GPU Calculations and Wait
All GPU calculations now run asynchronously with MATLAB. That is, when you
initiate a calculation on the GPU, MATLAB continues execution while the GPU runs its
calculations at the same time. The wait command now accommodates a GPU device, so
that you can synchronize MATLAB and the GPU. The form of the command is
wait(gpudev)
where gpudev is the object representing the GPU device to wait for. At this command,
MATLAB waits until all current calculations complete on the specified device.
Compatibility Considerations
In previous releases, MATLAB and the GPU were synchronous, so that any calls to the
GPU had to complete before MATLAB proceeded to the next command. This is no longer
the case. Now MATLAB continues while the GPU is running. The wait command lets
you time GPU code execution.
Verify GPUArray or CUDAKernel Exists on the Device
The new function existsOnGPU lets you verify that a GPUArray or CUDAKernel exists
on the current GPU device, and that its data is accessible from MATLAB. It is possible to
reset the GPU device, so that a GPUArray or CUDAKernel object variable still exists in
your MATLAB workspace even though it is no longer available on the GPU. For example,
you can reset a GPU device using the command gpuDevice(index) or reset(dev):
index = 1;
g = gpuDevice(index);
R = parallel.gpu.GPUArray.rand(4,4)
0.5465 0.3000 0.4067 0.6110
0.9024 0.8965 0.6635 0.7709