vector_scal_cpu.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * * The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <starpu.h>
  31. /* This kernel takes a buffer and scales it by a constant factor */
  32. void scal_cpu_func(void *buffers[], void *cl_arg)
  33. {
  34. unsigned i;
  35. float *factor = cl_arg;
  36. /*
  37. * The "buffers" array matches the task->handles array: for instance
  38. * task->handles[0] is a handle that corresponds to a data with
  39. * vector "interface", so that the first entry of the array in the
  40. * codelet is a pointer to a structure describing such a vector (ie.
  41. * struct starpu_vector_interface *). Here, we therefore manipulate
  42. * the buffers[0] element as a vector: nx gives the number of elements
  43. * in the array, ptr gives the location of the array (that was possibly
  44. * migrated/replicated), and elemsize gives the size of each elements.
  45. */
  46. struct starpu_vector_interface *vector = buffers[0];
  47. /* length of the vector */
  48. unsigned n = STARPU_VECTOR_GET_NX(vector);
  49. /* get a pointer to the local copy of the vector : note that we have to
  50. * cast it in (float *) since a vector could contain any type of
  51. * elements so that the .ptr field is actually a uintptr_t */
  52. float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
  53. /* scale the vector */
  54. for (i = 0; i < n; i++)
  55. val[i] *= *factor;
  56. }