multiformat.c 2.1 KB

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