generic.c 3.7 KB

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