vector_scal_cpu.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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 <starpu.h>
  17. /* This kernel takes a buffer and scales it by a constant factor */
  18. void vector_scal_cpu(void *buffers[], void *cl_arg)
  19. {
  20. unsigned i;
  21. float *factor = cl_arg;
  22. /*
  23. * The "buffers" array matches the task->handles array: for instance
  24. * task->handles[0] is a handle that corresponds to a data with
  25. * vector "interface", so that the first entry of the array in the
  26. * codelet is a pointer to a structure describing such a vector (ie.
  27. * struct starpu_vector_interface *). Here, we therefore manipulate
  28. * the buffers[0] element as a vector: nx gives the number of elements
  29. * in the array, ptr gives the location of the array (that was possibly
  30. * migrated/replicated), and elemsize gives the size of each elements.
  31. */
  32. struct starpu_vector_interface *vector = 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 (i = 0; i < n; i++)
  41. val[i] *= *factor;
  42. }