vector_scal_cuda.texi 861 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * This example complements vector_scale.c: here we implement a CUDA version.
  3. */
  4. #include <starpu.h>
  5. static __global__ void vector_mult_cuda(float *val, unsigned n,
  6. float factor)
  7. @{
  8. unsigned i;
  9. for(i = 0 ; i < n ; i++)
  10. val[i] *= factor;
  11. @}
  12. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  13. @{
  14. float *factor = (float *)_args;
  15. struct starpu_vector_interface_s *vector = (struct starpu_vector_interface_s *) buffers[0];
  16. /* length of the vector */
  17. unsigned n = STARPU_GET_VECTOR_NX(vector);
  18. /* local copy of the vector pointer */
  19. float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
  20. /* TODO: use more blocks and threads in blocks */
  21. vector_mult_cuda<<<1,1>>>(val, n, *factor);
  22. cudaThreadSynchronize();
  23. @}