starpu_profiling.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014,2016-2017 Université de Bordeaux
  4. * Copyright (C) 2010-2011,2013,2015,2017 CNRS
  5. * Copyright (C) 2016 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_PROFILING_H__
  19. #define __STARPU_PROFILING_H__
  20. #include <starpu.h>
  21. #include <errno.h>
  22. #include <time.h>
  23. #include <starpu_util.h>
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #define STARPU_PROFILING_DISABLE 0
  29. #define STARPU_PROFILING_ENABLE 1
  30. struct starpu_profiling_task_info
  31. {
  32. struct timespec submit_time;
  33. struct timespec push_start_time;
  34. struct timespec push_end_time;
  35. struct timespec pop_start_time;
  36. struct timespec pop_end_time;
  37. struct timespec acquire_data_start_time;
  38. struct timespec acquire_data_end_time;
  39. struct timespec start_time;
  40. struct timespec end_time;
  41. struct timespec release_data_start_time;
  42. struct timespec release_data_end_time;
  43. struct timespec callback_start_time;
  44. struct timespec callback_end_time;
  45. /* TODO add expected length, expected start/end ? */
  46. int workerid;
  47. uint64_t used_cycles;
  48. uint64_t stall_cycles;
  49. double energy_consumed;
  50. };
  51. struct starpu_profiling_worker_info
  52. {
  53. struct timespec start_time;
  54. struct timespec total_time;
  55. struct timespec executing_time;
  56. struct timespec sleeping_time;
  57. int executed_tasks;
  58. uint64_t used_cycles;
  59. uint64_t stall_cycles;
  60. double energy_consumed;
  61. double flops;
  62. };
  63. struct starpu_profiling_bus_info
  64. {
  65. struct timespec start_time;
  66. struct timespec total_time;
  67. int long long transferred_bytes;
  68. int transfer_count;
  69. };
  70. void starpu_profiling_init(void);
  71. void starpu_profiling_set_id(int new_id);
  72. int starpu_profiling_status_set(int status);
  73. int starpu_profiling_status_get(void);
  74. #ifdef BUILDING_STARPU
  75. #include <common/utils.h>
  76. #ifdef __GNUC__
  77. extern int _starpu_profiling;
  78. #define starpu_profiling_status_get() ({ \
  79. int __ret; \
  80. ANNOTATE_HAPPENS_AFTER(&_starpu_profiling); \
  81. __ret = _starpu_profiling; \
  82. ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling); \
  83. __ret; \
  84. })
  85. #endif
  86. #endif
  87. int starpu_profiling_worker_get_info(int workerid, struct starpu_profiling_worker_info *worker_info);
  88. int starpu_bus_get_count(void);
  89. int starpu_bus_get_id(int src, int dst);
  90. int starpu_bus_get_src(int busid);
  91. int starpu_bus_get_dst(int busid);
  92. void starpu_bus_set_direct(int busid, int direct);
  93. int starpu_bus_get_direct(int busid);
  94. void starpu_bus_set_ngpus(int busid, int ngpus);
  95. int starpu_bus_get_ngpus(int busid);
  96. int starpu_bus_get_profiling_info(int busid, struct starpu_profiling_bus_info *bus_info);
  97. /* Some helper functions to manipulate profiling API output */
  98. /* Reset timespec */
  99. static __starpu_inline void starpu_timespec_clear(struct timespec *tsp)
  100. {
  101. tsp->tv_sec = 0;
  102. tsp->tv_nsec = 0;
  103. }
  104. #define STARPU_NS_PER_S 1000000000
  105. /* Computes result = a + b */
  106. static __starpu_inline void starpu_timespec_add(struct timespec *a,
  107. struct timespec *b,
  108. struct timespec *result)
  109. {
  110. result->tv_sec = a->tv_sec + b->tv_sec;
  111. result->tv_nsec = a->tv_nsec + b->tv_nsec;
  112. if (result->tv_nsec >= STARPU_NS_PER_S)
  113. {
  114. ++(result)->tv_sec;
  115. result->tv_nsec -= STARPU_NS_PER_S;
  116. }
  117. }
  118. /* Computes res += b */
  119. static __starpu_inline void starpu_timespec_accumulate(struct timespec *result,
  120. struct timespec *a)
  121. {
  122. result->tv_sec += a->tv_sec;
  123. result->tv_nsec += a->tv_nsec;
  124. if (result->tv_nsec >= STARPU_NS_PER_S)
  125. {
  126. ++(result)->tv_sec;
  127. result->tv_nsec -= STARPU_NS_PER_S;
  128. }
  129. }
  130. /* Computes result = a - b */
  131. static __starpu_inline void starpu_timespec_sub(const struct timespec *a,
  132. const struct timespec *b,
  133. struct timespec *result)
  134. {
  135. result->tv_sec = a->tv_sec - b->tv_sec;
  136. result->tv_nsec = a->tv_nsec - b->tv_nsec;
  137. if ((result)->tv_nsec < 0)
  138. {
  139. --(result)->tv_sec;
  140. result->tv_nsec += STARPU_NS_PER_S;
  141. }
  142. }
  143. #define starpu_timespec_cmp(a, b, CMP) \
  144. (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec CMP (b)->tv_nsec) : ((a)->tv_sec CMP (b)->tv_sec))
  145. double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);
  146. double starpu_timing_timespec_to_us(struct timespec *ts);
  147. void starpu_profiling_bus_helper_display_summary(void);
  148. void starpu_profiling_worker_helper_display_summary(void);
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* __STARPU_PROFILING_H__ */