advanced-api.texi 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. @node FXT Support
  2. @section FXT Support
  3. @deftypefun void starpu_fxt_start_profiling (void)
  4. Start recording the trace. The trace is by default started from
  5. @code{starpu_init()} call, but can be paused by using
  6. @code{starpu_fxt_stop_profiling}, in which case
  7. @code{starpu_fxt_start_profiling} should be called to specify when to resume
  8. recording events.
  9. @end deftypefun
  10. @deftypefun void starpu_fxt_stop_profiling (void)
  11. Stop recording the trace. The trace is by default stopped at
  12. @code{starpu_shutdown()} call. @code{starpu_fxt_stop_profiling} can however be
  13. used to stop it earlier. @code{starpu_fxt_start_profiling} can then be called to
  14. start recording it again, etc.
  15. @end deftypefun
  16. @node MPI
  17. @section MPI
  18. @menu
  19. * Initialisation::
  20. * Communication::
  21. * Communication cache::
  22. @end menu
  23. @node Initialisation
  24. @subsection Initialisation
  25. @deftypefun int starpu_mpi_init (int *@var{argc}, char ***@var{argv}, int initialize_mpi)
  26. Initializes the starpumpi library. @code{initialize_mpi} indicates if
  27. MPI should be initialized or not by StarPU. If the value is not @code{0},
  28. MPI will be initialized by calling @code{MPI_Init_Thread(argc, argv,
  29. MPI_THREAD_SERIALIZED, ...)}.
  30. @end deftypefun
  31. @deftypefun int starpu_mpi_initialize (void)
  32. This function has been made deprecated. One should use instead the
  33. function @code{starpu_mpi_init()} defined above.
  34. This function does not call @code{MPI_Init}, it should be called beforehand.
  35. @end deftypefun
  36. @deftypefun int starpu_mpi_initialize_extended (int *@var{rank}, int *@var{world_size})
  37. This function has been made deprecated. One should use instead the
  38. function @code{starpu_mpi_init()} defined above.
  39. MPI will be initialized by starpumpi by calling @code{MPI_Init_Thread(argc, argv,
  40. MPI_THREAD_SERIALIZED, ...)}.
  41. @end deftypefun
  42. @deftypefun int starpu_mpi_shutdown (void)
  43. Cleans the starpumpi library. This must be called between calling
  44. @code{starpu_mpi} functions and @code{starpu_shutdown()}.
  45. @code{MPI_Finalize()} will be called if StarPU-MPI has been initialized
  46. by @code{starpu_mpi_init()}.
  47. @end deftypefun
  48. @deftypefun void starpu_mpi_comm_amounts_retrieve (size_t *@var{comm_amounts})
  49. Retrieve the current amount of communications from the current node in
  50. the array @code{comm_amounts} which must have a size greater or equal
  51. to the world size. Communications statistics must be enabled
  52. (@pxref{STARPU_COMM_STATS}).
  53. @end deftypefun
  54. @node Communication
  55. @subsection Communication
  56. @deftypefun int starpu_mpi_send (starpu_data_handle_t @var{data_handle}, int @var{dest}, int @var{mpi_tag}, MPI_Comm @var{comm})
  57. Performs a standard-mode, blocking send of @var{data_handle} to the
  58. node @var{dest} using the message tag @code{mpi_tag} within the
  59. communicator @var{comm}.
  60. @end deftypefun
  61. @deftypefun int starpu_mpi_recv (starpu_data_handle_t @var{data_handle}, int @var{source}, int @var{mpi_tag}, MPI_Comm @var{comm}, MPI_Status *@var{status})
  62. Performs a standard-mode, blocking receive in @var{data_handle} from the
  63. node @var{source} using the message tag @code{mpi_tag} within the
  64. communicator @var{comm}.
  65. @end deftypefun
  66. @deftypefun int starpu_mpi_isend (starpu_data_handle_t @var{data_handle}, starpu_mpi_req *@var{req}, int @var{dest}, int @var{mpi_tag}, MPI_Comm @var{comm})
  67. Posts a standard-mode, non blocking send of @var{data_handle} to the
  68. node @var{dest} using the message tag @code{mpi_tag} within the
  69. communicator @var{comm}. After the call, the pointer to the request
  70. @var{req} can be used to test or to wait for the completion of the communication.
  71. @end deftypefun
  72. @deftypefun int starpu_mpi_irecv (starpu_data_handle_t @var{data_handle}, starpu_mpi_req *@var{req}, int @var{source}, int @var{mpi_tag}, MPI_Comm @var{comm})
  73. Posts a nonblocking receive in @var{data_handle} from the
  74. node @var{source} using the message tag @code{mpi_tag} within the
  75. communicator @var{comm}. After the call, the pointer to the request
  76. @var{req} can be used to test or to wait for the completion of the communication.
  77. @end deftypefun
  78. @deftypefun int starpu_mpi_isend_detached (starpu_data_handle_t @var{data_handle}, int @var{dest}, int @var{mpi_tag}, MPI_Comm @var{comm}, void (*@var{callback})(void *), void *@var{arg})
  79. Posts a standard-mode, non blocking send of @var{data_handle} to the
  80. node @var{dest} using the message tag @code{mpi_tag} within the
  81. communicator @var{comm}. On completion, the @var{callback} function is
  82. called with the argument @var{arg}. Similarly to the pthread detached
  83. functionality, when a detached communication completes, its resources
  84. are automatically released back to the system, there is no need to
  85. test or to wait for the completion of the request.
  86. @end deftypefun
  87. @deftypefun int starpu_mpi_irecv_detached (starpu_data_handle_t @var{data_handle}, int @var{source}, int @var{mpi_tag}, MPI_Comm @var{comm}, void (*@var{callback})(void *), void *@var{arg})
  88. Posts a nonblocking receive in @var{data_handle} from the
  89. node @var{source} using the message tag @code{mpi_tag} within the
  90. communicator @var{comm}. On completion, the @var{callback} function is
  91. called with the argument @var{arg}. Similarly to the pthread detached
  92. functionality, when a detached communication completes, its resources
  93. are automatically released back to the system, there is no need to
  94. test or to wait for the completion of the request.
  95. @end deftypefun
  96. @deftypefun int starpu_mpi_wait (starpu_mpi_req *@var{req}, MPI_Status *@var{status})
  97. Returns when the operation identified by request @var{req} is complete.
  98. @end deftypefun
  99. @deftypefun int starpu_mpi_test (starpu_mpi_req *@var{req}, int *@var{flag}, MPI_Status *@var{status})
  100. If the operation identified by @var{req} is complete, set @var{flag}
  101. to 1. The @var{status} object is set to contain information on the
  102. completed operation.
  103. @end deftypefun
  104. @deftypefun int starpu_mpi_barrier (MPI_Comm @var{comm})
  105. Blocks the caller until all group members of the communicator
  106. @var{comm} have called it.
  107. @end deftypefun
  108. @deftypefun int starpu_mpi_isend_detached_unlock_tag (starpu_data_handle_t @var{data_handle}, int @var{dest}, int @var{mpi_tag}, MPI_Comm @var{comm}, starpu_tag_t @var{tag})
  109. Posts a standard-mode, non blocking send of @var{data_handle} to the
  110. node @var{dest} using the message tag @code{mpi_tag} within the
  111. communicator @var{comm}. On completion, @var{tag} is unlocked.
  112. @end deftypefun
  113. @deftypefun int starpu_mpi_irecv_detached_unlock_tag (starpu_data_handle_t @var{data_handle}, int @var{source}, int @var{mpi_tag}, MPI_Comm @var{comm}, starpu_tag_t @var{tag})
  114. Posts a nonblocking receive in @var{data_handle} from the
  115. node @var{source} using the message tag @code{mpi_tag} within the
  116. communicator @var{comm}. On completion, @var{tag} is unlocked.
  117. @end deftypefun
  118. @deftypefun int starpu_mpi_isend_array_detached_unlock_tag (unsigned @var{array_size}, starpu_data_handle_t *@var{data_handle}, int *@var{dest}, int *@var{mpi_tag}, MPI_Comm *@var{comm}, starpu_tag_t @var{tag})
  119. Posts @var{array_size} standard-mode, non blocking send. Each post
  120. sends the n-th data of the array @var{data_handle} to the n-th node of
  121. the array @var{dest}
  122. using the n-th message tag of the array @code{mpi_tag} within the n-th
  123. communicator of the array
  124. @var{comm}. On completion of the all the requests, @var{tag} is unlocked.
  125. @end deftypefun
  126. @deftypefun int starpu_mpi_irecv_array_detached_unlock_tag (unsigned @var{array_size}, starpu_data_handle_t *@var{data_handle}, int *@var{source}, int *@var{mpi_tag}, MPI_Comm *@var{comm}, starpu_tag_t @var{tag})
  127. Posts @var{array_size} nonblocking receive. Each post receives in the
  128. n-th data of the array @var{data_handle} from the n-th
  129. node of the array @var{source} using the n-th message tag of the array
  130. @code{mpi_tag} within the n-th communicator of the array @var{comm}.
  131. On completion of the all the requests, @var{tag} is unlocked.
  132. @end deftypefun
  133. @node Communication cache
  134. @subsection Communication cache
  135. @deftypefun void starpu_mpi_cache_flush (MPI_Comm @var{comm}, starpu_data_handle_t @var{data_handle})
  136. Clear the send and receive communication cache for the data
  137. @var{data_handle}. The function has to be called synchronously by all
  138. the MPI nodes.
  139. The function does nothing if the cache mechanism is disabled (@pxref{STARPU_MPI_CACHE}).
  140. @end deftypefun
  141. @deftypefun void starpu_mpi_cache_flush_all_data (MPI_Comm @var{comm})
  142. Clear the send and receive communication cache for all data. The
  143. function has to be called synchronously by all the MPI nodes.
  144. The function does nothing if the cache mechanism is disabled (@pxref{STARPU_MPI_CACHE}).
  145. @end deftypefun
  146. @node Task Bundles
  147. @section Task Bundles
  148. @deftp {Data Type} {starpu_task_bundle_t}
  149. Opaque structure describing a list of tasks that should be scheduled
  150. on the same worker whenever it's possible. It must be considered as a
  151. hint given to the scheduler as there is no guarantee that they will be
  152. executed on the same worker.
  153. @end deftp
  154. @deftypefun void starpu_task_bundle_create ({starpu_task_bundle_t *}@var{bundle})
  155. Factory function creating and initializing @var{bundle}, when the call returns, memory needed is allocated and @var{bundle} is ready to use.
  156. @end deftypefun
  157. @deftypefun int starpu_task_bundle_insert (starpu_task_bundle_t @var{bundle}, {struct starpu_task *}@var{task})
  158. Insert @var{task} in @var{bundle}. Until @var{task} is removed from @var{bundle} its expected length and data transfer time will be considered along those of the other tasks of @var{bundle}.
  159. This function mustn't be called if @var{bundle} is already closed and/or @var{task} is already submitted.
  160. @end deftypefun
  161. @deftypefun int starpu_task_bundle_remove (starpu_task_bundle_t @var{bundle}, {struct starpu_task *}@var{task})
  162. Remove @var{task} from @var{bundle}.
  163. Of course @var{task} must have been previously inserted @var{bundle}.
  164. This function mustn't be called if @var{bundle} is already closed and/or @var{task} is already submitted. Doing so would result in undefined behaviour.
  165. @end deftypefun
  166. @deftypefun void starpu_task_bundle_close (starpu_task_bundle_t @var{bundle})
  167. Inform the runtime that the user won't modify @var{bundle} anymore, it means no more inserting or removing task. Thus the runtime can destroy it when possible.
  168. @end deftypefun
  169. @deftypefun double starpu_task_bundle_expected_length (starpu_task_bundle_t @var{bundle}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  170. Return the expected duration of the entire task bundle in µs.
  171. @end deftypefun
  172. @deftypefun double starpu_task_bundle_expected_power (starpu_task_bundle_t @var{bundle}, enum starpu_perf_archtype @var{arch}, unsigned @var{nimpl})
  173. Return the expected power consumption of the entire task bundle in J.
  174. @end deftypefun
  175. @deftypefun double starpu_task_bundle_expected_data_transfer_time (starpu_task_bundle_t @var{bundle}, unsigned @var{memory_node})
  176. Return the time (in µs) expected to transfer all data used within the bundle.
  177. @end deftypefun
  178. @node Task Lists
  179. @section Task Lists
  180. @deftp {Data Type} {struct starpu_task_list}
  181. Stores a double-chained list of tasks
  182. @end deftp
  183. @deftypefun void starpu_task_list_init ({struct starpu_task_list *}@var{list})
  184. Initialize a list structure
  185. @end deftypefun
  186. @deftypefun void starpu_task_list_push_front ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  187. Push a task at the front of a list
  188. @end deftypefun
  189. @deftypefun void starpu_task_list_push_back ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  190. Push a task at the back of a list
  191. @end deftypefun
  192. @deftypefun {struct starpu_task *} starpu_task_list_front ({struct starpu_task_list *}@var{list})
  193. Get the front of the list (without removing it)
  194. @end deftypefun
  195. @deftypefun {struct starpu_task *} starpu_task_list_back ({struct starpu_task_list *}@var{list})
  196. Get the back of the list (without removing it)
  197. @end deftypefun
  198. @deftypefun int starpu_task_list_empty ({struct starpu_task_list *}@var{list})
  199. Test if a list is empty
  200. @end deftypefun
  201. @deftypefun void starpu_task_list_erase ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  202. Remove an element from the list
  203. @end deftypefun
  204. @deftypefun {struct starpu_task *} starpu_task_list_pop_front ({struct starpu_task_list *}@var{list})
  205. Remove the element at the front of the list
  206. @end deftypefun
  207. @deftypefun {struct starpu_task *} starpu_task_list_pop_back ({struct starpu_task_list *}@var{list})
  208. Remove the element at the back of the list
  209. @end deftypefun
  210. @deftypefun {struct starpu_task *} starpu_task_list_begin ({struct starpu_task_list *}@var{list})
  211. Get the first task of the list.
  212. @end deftypefun
  213. @deftypefun {struct starpu_task *} starpu_task_list_end ({struct starpu_task_list *}@var{list})
  214. Get the end of the list.
  215. @end deftypefun
  216. @deftypefun {struct starpu_task *} starpu_task_list_next ({struct starpu_task *}@var{task})
  217. Get the next task of the list. This is not erase-safe.
  218. @end deftypefun
  219. @node Using Parallel Tasks
  220. @section Using Parallel Tasks
  221. These are used by parallel tasks:
  222. @deftypefun int starpu_combined_worker_get_size (void)
  223. Return the size of the current combined worker, i.e. the total number of cpus
  224. running the same task in the case of SPMD parallel tasks, or the total number
  225. of threads that the task is allowed to start in the case of FORKJOIN parallel
  226. tasks.
  227. @end deftypefun
  228. @deftypefun int starpu_combined_worker_get_rank (void)
  229. Return the rank of the current thread within the combined worker. Can only be
  230. used in FORKJOIN parallel tasks, to know which part of the task to work on.
  231. @end deftypefun
  232. Most of these are used for schedulers which support parallel tasks.
  233. @deftypefun unsigned starpu_combined_worker_get_count (void)
  234. Return the number of different combined workers.
  235. @end deftypefun
  236. @deftypefun int starpu_combined_worker_get_id (void)
  237. Return the identifier of the current combined worker.
  238. @end deftypefun
  239. @deftypefun int starpu_combined_worker_assign_workerid (int @var{nworkers}, int @var{workerid_array}[])
  240. Register a new combined worker and get its identifier
  241. @end deftypefun
  242. @deftypefun int starpu_combined_worker_get_description (int @var{workerid}, {int *}@var{worker_size}, {int **}@var{combined_workerid})
  243. Get the description of a combined worker
  244. @end deftypefun
  245. @deftypefun int starpu_combined_worker_can_execute_task (unsigned @var{workerid}, {struct starpu_task *}@var{task}, unsigned @var{nimpl})
  246. Variant of starpu_worker_can_execute_task compatible with combined workers
  247. @end deftypefun
  248. @deftp {Data Type} {struct starpu_machine_topology}
  249. @table @asis
  250. @item @code{unsigned nworkers}
  251. Total number of workers.
  252. @item @code{unsigned ncombinedworkers}
  253. Total number of combined workers.
  254. @item @code{hwloc_topology_t hwtopology}
  255. Topology as detected by hwloc.
  256. To maintain ABI compatibility when hwloc is not available, the field
  257. is replaced with @code{void *dummy}
  258. @item @code{unsigned nhwcpus}
  259. Total number of CPUs, as detected by the topology code. May be different from
  260. the actual number of CPU workers.
  261. @item @code{unsigned nhwcudagpus}
  262. Total number of CUDA devices, as detected. May be different from the actual
  263. number of CUDA workers.
  264. @item @code{unsigned nhwopenclgpus}
  265. Total number of OpenCL devices, as detected. May be different from the actual
  266. number of CUDA workers.
  267. @item @code{unsigned ncpus}
  268. Actual number of CPU workers used by StarPU.
  269. @item @code{unsigned ncudagpus}
  270. Actual number of CUDA workers used by StarPU.
  271. @item @code{unsigned nopenclgpus}
  272. Actual number of OpenCL workers used by StarPU.
  273. @item @code{unsigned workers_bindid[STARPU_NMAXWORKERS]}
  274. Indicates the successive cpu identifier that should be used to bind the
  275. workers. It is either filled according to the user's explicit
  276. parameters (from starpu_conf) or according to the STARPU_WORKERS_CPUID env.
  277. variable. Otherwise, a round-robin policy is used to distributed the workers
  278. over the cpus.
  279. @item @code{unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  280. Indicates the successive cpu identifier that should be used by the CUDA
  281. driver. It is either filled according to the user's explicit parameters (from
  282. starpu_conf) or according to the STARPU_WORKERS_CUDAID env. variable. Otherwise,
  283. they are taken in ID order.
  284. @item @code{unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS]}
  285. Indicates the successive cpu identifier that should be used by the OpenCL
  286. driver. It is either filled according to the user's explicit parameters (from
  287. starpu_conf) or according to the STARPU_WORKERS_OPENCLID env. variable. Otherwise,
  288. they are taken in ID order.
  289. @end table
  290. @end deftp
  291. @node Scheduling Contexts
  292. @section Scheduling Contexts
  293. StarPU permits on one hand grouping workers in combined workers in order to execute a parallel task and on the other hand grouping tasks in bundles that will be executed by a single specified worker.
  294. In contrast when we group workers in scheduling contexts we submit starpu tasks to them and we schedule them with the policy assigned to the context.
  295. Scheduling contexts can be created, deleted and modified dynamically.
  296. @deftypefun unsigned starpu_sched_ctx_create (const char *@var{policy_name}, int *@var{workerids_ctx}, int @var{nworkers_ctx}, const char *@var{sched_ctx_name})
  297. This function creates a scheduling context which uses the scheduling policy indicated in the first argument and assigns the workers indicated in the second argument to execute the tasks submitted to it.
  298. The return value represents the identifier of the context that has just been created. It will be further used to indicate the context the tasks will be submitted to. The return value should be at most @code{STARPU_NMAX_SCHED_CTXS}.
  299. @end deftypefun
  300. @deftypefun void starpu_sched_ctx_delete (unsigned @var{sched_ctx_id})
  301. Delete scheduling context @var{sched_ctx_id} and transfer remaining workers to the inheritor scheduling context.
  302. @end deftypefun
  303. @deftypefun void starpu_sched_ctx_add_workers ({int *}@var{workerids_ctx}, int @var{nworkers_ctx}, unsigned @var{sched_ctx_id})
  304. This function adds dynamically the workers indicated in the first argument to the context indicated in the last argument. The last argument cannot be greater than @code{STARPU_NMAX_SCHED_CTXS}.
  305. @end deftypefun
  306. @deftypefun void starpu_sched_ctx_remove_workers ({int *}@var{workerids_ctx}, int @var{nworkers_ctx}, unsigned @var{sched_ctx_id})
  307. This function removes the workers indicated in the first argument from the context indicated in the last argument. The last argument cannot be greater than @code{STARPU_NMAX_SCHED_CTXS}.
  308. @end deftypefun
  309. A scheduling context manages a collection of workers that can be memorized using different data structures. Thus, a generic structure is available in order to simplify the choice of its type.
  310. Only the list data structure is available but further data structures(like tree) implementations are foreseen.
  311. @deftp {Data Type} {struct starpu_worker_collection}
  312. @table @asis
  313. @item @code{void *workerids}
  314. The workerids managed by the collection
  315. @item @code{unsigned nworkers}
  316. The number of workerids
  317. @item @code{pthread_key_t cursor_key} (optional)
  318. The cursor needed to iterate the collection (depending on the data structure)
  319. @item @code{int type}
  320. The type of structure (currently STARPU_WORKER_LIST is the only one available)
  321. @item @code{unsigned (*has_next)(struct starpu_worker_collection *workers)}
  322. Checks if there is a next worker
  323. @item @code{int (*get_next)(struct starpu_worker_collection *workers)}
  324. Gets the next worker
  325. @item @code{int (*add)(struct starpu_worker_collection *workers, int worker)}
  326. Adds a worker to the collection
  327. @item @code{int (*remove)(struct starpu_worker_collection *workers, int worker)}
  328. Removes a worker from the collection
  329. @item @code{void* (*init)(struct starpu_worker_collection *workers)}
  330. Initialize the collection
  331. @item @code{void (*deinit)(struct starpu_worker_collection *workers)}
  332. Deinitialize the colection
  333. @item @code{void (*init_cursor)(struct starpu_worker_collection *workers)} (optional)
  334. Initialize the cursor if there is one
  335. @item @code{void (*deinit_cursor)(struct starpu_worker_collection *workers)} (optional)
  336. Deinitialize the cursor if there is one
  337. @end table
  338. @end deftp
  339. @deftypefun struct starpu_worker_collection* starpu_sched_ctx_create_worker_collection (unsigned @var{sched_ctx_id}, int @var{type})
  340. Create a worker collection of the type indicated by the last parameter for the context specified through the first parameter.
  341. @end deftypefun
  342. @deftypefun void starpu_sched_ctx_delete_worker_collection (unsigned @var{sched_ctx_id})
  343. Delete the worker collection of the specified scheduling context
  344. @end deftypefun
  345. @deftypefun struct starpu_worker_collection* starpu_sched_ctx_get_worker_collection (unsigned @var{sched_ctx_id})
  346. Return the worker collection managed by the indicated context
  347. @end deftypefun
  348. @deftypefun pthread_mutex_t* starpu_sched_ctx_get_changing_ctx_mutex (unsigned @var{sched_ctx_id})
  349. TODO
  350. @end deftypefun
  351. @deftypefun void starpu_sched_ctx_set_context (unsigned *@var{sched_ctx_id})
  352. Set the scheduling context the subsequent tasks will be submitted to
  353. @end deftypefun
  354. @deftypefun unsigned starpu_sched_ctx_get_context (void)
  355. Return the scheduling context the tasks are currently submitted to
  356. @end deftypefun
  357. @deftypefun unsigned starpu_sched_ctx_get_nworkers (unsigned @var{sched_ctx_id})
  358. Return the number of workers managed by the specified contexts
  359. (Usually needed to verify if it manages any workers or if it should be blocked)
  360. @end deftypefun
  361. @deftypefun unsigned starpu_sched_ctx_get_nshared_workers (unsigned @var{sched_ctx_id}, unsigned @var{sched_ctx_id2})
  362. Return the number of workers shared by two contexts
  363. @end deftypefun
  364. @node Scheduling Policy
  365. @section Scheduling Policy
  366. TODO
  367. While StarPU comes with a variety of scheduling policies (@pxref{Task
  368. scheduling policy}), it may sometimes be desirable to implement custom
  369. policies to address specific problems. The API described below allows
  370. users to write their own scheduling policy.
  371. @deftp {Data Type} {struct starpu_sched_policy}
  372. This structure contains all the methods that implement a scheduling policy. An
  373. application may specify which scheduling strategy in the @code{sched_policy}
  374. field of the @code{starpu_conf} structure passed to the @code{starpu_init}
  375. function. The different fields are:
  376. @table @asis
  377. @item @code{void (*init_sched)(unsigned sched_ctx_id)}
  378. Initialize the scheduling policy.
  379. @item @code{void (*deinit_sched)(unsigned sched_ctx_id)}
  380. Cleanup the scheduling policy.
  381. @item @code{int (*push_task)(struct starpu_task *)}
  382. Insert a task into the scheduler.
  383. @item @code{void (*push_task_notify)(struct starpu_task *, int workerid)}
  384. Notify the scheduler that a task was pushed on a given worker. This method is
  385. called when a task that was explicitely assigned to a worker becomes ready and
  386. is about to be executed by the worker. This method therefore permits to keep
  387. the state of of the scheduler coherent even when StarPU bypasses the scheduling
  388. strategy.
  389. @item @code{struct starpu_task *(*pop_task)(unsigned sched_ctx_id)} (optional)
  390. Get a task from the scheduler. The mutex associated to the worker is already
  391. taken when this method is called. If this method is defined as @code{NULL}, the
  392. worker will only execute tasks from its local queue. In this case, the
  393. @code{push_task} method should use the @code{starpu_push_local_task} method to
  394. assign tasks to the different workers.
  395. @item @code{struct starpu_task *(*pop_every_task)(unsigned sched_ctx_id)}
  396. Remove all available tasks from the scheduler (tasks are chained by the means
  397. of the prev and next fields of the starpu_task structure). The mutex associated
  398. to the worker is already taken when this method is called. This is currently
  399. not used.
  400. @item @code{void (*pre_exec_hook)(struct starpu_task *)} (optional)
  401. This method is called every time a task is starting.
  402. @item @code{void (*post_exec_hook)(struct starpu_task *)} (optional)
  403. This method is called every time a task has been executed.
  404. @item @code{void (*add_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)}
  405. Initialize scheduling structures corresponding to each worker used by the policy.
  406. @item @code{void (*remove_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)}
  407. Deinitialize scheduling structures corresponding to each worker used by the policy.
  408. @item @code{const char *policy_name} (optional)
  409. Name of the policy.
  410. @item @code{const char *policy_description} (optional)
  411. Description of the policy.
  412. @end table
  413. @end deftp
  414. @deftypefun {struct starpu_sched_policy **} starpu_sched_get_predefined_policies ()
  415. Return an NULL-terminated array of all the predefined scheduling policies.
  416. @end deftypefun
  417. @deftypefun void starpu_sched_ctx_set_policy_data (unsigned @var{sched_ctx_id}, {void *} @var{policy_data})
  418. Each scheduling policy uses some specific data (queues, variables, additional condition variables).
  419. It is memorize through a local structure. This function assigns it to a scheduling context.
  420. @end deftypefun
  421. @deftypefun void* starpu_sched_ctx_get_policy_data (unsigned @var{sched_ctx_id})
  422. Returns the policy data previously assigned to a context
  423. @end deftypefun
  424. @deftypefun void starpu_task_set_min_priority (int @var{min_prio})
  425. Defines the minimum task priority level supported by the scheduling policy. The
  426. default minimum priority level is the same as the default priority level which
  427. is 0 by convention. The application may access that value by calling the
  428. @code{starpu_task_get_min_priority} function. This function should only be
  429. called from the initialization method of the scheduling policy, and should not
  430. be used directly from the application.
  431. @end deftypefun
  432. @deftypefun void starpu_task_set_max_priority (int @var{max_prio})
  433. Defines the maximum priority level supported by the scheduling policy. The
  434. default maximum priority level is 1. The application may access that value by
  435. calling the @code{starpu_task_get_max_priority} function. This function should
  436. only be called from the initialization method of the scheduling policy, and
  437. should not be used directly from the application.
  438. @end deftypefun
  439. @deftypefun int starpu_task_get_min_priority (void)
  440. Returns the current minimum priority level supported by the
  441. scheduling policy
  442. @end deftypefun
  443. @deftypefun int starpu_task_get_max_priority (void)
  444. Returns the current maximum priority level supported by the
  445. scheduling policy
  446. @end deftypefun
  447. @deftypefun int starpu_push_local_task (int @var{workerid}, {struct starpu_task} *@var{task}, int @var{back})
  448. The scheduling policy may put tasks directly into a worker's local queue so
  449. that it is not always necessary to create its own queue when the local queue
  450. is sufficient. If @var{back} not null, @var{task} is put at the back of the queue
  451. where the worker will pop tasks first. Setting @var{back} to 0 therefore ensures
  452. a FIFO ordering.
  453. @end deftypefun
  454. @deftypefun int starpu_push_task_end ({struct starpu_task} *@var{task})
  455. This function must be called by a scheduler to notify that the given
  456. task has just been pushed.
  457. @end deftypefun
  458. @deftypefun int starpu_worker_can_execute_task (unsigned @var{workerid}, {struct starpu_task *}@var{task}, unsigned {nimpl})
  459. Check if the worker specified by workerid can execute the codelet. Schedulers need to call it before assigning a task to a worker, otherwise the task may fail to execute.
  460. @end deftypefun
  461. @deftypefun double starpu_timing_now (void)
  462. Return the current date in µs
  463. @end deftypefun
  464. @deftypefun uint32_t starpu_task_footprint ({struct starpu_perfmodel *}@var{model}, {struct starpu_task *} @var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  465. Returns the footprint for a given task
  466. @end deftypefun
  467. @deftypefun double starpu_task_expected_length ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  468. Returns expected task duration in µs
  469. @end deftypefun
  470. @deftypefun double starpu_worker_get_relative_speedup ({enum starpu_perf_archtype} @var{perf_archtype})
  471. Returns an estimated speedup factor relative to CPU speed
  472. @end deftypefun
  473. @deftypefun double starpu_task_expected_data_transfer_time (unsigned @var{memory_node}, {struct starpu_task *}@var{task})
  474. Returns expected data transfer time in µs
  475. @end deftypefun
  476. @deftypefun double starpu_data_expected_transfer_time (starpu_data_handle_t @var{handle}, unsigned @var{memory_node}, {enum starpu_access_mode} @var{mode})
  477. Predict the transfer time (in µs) to move a handle to a memory node
  478. @end deftypefun
  479. @deftypefun double starpu_task_expected_power ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  480. Returns expected power consumption in J
  481. @end deftypefun
  482. @deftypefun double starpu_task_expected_conversion_time ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned {nimpl})
  483. Returns expected conversion time in ms (multiformat interface only)
  484. @end deftypefun
  485. @node Running drivers
  486. @section Running drivers
  487. @deftypefun int starpu_driver_run ({struct starpu_driver *}@var{d})
  488. Initialize the given driver, run it until it receives a request to terminate,
  489. deinitialize it and return 0 on success. It returns -EINVAL if @code{d->type}
  490. is not a valid StarPU device type (STARPU_CPU_WORKER, STARPU_CUDA_WORKER or
  491. STARPU_OPENCL_WORKER). This is the same as using the following
  492. functions: calling @code{starpu_driver_init()}, then calling
  493. @code{starpu_driver_run_once()} in a loop, and eventually
  494. @code{starpu_driver_deinit()}.
  495. @end deftypefun
  496. @deftypefun int starpu_driver_init (struct starpu_driver *@var{d})
  497. Initialize the given driver. Returns 0 on success, -EINVAL if
  498. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  499. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  500. @end deftypefun
  501. @deftypefun int starpu_driver_run_once (struct starpu_driver *@var{d})
  502. Run the driver once, then returns 0 on success, -EINVAL if
  503. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  504. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  505. @end deftypefun
  506. @deftypefun int starpu_driver_deinit (struct starpu_driver *@var{d})
  507. Deinitialize the given driver. Returns 0 on success, -EINVAL if
  508. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  509. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  510. @end deftypefun
  511. @deftypefun void starpu_drivers_request_termination (void)
  512. Notify all running drivers they should terminate.
  513. @end deftypefun
  514. @node Expert mode
  515. @section Expert mode
  516. @deftypefun void starpu_wake_all_blocked_workers (void)
  517. Wake all the workers, so they can inspect data requests and task submissions
  518. again.
  519. @end deftypefun
  520. @deftypefun int starpu_progression_hook_register (unsigned (*@var{func})(void *arg), void *@var{arg})
  521. Register a progression hook, to be called when workers are idle.
  522. @end deftypefun
  523. @deftypefun void starpu_progression_hook_deregister (int @var{hook_id})
  524. Unregister a given progression hook.
  525. @end deftypefun