vector_scal_cpu.texi 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #include <starpu.h>
  2. /* This kernel takes a buffer and scales it by a constant factor */
  3. void scal_cpu_func(void *buffers[], void *cl_arg)
  4. @{
  5. unsigned i;
  6. float *factor = cl_arg;
  7. /*
  8. * The "buffers" array matches the task->buffers array: for instance
  9. * task->buffers[0].handle is a handle that corresponds to a data with
  10. * vector "interface", so that the first entry of the array in the
  11. * codelet is a pointer to a structure describing such a vector (ie.
  12. * struct starpu_vector_interface_s *). Here, we therefore manipulate
  13. * the buffers[0] element as a vector: nx gives the number of elements
  14. * in the array, ptr gives the location of the array (that was possibly
  15. * migrated/replicated), and elemsize gives the size of each elements.
  16. */
  17. starpu_vector_interface_t *vector = buffers[0];
  18. /* length of the vector */
  19. unsigned n = STARPU_GET_VECTOR_NX(vector);
  20. /* get a pointer to the local copy of the vector : note that we have to
  21. * cast it in (float *) since a vector could contain any type of
  22. * elements so that the .ptr field is actually a uintptr_t */
  23. float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
  24. /* scale the vector */
  25. for (i = 0; i < n; i++)
  26. val[i] *= *factor;
  27. @}