cpu_vector_scal.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <stdio.h>
  17. #include <stdint.h>
  18. #include <starpu.h>
  19. #include <math.h>
  20. struct params {
  21. int32_t m;
  22. float k;
  23. float l;
  24. };
  25. float cpu_vector_scal(void *buffers[], void *cl_arg)
  26. {
  27. /* get scalar parameters from cl_arg */
  28. struct params *scalars = (struct params *) cl_arg;
  29. int m = scalars->m;
  30. float k = scalars->k;
  31. float l = scalars->l;
  32. struct starpu_vector_interface *vector = (struct starpu_vector_interface *) buffers[0];
  33. /* length of the vector */
  34. unsigned n = STARPU_VECTOR_GET_NX(vector);
  35. /* get a pointer to the local copy of the vector : note that we have to
  36. * cast it in (float *) since a vector could contain any type of
  37. * elements so that the .ptr field is actually a uintptr_t */
  38. float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
  39. /* scale the vector */
  40. for (unsigned i = 0; i < n; i++)
  41. val[i] = val[i] * m + l + k;
  42. return 0.0;
  43. }
  44. char* CPU = "cpu_vector_scal";
  45. char* GPU = "gpu_vector_scal";
  46. extern char *starpu_find_function(char *name, char *device) {
  47. if (!strcmp(device,"gpu")) return GPU;
  48. return CPU;
  49. }