generic.c 3.7 KB

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