multiformat_conversion_codelets.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  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. #include <starpu.h>
  17. #include "multiformat_types.h"
  18. #ifdef STARPU_USE_CUDA
  19. void cpu_to_cuda(void *buffers[], void *arg)
  20. {
  21. struct point *src = STARPU_MULTIFORMAT_GET_PTR(buffers[0]);
  22. struct struct_of_arrays *dst = STARPU_MULTIFORMAT_GET_CUDA_PTR(buffers[0]);
  23. int n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  24. int i;
  25. for (i = 0; i < n; i++) {
  26. dst->x[i] = src[i].x;
  27. dst->y[i] = src[i].y;
  28. }
  29. }
  30. void cuda_to_cpu(void *buffers[], void *arg)
  31. {
  32. struct struct_of_arrays *src = STARPU_MULTIFORMAT_GET_CUDA_PTR(buffers[0]);
  33. struct point *dst = STARPU_MULTIFORMAT_GET_PTR(buffers[0]);
  34. int n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  35. int i;
  36. for (i = 0; i < n; i++) {
  37. dst[i].x = src->x[i];
  38. dst[i].y = src->y[i];
  39. }
  40. }
  41. extern void cpu_to_cuda_cuda_func(void *buffers[], void *args);
  42. starpu_codelet cpu_to_cuda_cl = {
  43. .where = STARPU_CUDA,
  44. .cpu_func = cpu_to_cuda,
  45. .cuda_func = cpu_to_cuda_cuda_func,
  46. .nbuffers = 1
  47. };
  48. starpu_codelet cuda_to_cpu_cl = {
  49. .where = STARPU_CPU,
  50. .cpu_func = cuda_to_cpu,
  51. .nbuffers = 1
  52. };
  53. #endif
  54. #ifdef STARPU_USE_OPENCL
  55. void cpu_to_opencl(void *buffers[], void *arg)
  56. {
  57. fprintf(stderr, "User Entering %s\n", __func__);
  58. struct point *src = STARPU_MULTIFORMAT_GET_PTR(buffers[0]);
  59. struct struct_of_arrays *dst = STARPU_MULTIFORMAT_GET_OPENCL_PTR(buffers[0]);
  60. int n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  61. int i;
  62. for (i = 0; i < n; i++) {
  63. dst->x[i] = src[i].x;
  64. dst->y[i] = src[i].y;
  65. }
  66. }
  67. void opencl_to_cpu(void *buffers[], void *arg)
  68. {
  69. fprintf(stderr, "User Entering %s\n", __func__);
  70. struct struct_of_arrays *src = STARPU_MULTIFORMAT_GET_OPENCL_PTR(buffers[0]);
  71. struct point *dst = STARPU_MULTIFORMAT_GET_PTR(buffers[0]);
  72. int n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  73. int i;
  74. for (i = 0; i < n; i++) {
  75. dst[i].x = src->x[i];
  76. dst[i].y = src->y[i];
  77. }
  78. }
  79. extern void cpu_to_opencl_opencl_func(void *buffers[], void *args);
  80. starpu_codelet cpu_to_opencl_cl = {
  81. .where = STARPU_OPENCL,
  82. .cpu_func = cpu_to_opencl,
  83. .opencl_func = cpu_to_opencl_opencl_func,
  84. .nbuffers = 1
  85. };
  86. starpu_codelet opencl_to_cpu_cl = {
  87. .where = STARPU_CPU,
  88. .cpu_func = opencl_to_cpu,
  89. .nbuffers = 1
  90. };
  91. #endif