vector_scal_cuda.texi 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. @copying
  2. Copyright (C) 2009-2011 Université de Bordeaux 1
  3. Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3
  6. or any later version published by the Free Software Foundation;
  7. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  8. See the GNU Free Documentation License in COPYING.GFDL for more details.
  9. @end copying
  10. @smallexample
  11. #include <starpu.h>
  12. #include <starpu_cuda.h>
  13. static __global__ void vector_mult_cuda(float *val, unsigned n,
  14. float factor)
  15. @{
  16. unsigned i = blockIdx.x*blockDim.x + threadIdx.x;
  17. if (i < n)
  18. val[i] *= factor;
  19. @}
  20. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  21. @{
  22. float *factor = (float *)_args;
  23. /* length of the vector */
  24. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  25. /* local copy of the vector pointer */
  26. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  27. unsigned threads_per_block = 64;
  28. unsigned nblocks = (n + threads_per_block-1) / threads_per_block;
  29. vector_mult_cuda<<<nblocks,threads_per_block, 0, starpu_cuda_get_local_stream()>>>(val, n, *factor);
  30. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  31. @}
  32. @end smallexample