MATLAB PARALLEL COMPUTING TOOLBOX - S Guía de usuario Pagina 272

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 656
  • Tabla de contenidos
  • SOLUCIÓN DE PROBLEMAS
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 271
9 GPU Computing
9-14
Example: Run Your MATLAB Code
In this example, a small function applies correction data to an array of measurement
data. The function defined in the file myCal.m is:
function c = myCal(rawdata, gain, offst)
c = (rawdata .* gain) + offst;
The function performs only element-wise operations when applying a gain factor and
offset to each element of the rawdata array.
Create some nominal measurement:
meas = ones(1000)*3; % 1000-by-1000 matrix
The function allows the gain and offset to be arrays of the same size as rawdata, so that
unique corrections can be applied to individual measurements. In a typical situation, you
might keep the correction data on the GPU so that you do not have to transfer it for each
application:
gn = rand(1000,'gpuArray')/100 + 0.995;
offs = rand(1000,'gpuArray')/50 - 0.01;
Run your calibration function on the GPU:
corrected = arrayfun(@myCal,meas,gn,offs);
This runs on the GPU because the input arguments gn and offs are already in GPU
memory.
Retrieve the corrected results from the GPU to the MATLAB workspace:
results = gather(corrected);
Vista de pagina 271
1 2 ... 267 268 269 270 271 272 273 274 275 276 277 ... 655 656

Comentarios a estos manuales

Sin comentarios