generic.c 5.1 KB

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