workers.doxy 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013,2017 Inria
  4. * Copyright (C) 2010-2017, 2019 CNRS
  5. * Copyright (C) 2009-2011,2014,2016-2019 Université de Bordeaux
  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. /*! \defgroup API_Workers_Properties Workers’ Properties
  19. \def STARPU_NMAXWORKERS
  20. \ingroup API_Workers_Properties
  21. Define the maximum number of workers managed by StarPU.
  22. \def STARPU_MAXCPUS
  23. \ingroup API_Workers_Properties
  24. Define the maximum number of CPU workers managed by StarPU. The default value can be modified at
  25. configure by using the option \ref enable-maxcpus "--enable-maxcpus".
  26. \def STARPU_MAXNUMANODES
  27. \ingroup API_Workers_Properties
  28. Define the maximum number of NUMA nodes managed by StarPU. The default value can be modified at
  29. configure by using the option \ref enable-maxnumanodes "--enable-maxnumanodes".
  30. \def STARPU_MAXNODES
  31. \ingroup API_Workers_Properties
  32. Define the maximum number of memory nodes managed by StarPU. The default value can be modified at
  33. configure by using the option \ref enable-maxnodes "--enable-maxnodes". Reducing it allows to
  34. considerably reduce memory used by StarPU data structures.
  35. \enum starpu_node_kind
  36. \ingroup API_Workers_Properties
  37. TODO
  38. \var starpu_node_kind::STARPU_UNUSED
  39. TODO
  40. \var starpu_node_kind::STARPU_CPU_RAM
  41. TODO
  42. \var starpu_node_kind::STARPU_CUDA_RAM
  43. TODO
  44. \var starpu_node_kind::STARPU_OPENCL_RAM
  45. TODO
  46. \var starpu_node_kind::STARPU_DISK_RAM
  47. TODO
  48. \var starpu_node_kind::STARPU_MIC_RAM
  49. TODO
  50. \var starpu_node_kind::STARPU_SCC_RAM
  51. This node kind is not used anymore, but implementations in
  52. interfaces will be useful for MPI.
  53. \var starpu_node_kind::STARPU_SCC_SHM
  54. TODO
  55. \var starpu_node_kind::STARPU_MPI_MS_RAM
  56. TODO
  57. \enum starpu_worker_archtype
  58. \ingroup API_Workers_Properties
  59. Worker Architecture Type
  60. \var starpu_worker_archtype::STARPU_ANY_WORKER
  61. any worker, used in the hypervisor
  62. \var starpu_worker_archtype::STARPU_CPU_WORKER
  63. CPU core
  64. \var starpu_worker_archtype::STARPU_CUDA_WORKER
  65. NVIDIA CUDA device
  66. \var starpu_worker_archtype::STARPU_OPENCL_WORKER
  67. OpenCL device
  68. \var starpu_worker_archtype::STARPU_MIC_WORKER
  69. Intel MIC device
  70. \var starpu_worker_archtype::STARPU_SCC_WORKER
  71. Intel SCC device
  72. \var starpu_worker_archtype::STARPU_MPI_MS_WORKER
  73. MPI Slave device
  74. \struct starpu_worker_collection
  75. \ingroup API_Workers_Properties
  76. A scheduling context manages a collection of workers that can
  77. be memorized using different data structures. Thus, a generic
  78. structure is available in order to simplify the choice of its type.
  79. Only the list data structure is available but further data
  80. structures(like tree) implementations are foreseen.
  81. \var void *starpu_worker_collection::workerids
  82. The workerids managed by the collection
  83. \var void *starpu_worker_collection::collection_private
  84. todo
  85. \var void *starpu_worker_collection::unblocked_workers
  86. todo
  87. \var unsigned starpu_worker_collection::nunblocked_workers
  88. todo
  89. \var void *starpu_worker_collection::masters
  90. todo
  91. \var unsigned starpu_worker_collection::nmasters
  92. todo
  93. \var char starpu_worker_collection::present[STARPU_NMAXWORKERS]
  94. todo
  95. \var char starpu_worker_collection::is_unblocked[STARPU_NMAXWORKERS]
  96. todo
  97. \var char starpu_worker_collection::is_master[STARPU_NMAXWORKERS]
  98. todo
  99. \var unsigned starpu_worker_collection::nworkers
  100. The number of workers in the collection
  101. \var enum starpu_worker_collection_type starpu_worker_collection::type
  102. The type of structure
  103. \var unsigned (*starpu_worker_collection::has_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
  104. Check if there is another element in collection
  105. \var int (*starpu_worker_collection::get_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
  106. Return the next element in the collection
  107. \var int (*starpu_worker_collection::add)(struct starpu_worker_collection *workers, int worker)
  108. Add a new element in the collection
  109. \var int (*starpu_worker_collection::remove)(struct starpu_worker_collection *workers, int worker)
  110. Remove an element from the collection
  111. \var void (*starpu_worker_collection::init)(struct starpu_worker_collection *workers)
  112. Initialize the collection
  113. \var void (*starpu_worker_collection::deinit)(struct starpu_worker_collection *workers)
  114. Deinitialize the colection
  115. \var void (*starpu_worker_collection::init_iterator)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
  116. Initialize the cursor if there is one
  117. \var void (*starpu_worker_collection::init_iterator_for_parallel_tasks)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it, struct starpu_task *task);
  118. todo
  119. \enum starpu_worker_collection_type
  120. \ingroup API_Workers_Properties
  121. Types of structures the worker collection can implement
  122. \var starpu_worker_collection_type::STARPU_WORKER_LIST
  123. The collection is an array
  124. \var starpu_worker_collection_type::STARPU_WORKER_TREE
  125. The collection is a tree
  126. \struct starpu_sched_ctx_iterator
  127. \ingroup API_Workers_Properties
  128. Structure needed to iterate on the collection
  129. \var int starpu_sched_ctx_iterator::cursor
  130. The index of the current worker in the collection, needed when
  131. iterating on the collection.
  132. \fn unsigned starpu_worker_get_sched_ctx_id_stream(unsigned stream_workerid)
  133. \ingroup API_Workers_Properties
  134. todo
  135. \fn unsigned starpu_worker_get_sched_ctx_list(int worker, unsigned **sched_ctx)
  136. \ingroup API_Workers_Properties
  137. todo
  138. \fn int starpu_worker_get_stream_workerids(unsigned devid, int *workerids, enum starpu_worker_archtype type)
  139. \ingroup API_Workers_Properties
  140. todo
  141. \fn unsigned starpu_worker_is_blocked_in_parallel(int workerid)
  142. \ingroup API_Workers_Properties
  143. todo
  144. \fn unsigned starpu_worker_is_slave_somewhere(int workerid)
  145. \ingroup API_Workers_Properties
  146. todo
  147. \fn unsigned starpu_worker_is_combined_worker(int id)
  148. \ingroup API_Workers_Properties
  149. todo
  150. \fn unsigned starpu_worker_get_count(void)
  151. \ingroup API_Workers_Properties
  152. Return the number of workers (i.e. processing units executing StarPU
  153. tasks). The return value should be at most \ref STARPU_NMAXWORKERS.
  154. \fn int starpu_worker_get_count_by_type(enum starpu_worker_archtype type)
  155. \ingroup API_Workers_Properties
  156. Return the number of workers of \p type. A positive (or
  157. <c>NULL</c>) value is returned in case of success, <c>-EINVAL</c>
  158. indicates that \p type is not valid otherwise.
  159. \fn unsigned starpu_cpu_worker_get_count(void)
  160. \ingroup API_Workers_Properties
  161. Return the number of CPUs controlled by StarPU. The return value should be at most \ref STARPU_MAXCPUS.
  162. \fn unsigned starpu_cuda_worker_get_count(void)
  163. \ingroup API_Workers_Properties
  164. Return the number of CUDA devices controlled by StarPU. The return value should be at most \ref STARPU_MAXCUDADEVS.
  165. \fn unsigned starpu_mic_worker_get_count(void)
  166. \ingroup API_Workers_Properties
  167. Return the number of MIC workers controlled by StarPU.
  168. \fn unsigned starpu_mic_device_get_count(void)
  169. \ingroup API_Workers_Properties
  170. Return the number of MIC devices controlled by StarPU. The return value should be at most \ref STARPU_MAXMICDEVS.
  171. \fn unsigned starpu_mpi_ms_worker_get_count(void)
  172. \ingroup API_Workers_Properties
  173. Return the number of MPI Master Slave workers controlled by StarPU.
  174. \fn unsigned starpu_scc_worker_get_count(void)
  175. \ingroup API_Workers_Properties
  176. Return the number of SCC devices controlled by StarPU. The return value should be at most \ref STARPU_MAXSCCDEVS.
  177. \fn unsigned starpu_opencl_worker_get_count(void)
  178. \ingroup API_Workers_Properties
  179. Return the number of OpenCL devices controlled by StarPU. The return value should be at most \ref STARPU_MAXOPENCLDEVS.
  180. \fn int starpu_worker_get_id(void)
  181. \ingroup API_Workers_Properties
  182. Return the identifier of the current worker, i.e the one associated to
  183. the calling thread. The return value is either \c -1 if the current
  184. context is not a StarPU worker (i.e. when called from the application
  185. outside a task or a callback), or an integer between \c 0 and
  186. starpu_worker_get_count() - \c 1.
  187. \fn unsigned starpu_worker_get_id_check(void)
  188. \ingroup API_Workers_Properties
  189. Similar to starpu_worker_get_id(), but abort when called from outside
  190. a worker (i.e. when starpu_worker_get_id() would return \c -1).
  191. \fn unsigned starpu_worker_get_ids_by_type(enum starpu_worker_archtype type, int *workerids, unsigned maxsize)
  192. \ingroup API_Workers_Properties
  193. Get the list of identifiers of workers of \p type. Fill the array \p
  194. workerids with the identifiers of the \p workers. The argument \p
  195. maxsize indicates the size of the array \p workerids. The return
  196. value gives the number of identifiers that were put in the array.
  197. <c>-ERANGE</c> is returned is \p maxsize is lower than the number of workers
  198. with the appropriate type: in that case, the array is filled with the
  199. \p maxsize first elements. To avoid such overflows, the value of maxsize
  200. can be chosen by the means of the function
  201. starpu_worker_get_count_by_type(), or by passing a value greater or
  202. equal to \ref STARPU_NMAXWORKERS.
  203. \fn int starpu_worker_get_by_type(enum starpu_worker_archtype type, int num)
  204. \ingroup API_Workers_Properties
  205. Return the identifier of the \p num -th worker that has the
  206. specified \p type. If there is no such worker, -1 is returned.
  207. \fn int starpu_worker_get_by_devid(enum starpu_worker_archtype type, int devid)
  208. \ingroup API_Workers_Properties
  209. Return the identifier of the worker that has the specified \p type
  210. and device id \p devid (which may not be the n-th, if some
  211. devices are skipped for instance). If there is no such worker, \c -1 is
  212. returned.
  213. \fn int starpu_worker_get_devid(int id)
  214. \ingroup API_Workers_Properties
  215. Return the device id of the worker \p id. The
  216. worker should be identified with the value returned by the
  217. starpu_worker_get_id() function. In the case of a CUDA worker, this
  218. device identifier is the logical device identifier exposed by CUDA
  219. (used by the function \c cudaGetDevice() for instance). The device
  220. identifier of a CPU worker is the logical identifier of the core on
  221. which the worker was bound; this identifier is either provided by the
  222. OS or by the library <c>hwloc</c> in case it is available.
  223. \fn int starpu_worker_get_devids(enum starpu_worker_archtype type, int *devids, int num)
  224. \ingroup API_Workers_Properties
  225. todo
  226. \fn int starpu_worker_get_bindid(int workerid)
  227. \ingroup API_Workers_Properties
  228. todo
  229. \fn enum starpu_worker_archtype starpu_worker_get_type(int id)
  230. \ingroup API_Workers_Properties
  231. Return the type of processing unit associated to the worker \p id. The
  232. worker identifier is a value returned by the function
  233. starpu_worker_get_id()). The return value indicates the architecture
  234. of the worker: ::STARPU_CPU_WORKER for a CPU core,
  235. ::STARPU_CUDA_WORKER for a CUDA device, and ::STARPU_OPENCL_WORKER for
  236. a OpenCL device. The return value for an invalid identifier is
  237. unspecified.
  238. \fn void starpu_worker_get_name(int id, char *dst, size_t maxlen)
  239. \ingroup API_Workers_Properties
  240. Allow to get the name of the worker \p id. StarPU associates a unique
  241. human readable string to each processing unit. This function copies at
  242. most the \p maxlen first bytes of the unique string associated to the
  243. worker \p id into the \p dst buffer. The caller is responsible for
  244. ensuring that \p dst is a valid pointer to a buffer of \p maxlen bytes
  245. at least. Calling this function on an invalid identifier results in an
  246. unspecified behaviour.
  247. \fn void starpu_worker_display_names(FILE *output, enum starpu_worker_archtype type)
  248. \ingroup API_Workers_Properties
  249. Display on \p output the list (if any) of all the workers of the given
  250. \p type.
  251. \fn unsigned starpu_worker_get_memory_node(unsigned workerid)
  252. \ingroup API_Workers_Properties
  253. Return the identifier of the memory node associated to the worker
  254. identified by \p workerid.
  255. \fn enum starpu_node_kind starpu_node_get_kind(unsigned node)
  256. \ingroup API_Workers_Properties
  257. Return the type of \p node as defined by
  258. ::starpu_node_kind. For example, when defining a new data interface,
  259. this function should be used in the allocation function to determine
  260. on which device the memory needs to be allocated.
  261. \fn int starpu_memory_nodes_numa_id_to_devid(int osid)
  262. \ingroup API_Workers_Properties
  263. Return the identifier of the memory node associated to the NUMA
  264. node identified by \p osid by the Operating System.
  265. \fn int starpu_memory_nodes_numa_devid_to_id(unsigned id);
  266. \ingroup API_Workers_Properties
  267. Return the Operating System identifier of the memory node
  268. whose StarPU identifier is \p id.
  269. \fn char *starpu_worker_get_type_as_string(enum starpu_worker_archtype type)
  270. \ingroup API_Workers_Properties
  271. Return worker \p type as a string.
  272. \fn int starpu_worker_sched_op_pending(void)
  273. \ingroup API_Workers_Properties
  274. Return \c !0 if current worker has a scheduling operation in progress,
  275. and \c 0 otherwise.
  276. \fn void starpu_worker_relax_on(void)
  277. \ingroup API_Workers_Properties
  278. Allow other threads and workers to temporarily observe the current
  279. worker state, even though it is performing a scheduling operation.
  280. Must be called by a worker before performing a potentially blocking
  281. call such as acquiring a mutex other than its own sched_mutex. This
  282. function increases \c state_relax_refcnt from the current worker. No
  283. more than <c>UINT_MAX-1</c> nested starpu_worker_relax_on() calls should performed on
  284. the same worker. This function is automatically called by
  285. starpu_worker_lock() to relax the caller worker state while attempting
  286. to lock the target worker.
  287. \fn void starpu_worker_relax_off(void)
  288. \ingroup API_Workers_Properties
  289. Must be called after a potentially blocking call is complete, to
  290. restore the relax state in place before the corresponding starpu_worker_relax_on().
  291. Decreases \c state_relax_refcnt. Calls to starpu_worker_relax_on()
  292. and starpu_worker_relax_off() must be properly paired. This
  293. function is automatically called by starpu_worker_unlock() after the
  294. target worker has been unlocked.
  295. \fn int starpu_worker_get_relax_state(void)
  296. \ingroup API_Workers_Properties
  297. Returns \c !0 if the current worker \c state_relax_refcnt!=0 and \c 0
  298. otherwise.
  299. \fn void starpu_worker_lock(int workerid)
  300. \ingroup API_Workers_Properties
  301. Acquire the sched mutex of \p workerid. If the caller is a worker,
  302. distinct from \p workerid, the caller worker automatically enters a relax
  303. state while acquiring the target worker lock.
  304. \fn int starpu_worker_trylock(int workerid)
  305. \ingroup API_Workers_Properties
  306. Attempt to acquire the sched mutex of \p workerid. Returns \c 0 if
  307. successful, \c !0 if \p workerid sched mutex is held or the
  308. corresponding worker is not in a relax state.
  309. If the caller is a worker, distinct from \p workerid, the caller
  310. worker automatically enters relax state if successfully acquiring the target
  311. worker lock.
  312. \fn void starpu_worker_unlock(int workerid)
  313. \ingroup API_Workers_Properties
  314. Release the previously acquired sched mutex of \p workerid. Restore
  315. the relax state of the caller worker if needed.
  316. \fn void starpu_worker_lock_self(void)
  317. \ingroup API_Workers_Properties
  318. Acquire the current worker sched mutex.
  319. \fn void starpu_worker_unlock_self(void)
  320. \ingroup API_Workers_Properties
  321. Release the current worker sched mutex.
  322. \fn int starpu_wake_worker_relax(int workerid)
  323. \ingroup API_Workers_Properties
  324. Wake up \p workerid while temporarily entering the current worker relax state
  325. if needed during the waiting process. Return 1 if \p workerid has been woken
  326. up or its state_keep_awake flag has been set to \c 1, and \c 0 otherwise (if \p
  327. workerid was not in the STATE_SLEEPING or in the STATE_SCHEDULING).
  328. \fn int starpu_wake_worker_relax_light(int workerid)
  329. \ingroup API_Workers_Properties
  330. This is a light version of starpu_wake_worker_relax() which, when possible,
  331. speculatively set keep_awake on the target worker without waiting for the worker
  332. to enter the relax state.
  333. \fn void starpu_worker_set_waking_up_callback(void (*callback)(unsigned workerid))
  334. \ingroup API_Workers_Properties
  335. If StarPU was compiled with blocking drivers support and worker callbacks support
  336. enabled, allow to specify an external resource manager callback to be notified
  337. about workers waking-up.
  338. \fn void starpu_worker_set_going_to_sleep_callback(void (*callback)(unsigned workerid))
  339. \ingroup API_Workers_Properties
  340. If StarPU was compiled with blocking drivers support and worker callbacks support
  341. enabled, allow to specify an external resource manager callback to be notified
  342. about workers going to sleep.
  343. \fn hwloc_cpuset_t starpu_worker_get_hwloc_cpuset(int workerid)
  344. \ingroup API_Workers_Properties
  345. If StarPU was compiled with \c hwloc support, return a duplicate of the
  346. \c hwloc cpuset associated with the worker \p workerid. The returned cpuset is obtained
  347. from a \c hwloc_bitmap_dup() function call. It must be freed by the caller
  348. using \c hwloc_bitmap_free().
  349. \fn hwloc_obj_t starpu_worker_get_hwloc_obj(int workerid)
  350. \ingroup API_Workers_Properties
  351. If StarPU was compiled with \c hwloc support, return the \c hwloc object corresponding to
  352. the worker \p workerid.
  353. */