generic.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. struct starpu_multiformat_data_interface_ops ops =
  83. {
  84. #ifdef STARPU_USE_CUDA
  85. .cuda_elemsize = sizeof(int),
  86. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  87. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  88. #endif
  89. #ifdef STARPU_USE_OPENCL
  90. .opencl_elemsize = sizeof(int),
  91. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  92. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  93. #endif
  94. .cpu_elemsize = sizeof(int)
  95. };
  96. void
  97. print_stats(struct stats *s)
  98. {
  99. #ifdef STARPU_USE_CPU
  100. FPRINTF(stderr, "cpu : %u\n", s->cpu);
  101. #endif /* !STARPU_USE_CPU */
  102. #ifdef STARPU_USE_CUDA
  103. FPRINTF(stderr, "cuda : %u\n"
  104. "cpu->cuda : %u\n"
  105. "cuda->cpu : %u\n",
  106. s->cuda,
  107. s->cpu_to_cuda,
  108. s->cuda_to_cpu);
  109. #endif /* !STARPU_USE_CUDA */
  110. #ifdef STARPU_USE_OPENCL
  111. FPRINTF(stderr, "opencl : %u\n"
  112. "cpu->opencl : %u\n"
  113. "opencl->cpu : %u\n",
  114. s->opencl,
  115. s->cpu_to_opencl,
  116. s->opencl_to_cpu);
  117. #endif /* !STARPU_USE_OPENCL */
  118. }
  119. void reset_stats(struct stats *s)
  120. {
  121. #ifdef STARPU_USE_CPU
  122. s->cpu = 0;
  123. #endif /* !STARPU_USE_CPU */
  124. #ifdef STARPU_USE_CUDA
  125. s->cuda = 0;
  126. s->cpu_to_cuda = 0;
  127. s->cuda_to_cpu = 0;
  128. #endif /* !STARPU_USE_CUDA */
  129. #ifdef STARPU_USE_OPENCL
  130. s->opencl = 0;
  131. s->cpu_to_opencl = 0;
  132. s->opencl_to_cpu = 0;
  133. #endif /* !STARPU_USE_OPENCL */
  134. }
  135. int
  136. compare_stats(struct stats *s1, struct stats *s2)
  137. {
  138. if (
  139. #ifdef STARPU_USE_CPU
  140. s1->cpu == s2->cpu &&
  141. #endif /* !STARPU_USE_CPU */
  142. #ifdef STARPU_USE_CUDA
  143. s1->cuda == s2->cuda &&
  144. s1->cpu_to_cuda == s2->cpu_to_cuda &&
  145. s1->cuda_to_cpu == s2->cuda_to_cpu &&
  146. #endif /* !STARPU_USE_CUDA */
  147. #ifdef STARPU_USE_OPENCL
  148. s1->opencl == s2->opencl &&
  149. s1->cpu_to_opencl == s2->cpu_to_opencl &&
  150. s1->opencl_to_cpu == s2->opencl_to_cpu &&
  151. #endif /* !STARPU_USE_OPENCL */
  152. 1 /* Just so the build does not fail if we disable EVERYTHING */
  153. )
  154. return 0;
  155. else
  156. return 1;
  157. }