Speedup with GPU¶
Any script implemented using the library can be easily switched to GPU computation. To that end, one only needs two simple functions:
useGPU() takes one single argument which can be
gpuCpuConverter() allows to convert numeric variables to the correct type according to the option selected with
useGPU() (respectively, double, gpuarray or cuda). For instance, if x is a
useGPU is set to 0, then
x=gpuCpuConverter(x) will not change x.
But if x is a
useGPU is set to 1, then
x=gpuCpuConverter(x) will convert x to a
(and send it to the graphic card). Hence, for each created/loaded variable “x” which is sufficiently large
(i.e. not for small vectors), one has to add the following line to the script
Then, the switch between CPU and GPU computation is simply controlled by
useGPU() which can be placed at the beginning of the script.
Functions which generate data¶
Matlab functions such as
zeros() require a memory allocation. When GPU is activated, it is faster to generate directly
these data on the graphic card instead of allocating CPU memory and then transfering them to the GPU. In order to make things transparents and
keep the code clear, all the occurences of
zeros() (i.e. within scripts but also within library classes) should be replaced by
zeros_(). These two functions have been defined in order to allocate the memory on the CPU or directly on the GPU according to the state of
The 3D deconvolution example provided in the “Example/” folder of the library shows a concrete use of the GPU functionality.