generic.c 5.4 KB

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