generic.c 3.8 KB

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