datastats.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <datawizard/datastats.h>
  19. #include <datawizard/coherency.h>
  20. #include <common/config.h>
  21. #ifdef STARPU_ENABLE_STATS
  22. /* measure the cache hit ratio for each node */
  23. static unsigned hit_cnt[STARPU_MAXNODES];
  24. static unsigned miss_cnt[STARPU_MAXNODES];
  25. #endif
  26. void _starpu_msi_cache_hit(unsigned node STARPU_ATTRIBUTE_UNUSED)
  27. {
  28. #ifdef STARPU_ENABLE_STATS
  29. STARPU_HG_DISABLE_CHECKING(hit_cnt[node]);
  30. hit_cnt[node]++;
  31. #endif
  32. }
  33. void _starpu_msi_cache_miss(unsigned node STARPU_ATTRIBUTE_UNUSED)
  34. {
  35. #ifdef STARPU_ENABLE_STATS
  36. STARPU_HG_DISABLE_CHECKING(miss_cnt[node]);
  37. miss_cnt[node]++;
  38. #endif
  39. }
  40. void _starpu_display_msi_stats(void)
  41. {
  42. #ifdef STARPU_ENABLE_STATS
  43. unsigned node;
  44. unsigned total_hit_cnt = 0;
  45. unsigned total_miss_cnt = 0;
  46. fprintf(stderr, "\n#---------------------\n");
  47. fprintf(stderr, "MSI cache stats :\n");
  48. for (node = 0; node < STARPU_MAXNODES; node++)
  49. {
  50. total_hit_cnt += hit_cnt[node];
  51. total_miss_cnt += miss_cnt[node];
  52. }
  53. fprintf(stderr, "TOTAL MSI stats\thit %u (%2.2f \%%)\tmiss %u (%2.2f \%%)\n", total_hit_cnt, (100.0f*total_hit_cnt)/(total_hit_cnt+total_miss_cnt), total_miss_cnt, (100.0f*total_miss_cnt)/(total_hit_cnt+total_miss_cnt));
  54. for (node = 0; node < STARPU_MAXNODES; node++)
  55. {
  56. if (hit_cnt[node]+miss_cnt[node])
  57. {
  58. fprintf(stderr, "memory node %d\n", node);
  59. fprintf(stderr, "\thit : %u (%2.2f \%%)\n", hit_cnt[node], (100.0f*hit_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  60. fprintf(stderr, "\tmiss : %u (%2.2f \%%)\n", miss_cnt[node], (100.0f*miss_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  61. }
  62. }
  63. fprintf(stderr, "#---------------------\n");
  64. #endif
  65. }
  66. /* measure the efficiency of our allocation cache */
  67. #ifdef STARPU_ENABLE_STATS
  68. static unsigned alloc_cnt[STARPU_MAXNODES];
  69. static unsigned alloc_cache_hit_cnt[STARPU_MAXNODES];
  70. #endif
  71. void _starpu_allocation_cache_hit(unsigned node STARPU_ATTRIBUTE_UNUSED)
  72. {
  73. #ifdef STARPU_ENABLE_STATS
  74. STARPU_HG_DISABLE_CHECKING(alloc_cache_hit_cnt[node]);
  75. alloc_cache_hit_cnt[node]++;
  76. #endif
  77. }
  78. void _starpu_data_allocation_inc_stats(unsigned node STARPU_ATTRIBUTE_UNUSED)
  79. {
  80. #ifdef STARPU_ENABLE_STATS
  81. STARPU_HG_DISABLE_CHECKING(alloc_cnt[node]);
  82. alloc_cnt[node]++;
  83. #endif
  84. }
  85. void _starpu_display_alloc_cache_stats(void)
  86. {
  87. #ifdef STARPU_ENABLE_STATS
  88. fprintf(stderr, "\n#---------------------\n");
  89. fprintf(stderr, "Allocation cache stats:\n");
  90. unsigned node;
  91. for (node = 0; node < STARPU_MAXNODES; node++)
  92. {
  93. if (alloc_cnt[node])
  94. {
  95. fprintf(stderr, "memory node %d\n", node);
  96. fprintf(stderr, "\ttotal alloc : %u\n", alloc_cnt[node]);
  97. fprintf(stderr, "\tcached alloc: %u (%2.2f \%%)\n",
  98. alloc_cache_hit_cnt[node], (100.0f*alloc_cache_hit_cnt[node])/(alloc_cnt[node]));
  99. }
  100. else
  101. fprintf(stderr, "No allocation on node %d\n", node);
  102. }
  103. fprintf(stderr, "#---------------------\n");
  104. #endif
  105. }
  106. /* measure the amount of data transfers between each pair of nodes */
  107. #ifdef STARPU_ENABLE_STATS
  108. static size_t comm_amount[STARPU_MAXNODES][STARPU_MAXNODES];
  109. #endif /* STARPU_ENABLE_STATS */
  110. void _starpu_comm_amounts_inc(unsigned src STARPU_ATTRIBUTE_UNUSED, unsigned dst STARPU_ATTRIBUTE_UNUSED, size_t size STARPU_ATTRIBUTE_UNUSED)
  111. {
  112. #ifdef STARPU_ENABLE_STATS
  113. STARPU_HG_DISABLE_CHECKING(comm_amount[src][dst]);
  114. comm_amount[src][dst] += size;
  115. #endif /* STARPU_ENABLE_STATS */
  116. }
  117. void _starpu_display_comm_amounts(void)
  118. {
  119. #ifdef STARPU_DEVEL
  120. # warning TODO. The information displayed here seems to be similar to the one displayed by starpu_profiling_bus_helper_display_summary()
  121. #endif
  122. #ifdef STARPU_ENABLE_STATS
  123. unsigned src, dst;
  124. size_t sum = 0;
  125. fprintf(stderr, "\n#---------------------\n");
  126. fprintf(stderr, "Data transfer stats:\n");
  127. for (dst = 0; dst < STARPU_MAXNODES; dst++)
  128. for (src = 0; src < STARPU_MAXNODES; src++)
  129. {
  130. sum += comm_amount[src][dst];
  131. sum += comm_amount[dst][src];
  132. }
  133. fprintf(stderr, "TOTAL transfers %f MB\n", (float)sum/1024/1024);
  134. for (dst = 0; dst < STARPU_MAXNODES; dst++)
  135. for (src = dst + 1; src < STARPU_MAXNODES; src++)
  136. {
  137. if (comm_amount[src][dst])
  138. fprintf(stderr, "\t%d <-> %d\t%f MB\n\t\t%d -> %d\t%f MB\n\t\t%d -> %d\t%f MB\n",
  139. src, dst, ((float)comm_amount[src][dst] + (float)comm_amount[dst][src])/(1024*1024),
  140. src, dst, ((float)comm_amount[src][dst])/(1024*1024),
  141. dst, src, ((float)comm_amount[dst][src])/(1024*1024));
  142. }
  143. fprintf(stderr, "#---------------------\n");
  144. #endif
  145. }