generic.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-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. #include <starpu.h>
  17. #include "generic.h"
  18. #include "../../../../helper.h"
  19. struct stats global_stats;
  20. #ifdef STARPU_USE_CPU
  21. void cpu_func(void *buffers[], void *args)
  22. {
  23. (void)buffers;
  24. (void)args;
  25. STARPU_SKIP_IF_VALGRIND;
  26. global_stats.cpu++;
  27. }
  28. #endif /* !STARPU_USE_CPU */
  29. #ifdef STARPU_USE_CUDA
  30. void cuda_func(void *buffers[], void *args)
  31. {
  32. (void)buffers;
  33. (void)args;
  34. STARPU_SKIP_IF_VALGRIND;
  35. global_stats.cuda++;
  36. }
  37. void cpu_to_cuda_func(void *buffers[], void *args)
  38. {
  39. (void)buffers;
  40. (void)args;
  41. STARPU_SKIP_IF_VALGRIND;
  42. global_stats.cpu_to_cuda++;
  43. }
  44. void cuda_to_cpu_func(void *buffers[], void *args)
  45. {
  46. (void)buffers;
  47. (void)args;
  48. STARPU_SKIP_IF_VALGRIND;
  49. global_stats.cuda_to_cpu++;
  50. }
  51. struct starpu_codelet cpu_to_cuda_cl =
  52. {
  53. .cuda_funcs = {cpu_to_cuda_func},
  54. .nbuffers = 1,
  55. .modes = { STARPU_RW },
  56. };
  57. struct starpu_codelet cuda_to_cpu_cl =
  58. {
  59. .cpu_funcs = {cuda_to_cpu_func},
  60. .nbuffers = 1,
  61. .modes = { STARPU_RW },
  62. };
  63. #endif /* !STARPU_USE_CUDA */
  64. #ifdef STARPU_USE_OPENCL
  65. void opencl_func(void *buffers[], void *args)
  66. {
  67. (void)buffers;
  68. (void)args;
  69. STARPU_SKIP_IF_VALGRIND;
  70. global_stats.opencl++;
  71. }
  72. static
  73. void cpu_to_opencl_func(void *buffers[], void *args)
  74. {
  75. (void)buffers;
  76. (void)args;
  77. STARPU_SKIP_IF_VALGRIND;
  78. global_stats.cpu_to_opencl++;
  79. }
  80. static
  81. void opencl_to_cpu_func(void *buffers[], void *args)
  82. {
  83. (void)buffers;
  84. (void)args;
  85. STARPU_SKIP_IF_VALGRIND;
  86. global_stats.opencl_to_cpu++;
  87. }
  88. struct starpu_codelet cpu_to_opencl_cl =
  89. {
  90. .opencl_funcs = {cpu_to_opencl_func},
  91. .nbuffers = 1,
  92. .modes = { STARPU_RW },
  93. };
  94. struct starpu_codelet opencl_to_cpu_cl =
  95. {
  96. .cpu_funcs = {opencl_to_cpu_func},
  97. .nbuffers = 1,
  98. .modes = { STARPU_RW },
  99. };
  100. #endif /* !STARPU_USE_OPENCL */
  101. #ifdef STARPU_USE_MIC
  102. void mic_dummy_kernel(void *buffers[], void *args)
  103. {
  104. (void)buffers;
  105. (void)args;
  106. }
  107. starpu_mic_kernel_t mic_get_kernel()
  108. {
  109. static starpu_mic_func_symbol_t mic_symbol = NULL;
  110. if (mic_symbol == NULL)
  111. starpu_mic_register_kernel(&mic_symbol, "mic_dummy_kernel");
  112. return starpu_mic_get_kernel(mic_symbol);
  113. }
  114. starpu_mic_kernel_t mic_func()
  115. {
  116. STARPU_SKIP_IF_VALGRIND;
  117. global_stats.mic++;
  118. return mic_get_kernel();
  119. }
  120. starpu_mic_kernel_t cpu_to_mic_func()
  121. {
  122. STARPU_SKIP_IF_VALGRIND;
  123. global_stats.cpu_to_mic++;
  124. return mic_get_kernel();
  125. }
  126. void mic_to_cpu_func(void *buffers[], void *args)
  127. {
  128. (void)buffers;
  129. (void)args;
  130. STARPU_SKIP_IF_VALGRIND;
  131. global_stats.mic_to_cpu++;
  132. }
  133. struct starpu_codelet cpu_to_mic_cl =
  134. {
  135. .mic_funcs = {cpu_to_mic_func},
  136. .nbuffers = 1,
  137. .modes = { STARPU_RW },
  138. };
  139. struct starpu_codelet mic_to_cpu_cl =
  140. {
  141. .cpu_funcs = {mic_to_cpu_func},
  142. .nbuffers = 1,
  143. .modes = { STARPU_RW },
  144. };
  145. #endif // STARPU_USE_MIC
  146. struct starpu_multiformat_data_interface_ops ops =
  147. {
  148. #ifdef STARPU_USE_CUDA
  149. .cuda_elemsize = sizeof(int),
  150. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  151. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  152. #endif
  153. #ifdef STARPU_USE_OPENCL
  154. .opencl_elemsize = sizeof(int),
  155. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  156. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  157. #endif
  158. #ifdef STARPU_USE_MIC
  159. .mic_elemsize = sizeof(int),
  160. .cpu_to_mic_cl = &cpu_to_mic_cl,
  161. .mic_to_cpu_cl = &mic_to_cpu_cl,
  162. #endif
  163. .cpu_elemsize = sizeof(int)
  164. };
  165. void
  166. print_stats(struct stats *s)
  167. {
  168. #ifdef STARPU_USE_CPU
  169. FPRINTF(stderr, "cpu : %u\n", s->cpu);
  170. #endif /* !STARPU_USE_CPU */
  171. #ifdef STARPU_USE_CUDA
  172. FPRINTF(stderr, "cuda : %u\n"
  173. "cpu->cuda : %u\n"
  174. "cuda->cpu : %u\n",
  175. s->cuda,
  176. s->cpu_to_cuda,
  177. s->cuda_to_cpu);
  178. #endif /* !STARPU_USE_CUDA */
  179. #ifdef STARPU_USE_OPENCL
  180. FPRINTF(stderr, "opencl : %u\n"
  181. "cpu->opencl : %u\n"
  182. "opencl->cpu : %u\n",
  183. s->opencl,
  184. s->cpu_to_opencl,
  185. s->opencl_to_cpu);
  186. #endif /* !STARPU_USE_OPENCL */
  187. #ifdef STARPU_USE_MIC
  188. FPRINTF(stderr, "mic : %u\n"
  189. "cpu->mic : %u\n"
  190. "mic->cpu : %u\n",
  191. s->mic,
  192. s->cpu_to_mic,
  193. s->mic_to_cpu);
  194. #endif
  195. }
  196. void reset_stats(struct stats *s)
  197. {
  198. #ifdef STARPU_USE_CPU
  199. s->cpu = 0;
  200. #endif /* !STARPU_USE_CPU */
  201. #ifdef STARPU_USE_CUDA
  202. s->cuda = 0;
  203. s->cpu_to_cuda = 0;
  204. s->cuda_to_cpu = 0;
  205. #endif /* !STARPU_USE_CUDA */
  206. #ifdef STARPU_USE_OPENCL
  207. s->opencl = 0;
  208. s->cpu_to_opencl = 0;
  209. s->opencl_to_cpu = 0;
  210. #endif /* !STARPU_USE_OPENCL */
  211. #ifdef STARPU_USE_MIC
  212. s->mic = 0;
  213. s->cpu_to_mic = 0;
  214. s->mic_to_cpu = 0;
  215. #endif
  216. }
  217. int
  218. compare_stats(struct stats *s1, struct stats *s2)
  219. {
  220. if (
  221. #ifdef STARPU_USE_CPU
  222. s1->cpu == s2->cpu &&
  223. #endif /* !STARPU_USE_CPU */
  224. #ifdef STARPU_USE_CUDA
  225. s1->cuda == s2->cuda &&
  226. s1->cpu_to_cuda == s2->cpu_to_cuda &&
  227. s1->cuda_to_cpu == s2->cuda_to_cpu &&
  228. #endif /* !STARPU_USE_CUDA */
  229. #ifdef STARPU_USE_OPENCL
  230. s1->opencl == s2->opencl &&
  231. s1->cpu_to_opencl == s2->cpu_to_opencl &&
  232. s1->opencl_to_cpu == s2->opencl_to_cpu &&
  233. #endif /* !STARPU_USE_OPENCL */
  234. #ifdef STARPU_USE_MIC
  235. s1->mic == s2->mic &&
  236. s1->cpu_to_mic == s2->cpu_to_mic &&
  237. s1->mic_to_cpu == s2->mic_to_cpu &&
  238. #endif
  239. 1 /* Just so the build does not fail if we disable EVERYTHING */
  240. )
  241. return 0;
  242. else
  243. return 1;
  244. }