generic.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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. .modes = { STARPU_RW },
  56. };
  57. struct starpu_codelet cuda_to_cpu_cl =
  58. {
  59. .cpu_funcs = {cuda_to_cpu_func},
  60. .nbuffers = 1,
  61. .modes = { STARPU_RW },
  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. .modes = { STARPU_RW },
  93. };
  94. struct starpu_codelet opencl_to_cpu_cl =
  95. {
  96. .cpu_funcs = {opencl_to_cpu_func},
  97. .nbuffers = 1,
  98. .modes = { STARPU_RW },
  99. };
  100. #endif /* !STARPU_USE_OPENCL */
  101. struct starpu_multiformat_data_interface_ops ops =
  102. {
  103. #ifdef STARPU_USE_CUDA
  104. .cuda_elemsize = sizeof(int),
  105. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  106. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  107. #endif
  108. #ifdef STARPU_USE_OPENCL
  109. .opencl_elemsize = sizeof(int),
  110. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  111. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  112. #endif
  113. .cpu_elemsize = sizeof(int)
  114. };
  115. void
  116. print_stats(struct stats *s)
  117. {
  118. #ifdef STARPU_USE_CPU
  119. FPRINTF(stderr, "cpu : %u\n", s->cpu);
  120. #endif /* !STARPU_USE_CPU */
  121. #ifdef STARPU_USE_CUDA
  122. FPRINTF(stderr, "cuda : %u\n"
  123. "cpu->cuda : %u\n"
  124. "cuda->cpu : %u\n",
  125. s->cuda,
  126. s->cpu_to_cuda,
  127. s->cuda_to_cpu);
  128. #endif /* !STARPU_USE_CUDA */
  129. #ifdef STARPU_USE_OPENCL
  130. FPRINTF(stderr, "opencl : %u\n"
  131. "cpu->opencl : %u\n"
  132. "opencl->cpu : %u\n",
  133. s->opencl,
  134. s->cpu_to_opencl,
  135. s->opencl_to_cpu);
  136. #endif /* !STARPU_USE_OPENCL */
  137. }
  138. void reset_stats(struct stats *s)
  139. {
  140. #ifdef STARPU_USE_CPU
  141. s->cpu = 0;
  142. #endif /* !STARPU_USE_CPU */
  143. #ifdef STARPU_USE_CUDA
  144. s->cuda = 0;
  145. s->cpu_to_cuda = 0;
  146. s->cuda_to_cpu = 0;
  147. #endif /* !STARPU_USE_CUDA */
  148. #ifdef STARPU_USE_OPENCL
  149. s->opencl = 0;
  150. s->cpu_to_opencl = 0;
  151. s->opencl_to_cpu = 0;
  152. #endif /* !STARPU_USE_OPENCL */
  153. }
  154. int
  155. compare_stats(struct stats *s1, struct stats *s2)
  156. {
  157. if (
  158. #ifdef STARPU_USE_CPU
  159. s1->cpu == s2->cpu &&
  160. #endif /* !STARPU_USE_CPU */
  161. #ifdef STARPU_USE_CUDA
  162. s1->cuda == s2->cuda &&
  163. s1->cpu_to_cuda == s2->cpu_to_cuda &&
  164. s1->cuda_to_cpu == s2->cuda_to_cpu &&
  165. #endif /* !STARPU_USE_CUDA */
  166. #ifdef STARPU_USE_OPENCL
  167. s1->opencl == s2->opencl &&
  168. s1->cpu_to_opencl == s2->cpu_to_opencl &&
  169. s1->opencl_to_cpu == s2->opencl_to_cpu &&
  170. #endif /* !STARPU_USE_OPENCL */
  171. 1 /* Just so the build does not fail if we disable EVERYTHING */
  172. )
  173. return 0;
  174. else
  175. return 1;
  176. }