workers.doxy 15 KB

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