generic.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #if STARPU_HAVE_VALGRIND_H
  18. #include <valgrind/valgrind.h>
  19. #endif
  20. #include <starpu_data_interfaces.h>
  21. #include "generic.h"
  22. #include "../../../../helper.h"
  23. struct stats global_stats;
  24. #ifdef STARPU_USE_CPU
  25. void cpu_func(void *buffers[], void *args)
  26. {
  27. STARPU_SKIP_IF_VALGRIND;
  28. global_stats.cpu++;
  29. }
  30. #endif /* !STARPU_USE_CPU */
  31. #ifdef STARPU_USE_CUDA
  32. void cuda_func(void *buffers[], void *args)
  33. {
  34. STARPU_SKIP_IF_VALGRIND;
  35. global_stats.cuda++;
  36. }
  37. void cpu_to_cuda_func(void *buffers[], void *args)
  38. {
  39. STARPU_SKIP_IF_VALGRIND;
  40. global_stats.cpu_to_cuda++;
  41. }
  42. void cuda_to_cpu_func(void *buffers[], void *args)
  43. {
  44. STARPU_SKIP_IF_VALGRIND;
  45. global_stats.cuda_to_cpu++;
  46. }
  47. struct starpu_codelet cpu_to_cuda_cl =
  48. {
  49. .where = STARPU_CUDA,
  50. .cuda_funcs = {cpu_to_cuda_func, NULL},
  51. .nbuffers = 1
  52. };
  53. struct starpu_codelet cuda_to_cpu_cl =
  54. {
  55. .where = STARPU_CPU,
  56. .cpu_funcs = {cuda_to_cpu_func, NULL},
  57. .nbuffers = 1
  58. };
  59. #endif /* !STARPU_USE_CUDA */
  60. #ifdef STARPU_USE_OPENCL
  61. void opencl_func(void *buffers[], void *args)
  62. {
  63. STARPU_SKIP_IF_VALGRIND;
  64. global_stats.opencl++;
  65. }
  66. void cpu_to_opencl_func(void *buffers[], void *args)
  67. {
  68. STARPU_SKIP_IF_VALGRIND;
  69. global_stats.cpu_to_opencl++;
  70. }
  71. void opencl_to_cpu_func(void *buffers[], void *args)
  72. {
  73. STARPU_SKIP_IF_VALGRIND;
  74. global_stats.opencl_to_cpu++;
  75. }
  76. struct starpu_codelet cpu_to_opencl_cl =
  77. {
  78. .where = STARPU_OPENCL,
  79. .opencl_funcs = {cpu_to_opencl_func, NULL},
  80. .nbuffers = 1
  81. };
  82. struct starpu_codelet opencl_to_cpu_cl =
  83. {
  84. .where = STARPU_CPU,
  85. .cpu_funcs = {opencl_to_cpu_func, NULL},
  86. .nbuffers = 1
  87. };
  88. #endif /* !STARPU_USE_OPENCL */
  89. struct starpu_multiformat_data_interface_ops ops =
  90. {
  91. #ifdef STARPU_USE_CUDA
  92. .cuda_elemsize = sizeof(int),
  93. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  94. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  95. #endif
  96. #ifdef STARPU_USE_OPENCL
  97. .opencl_elemsize = sizeof(int),
  98. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  99. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  100. #endif
  101. .cpu_elemsize = sizeof(int)
  102. };
  103. void
  104. print_stats(struct stats *s)
  105. {
  106. #ifdef STARPU_USE_CPU
  107. FPRINTF(stderr, "cpu : %d\n", s->cpu);
  108. #endif /* !STARPU_USE_CPU */
  109. #ifdef STARPU_USE_CUDA
  110. FPRINTF(stderr, "cuda : %d\n"
  111. "cpu->cuda : %d\n"
  112. "cuda->cpu : %d\n",
  113. s->cuda,
  114. s->cpu_to_cuda,
  115. s->cuda_to_cpu);
  116. #endif /* !STARPU_USE_CUDA */
  117. #ifdef STARPU_USE_OPENCL
  118. FPRINTF(stderr, "opencl : %d\n"
  119. "cpu->opencl : %d\n"
  120. "opencl->cpu : %d\n",
  121. s->opencl,
  122. s->cpu_to_opencl,
  123. s->opencl_to_cpu);
  124. #endif /* !STARPU_USE_OPENCL */
  125. }
  126. void reset_stats(struct stats *s)
  127. {
  128. #ifdef STARPU_USE_CPU
  129. s->cpu = 0;
  130. #endif /* !STARPU_USE_CPU */
  131. #ifdef STARPU_USE_CUDA
  132. s->cuda = 0;
  133. s->cpu_to_cuda = 0;
  134. s->cuda_to_cpu = 0;
  135. #endif /* !STARPU_USE_CUDA */
  136. #ifdef STARPU_USE_OPENCL
  137. s->opencl = 0;
  138. s->cpu_to_opencl = 0;
  139. s->opencl_to_cpu = 0;
  140. #endif /* !STARPU_USE_OPENCL */
  141. }
  142. int
  143. compare_stats(struct stats *s1, struct stats *s2)
  144. {
  145. if (
  146. #ifdef STARPU_USE_CPU
  147. s1->cpu == s2->cpu &&
  148. #endif /* !STARPU_USE_CPU */
  149. #ifdef STARPU_USE_CUDA
  150. s1->cuda == s2->cuda &&
  151. s1->cpu_to_cuda == s2->cpu_to_cuda &&
  152. s1->cuda_to_cpu == s2->cuda_to_cpu &&
  153. #endif /* !STARPU_USE_CUDA */
  154. #ifdef STARPU_USE_OPENCL
  155. s1->opencl == s2->opencl &&
  156. s1->cpu_to_opencl == s2->cpu_to_opencl &&
  157. s1->opencl_to_cpu == s2->opencl_to_cpu &&
  158. #endif /* !STARPU_USE_OPENCL */
  159. 1 /* Just so the build does not fail if we disable EVERYTHING */
  160. )
  161. return 0;
  162. else
  163. return 1;
  164. }