vector_scal_cpu.c 2.0 KB

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