vector_scal_cuda.texi 870 B

123456789101112131415161718192021222324252627
  1. #include <starpu.h>
  2. static __global__ void vector_mult_cuda(unsigned n, float *val,
  3. float factor)
  4. {
  5. unsigned i = blockIdx.x*blockDim.x + threadIdx.x;
  6. if (i < n)
  7. val[i] *= factor;
  8. }
  9. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  10. {
  11. float *factor = (float *)_args;
  12. /* length of the vector */
  13. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  14. /* local copy of the vector pointer */
  15. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  16. unsigned threads_per_block = 64;
  17. unsigned nblocks = (n + threads_per_block-1) / threads_per_block;
  18. vector_mult_cuda<<<nblocks,threads_per_block, 0, starpu_cuda_get_local_stream()>>>
  19. (n, val, *factor);
  20. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  21. }