starpurm.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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. #ifndef __STARPURM_H
  17. #define __STARPURM_H
  18. #include <hwloc.h>
  19. #include <starpurm_config.h>
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. /**
  25. @defgroup API_Interop_Support Interoperability Support
  26. @brief This section describes the interface supplied by StarPU to
  27. interoperate with other runtime systems.
  28. @{
  29. */
  30. /**
  31. StarPU Resource Manager return type.
  32. */
  33. enum e_starpurm_drs_ret
  34. {
  35. /**
  36. Dynamic resource sharing operation succeeded.
  37. */
  38. starpurm_DRS_SUCCESS = 0,
  39. /**
  40. Dynamic resource sharing is disabled.
  41. */
  42. starpurm_DRS_DISABLD = -1,
  43. /**
  44. Dynamic resource sharing operation is not authorized or
  45. implemented.
  46. */
  47. starpurm_DRS_PERM = -2,
  48. /**
  49. Dynamic resource sharing operation has been called with one
  50. or more invalid parameters.
  51. */
  52. starpurm_DRS_EINVAL = -3
  53. #if 0
  54. /* Unused for now */
  55. starpurm_DRS_NOTED,
  56. starpurm_DRS_REQST
  57. #endif
  58. };
  59. typedef int starpurm_drs_ret_t;
  60. typedef void *starpurm_drs_desc_t;
  61. typedef void *starpurm_drs_cbs_t;
  62. typedef void (*starpurm_drs_cb_t)(void *);
  63. typedef void *starpurm_block_cond_t;
  64. typedef int (*starpurm_polling_t)(void *);
  65. /**
  66. @name Initialisation
  67. @{
  68. */
  69. /**
  70. Resource enforcement
  71. */
  72. void starpurm_initialize_with_cpuset(hwloc_cpuset_t initially_owned_cpuset);
  73. /**
  74. Initialize StarPU and the StarPU-RM resource management module. The
  75. starpu_init() function should not have been called before the call
  76. to starpurm_initialize(). The starpurm_initialize() function will
  77. take care of this
  78. */
  79. void starpurm_initialize(void);
  80. /**
  81. Shutdown StarPU-RM and StarPU. The starpu_shutdown() function
  82. should not be called before. The starpurm_shutdown() function will
  83. take care of this.
  84. */
  85. void starpurm_shutdown(void);
  86. /** @} */
  87. /**
  88. @name Spawn
  89. @{
  90. */
  91. /**
  92. Allocate a temporary context spanning the units selected in the
  93. cpuset bitmap, set it as the default context for the current
  94. thread, and call user function \p f. Upon the return of user
  95. function \p f, the temporary context is freed and the previous
  96. default context for the current thread is restored.
  97. */
  98. void starpurm_spawn_kernel_on_cpus(void *data, void(*f)(void *), void *args, hwloc_cpuset_t cpuset);
  99. /**
  100. Spawn a POSIX thread and returns immediately. The thread spawned
  101. will allocate a temporary context spanning the units selected in
  102. the cpuset bitmap, set it as the default context for the current
  103. thread, and call user function \p f. Upon the return of user
  104. function \p f, the temporary context will be freed and the previous
  105. default context for the current thread restored. A user specified
  106. callback \p cb_f will be called just before the termination of the
  107. thread.
  108. */
  109. void starpurm_spawn_kernel_on_cpus_callback(void *data, void(*f)(void *), void *args, hwloc_cpuset_t cpuset, void(*cb_f)(void *), void *cb_args);
  110. void starpurm_spawn_kernel_callback(void *data, void(*f)(void *), void *args, void(*cb_f)(void *), void *cb_args);
  111. /** @} */
  112. /**
  113. @name DynamicResourceSharing
  114. @{
  115. */
  116. /**
  117. Turn-on dynamic resource sharing support.
  118. */
  119. starpurm_drs_ret_t starpurm_set_drs_enable(starpurm_drs_desc_t *spd);
  120. /**
  121. Turn-off dynamic resource sharing support.
  122. */
  123. starpurm_drs_ret_t starpurm_set_drs_disable(starpurm_drs_desc_t *spd);
  124. /**
  125. Return the state of the dynamic resource sharing support (\p =!0
  126. enabled, \p =0 disabled).
  127. */
  128. int starpurm_drs_enabled_p(void);
  129. /**
  130. Set the maximum number of CPU computing units available for StarPU
  131. computations to \p max. This number cannot exceed the maximum
  132. number of StarPU's CPU worker allocated at start-up time.
  133. */
  134. starpurm_drs_ret_t starpurm_set_max_parallelism(starpurm_drs_desc_t *spd, int max);
  135. #if 0
  136. /* Unused for now */
  137. starpurm_drs_ret_t starpurm_callback_set(starpurm_drs_desc_t *spd, starpurm_drs_cbs_t which, starpurm_drs_cb_t callback);
  138. starpurm_drs_ret_t starpurm_callback_get(starpurm_drs_desc_t *spd, starpurm_drs_cbs_t which, starpurm_drs_cb_t *callback);
  139. #endif
  140. /**
  141. Extend StarPU's default scheduling context to execute tasks on
  142. worker corresponding to logical unit \p cpuid. If StarPU does not
  143. have a worker thread initialized for logical unit \p cpuid, do
  144. nothing.
  145. */
  146. starpurm_drs_ret_t starpurm_assign_cpu_to_starpu(starpurm_drs_desc_t *spd, int cpuid);
  147. /**
  148. Extend StarPU's default scheduling context to execute tasks on \p
  149. ncpus more workers, up to the number of StarPU worker threads
  150. initialized.
  151. */
  152. starpurm_drs_ret_t starpurm_assign_cpus_to_starpu(starpurm_drs_desc_t *spd, int ncpus);
  153. /**
  154. Extend StarPU's default scheduling context to execute tasks on the
  155. additional logical units selected in \p mask. Logical units of \p
  156. mask for which no StarPU worker is initialized are silently ignored.
  157. */
  158. starpurm_drs_ret_t starpurm_assign_cpu_mask_to_starpu(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  159. /**
  160. Set StarPU's default scheduling context to execute tasks on all
  161. available logical units for which a StarPU worker has been
  162. initialized.
  163. */
  164. starpurm_drs_ret_t starpurm_assign_all_cpus_to_starpu(starpurm_drs_desc_t *spd);
  165. /**
  166. Shrink StarPU's default scheduling context so as to not execute
  167. tasks on worker corresponding to logical unit \p cpuid. If StarPU
  168. does not have a worker thread initialized for logical unit \p
  169. cpuid, do nothing.
  170. */
  171. starpurm_drs_ret_t starpurm_withdraw_cpu_from_starpu(starpurm_drs_desc_t *spd, int cpuid);
  172. /**
  173. Shrink StarPU's default scheduling context to execute tasks on \p
  174. ncpus less workers.
  175. */
  176. starpurm_drs_ret_t starpurm_withdraw_cpus_from_starpu(starpurm_drs_desc_t *spd, int ncpus);
  177. /**
  178. Shrink StarPU's default scheduling context so as to not execute
  179. tasks on the logical units selected in \p mask. Logical units of \p
  180. mask for which no StarPU worker is initialized are silently ignored.
  181. */
  182. starpurm_drs_ret_t starpurm_withdraw_cpu_mask_from_starpu(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  183. /**
  184. Shrink StarPU's default scheduling context so as to remove all
  185. logical units.
  186. */
  187. starpurm_drs_ret_t starpurm_withdraw_all_cpus_from_starpu(starpurm_drs_desc_t *spd);
  188. /* --- */
  189. /**
  190. Synonym for starpurm_assign_all_cpus_to_starpu().
  191. */
  192. starpurm_drs_ret_t starpurm_lend(starpurm_drs_desc_t *spd);
  193. /**
  194. Synonym for starpurm_assign_cpu_to_starpu().
  195. */
  196. starpurm_drs_ret_t starpurm_lend_cpu(starpurm_drs_desc_t *spd, int cpuid);
  197. /**
  198. Synonym for starpurm_assign_cpus_to_starpu().
  199. */
  200. starpurm_drs_ret_t starpurm_lend_cpus(starpurm_drs_desc_t *spd, int ncpus);
  201. /**
  202. Synonym for starpurm_assign_cpu_mask_to_starpu().
  203. */
  204. starpurm_drs_ret_t starpurm_lend_cpu_mask(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  205. /**
  206. Synonym for starpurm_withdraw_all_cpus_from_starpu().
  207. */
  208. starpurm_drs_ret_t starpurm_reclaim(starpurm_drs_desc_t *spd);
  209. /**
  210. Synonym for starpurm_withdraw_cpu_from_starpu().
  211. */
  212. starpurm_drs_ret_t starpurm_reclaim_cpu(starpurm_drs_desc_t *spd, int cpuid);
  213. /**
  214. Synonym for starpurm_withdraw_cpus_from_starpu().
  215. */
  216. starpurm_drs_ret_t starpurm_reclaim_cpus(starpurm_drs_desc_t *spd, int ncpus);
  217. /**
  218. Synonym for starpurm_withdraw_cpu_mask_from_starpu().
  219. */
  220. starpurm_drs_ret_t starpurm_reclaim_cpu_mask(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  221. /**
  222. Synonym for starpurm_withdraw_all_cpus_from_starpu().
  223. */
  224. starpurm_drs_ret_t starpurm_acquire(starpurm_drs_desc_t *spd);
  225. /**
  226. Synonym for starpurm_withdraw_cpu_from_starpu().
  227. */
  228. starpurm_drs_ret_t starpurm_acquire_cpu(starpurm_drs_desc_t *spd, int cpuid);
  229. /**
  230. Synonym for starpurm_withdraw_cpus_from_starpu().
  231. */
  232. starpurm_drs_ret_t starpurm_acquire_cpus(starpurm_drs_desc_t *spd, int ncpus);
  233. /**
  234. Synonym for starpurm_withdraw_cpu_mask_from_starpu().
  235. */
  236. starpurm_drs_ret_t starpurm_acquire_cpu_mask(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  237. /**
  238. Synonym for starpurm_assign_all_cpus_to_starpu().
  239. */
  240. starpurm_drs_ret_t starpurm_return_all(starpurm_drs_desc_t *spd);
  241. /**
  242. Synonym for starpurm_assign_cpu_to_starpu().
  243. */
  244. starpurm_drs_ret_t starpurm_return_cpu(starpurm_drs_desc_t *spd, int cpuid);
  245. #if 0
  246. /* Pause/resume (not implemented) */
  247. starpurm_drs_ret_t starpurm_create_block_condition(starpurm_block_cond_t *cond);
  248. void starpurm_block_current_task(starpurm_block_cond_t *cond);
  249. void starpurm_signal_block_condition(starpurm_block_cond_t *cond);
  250. void starpurm_register_polling_service(const char *service_name, starpurm_polling_t function, void *data);
  251. void starpurm_unregister_polling_service(const char *service_name, starpurm_polling_t function, void *data);
  252. #endif
  253. /** @} */
  254. /**
  255. @name Devices
  256. @{
  257. */
  258. /**
  259. Return the device type ID constant associated to the device type name.
  260. Valid names for \p type_str are:
  261. - \c "cpu": regular CPU unit;
  262. - \c "opencl": OpenCL device unit;
  263. - \c "cuda": nVidia CUDA device unit;
  264. - \c "mic": Intel KNC type device unit.
  265. */
  266. int starpurm_get_device_type_id(const char *type_str);
  267. /**
  268. Return the device type name associated to the device type ID
  269. constant.
  270. */
  271. const char *starpurm_get_device_type_name(int type_id);
  272. /**
  273. Return the number of initialized StarPU worker for the device type
  274. \p type_id.
  275. */
  276. int starpurm_get_nb_devices_by_type(int type_id);
  277. /**
  278. Return the unique ID assigned to the \p device_rank nth device of
  279. type \p type_id.
  280. */
  281. int starpurm_get_device_id(int type_id, int device_rank);
  282. /**
  283. Extend StarPU's default scheduling context to use \p unit_rank nth
  284. device of type \p type_id.
  285. */
  286. starpurm_drs_ret_t starpurm_assign_device_to_starpu(starpurm_drs_desc_t *spd, int type_id, int unit_rank);
  287. /**
  288. Extend StarPU's default scheduling context to use \p ndevices more
  289. devices of type \p type_id, up to the number of StarPU workers
  290. initialized for such device type.
  291. */
  292. starpurm_drs_ret_t starpurm_assign_devices_to_starpu(starpurm_drs_desc_t *spd, int type_id, int ndevices);
  293. /**
  294. Extend StarPU's default scheduling context to use additional
  295. devices as designated by their corresponding StarPU worker
  296. thread(s) CPU-set \p mask.
  297. */
  298. starpurm_drs_ret_t starpurm_assign_device_mask_to_starpu(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  299. /**
  300. Extend StarPU's default scheduling context to use all devices of
  301. type \p type_id for which it has a worker thread initialized.
  302. */
  303. starpurm_drs_ret_t starpurm_assign_all_devices_to_starpu(starpurm_drs_desc_t *spd, int type_id);
  304. /**
  305. Shrink StarPU's default scheduling context to not use \p unit_rank
  306. nth device of type \p type_id.
  307. */
  308. starpurm_drs_ret_t starpurm_withdraw_device_from_starpu(starpurm_drs_desc_t *spd, int type_id, int unit_rank);
  309. /**
  310. Shrink StarPU's default scheduling context to use \p ndevices less
  311. devices of type \p type_id.
  312. */
  313. starpurm_drs_ret_t starpurm_withdraw_devices_from_starpu(starpurm_drs_desc_t *spd, int type_id, int ndevices);
  314. /**
  315. Shrink StarPU's default scheduling context to not use devices
  316. designated by their corresponding StarPU worker thread(s) CPU-set
  317. \p mask.
  318. */
  319. starpurm_drs_ret_t starpurm_withdraw_device_mask_from_starpu(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  320. /**
  321. Shrink StarPU's default scheduling context to use no devices of
  322. type \p type_id.
  323. */
  324. starpurm_drs_ret_t starpurm_withdraw_all_devices_from_starpu(starpurm_drs_desc_t *spd, int type_id);
  325. /* --- */
  326. /**
  327. Synonym for starpurm_assign_device_to_starpu().
  328. */
  329. starpurm_drs_ret_t starpurm_lend_device(starpurm_drs_desc_t *spd, int type_id, int unit_rank);
  330. /**
  331. Synonym for starpurm_assign_devices_to_starpu().
  332. */
  333. starpurm_drs_ret_t starpurm_lend_devices(starpurm_drs_desc_t *spd, int type_id, int ndevices);
  334. /**
  335. Synonym for starpurm_assign_device_mask_to_starpu().
  336. */
  337. starpurm_drs_ret_t starpurm_lend_device_mask(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  338. /**
  339. Synonym for starpurm_assign_all_devices_to_starpu().
  340. */
  341. starpurm_drs_ret_t starpurm_lend_all_devices(starpurm_drs_desc_t *spd, int type_id);
  342. /**
  343. Synonym for starpurm_withdraw_device_from_starpu().
  344. */
  345. starpurm_drs_ret_t starpurm_reclaim_device(starpurm_drs_desc_t *spd, int type_id, int unit_rank);
  346. /**
  347. Synonym for starpurm_withdraw_devices_from_starpu().
  348. */
  349. starpurm_drs_ret_t starpurm_reclaim_devices(starpurm_drs_desc_t *spd, int type_id, int ndevices);
  350. /**
  351. Synonym for starpurm_withdraw_device_mask_from_starpu().
  352. */
  353. starpurm_drs_ret_t starpurm_reclaim_device_mask(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  354. /**
  355. Synonym for starpurm_withdraw_all_devices_from_starpu().
  356. */
  357. starpurm_drs_ret_t starpurm_reclaim_all_devices(starpurm_drs_desc_t *spd, int type_id);
  358. /**
  359. Synonym for starpurm_withdraw_device_from_starpu().
  360. */
  361. starpurm_drs_ret_t starpurm_acquire_device(starpurm_drs_desc_t *spd, int type_id, int unit_rank);
  362. /**
  363. Synonym for starpurm_withdraw_devices_from_starpu().
  364. */
  365. starpurm_drs_ret_t starpurm_acquire_devices(starpurm_drs_desc_t *spd, int type_id, int ndevices);
  366. /**
  367. Synonym for starpurm_withdraw_device_mask_from_starpu().
  368. */
  369. starpurm_drs_ret_t starpurm_acquire_device_mask(starpurm_drs_desc_t *spd, const hwloc_cpuset_t mask);
  370. /**
  371. Synonym for starpurm_withdraw_all_devices_from_starpu().
  372. */
  373. starpurm_drs_ret_t starpurm_acquire_all_devices(starpurm_drs_desc_t *spd, int type_id);
  374. /**
  375. Synonym for starpurm_assign_all_devices_to_starpu().
  376. */
  377. starpurm_drs_ret_t starpurm_return_all_devices(starpurm_drs_desc_t *spd, int type_id);
  378. /**
  379. Synonym for starpurm_assign_device_to_starpu().
  380. */
  381. starpurm_drs_ret_t starpurm_return_device(starpurm_drs_desc_t *spd, int type_id, int unit_rank);
  382. /** @} */
  383. /**
  384. @name CpusetsQueries
  385. @{
  386. */
  387. /**
  388. Return the CPU-set of the StarPU worker associated to the \p
  389. unit_rank nth unit of type \p type_id.
  390. */
  391. hwloc_cpuset_t starpurm_get_device_worker_cpuset(int type_id, int unit_rank);
  392. /**
  393. Return the cumulated CPU-set of all StarPU worker threads.
  394. */
  395. hwloc_cpuset_t starpurm_get_global_cpuset(void);
  396. /**
  397. Return the CPU-set of the StarPU worker threads currently selected
  398. in the default StarPU's scheduling context.
  399. */
  400. hwloc_cpuset_t starpurm_get_selected_cpuset(void);
  401. /**
  402. Return the cumulated CPU-set of all CPU StarPU worker threads.
  403. */
  404. hwloc_cpuset_t starpurm_get_all_cpu_workers_cpuset(void);
  405. /**
  406. Return the cumulated CPU-set of all "non-CPU" StarPU worker
  407. threads.
  408. */
  409. hwloc_cpuset_t starpurm_get_all_device_workers_cpuset(void);
  410. /**
  411. Return the cumulated CPU-set of all StarPU worker threads for
  412. devices of type \p typeid.
  413. */
  414. hwloc_cpuset_t starpurm_get_all_device_workers_cpuset_by_type(int typeid);
  415. /** @} */
  416. /** @} */
  417. #ifdef __cplusplus
  418. }
  419. #endif
  420. #endif /* __STARPURM_H */