vector_scal_plugin_cuda.cu 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011,2013,2015,2017 CNRS
  4. * Copyright (C) 2010,2014,2016 Université de Bordeaux
  5. * Copyright (C) 2012 Inria
  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 vector_scal_cuda (unsigned int size, float vector[], float factor)
  30. {
  31. unsigned threads_per_block = 64;
  32. unsigned nblocks = (size + threads_per_block - 1) / threads_per_block;
  33. vector_mult_cuda <<< nblocks, threads_per_block, 0,
  34. starpu_cuda_get_local_stream () >>> (size, vector, factor);
  35. cudaStreamSynchronize (starpu_cuda_get_local_stream ());
  36. }