starpu_profiling.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2013 CNRS
  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. #ifndef __STARPU_PROFILING_H__
  18. #define __STARPU_PROFILING_H__
  19. #include <starpu.h>
  20. #include <errno.h>
  21. #include <time.h>
  22. #include <starpu_util.h>
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #define STARPU_PROFILING_DISABLE 0
  28. #define STARPU_PROFILING_ENABLE 1
  29. struct starpu_profiling_task_info
  30. {
  31. struct timespec submit_time;
  32. struct timespec push_start_time;
  33. struct timespec push_end_time;
  34. struct timespec pop_start_time;
  35. struct timespec pop_end_time;
  36. struct timespec acquire_data_start_time;
  37. struct timespec acquire_data_end_time;
  38. struct timespec start_time;
  39. struct timespec end_time;
  40. struct timespec release_data_start_time;
  41. struct timespec release_data_end_time;
  42. struct timespec callback_start_time;
  43. struct timespec callback_end_time;
  44. /* TODO add expected length, expected start/end ? */
  45. int workerid;
  46. uint64_t used_cycles;
  47. uint64_t stall_cycles;
  48. double energy_consumed;
  49. };
  50. struct starpu_profiling_worker_info
  51. {
  52. struct timespec start_time;
  53. struct timespec total_time;
  54. struct timespec executing_time;
  55. struct timespec sleeping_time;
  56. int executed_tasks;
  57. uint64_t used_cycles;
  58. uint64_t stall_cycles;
  59. double energy_consumed;
  60. double flops;
  61. };
  62. struct starpu_profiling_bus_info
  63. {
  64. struct timespec start_time;
  65. struct timespec total_time;
  66. int long long transferred_bytes;
  67. int transfer_count;
  68. };
  69. void starpu_profiling_init(void);
  70. void starpu_profiling_set_id(int new_id);
  71. int starpu_profiling_status_set(int status);
  72. int starpu_profiling_status_get(void);
  73. #ifdef BUILDING_STARPU
  74. #include <common/utils.h>
  75. #ifdef __GNUC__
  76. extern int _starpu_profiling;
  77. #define starpu_profiling_status_get() ({ \
  78. int __ret; \
  79. ANNOTATE_HAPPENS_AFTER(&_starpu_profiling); \
  80. __ret = _starpu_profiling; \
  81. ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling); \
  82. __ret; \
  83. })
  84. #endif
  85. #endif
  86. int starpu_profiling_worker_get_info(int workerid, struct starpu_profiling_worker_info *worker_info);
  87. int starpu_bus_get_count(void);
  88. int starpu_bus_get_id(int src, int dst);
  89. int starpu_bus_get_src(int busid);
  90. int starpu_bus_get_dst(int busid);
  91. void starpu_bus_set_direct(int busid, int direct);
  92. int starpu_bus_get_direct(int busid);
  93. void starpu_bus_set_ngpus(int busid, int ngpus);
  94. int starpu_bus_get_ngpus(int busid);
  95. int starpu_bus_get_profiling_info(int busid, struct starpu_profiling_bus_info *bus_info);
  96. /* Some helper functions to manipulate profiling API output */
  97. /* Reset timespec */
  98. static __starpu_inline void starpu_timespec_clear(struct timespec *tsp)
  99. {
  100. tsp->tv_sec = 0;
  101. tsp->tv_nsec = 0;
  102. }
  103. /* Computes result = a + b */
  104. static __starpu_inline void starpu_timespec_add(struct timespec *a,
  105. struct timespec *b,
  106. struct timespec *result)
  107. {
  108. result->tv_sec = a->tv_sec + b->tv_sec;
  109. result->tv_nsec = a->tv_nsec + b->tv_nsec;
  110. if (result->tv_nsec >= 1000000000)
  111. {
  112. ++(result)->tv_sec;
  113. result->tv_nsec -= 1000000000;
  114. }
  115. }
  116. /* Computes res += b */
  117. static __starpu_inline void starpu_timespec_accumulate(struct timespec *result,
  118. struct timespec *a)
  119. {
  120. result->tv_sec += a->tv_sec;
  121. result->tv_nsec += a->tv_nsec;
  122. if (result->tv_nsec >= 1000000000)
  123. {
  124. ++(result)->tv_sec;
  125. result->tv_nsec -= 1000000000;
  126. }
  127. }
  128. /* Computes result = a - b */
  129. static __starpu_inline void starpu_timespec_sub(const struct timespec *a,
  130. const struct timespec *b,
  131. struct timespec *result)
  132. {
  133. result->tv_sec = a->tv_sec - b->tv_sec;
  134. result->tv_nsec = a->tv_nsec - b->tv_nsec;
  135. if ((result)->tv_nsec < 0)
  136. {
  137. --(result)->tv_sec;
  138. result->tv_nsec += 1000000000;
  139. }
  140. }
  141. #define starpu_timespec_cmp(a, b, CMP) \
  142. (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec CMP (b)->tv_nsec) : ((a)->tv_sec CMP (b)->tv_sec))
  143. double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);
  144. double starpu_timing_timespec_to_us(struct timespec *ts);
  145. void starpu_profiling_bus_helper_display_summary(void);
  146. void starpu_profiling_worker_helper_display_summary(void);
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif /* __STARPU_PROFILING_H__ */