debug.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2014,2016 Université de Bordeaux
  4. * Copyright (C) 2010,2011,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 __DEBUG_H__
  19. #define __DEBUG_H__
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <stdarg.h>
  23. #include <common/config.h>
  24. #include <core/workers.h>
  25. #if defined(STARPU_USE_AYUDAME1)
  26. /* Ayudame 1 API */
  27. # include <Ayudame.h>
  28. # ifndef AYU_RT_STARPU
  29. # define AYU_RT_STARPU 4
  30. # endif
  31. # define STARPU_AYU_EVENT AYU_event
  32. # define STARPU_AYU_PREINIT() \
  33. if (AYU_event) \
  34. { \
  35. enum ayu_runtime_t ayu_rt = AYU_RT_STARPU; \
  36. AYU_event(AYU_PREINIT, 0, (void*) &ayu_rt); \
  37. }
  38. # define STARPU_AYU_INIT() \
  39. if (AYU_event) \
  40. { \
  41. AYU_event(AYU_INIT, 0, NULL); \
  42. }
  43. # define STARPU_AYU_FINISH() \
  44. if (AYU_event) \
  45. { \
  46. AYU_event(AYU_FINISH, 0, NULL); \
  47. }
  48. # define STARPU_AYU_ADDDEPENDENCY(previous, handle, job_id) \
  49. if (AYU_event) \
  50. { \
  51. uintptr_t __AYU_data[3] = { (previous), (uintptr_t) (handle), (uintptr_t) (handle) }; \
  52. AYU_event(AYU_ADDDEPENDENCY, (job_id), __AYU_data); \
  53. }
  54. # define STARPU_AYU_REMOVETASK(job_id) \
  55. if (AYU_event) \
  56. { \
  57. AYU_event(AYU_REMOVETASK, (job_id), NULL); \
  58. }
  59. # define STARPU_AYU_ADDTASK(job_id, task) \
  60. if (AYU_event) \
  61. { \
  62. int64_t __AYU_data[2] = { \
  63. ((struct starpu_task *)(task))!=NULL?_starpu_ayudame_get_func_id(((struct starpu_task *)(task))->cl):0, \
  64. ((struct starpu_task *)(task))!=NULL?((struct starpu_task *)(task))->priority-STARPU_MIN_PRIO:0 \
  65. }; \
  66. AYU_event(AYU_ADDTASK, (job_id), __AYU_data); \
  67. }
  68. # define STARPU_AYU_PRERUNTASK(job_id, workerid) \
  69. if (AYU_event) \
  70. { \
  71. intptr_t __id = (workerid); \
  72. AYU_event(AYU_PRERUNTASK, (job_id), &__id); \
  73. }
  74. # define STARPU_AYU_RUNTASK(job_id) \
  75. if (AYU_event) \
  76. { \
  77. AYU_event(AYU_RUNTASK, (job_id), NULL); \
  78. }
  79. # define STARPU_AYU_POSTRUNTASK(job_id) \
  80. if (AYU_event) \
  81. { \
  82. AYU_event(AYU_POSTRUNTASK, (job_id), NULL); \
  83. }
  84. # define STARPU_AYU_ADDTOTASKQUEUE(job_id, worker_id) \
  85. if (AYU_event) \
  86. { \
  87. intptr_t __id = (worker_id); \
  88. AYU_event(AYU_ADDTASKTOQUEUE, (job_id), &__id); \
  89. }
  90. # define STARPU_AYU_BARRIER() \
  91. if (AYU_event) \
  92. { \
  93. AYU_event(AYU_BARRIER, 0, NULL); \
  94. }
  95. #elif defined(STARPU_USE_AYUDAME2)
  96. /* Ayudame 2 API */
  97. # include <ayudame.h>
  98. # define STARPU_AYU_EVENT ayu_event
  99. # define STARPU_AYU_PREINIT()
  100. # define STARPU_AYU_INIT()
  101. # define STARPU_AYU_FINISH() \
  102. if (ayu_event){ \
  103. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  104. ayu_event_data_t __data; \
  105. __data.common.client_id = __cli_id; \
  106. ayu_event(AYU_FINISH, __data); \
  107. }
  108. # define STARPU_AYU_ADDDEPENDENCY(previous, handle, job_id) \
  109. if (ayu_event) \
  110. { \
  111. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  112. ayu_event_data_t __data; \
  113. uint64_t __dep_id=0; \
  114. __dep_id |= (previous) << 0; \
  115. __dep_id |= (job_id) << 24; \
  116. __dep_id |= (uintptr_t) (handle) << 48; \
  117. __data.common.client_id = __cli_id; \
  118. __data.add_dependency.dependency_id = __dep_id; \
  119. __data.add_dependency.from_id=(previous); \
  120. __data.add_dependency.to_id=(job_id); \
  121. __data.add_dependency.dependency_label = "dep"; \
  122. ayu_event(AYU_ADDDEPENDENCY, __data); \
  123. ayu_wipe_data(&__data); \
  124. \
  125. char __buf[32]; \
  126. snprintf(__buf, sizeof(__buf), "%llu", (unsigned long long)(uintptr_t) (handle)); \
  127. __data.common.client_id = __cli_id; \
  128. __data.set_property.property_owner_id = __dep_id; \
  129. __data.set_property.key = "dep_address_value"; \
  130. __data.set_property.value = __buf; \
  131. ayu_event(AYU_SETPROPERTY, __data); \
  132. ayu_wipe_data(&__data); \
  133. }
  134. # define STARPU_AYU_REMOVETASK(job_id) \
  135. if (ayu_event) \
  136. { \
  137. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  138. ayu_event_data_t __data; \
  139. __data.common.client_id = __cli_id; \
  140. __data.set_property.property_owner_id = (job_id); \
  141. __data.set_property.key = "state"; \
  142. __data.set_property.value = "finished"; \
  143. ayu_event(AYU_SETPROPERTY, __data); \
  144. ayu_wipe_data(&__data); \
  145. }
  146. # define STARPU_AYU_ADDTASK(job_id, task) \
  147. if (ayu_event) \
  148. { \
  149. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  150. ayu_event_data_t __data; \
  151. __data.common.client_id = __cli_id; \
  152. __data.add_task.task_id = (job_id); \
  153. __data.add_task.scope_id = 0; \
  154. __data.add_task.task_label = "task"; \
  155. ayu_event(AYU_ADDTASK, __data); \
  156. ayu_wipe_data(&__data); \
  157. \
  158. if ((task) != NULL) \
  159. { \
  160. char __buf[32]; \
  161. snprintf(__buf, sizeof(__buf), "%d", ((struct starpu_task *)(task))->priority); \
  162. __data.common.client_id = __cli_id; \
  163. __data.set_property.property_owner_id = (job_id); \
  164. __data.set_property.key = "priority"; \
  165. __data.set_property.value = __buf; \
  166. ayu_event(AYU_SETPROPERTY, __data); \
  167. ayu_wipe_data(&__data); \
  168. \
  169. const char *__name = ((struct starpu_task *)(task))->name != NULL?((struct starpu_task *)(task))->name: \
  170. ((struct starpu_task *)(task))->cl->name != NULL?((struct starpu_task *)(task))->cl->name:"<no_name>"; \
  171. __data.common.client_id = __cli_id; \
  172. __data.set_property.property_owner_id = (job_id); \
  173. __data.set_property.key = "function_name"; \
  174. __data.set_property.value = __name; \
  175. ayu_event(AYU_SETPROPERTY, __data); \
  176. ayu_wipe_data(&__data); \
  177. } \
  178. }
  179. # define STARPU_AYU_PRERUNTASK(job_id, workerid) \
  180. if (ayu_event) \
  181. { \
  182. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  183. ayu_event_data_t __data; \
  184. __data.common.client_id = __cli_id; \
  185. __data.set_property.property_owner_id = (job_id); \
  186. __data.set_property.key = "state"; \
  187. __data.set_property.value = "running"; \
  188. ayu_event(AYU_SETPROPERTY, __data); \
  189. ayu_wipe_data(&__data); \
  190. \
  191. char __buf[32]; \
  192. snprintf(__buf, sizeof(__buf), "%d", (workerid)); \
  193. __data.common.client_id = __cli_id; \
  194. __data.set_property.property_owner_id = (job_id); \
  195. __data.set_property.key = "worker"; \
  196. __data.set_property.value = __buf; \
  197. ayu_event(AYU_SETPROPERTY, __data); \
  198. ayu_wipe_data(&__data); \
  199. }
  200. # define STARPU_AYU_RUNTASK(job_id) \
  201. if (ayu_event) { \
  202. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  203. ayu_event_data_t __data; \
  204. __data.common.client_id = __cli_id; \
  205. __data.set_property.property_owner_id = (job_id); \
  206. __data.set_property.key = "state"; \
  207. __data.set_property.value = "running"; \
  208. ayu_event(AYU_SETPROPERTY, __data); \
  209. ayu_wipe_data(&__data); \
  210. }
  211. # define STARPU_AYU_POSTRUNTASK(job_id) \
  212. if (ayu_event) \
  213. { \
  214. /* TODO ADD thread id core id etc */ \
  215. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  216. ayu_event_data_t __data; \
  217. __data.common.client_id = __cli_id; \
  218. __data.set_property.property_owner_id = (job_id); \
  219. __data.set_property.key = "state"; \
  220. __data.set_property.value = "finished"; \
  221. ayu_event(AYU_SETPROPERTY, __data); \
  222. ayu_wipe_data(&__data); \
  223. }
  224. # define STARPU_AYU_ADDTOTASKQUEUE(job_id, worker_id) \
  225. if (ayu_event) \
  226. { \
  227. ayu_client_id_t __cli_id = get_client_id(AYU_CLIENT_STARPU); \
  228. ayu_event_data_t __data; \
  229. __data.common.client_id = __cli_id; \
  230. __data.set_property.property_owner_id = (job_id); \
  231. __data.set_property.key = "state"; \
  232. __data.set_property.value = "queued"; \
  233. ayu_event(AYU_SETPROPERTY, __data); \
  234. ayu_wipe_data(&__data); \
  235. \
  236. char __buf[32]; \
  237. snprintf(__buf, sizeof(__buf), "%d", (int)(worker_id)); \
  238. __data.common.client_id = __cli_id; \
  239. __data.set_property.property_owner_id = (job_id); \
  240. __data.set_property.key = "worker"; \
  241. __data.set_property.value = __buf; \
  242. ayu_event(AYU_SETPROPERTY, __data); \
  243. ayu_wipe_data(&__data); \
  244. }
  245. # define STARPU_AYU_BARRIER() \
  246. if (ayu_event) \
  247. { \
  248. /* How to generate a barrier event with Ayudame 2? */ \
  249. }
  250. #else
  251. # define STARPU_AYU_EVENT (0)
  252. # define STARPU_AYU_PREINIT()
  253. # define STARPU_AYU_INIT()
  254. # define STARPU_AYU_FINISH()
  255. # define STARPU_AYU_ADDDEPENDENCY(previous, handle, next_job)
  256. # define STARPU_AYU_REMOVETASK(job_id)
  257. # define STARPU_AYU_ADDTASK(job_id, task)
  258. # define STARPU_AYU_PRERUNTASK(job_id, workerid)
  259. # define STARPU_AYU_RUNTASK(job_id)
  260. # define STARPU_AYU_POSTRUNTASK(job_id)
  261. # define STARPU_AYU_ADDTOTASKQUEUE(job_id, worker_id)
  262. # define STARPU_AYU_BARRIER()
  263. #endif
  264. /* Create a file that will contain StarPU's log */
  265. void _starpu_open_debug_logfile(void);
  266. /* Close StarPU's log file */
  267. void _starpu_close_debug_logfile(void);
  268. /* Write into StarPU's log file */
  269. void _starpu_print_to_logfile(const char *format, ...) STARPU_ATTRIBUTE_FORMAT(printf, 1, 2);
  270. /* Tell gdb whether FXT is compiled in or not */
  271. extern int _starpu_use_fxt;
  272. #if defined(STARPU_USE_AYUDAME1)
  273. /* Get an Ayudame id for CL */
  274. int64_t _starpu_ayudame_get_func_id(struct starpu_codelet *cl);
  275. #endif
  276. void _starpu_watchdog_init(void);
  277. void _starpu_watchdog_shutdown(void);
  278. #endif // __DEBUG_H__