vector_scal_cpu.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. /* This kernel takes a buffer and scales it by a constant factor */
  19. void scal_cpu_func(void *buffers[], void *cl_arg)
  20. {
  21. unsigned i;
  22. float *factor = cl_arg;
  23. /*
  24. * The "buffers" array matches the task->handles array: for instance
  25. * task->handles[0] is a handle that corresponds to a data with
  26. * vector "interface", so that the first entry of the array in the
  27. * codelet is a pointer to a structure describing such a vector (ie.
  28. * struct starpu_vector_interface *). Here, we therefore manipulate
  29. * the buffers[0] element as a vector: nx gives the number of elements
  30. * in the array, ptr gives the location of the array (that was possibly
  31. * migrated/replicated), and elemsize gives the size of each elements.
  32. */
  33. struct starpu_vector_interface *vector = buffers[0];
  34. /* length of the vector */
  35. unsigned n = STARPU_VECTOR_GET_NX(vector);
  36. /* get a pointer to the local copy of the vector : note that we have to
  37. * cast it in (float *) since a vector could contain any type of
  38. * elements so that the .ptr field is actually a uintptr_t */
  39. float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
  40. /* scale the vector */
  41. for (i = 0; i < n; i++)
  42. val[i] *= *factor;
  43. }