vector_scal_cuda.texi 856 B

1234567891011121314151617181920212223242526
  1. #include <starpu.h>
  2. static __global__ void vector_mult_cuda(float *val, unsigned n,
  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()>>>(val, n, *factor);
  19. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  20. @}