vector_scal_plugin_cuda.cu 1.5 KB

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