generic.c 5.4 KB

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