cpu_vector_scal.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <starpu.h>
  4. #include <math.h>
  5. struct params {
  6. int32_t m;
  7. float k;
  8. float l;
  9. };
  10. float cpu_vector_scal(void *buffers[], void *cl_arg)
  11. {
  12. /* get scalar parameters from cl_arg */
  13. struct params *scalars = (struct params *) cl_arg;
  14. int m = scalars->m;
  15. float k = scalars->k;
  16. float l = scalars->l;
  17. struct starpu_vector_interface *vector = (struct starpu_vector_interface *) buffers[0];
  18. /* length of the vector */
  19. unsigned n = STARPU_VECTOR_GET_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_VECTOR_GET_PTR(vector);
  24. /* scale the vector */
  25. for (unsigned i = 0; i < n; i++)
  26. val[i] = val[i] * k + l + m;
  27. return 0.0;
  28. }
  29. char* CPU = "cpu_vector_scal";
  30. char* GPU = "gpu_vector_scal";
  31. extern char *starpu_find_function(char *name, char *device) {
  32. if (!strcmp(device,"gpu")) return GPU;
  33. return CPU;
  34. }