workers.doxy 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 int starpu_memory_nodes_numa_id_to_devid(int osid)
  224. \ingroup API_Workers_Properties
  225. Return the identifier of the memory node associated to the NUMA
  226. node identified by \p osid by the Operating System.
  227. \fn int starpu_memory_nodes_numa_devid_to_id(unsigned id);
  228. \ingroup API_Workers_Properties
  229. Return the Operating System identifier of the memory node
  230. whose StarPU identifier is \p id.
  231. \fn char *starpu_worker_get_type_as_string(enum starpu_worker_archtype type)
  232. \ingroup API_Workers_Properties
  233. Return worker \p type as a string.
  234. \fn int starpu_worker_sched_op_pending(void)
  235. \ingroup API_Workers_Properties
  236. Return \c !0 if current worker has a scheduling operation in progress,
  237. and \c 0 otherwise.
  238. \fn void starpu_worker_relax_on(void)
  239. \ingroup API_Workers_Properties
  240. Allow other threads and workers to temporarily observe the current
  241. worker state, even though it is performing a scheduling operation.
  242. Must be called by a worker before performing a potentially blocking
  243. call such as acquiring a mutex other than its own sched_mutex. This
  244. function increases \c state_relax_refcnt from the current worker. No
  245. more than <c>UINT_MAX-1</c> nested relax_on calls should performed on
  246. the same worker. This function is automatically called by \ref
  247. starpu_worker_lock to relax the caller worker state while attempting
  248. to lock the targer worker.
  249. \fn void starpu_worker_relax_off(void)
  250. \ingroup API_Workers_Properties
  251. Must be called after a potentially blocking call is complete, to
  252. restore the relax state in place before the corresponding relax_on.
  253. Decreases \c state_relax_refcnt. Calls to \ref starpu_worker_relax_on
  254. and \c starpu_worker_relax_off must be well parenthesized. This
  255. function is automatically called by \ref starpu_worker_unlock after the
  256. target worker has been unlocked.
  257. \fn int starpu_worker_get_relax_state(void)
  258. \ingroup API_Workers_Properties
  259. Returns \c !0 if the current worker \c state_relax_refcnt!=0 and \c 0
  260. otherwise.
  261. \fn void starpu_worker_lock(int workerid)
  262. \ingroup API_Workers_Properties
  263. Acquire the sched mutex of \p workerid. If the caller is a worker,
  264. distinct from \p workerid, the caller worker automatically enter relax
  265. state while acquiring the target worker lock.
  266. \fn int starpu_worker_trylock(int workerid)
  267. \ingroup API_Workers_Properties
  268. Attempt to acquire the sched mutex of \p workerid. Returns \c 0 if
  269. successful, \c !0 if \p workerid sched mutex is held or the
  270. corresponding worker is not in relaxed stated.
  271. If the caller is a worker, distinct from \p workerid, the caller
  272. worker automatically enter relax state if successfully acquiring the target
  273. worker lock.
  274. \fn void starpu_worker_unlock(int workerid)
  275. \ingroup API_Workers_Properties
  276. Release the previously acquired sched mutex of \p workerid. Restore
  277. the relaxed state of the caller worker if needed.
  278. \fn void starpu_worker_lock_self(void)
  279. \ingroup API_Workers_Properties
  280. Acquire the current worker sched mutex.
  281. \fn void starpu_worker_unlock_self(void)
  282. \ingroup API_Workers_Properties
  283. Release the current worker sched mutex.
  284. \fn int starpu_wake_worker_relax(int workerid)
  285. \ingroup API_Workers_Properties
  286. Wake up \p workerid while temporarily entering the current worker relaxed state
  287. if needed during the waiting process. Returns 1 if \p workerid has been woken
  288. up or its state_keep_awake flag has been set to 1, and 0 otherwise (if \p
  289. workerid was not in the STATE_SLEEPING or in the STATE_SCHEDULING).
  290. \fn hwloc_cpuset_t starpu_worker_get_hwloc_cpuset(int workerid)
  291. \ingroup API_Workers_Properties
  292. If StarPU was compiled with hwloc support, returns a duplicate of the
  293. hwloc cpuset associated with the worker \p workerid. The returned cpuset is obtained
  294. from a \c hwloc_bitmap_dup() function call. It must be freed by the caller
  295. using \c hwloc_bitmap_free().
  296. */