workers.doxy 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2016, 2017 CNRS
  5. * Copyright (C) 2011, 2012, 2017 INRIA
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Workers_Properties Workers’ Properties
  9. \def STARPU_NMAXWORKERS
  10. \ingroup API_Workers_Properties
  11. Define the maximum number of workers managed by StarPU.
  12. \def STARPU_MAXCPUS
  13. \ingroup API_Workers_Properties
  14. Define the maximum number of CPU workers managed by StarPU. The default value can be modified at
  15. configure by using the option \ref enable-maxcpus "--enable-maxcpus".
  16. \def STARPU_MAXNODES
  17. \ingroup API_Workers_Properties
  18. Define the maximum number of memory nodes managed by StarPU. The default value can be modified at
  19. configure by using the option \ref enable-maxnodes "--enable-maxnodes". Reducing it allows to
  20. considerably reduce memory used by StarPU data structures.
  21. \enum starpu_node_kind
  22. \ingroup API_Workers_Properties
  23. TODO
  24. \var starpu_node_kind::STARPU_UNUSED
  25. TODO
  26. \var starpu_node_kind::STARPU_CPU_RAM
  27. TODO
  28. \var starpu_node_kind::STARPU_CUDA_RAM
  29. TODO
  30. \var starpu_node_kind::STARPU_OPENCL_RAM
  31. TODO
  32. \var starpu_node_kind::STARPU_DISK_RAM
  33. TODO
  34. \var starpu_node_kind::STARPU_MIC_RAM
  35. TODO
  36. \var starpu_node_kind::STARPU_SCC_RAM
  37. This node kind is not used anymore, but implementations in
  38. interfaces will be useful for MPI.
  39. \var starpu_node_kind::STARPU_SCC_SHM
  40. TODO
  41. \var starpu_node_kind::STARPU_MPI_MS_RAM
  42. TODO
  43. \enum starpu_worker_archtype
  44. \ingroup API_Workers_Properties
  45. Worker Architecture Type
  46. \var starpu_worker_archtype::STARPU_ANY_WORKER
  47. any worker, used in the hypervisor
  48. \var starpu_worker_archtype::STARPU_CPU_WORKER
  49. CPU core
  50. \var starpu_worker_archtype::STARPU_CUDA_WORKER
  51. NVIDIA CUDA device
  52. \var starpu_worker_archtype::STARPU_OPENCL_WORKER
  53. OpenCL device
  54. \var starpu_worker_archtype::STARPU_MIC_WORKER
  55. Intel MIC device
  56. \var starpu_worker_archtype::STARPU_SCC_WORKER
  57. Intel SCC device
  58. \var starpu_worker_archtype::STARPU_MPI_MS_WORKER
  59. MPI Slave device
  60. \struct starpu_worker_collection
  61. \ingroup API_Workers_Properties
  62. A scheduling context manages a collection of workers that can
  63. be memorized using different data structures. Thus, a generic
  64. structure is available in order to simplify the choice of its type.
  65. Only the list data structure is available but further data
  66. structures(like tree) implementations are foreseen.
  67. \var void *starpu_worker_collection::workerids
  68. The workerids managed by the collection
  69. \var void *starpu_worker_collection::collection_private
  70. todo
  71. \var void *starpu_worker_collection::unblocked_workers
  72. todo
  73. \var unsigned starpu_worker_collection::nunblocked_workers
  74. todo
  75. \var void *starpu_worker_collection::masters
  76. todo
  77. \var unsigned starpu_worker_collection::nmasters
  78. todo
  79. \var char starpu_worker_collection::present[STARPU_NMAXWORKERS]
  80. todo
  81. \var char starpu_worker_collection::is_unblocked[STARPU_NMAXWORKERS]
  82. todo
  83. \var char starpu_worker_collection::is_master[STARPU_NMAXWORKERS]
  84. todo
  85. \var unsigned starpu_worker_collection::nworkers
  86. The number of workers in the collection
  87. \var enum starpu_worker_collection_type starpu_worker_collection::type
  88. The type of structure
  89. \var unsigned (*starpu_worker_collection::has_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
  90. Check if there is another element in collection
  91. \var int (*starpu_worker_collection::get_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
  92. Return the next element in the collection
  93. \var int (*starpu_worker_collection::add)(struct starpu_worker_collection *workers, int worker)
  94. Add a new element in the collection
  95. \var int (*starpu_worker_collection::remove)(struct starpu_worker_collection *workers, int worker)
  96. Remove an element from the collection
  97. \var void (*starpu_worker_collection::init)(struct starpu_worker_collection *workers)
  98. Initialize the collection
  99. \var void (*starpu_worker_collection::deinit)(struct starpu_worker_collection *workers)
  100. Deinitialize the colection
  101. \var void (*starpu_worker_collection::init_iterator)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
  102. Initialize the cursor if there is one
  103. \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);
  104. todo
  105. \enum starpu_worker_collection_type
  106. \ingroup API_Workers_Properties
  107. Types of structures the worker collection can implement
  108. \var starpu_worker_collection_type::STARPU_WORKER_LIST
  109. The collection is an array
  110. \var starpu_worker_collection_type::STARPU_WORKER_TREE
  111. The collection is a tree
  112. \struct starpu_sched_ctx_iterator
  113. \ingroup API_Workers_Properties
  114. Structure needed to iterate on the collection
  115. \var int starpu_sched_ctx_iterator::cursor
  116. The index of the current worker in the collection, needed when
  117. iterating on the collection.
  118. \fn unsigned starpu_worker_get_count(void)
  119. \ingroup API_Workers_Properties
  120. Return the number of workers (i.e. processing units executing StarPU
  121. tasks). The returned value should be at most \ref STARPU_NMAXWORKERS.
  122. \fn int starpu_worker_get_count_by_type(enum starpu_worker_archtype type)
  123. \ingroup API_Workers_Properties
  124. Return the number of workers of \p type. A positive (or
  125. <c>NULL</c>) value is returned in case of success, <c>-EINVAL</c>
  126. indicates that \p type is not valid otherwise.
  127. \fn unsigned starpu_cpu_worker_get_count(void)
  128. \ingroup API_Workers_Properties
  129. Return the number of CPUs controlled by StarPU. The returned value should be at most \ref STARPU_MAXCPUS.
  130. \fn unsigned starpu_cuda_worker_get_count(void)
  131. \ingroup API_Workers_Properties
  132. Return the number of CUDA devices controlled by StarPU. The returned value should be at most \ref STARPU_MAXCUDADEVS.
  133. \fn unsigned starpu_mic_worker_get_count(void)
  134. \ingroup API_Workers_Properties
  135. Return the number of MIC workers controlled by StarPU.
  136. \fn unsigned starpu_mic_device_get_count(void)
  137. \ingroup API_Workers_Properties
  138. Return the number of MIC devices controlled by StarPU. The returned value should be at most \ref STARPU_MAXMICDEVS.
  139. \fn unsigned starpu_mpi_ms_worker_get_count(void)
  140. \ingroup API_Workers_Properties
  141. Return the number of MPI Master Slave workers controlled by StarPU.
  142. \fn unsigned starpu_scc_worker_get_count(void)
  143. \ingroup API_Workers_Properties
  144. Return the number of SCC devices controlled by StarPU. The returned value should be at most \ref STARPU_MAXSCCDEVS.
  145. \fn unsigned starpu_opencl_worker_get_count(void)
  146. \ingroup API_Workers_Properties
  147. Return the number of OpenCL devices controlled by StarPU. The returned value should be at most \ref STARPU_MAXOPENCLDEVS.
  148. \fn int starpu_worker_get_id(void)
  149. \ingroup API_Workers_Properties
  150. Return the identifier of the current worker, i.e the one associated to
  151. the calling thread. The returned value is either -1 if the current
  152. context is not a StarPU worker (i.e. when called from the application
  153. outside a task or a callback), or an integer between 0 and
  154. starpu_worker_get_count() - 1.
  155. \fn unsigned starpu_worker_get_id_check(void)
  156. \ingroup API_Workers_Properties
  157. Similar to starpu_worker_get_id(), but abort when called from outside
  158. a worker (i.e. when starpu_worker_get_id() would return -1).
  159. \fn unsigned starpu_worker_get_ids_by_type(enum starpu_worker_archtype type, int *workerids, unsigned maxsize)
  160. \ingroup API_Workers_Properties
  161. Get the list of identifiers of workers of \p type. Fill the array \p
  162. workerids with the identifiers of the \p workers. The argument \p
  163. maxsize indicates the size of the array \p workerids. The returned
  164. value gives the number of identifiers that were put in the array.
  165. <c>-ERANGE</c> is returned is \p maxsize is lower than the number of workers
  166. with the appropriate type: in that case, the array is filled with the
  167. \p maxsize first elements. To avoid such overflows, the value of maxsize
  168. can be chosen by the means of the function
  169. starpu_worker_get_count_by_type(), or by passing a value greater or
  170. equal to \ref STARPU_NMAXWORKERS.
  171. \fn int starpu_worker_get_by_type(enum starpu_worker_archtype type, int num)
  172. \ingroup API_Workers_Properties
  173. Return the identifier of the \p num -th worker that has the
  174. specified \p type. If there is no such worker, -1 is returned.
  175. \fn int starpu_worker_get_by_devid(enum starpu_worker_archtype type, int devid)
  176. \ingroup API_Workers_Properties
  177. Return the identifier of the worker that has the specified \p type
  178. and device id \p devid (which may not be the n-th, if some
  179. devices are skipped for instance). If there is no such worker, -1 is
  180. returned.
  181. \fn int starpu_worker_get_devid(int id)
  182. \ingroup API_Workers_Properties
  183. Return the device id of the worker \p id. The
  184. worker should be identified with the value returned by the
  185. starpu_worker_get_id() function. In the case of a CUDA worker, this
  186. device identifier is the logical device identifier exposed by CUDA
  187. (used by the function \c cudaGetDevice() for instance). The device
  188. identifier of a CPU worker is the logical identifier of the core on
  189. which the worker was bound; this identifier is either provided by the
  190. OS or by the library <c>hwloc</c> in case it is available.
  191. \fn enum starpu_worker_archtype starpu_worker_get_type(int id)
  192. \ingroup API_Workers_Properties
  193. Return the type of processing unit associated to the worker \p id. The
  194. worker identifier is a value returned by the function
  195. starpu_worker_get_id()). The returned value indicates the architecture
  196. of the worker: ::STARPU_CPU_WORKER for a CPU core,
  197. ::STARPU_CUDA_WORKER for a CUDA device, and ::STARPU_OPENCL_WORKER for
  198. a OpenCL device. The value returned for an invalid identifier is
  199. unspecified.
  200. \fn void starpu_worker_get_name(int id, char *dst, size_t maxlen)
  201. \ingroup API_Workers_Properties
  202. Allow to get the name of the worker \p id. StarPU associates a unique
  203. human readable string to each processing unit. This function copies at
  204. most the \p maxlen first bytes of the unique string associated to the
  205. worker \p id into the \p dst buffer. The caller is responsible for
  206. ensuring that \p dst is a valid pointer to a buffer of \p maxlen bytes
  207. at least. Calling this function on an invalid identifier results in an
  208. unspecified behaviour.
  209. \fn void starpu_worker_display_names(FILE *output, enum starpu_worker_archtype type)
  210. \ingroup API_Workers_Properties
  211. Display on \p output the list (if any) of all the workers of the given
  212. \p type.
  213. \fn unsigned starpu_worker_get_memory_node(unsigned workerid)
  214. \ingroup API_Workers_Properties
  215. Return the identifier of the memory node associated to the worker
  216. identified by \p workerid.
  217. \fn enum starpu_node_kind starpu_node_get_kind(unsigned node)
  218. \ingroup API_Workers_Properties
  219. Return the type of \p node as defined by
  220. ::starpu_node_kind. For example, when defining a new data interface,
  221. this function should be used in the allocation function to determine
  222. on which device the memory needs to be allocated.
  223. \fn char *starpu_worker_get_type_as_string(enum starpu_worker_archtype type)
  224. \ingroup API_Workers_Properties
  225. Return worker \p type as a string.
  226. \fn void _starpu_worker_request_blocking_in_parallel(struct _starpu_worker * const worker)
  227. \ingroup API_Workers_Properties
  228. Send a request to \p worker to block, before a parallel task is about
  229. to begin. The sched mutex of \p worker must be held before calling
  230. this function.
  231. \fn void _starpu_worker_request_unblocking_in_parallel(struct _starpu_worker * const worker)
  232. \ingroup API_Workers_Properties
  233. Send a request to \p worker to unblock, after a parallel task is
  234. complete. The sched mutex of \p worker must be held before calling
  235. this function.
  236. \fn void _starpu_worker_process_block_in_parallel_requests(struct _starpu_worker * const worker)
  237. \ingroup API_Workers_Properties
  238. Called by the \p worker to process incoming requests to block or
  239. unblock on parallel task boundaries. The sched mutex of \p worker must
  240. be held before calling this function.
  241. \fn void _starpu_worker_enter_sched_op(struct _starpu_worker * const worker)
  242. \ingroup API_Workers_Properties
  243. Mark the beginning of a scheduling operation by \p worker. No worker
  244. blocking operations on parallel tasks and no scheduling context change
  245. operations must be performed on contexts containing \p worker, on
  246. contexts about to add \p worker and on contexts about to remove \p
  247. worker, while the scheduling operation is in process. The sched mutex
  248. of \p worker may only be acquired permanently by another thread when
  249. no scheduling operation is in process, or when a scheduling operation
  250. is in process _and_ <c>worker->state_relax_refcnt!=0</>. If a
  251. scheduling operation is in process _and_
  252. <c>worker->state_relax_refcnt==0</c>, a thread other than \p worker
  253. must wait on condition <c>worker->sched_cond</> for
  254. <c>worker->state_relax_refcnt!=0</> to become true, before acquiring
  255. \p worker sched mutex permanently. The sched mutex of \p worker must
  256. be held before calling this function.
  257. \fn void _starpu_worker_leave_sched_op(struct _starpu_worker * const worker)
  258. \ingroup API_Workers_Properties
  259. Mark the end of a scheduling operation by \p worker. The sched mutex
  260. of \p worker must be held before calling this function.
  261. \fn int _starpu_worker_sched_op_pending(void)
  262. \ingroup API_Workers_Properties
  263. Return \c !0 if current worker has a scheduling operation in progress,
  264. and \c 0 otherwise.
  265. \fn void _starpu_worker_enter_changing_ctx_op(struct _starpu_worker * const worker)
  266. \ingroup API_Workers_Properties
  267. Must be called before altering a context related to worker \p worker
  268. whether about adding \p worker to a context, removing it from a
  269. context or modifying the set of workers of a context of which \p
  270. worker is a member, to mark the beginning of a context change
  271. operation. The sched mutex of \p worker must be held before calling
  272. this function.
  273. \fn void _starpu_worker_leave_changing_ctx_op(struct _starpu_worker * const worker)
  274. \ingroup API_Workers_Properties
  275. Mark the end of a context change operation. The sched mutex of \p
  276. worker must be held before calling this function.
  277. \fn void _starpu_worker_relax_on(void)
  278. \ingroup API_Workers_Properties
  279. Allow other threads and workers to temporarily observe the current
  280. worker state, even though it is performing a scheduling operation.
  281. Must be called by a worker before performing a potentially blocking
  282. call such as acquiring a mutex other than its own sched_mutex. This
  283. function increases \c state_relax_refcnt from the current worker. No
  284. more than <c>UINT_MAX-1</c> nested relax_on calls should performed on
  285. the same worker. This function is automatically called by \ref
  286. _starpu_worker_lock to relax the caller worker state while attempting
  287. to lock the targer worker.
  288. \fn void _starpu_worker_relax_on(void)
  289. \ingroup API_Workers_Properties
  290. Must be called after a potentially blocking call is complete, to
  291. restore the relax state in place before the corresponding relax_on.
  292. Decreases \c state_relax_refcnt. Calls to \ref _starpu_worker_relax_on
  293. and \c _starpu_worker_relax_off must be well parenthesized. This
  294. function is automatically called by \ref _starpu_worker_unlock after the
  295. target worker has been unlocked.
  296. \fn int _starpu_worker_get_relax_state(void)
  297. \ingroup API_Workers_Properties
  298. Returns \c !0 if the current worker \c state_relax_refcnt!=0 and \c 0
  299. otherwise.
  300. \fn void _starpu_worker_lock(int workerid)
  301. \ingroup API_Workers_Properties
  302. Acquire the sched mutex of \p workerid. If the caller is a worker,
  303. distinct from \p workerid, the caller worker automatically enter relax
  304. state while acquiring the target worker lock.
  305. \fn int _starpu_worker_trylock(int workerid)
  306. \ingroup API_Workers_Properties
  307. Attempt to acquire the sched mutex of \p workerid. Returns \c 0 if
  308. successful, \c !0 if \p workerid sched mutex is held or the
  309. corresponding worker is not in relaxed stated.
  310. If the caller is a worker, distinct from \p workerid, the caller
  311. worker automatically enter relax state if successfully acquiring the target
  312. worker lock.
  313. \fn void _starpu_worker_unlock(int workerid)
  314. \ingroup API_Workers_Properties
  315. Release the previously acquired sched mutex of \p workerid. Restore
  316. the relaxed state of the caller worker if needed.
  317. \fn void _starpu_worker_lock_self(void)
  318. \ingroup API_Workers_Properties
  319. Acquire the current worker sched mutex.
  320. \fn void _starpu_worker_unlock_self(void)
  321. \ingroup API_Workers_Properties
  322. Release the current worker sched mutex.
  323. \fn int _starpu_wake_worker_relax(int workerid)
  324. \ingroup API_Workers_Properties
  325. Wake up \p workerid while temporarily entering the current worker
  326. relaxed state if needed during the waiting process.
  327. \fn void _starpu_worker_refuse_task(struct _starpu_worker *worker, struct starpu_task *task)
  328. \ingroup API_Workers_Properties
  329. Allow a worker pulling a task it cannot execute to properly refuse it
  330. and send it back to the scheduler.
  331. */