multiformat.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2010-2013 Université de Bordeaux 1
  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. //! [To be included]
  18. #define NX 1024
  19. struct point array_of_structs[NX];
  20. starpu_data_handle_t handle;
  21. /*
  22. * The conversion of a piece of data is itself a task, though it is created,
  23. * submitted and destroyed by StarPU internals and not by the user. Therefore,
  24. * we have to define two codelets.
  25. * Note that for now the conversion from the CPU format to the GPU format has to
  26. * be executed on the GPU, and the conversion from the GPU to the CPU has to be
  27. * executed on the CPU.
  28. */
  29. #ifdef STARPU_USE_OPENCL
  30. void cpu_to_opencl_opencl_func(void *buffers[], void *args);
  31. struct starpu_codelet cpu_to_opencl_cl = {
  32. .where = STARPU_OPENCL,
  33. .opencl_funcs = { cpu_to_opencl_opencl_func, NULL },
  34. .nbuffers = 1,
  35. .modes = { STARPU_RW }
  36. };
  37. void opencl_to_cpu_func(void *buffers[], void *args);
  38. struct starpu_codelet opencl_to_cpu_cl = {
  39. .where = STARPU_CPU,
  40. .cpu_funcs = { opencl_to_cpu_func, NULL },
  41. .cpu_funcs_name = { "opencl_to_cpu_func", NULL },
  42. .nbuffers = 1,
  43. .modes = { STARPU_RW }
  44. };
  45. #endif
  46. struct starpu_multiformat_data_interface_ops format_ops = {
  47. #ifdef STARPU_USE_OPENCL
  48. .opencl_elemsize = 2 * sizeof(float),
  49. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  50. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  51. #endif
  52. .cpu_elemsize = 2 * sizeof(float),
  53. ...
  54. };
  55. starpu_multiformat_data_register(handle, 0, &array_of_structs, NX, &format_ops);
  56. //! [To be included]