generic.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. .where = STARPU_CUDA,
  47. .cuda_funcs = {cpu_to_cuda_func, NULL},
  48. .nbuffers = 1
  49. };
  50. struct starpu_codelet cuda_to_cpu_cl =
  51. {
  52. .where = STARPU_CPU,
  53. .cpu_funcs = {cuda_to_cpu_func, NULL},
  54. .nbuffers = 1
  55. };
  56. #endif /* !STARPU_USE_CUDA */
  57. #ifdef STARPU_USE_OPENCL
  58. void opencl_func(void *buffers[], void *args)
  59. {
  60. STARPU_SKIP_IF_VALGRIND;
  61. global_stats.opencl++;
  62. }
  63. void cpu_to_opencl_func(void *buffers[], void *args)
  64. {
  65. STARPU_SKIP_IF_VALGRIND;
  66. global_stats.cpu_to_opencl++;
  67. }
  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. .where = STARPU_OPENCL,
  76. .opencl_funcs = {cpu_to_opencl_func, NULL},
  77. .nbuffers = 1
  78. };
  79. struct starpu_codelet opencl_to_cpu_cl =
  80. {
  81. .where = STARPU_CPU,
  82. .cpu_funcs = {opencl_to_cpu_func, NULL},
  83. .nbuffers = 1
  84. };
  85. #endif /* !STARPU_USE_OPENCL */
  86. struct starpu_multiformat_data_interface_ops ops =
  87. {
  88. #ifdef STARPU_USE_CUDA
  89. .cuda_elemsize = sizeof(int),
  90. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  91. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  92. #endif
  93. #ifdef STARPU_USE_OPENCL
  94. .opencl_elemsize = sizeof(int),
  95. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  96. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  97. #endif
  98. .cpu_elemsize = sizeof(int)
  99. };
  100. void
  101. print_stats(struct stats *s)
  102. {
  103. #ifdef STARPU_USE_CPU
  104. FPRINTF(stderr, "cpu : %u\n", s->cpu);
  105. #endif /* !STARPU_USE_CPU */
  106. #ifdef STARPU_USE_CUDA
  107. FPRINTF(stderr, "cuda : %u\n"
  108. "cpu->cuda : %u\n"
  109. "cuda->cpu : %u\n",
  110. s->cuda,
  111. s->cpu_to_cuda,
  112. s->cuda_to_cpu);
  113. #endif /* !STARPU_USE_CUDA */
  114. #ifdef STARPU_USE_OPENCL
  115. FPRINTF(stderr, "opencl : %u\n"
  116. "cpu->opencl : %u\n"
  117. "opencl->cpu : %u\n",
  118. s->opencl,
  119. s->cpu_to_opencl,
  120. s->opencl_to_cpu);
  121. #endif /* !STARPU_USE_OPENCL */
  122. }
  123. void reset_stats(struct stats *s)
  124. {
  125. #ifdef STARPU_USE_CPU
  126. s->cpu = 0;
  127. #endif /* !STARPU_USE_CPU */
  128. #ifdef STARPU_USE_CUDA
  129. s->cuda = 0;
  130. s->cpu_to_cuda = 0;
  131. s->cuda_to_cpu = 0;
  132. #endif /* !STARPU_USE_CUDA */
  133. #ifdef STARPU_USE_OPENCL
  134. s->opencl = 0;
  135. s->cpu_to_opencl = 0;
  136. s->opencl_to_cpu = 0;
  137. #endif /* !STARPU_USE_OPENCL */
  138. }
  139. int
  140. compare_stats(struct stats *s1, struct stats *s2)
  141. {
  142. if (
  143. #ifdef STARPU_USE_CPU
  144. s1->cpu == s2->cpu &&
  145. #endif /* !STARPU_USE_CPU */
  146. #ifdef STARPU_USE_CUDA
  147. s1->cuda == s2->cuda &&
  148. s1->cpu_to_cuda == s2->cpu_to_cuda &&
  149. s1->cuda_to_cpu == s2->cuda_to_cpu &&
  150. #endif /* !STARPU_USE_CUDA */
  151. #ifdef STARPU_USE_OPENCL
  152. s1->opencl == s2->opencl &&
  153. s1->cpu_to_opencl == s2->cpu_to_opencl &&
  154. s1->opencl_to_cpu == s2->opencl_to_cpu &&
  155. #endif /* !STARPU_USE_OPENCL */
  156. 1 /* Just so the build does not fail if we disable EVERYTHING */
  157. )
  158. return 0;
  159. else
  160. return 1;
  161. }