vector_scal_cuda.texi 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. @c StarPU --- Runtime system for heterogeneous multicore architectures.
  2. @c
  3. @c Copyright (C) 2009-2011 Université de Bordeaux 1
  4. @c Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. @c
  6. @c StarPU is free software; you can redistribute it and/or modify
  7. @c it under the terms of the GNU Lesser General Public License as published by
  8. @c the Free Software Foundation; either version 2.1 of the License, or (at
  9. @c your option) any later version.
  10. @c
  11. @c StarPU is distributed in the hope that it will be useful, but
  12. @c WITHOUT ANY WARRANTY; without even the implied warranty of
  13. @c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. @c
  15. @c See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. #include <starpu.h>
  17. #include <starpu_cuda.h>
  18. static __global__ void vector_mult_cuda(float *val, unsigned n,
  19. float factor)
  20. @{
  21. unsigned i = blockIdx.x*blockDim.x + threadIdx.x;
  22. if (i < n)
  23. val[i] *= factor;
  24. @}
  25. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  26. @{
  27. float *factor = (float *)_args;
  28. /* length of the vector */
  29. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  30. /* local copy of the vector pointer */
  31. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  32. unsigned threads_per_block = 64;
  33. unsigned nblocks = (n + threads_per_block-1) / threads_per_block;
  34. vector_mult_cuda<<<nblocks,threads_per_block, 0, starpu_cuda_get_local_stream()>>>(val, n, *factor);
  35. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  36. @}