multiformat.c 2.3 KB

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