generic.c 5.2 KB

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