generic.c 5.5 KB

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