vector_scal_cpu.texi 1.3 KB

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