advanced-api.texi 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. @c -*-texinfo-*-
  2. @c This file is part of the StarPU Handbook.
  3. @c Copyright (C) 2009--2011 Universit@'e de Bordeaux 1
  4. @c Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. @c Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  6. @c See the file starpu.texi for copying conditions.
  7. @menu
  8. * Insert Task::
  9. * Tracing support::
  10. * MPI Interface::
  11. * Defining a new data interface::
  12. * Multiformat Data Interface::
  13. * Task Bundles::
  14. * Task Lists::
  15. * Using Parallel Tasks::
  16. * Scheduling Contexts::
  17. * Defining a new scheduling policy::
  18. * Running drivers::
  19. * Expert mode::
  20. @end menu
  21. @node Insert Task
  22. @section Insert Task
  23. @deftypefun int starpu_insert_task (struct starpu_codelet *@var{cl}, ...)
  24. Create and submit a task corresponding to @var{cl} with the following
  25. arguments. The argument list must be zero-terminated.
  26. The arguments following the codelets can be of the following types:
  27. @itemize
  28. @item
  29. @code{STARPU_R}, @code{STARPU_W}, @code{STARPU_RW}, @code{STARPU_SCRATCH}, @code{STARPU_REDUX} an access mode followed by a data handle;
  30. @item
  31. @code{STARPU_DATA_ARRAY} followed by an array of data handles and its number of elements;
  32. @item
  33. the specific values @code{STARPU_VALUE}, @code{STARPU_CALLBACK},
  34. @code{STARPU_CALLBACK_ARG}, @code{STARPU_CALLBACK_WITH_ARG},
  35. @code{STARPU_PRIORITY}, @code{STARPU_TAG}, followed by the appropriated objects
  36. as defined below.
  37. @end itemize
  38. When using @code{STARPU_DATA_ARRAY}, the access mode of the data
  39. handles is not defined.
  40. Parameters to be passed to the codelet implementation are defined
  41. through the type @code{STARPU_VALUE}. The function
  42. @code{starpu_codelet_unpack_args} must be called within the codelet
  43. implementation to retrieve them.
  44. @end deftypefun
  45. @defmac STARPU_VALUE
  46. this macro is used when calling @code{starpu_insert_task}, and must be
  47. followed by a pointer to a constant value and the size of the constant
  48. @end defmac
  49. @defmac STARPU_CALLBACK
  50. this macro is used when calling @code{starpu_insert_task}, and must be
  51. followed by a pointer to a callback function
  52. @end defmac
  53. @defmac STARPU_CALLBACK_ARG
  54. this macro is used when calling @code{starpu_insert_task}, and must be
  55. followed by a pointer to be given as an argument to the callback
  56. function
  57. @end defmac
  58. @defmac STARPU_CALLBACK_WITH_ARG
  59. this macro is used when calling @code{starpu_insert_task}, and must be
  60. followed by two pointers: one to a callback function, and the other to
  61. be given as an argument to the callback function; this is equivalent
  62. to using both @code{STARPU_CALLBACK} and
  63. @code{STARPU_CALLBACK_WITH_ARG}
  64. @end defmac
  65. @defmac STARPU_PRIORITY
  66. this macro is used when calling @code{starpu_insert_task}, and must be
  67. followed by a integer defining a priority level
  68. @end defmac
  69. @defmac STARPU_TAG
  70. this macro is used when calling @code{starpu_insert_task}, and must be
  71. followed by a tag.
  72. @end defmac
  73. @deftypefun void starpu_codelet_pack_args ({char **}@var{arg_buffer}, {size_t *}@var{arg_buffer_size}, ...)
  74. Pack arguments of type @code{STARPU_VALUE} into a buffer which can be
  75. given to a codelet and later unpacked with the function
  76. @code{starpu_codelet_unpack_args} defined below.
  77. @end deftypefun
  78. @deftypefun void starpu_codelet_unpack_args ({void *}@var{cl_arg}, ...)
  79. Retrieve the arguments of type @code{STARPU_VALUE} associated to a
  80. task automatically created using the function
  81. @code{starpu_insert_task} defined above.
  82. @end deftypefun
  83. @node Tracing support
  84. @section Tracing support
  85. @deftypefun void starpu_fxt_start_profiling (void)
  86. Start recording the trace. The trace is by default started from
  87. @code{starpu_init()} call, but can be paused by using
  88. @code{starpu_fxt_stop_profiling}, in which case
  89. @code{starpu_fxt_start_profiling} should be called to specify when to resume
  90. recording events.
  91. @end deftypefun
  92. @deftypefun void starpu_fxt_stop_profiling (void)
  93. Stop recording the trace. The trace is by default stopped at
  94. @code{starpu_shutdown()} call. @code{starpu_fxt_stop_profiling} can however be
  95. used to stop it earlier. @code{starpu_fxt_start_profiling} can then be called to
  96. start recording it again, etc.
  97. @end deftypefun
  98. @node MPI Interface
  99. @section MPI Interface
  100. @menu
  101. * Initialisation::
  102. * Communication::
  103. * Communication cache::
  104. @end menu
  105. @node Initialisation
  106. @subsection Initialisation
  107. @deftypefun int starpu_mpi_init (int *@var{argc}, char ***@var{argv}, int initialize_mpi)
  108. Initializes the starpumpi library. @code{initialize_mpi} indicates if
  109. MPI should be initialized or not by StarPU. If the value is not @code{0},
  110. MPI will be initialized by calling @code{MPI_Init_Thread(argc, argv,
  111. MPI_THREAD_SERIALIZED, ...)}.
  112. @end deftypefun
  113. @deftypefun int starpu_mpi_initialize (void)
  114. This function has been made deprecated. One should use instead the
  115. function @code{starpu_mpi_init()} defined above.
  116. This function does not call @code{MPI_Init}, it should be called beforehand.
  117. @end deftypefun
  118. @deftypefun int starpu_mpi_initialize_extended (int *@var{rank}, int *@var{world_size})
  119. This function has been made deprecated. One should use instead the
  120. function @code{starpu_mpi_init()} defined above.
  121. MPI will be initialized by starpumpi by calling @code{MPI_Init_Thread(argc, argv,
  122. MPI_THREAD_SERIALIZED, ...)}.
  123. @end deftypefun
  124. @deftypefun int starpu_mpi_shutdown (void)
  125. Cleans the starpumpi library. This must be called between calling
  126. @code{starpu_mpi} functions and @code{starpu_shutdown()}.
  127. @code{MPI_Finalize()} will be called if StarPU-MPI has been initialized
  128. by @code{starpu_mpi_init()}.
  129. @end deftypefun
  130. @deftypefun void starpu_mpi_comm_amounts_retrieve (size_t *@var{comm_amounts})
  131. Retrieve the current amount of communications from the current node in
  132. the array @code{comm_amounts} which must have a size greater or equal
  133. to the world size. Communications statistics must be enabled
  134. (@pxref{STARPU_COMM_STATS}).
  135. @end deftypefun
  136. @node Communication
  137. @subsection Communication
  138. @deftypefun int starpu_mpi_send (starpu_data_handle_t @var{data_handle}, int @var{dest}, int @var{mpi_tag}, MPI_Comm @var{comm})
  139. Performs a standard-mode, blocking send of @var{data_handle} to the
  140. node @var{dest} using the message tag @code{mpi_tag} within the
  141. communicator @var{comm}.
  142. @end deftypefun
  143. @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})
  144. Performs a standard-mode, blocking receive in @var{data_handle} from the
  145. node @var{source} using the message tag @code{mpi_tag} within the
  146. communicator @var{comm}.
  147. @end deftypefun
  148. @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})
  149. Posts a standard-mode, non blocking send of @var{data_handle} to the
  150. node @var{dest} using the message tag @code{mpi_tag} within the
  151. communicator @var{comm}. After the call, the pointer to the request
  152. @var{req} can be used to test or to wait for the completion of the communication.
  153. @end deftypefun
  154. @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})
  155. Posts a nonblocking receive in @var{data_handle} from the
  156. node @var{source} using the message tag @code{mpi_tag} within the
  157. communicator @var{comm}. After the call, the pointer to the request
  158. @var{req} can be used to test or to wait for the completion of the communication.
  159. @end deftypefun
  160. @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})
  161. Posts a standard-mode, non blocking send of @var{data_handle} to the
  162. node @var{dest} using the message tag @code{mpi_tag} within the
  163. communicator @var{comm}. On completion, the @var{callback} function is
  164. called with the argument @var{arg}. Similarly to the pthread detached
  165. functionality, when a detached communication completes, its resources
  166. are automatically released back to the system, there is no need to
  167. test or to wait for the completion of the request.
  168. @end deftypefun
  169. @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})
  170. Posts a nonblocking receive in @var{data_handle} from the
  171. node @var{source} using the message tag @code{mpi_tag} within the
  172. communicator @var{comm}. On completion, the @var{callback} function is
  173. called with the argument @var{arg}. Similarly to the pthread detached
  174. functionality, when a detached communication completes, its resources
  175. are automatically released back to the system, there is no need to
  176. test or to wait for the completion of the request.
  177. @end deftypefun
  178. @deftypefun int starpu_mpi_wait (starpu_mpi_req *@var{req}, MPI_Status *@var{status})
  179. Returns when the operation identified by request @var{req} is complete.
  180. @end deftypefun
  181. @deftypefun int starpu_mpi_test (starpu_mpi_req *@var{req}, int *@var{flag}, MPI_Status *@var{status})
  182. If the operation identified by @var{req} is complete, set @var{flag}
  183. to 1. The @var{status} object is set to contain information on the
  184. completed operation.
  185. @end deftypefun
  186. @deftypefun int starpu_mpi_barrier (MPI_Comm @var{comm})
  187. Blocks the caller until all group members of the communicator
  188. @var{comm} have called it.
  189. @end deftypefun
  190. @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})
  191. Posts a standard-mode, non blocking send of @var{data_handle} to the
  192. node @var{dest} using the message tag @code{mpi_tag} within the
  193. communicator @var{comm}. On completion, @var{tag} is unlocked.
  194. @end deftypefun
  195. @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})
  196. Posts a nonblocking receive in @var{data_handle} from the
  197. node @var{source} using the message tag @code{mpi_tag} within the
  198. communicator @var{comm}. On completion, @var{tag} is unlocked.
  199. @end deftypefun
  200. @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})
  201. Posts @var{array_size} standard-mode, non blocking send. Each post
  202. sends the n-th data of the array @var{data_handle} to the n-th node of
  203. the array @var{dest}
  204. using the n-th message tag of the array @code{mpi_tag} within the n-th
  205. communicator of the array
  206. @var{comm}. On completion of the all the requests, @var{tag} is unlocked.
  207. @end deftypefun
  208. @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})
  209. Posts @var{array_size} nonblocking receive. Each post receives in the
  210. n-th data of the array @var{data_handle} from the n-th
  211. node of the array @var{source} using the n-th message tag of the array
  212. @code{mpi_tag} within the n-th communicator of the array @var{comm}.
  213. On completion of the all the requests, @var{tag} is unlocked.
  214. @end deftypefun
  215. @node Communication cache
  216. @subsection Communication cache
  217. @deftypefun void starpu_mpi_cache_flush (MPI_Comm @var{comm}, starpu_data_handle_t @var{data_handle})
  218. Clear the send and receive communication cache for the data
  219. @var{data_handle}. The function has to be called synchronously by all
  220. the MPI nodes.
  221. The function does nothing if the cache mechanism is disabled (@pxref{STARPU_MPI_CACHE}).
  222. @end deftypefun
  223. @deftypefun void starpu_mpi_cache_flush_all_data (MPI_Comm @var{comm})
  224. Clear the send and receive communication cache for all data. The
  225. function has to be called synchronously by all the MPI nodes.
  226. The function does nothing if the cache mechanism is disabled (@pxref{STARPU_MPI_CACHE}).
  227. @end deftypefun
  228. @node Defining a new data interface
  229. @section Defining a new data interface
  230. @menu
  231. * Data Interface API:: Data Interface API
  232. * An example of data interface:: An example of data interface
  233. @end menu
  234. @node Data Interface API
  235. @subsection Data Interface API
  236. @deftp {Data Type} {struct starpu_data_interface_ops}
  237. @anchor{struct starpu_data_interface_ops}
  238. Per-interface data transfer methods.
  239. @table @asis
  240. @item @code{void (*register_data_handle)(starpu_data_handle_t handle, unsigned home_node, void *data_interface)}
  241. Register an existing interface into a data handle.
  242. @item @code{starpu_ssize_t (*allocate_data_on_node)(void *data_interface, unsigned node)}
  243. Allocate data for the interface on a given node.
  244. @item @code{ void (*free_data_on_node)(void *data_interface, unsigned node)}
  245. Free data of the interface on a given node.
  246. @item @code{ const struct starpu_data_copy_methods *copy_methods}
  247. ram/cuda/opencl synchronous and asynchronous transfer methods.
  248. @item @code{ void * (*handle_to_pointer)(starpu_data_handle_t handle, unsigned node)}
  249. Return the current pointer (if any) for the handle on the given node.
  250. @item @code{ size_t (*get_size)(starpu_data_handle_t handle)}
  251. Return an estimation of the size of data, for performance models.
  252. @item @code{ uint32_t (*footprint)(starpu_data_handle_t handle)}
  253. Return a 32bit footprint which characterizes the data size.
  254. @item @code{ int (*compare)(void *data_interface_a, void *data_interface_b)}
  255. Compare the data size of two interfaces.
  256. @item @code{ void (*display)(starpu_data_handle_t handle, FILE *f)}
  257. Dump the sizes of a handle to a file.
  258. @item @code{enum starpu_data_interface_id interfaceid}
  259. An identifier that is unique to each interface.
  260. @item @code{size_t interface_size}
  261. The size of the interface data descriptor.
  262. @item @code{int is_multiformat}
  263. todo
  264. @item @code{struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface)}
  265. todo
  266. @item @code{int (*pack_data)(starpu_data_handle_t handle, unsigned node, void **ptr, size_t *count)}
  267. Pack the data handle into a contiguous buffer at the address @code{ptr} and set the size of the newly created buffer in @code{count}
  268. @item @code{int (*unpack_data)(starpu_data_handle_t handle, unsigned node, void *ptr, size_t count)}
  269. Unpack the data handle from the contiguous buffer at the address @code{ptr} of size @var{count}
  270. @end table
  271. @end deftp
  272. @deftp {Data Type} {struct starpu_data_copy_methods}
  273. Defines the per-interface methods. If the @code{any_to_any} method is provided,
  274. it will be used by default if no more specific method is provided. It can still
  275. be useful to provide more specific method in case of e.g. available particular
  276. CUDA or OpenCL support.
  277. @table @asis
  278. @item @code{int (*@{ram,cuda,opencl@}_to_@{ram,cuda,opencl@})(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)}
  279. These 12 functions define how to copy data from the @var{src_interface}
  280. interface on the @var{src_node} node to the @var{dst_interface} interface
  281. on the @var{dst_node} node. They return 0 on success.
  282. @item @code{int (*@{ram,cuda@}_to_@{ram,cuda@}_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)}
  283. These 3 functions (@code{ram_to_ram} is not among these) define how to copy
  284. data from the @var{src_interface} interface on the @var{src_node} node to the
  285. @var{dst_interface} interface on the @var{dst_node} node, using the given
  286. @var{stream}. Must return 0 if the transfer was actually completed completely
  287. synchronously, or -EAGAIN if at least some transfers are still ongoing and
  288. should be awaited for by the core.
  289. @item @code{int (*@{ram,opencl@}_to_@{ram,opencl@}_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, /* cl_event * */ void *event)}
  290. These 3 functions (@code{ram_to_ram} is not among them) define how to copy
  291. data from the @var{src_interface} interface on the @var{src_node} node to the
  292. @var{dst_interface} interface on the @var{dst_node} node, by recording in
  293. @var{event}, a pointer to a cl_event, the event of the last submitted transfer.
  294. Must return 0 if the transfer was actually completed completely synchronously,
  295. or -EAGAIN if at least some transfers are still ongoing and should be awaited
  296. for by the core.
  297. @item @code{int (*any_to_any)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, void *async_data)}
  298. Define how to copy data from the @var{src_interface} interface on the
  299. @var{src_node} node to the @var{dst_interface} interface on the @var{dst_node}
  300. node. This is meant to be implemented through the @var{starpu_interface_copy}
  301. helper, to which @var{async_data} should be passed as such, and will be used to
  302. manage asynchronicity. This must return -EAGAIN if any of the
  303. @var{starpu_interface_copy} calls has returned -EAGAIN (i.e. at least some
  304. transfer is still ongoing), and return 0 otherwise.
  305. @end table
  306. @end deftp
  307. @deftypefun int starpu_interface_copy (uintptr_t @var{src}, size_t @var{src_offset}, unsigned @var{src_node}, uintptr_t @var{dst}, size_t @var{dst_offset}, unsigned @var{dst_node}, size_t @var{size}, {void *}@var{async_data})
  308. Copy @var{size} bytes from byte offset @var{src_offset} of @var{src} on
  309. @var{src_node} to byte offset @var{dst_offset} of @var{dst} on @var{dst_node}.
  310. This is to be used in the @var{any_to_any} copy method, which is provided with
  311. the @var{async_data} to be pased to @var{starpu_interface_copy}. this returns
  312. -EAGAIN if the transfer is still ongoing, or 0 if the transfer is already
  313. completed.
  314. @end deftypefun
  315. @deftypefun uint32_t starpu_crc32_be_n ({void *}@var{input}, size_t @var{n}, uint32_t @var{inputcrc})
  316. Compute the CRC of a byte buffer seeded by the inputcrc "current
  317. state". The return value should be considered as the new "current
  318. state" for future CRC computation. This is used for computing data size
  319. footprint.
  320. @end deftypefun
  321. @deftypefun uint32_t starpu_crc32_be (uint32_t @var{input}, uint32_t @var{inputcrc})
  322. Compute the CRC of a 32bit number seeded by the inputcrc "current
  323. state". The return value should be considered as the new "current
  324. state" for future CRC computation. This is used for computing data size
  325. footprint.
  326. @end deftypefun
  327. @deftypefun uint32_t starpu_crc32_string ({char *}@var{str}, uint32_t @var{inputcrc})
  328. Compute the CRC of a string seeded by the inputcrc "current state".
  329. The return value should be considered as the new "current state" for
  330. future CRC computation. This is used for computing data size footprint.
  331. @end deftypefun
  332. @node An example of data interface
  333. @subsection An example of data interface
  334. @deftypefun int starpu_data_interface_get_next_id (void)
  335. Returns the next available id for a newly created data interface.
  336. @end deftypefun
  337. Let's define a new data interface to manage complex numbers.
  338. @cartouche
  339. @smallexample
  340. /* interface for complex numbers */
  341. struct starpu_complex_interface
  342. @{
  343. double *real;
  344. double *imaginary;
  345. int nx;
  346. @};
  347. @end smallexample
  348. @end cartouche
  349. Registering such a data to StarPU is easily done using the function
  350. @code{starpu_data_register} (@pxref{Basic Data Management API}). The last
  351. parameter of the function, @code{interface_complex_ops}, will be
  352. described below.
  353. @cartouche
  354. @smallexample
  355. void starpu_complex_data_register(starpu_data_handle_t *handle,
  356. unsigned home_node, double *real, double *imaginary, int nx)
  357. @{
  358. struct starpu_complex_interface complex =
  359. @{
  360. .real = real,
  361. .imaginary = imaginary,
  362. .nx = nx
  363. @};
  364. if (interface_complex_ops.interfaceid == STARPU_UNKNOWN_INTERFACE_ID)
  365. @{
  366. interface_complex_ops.interfaceid = starpu_data_interface_get_next_id();
  367. @}
  368. starpu_data_register(handleptr, home_node, &complex, &interface_complex_ops);
  369. @}
  370. @end smallexample
  371. @end cartouche
  372. Different operations need to be defined for a data interface through
  373. the type @code{struct starpu_data_interface_ops} (@pxref{Data
  374. Interface API}). We only define here the basic operations needed to
  375. run simple applications. The source code for the different functions
  376. can be found in the file
  377. @code{examples/interface/complex_interface.c}.
  378. @cartouche
  379. @smallexample
  380. static struct starpu_data_interface_ops interface_complex_ops =
  381. @{
  382. .register_data_handle = complex_register_data_handle,
  383. .allocate_data_on_node = complex_allocate_data_on_node,
  384. .copy_methods = &complex_copy_methods,
  385. .get_size = complex_get_size,
  386. .footprint = complex_footprint,
  387. .interfaceid = STARPU_UNKNOWN_INTERFACE_ID,
  388. .interface_size = sizeof(struct starpu_complex_interface),
  389. @};
  390. @end smallexample
  391. @end cartouche
  392. Functions need to be defined to access the different fields of the
  393. complex interface from a StarPU data handle.
  394. @cartouche
  395. @smallexample
  396. double *starpu_complex_get_real(starpu_data_handle_t handle)
  397. @{
  398. struct starpu_complex_interface *complex_interface =
  399. (struct starpu_complex_interface *) starpu_data_get_interface_on_node(handle, 0);
  400. return complex_interface->real;
  401. @}
  402. double *starpu_complex_get_imaginary(starpu_data_handle_t handle);
  403. int starpu_complex_get_nx(starpu_data_handle_t handle);
  404. @end smallexample
  405. @end cartouche
  406. Similar functions need to be defined to access the different fields of the
  407. complex interface from a @code{void *} pointer to be used within codelet
  408. implemetations.
  409. @cartouche
  410. @smallexample
  411. #define STARPU_COMPLEX_GET_REAL(interface) \
  412. (((struct starpu_complex_interface *)(interface))->real)
  413. #define STARPU_COMPLEX_GET_IMAGINARY(interface) \
  414. (((struct starpu_complex_interface *)(interface))->imaginary)
  415. #define STARPU_COMPLEX_GET_NX(interface) \
  416. (((struct starpu_complex_interface *)(interface))->nx)
  417. @end smallexample
  418. @end cartouche
  419. Complex data interfaces can then be registered to StarPU.
  420. @cartouche
  421. @smallexample
  422. double real = 45.0;
  423. double imaginary = 12.0;
  424. starpu_complex_data_register(&handle1, 0, &real, &imaginary, 1);
  425. starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
  426. @end smallexample
  427. @end cartouche
  428. and used by codelets.
  429. @cartouche
  430. @smallexample
  431. void display_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args)
  432. @{
  433. int nx = STARPU_COMPLEX_GET_NX(descr[0]);
  434. double *real = STARPU_COMPLEX_GET_REAL(descr[0]);
  435. double *imaginary = STARPU_COMPLEX_GET_IMAGINARY(descr[0]);
  436. int i;
  437. for(i=0 ; i<nx ; i++)
  438. @{
  439. fprintf(stderr, "Complex[%d] = %3.2f + %3.2f i\n", i, real[i], imaginary[i]);
  440. @}
  441. @}
  442. @end smallexample
  443. @end cartouche
  444. The whole code for this complex data interface is available in the
  445. directory @code{examples/interface/}.
  446. @node Multiformat Data Interface
  447. @section Multiformat Data Interface
  448. @deftp {Data Type} {struct starpu_multiformat_data_interface_ops}
  449. The different fields are:
  450. @table @asis
  451. @item @code{size_t cpu_elemsize}
  452. the size of each element on CPUs,
  453. @item @code{size_t opencl_elemsize}
  454. the size of each element on OpenCL devices,
  455. @item @code{struct starpu_codelet *cpu_to_opencl_cl}
  456. pointer to a codelet which converts from CPU to OpenCL
  457. @item @code{struct starpu_codelet *opencl_to_cpu_cl}
  458. pointer to a codelet which converts from OpenCL to CPU
  459. @item @code{size_t cuda_elemsize}
  460. the size of each element on CUDA devices,
  461. @item @code{struct starpu_codelet *cpu_to_cuda_cl}
  462. pointer to a codelet which converts from CPU to CUDA
  463. @item @code{struct starpu_codelet *cuda_to_cpu_cl}
  464. pointer to a codelet which converts from CUDA to CPU
  465. @end table
  466. @end deftp
  467. @deftypefun void starpu_multiformat_data_register (starpu_data_handle_t *@var{handle}, unsigned @var{home_node}, void *@var{ptr}, uint32_t @var{nobjects}, struct starpu_multiformat_data_interface_ops *@var{format_ops})
  468. Register a piece of data that can be represented in different ways, depending upon
  469. the processing unit that manipulates it. It allows the programmer, for instance, to
  470. use an array of structures when working on a CPU, and a structure of arrays when
  471. working on a GPU.
  472. @var{nobjects} is the number of elements in the data. @var{format_ops} describes
  473. the format.
  474. @end deftypefun
  475. @defmac STARPU_MULTIFORMAT_GET_CPU_PTR ({void *}@var{interface})
  476. returns the local pointer to the data with CPU format.
  477. @end defmac
  478. @defmac STARPU_MULTIFORMAT_GET_CUDA_PTR ({void *}@var{interface})
  479. returns the local pointer to the data with CUDA format.
  480. @end defmac
  481. @defmac STARPU_MULTIFORMAT_GET_OPENCL_PTR ({void *}@var{interface})
  482. returns the local pointer to the data with OpenCL format.
  483. @end defmac
  484. @defmac STARPU_MULTIFORMAT_GET_NX ({void *}@var{interface})
  485. returns the number of elements in the data.
  486. @end defmac
  487. @node Task Bundles
  488. @section Task Bundles
  489. @deftp {Data Type} {starpu_task_bundle_t}
  490. Opaque structure describing a list of tasks that should be scheduled
  491. on the same worker whenever it's possible. It must be considered as a
  492. hint given to the scheduler as there is no guarantee that they will be
  493. executed on the same worker.
  494. @end deftp
  495. @deftypefun void starpu_task_bundle_create ({starpu_task_bundle_t *}@var{bundle})
  496. Factory function creating and initializing @var{bundle}, when the call returns, memory needed is allocated and @var{bundle} is ready to use.
  497. @end deftypefun
  498. @deftypefun int starpu_task_bundle_insert (starpu_task_bundle_t @var{bundle}, {struct starpu_task *}@var{task})
  499. 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}.
  500. This function mustn't be called if @var{bundle} is already closed and/or @var{task} is already submitted.
  501. @end deftypefun
  502. @deftypefun int starpu_task_bundle_remove (starpu_task_bundle_t @var{bundle}, {struct starpu_task *}@var{task})
  503. Remove @var{task} from @var{bundle}.
  504. Of course @var{task} must have been previously inserted @var{bundle}.
  505. 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.
  506. @end deftypefun
  507. @deftypefun void starpu_task_bundle_close (starpu_task_bundle_t @var{bundle})
  508. 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.
  509. @end deftypefun
  510. @deftypefun double starpu_task_bundle_expected_length (starpu_task_bundle_t @var{bundle}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  511. Return the expected duration of the entire task bundle in µs.
  512. @end deftypefun
  513. @deftypefun double starpu_task_bundle_expected_power (starpu_task_bundle_t @var{bundle}, enum starpu_perf_archtype @var{arch}, unsigned @var{nimpl})
  514. Return the expected power consumption of the entire task bundle in J.
  515. @end deftypefun
  516. @deftypefun double starpu_task_bundle_expected_data_transfer_time (starpu_task_bundle_t @var{bundle}, unsigned @var{memory_node})
  517. Return the time (in µs) expected to transfer all data used within the bundle.
  518. @end deftypefun
  519. @node Task Lists
  520. @section Task Lists
  521. @deftp {Data Type} {struct starpu_task_list}
  522. Stores a double-chained list of tasks
  523. @end deftp
  524. @deftypefun void starpu_task_list_init ({struct starpu_task_list *}@var{list})
  525. Initialize a list structure
  526. @end deftypefun
  527. @deftypefun void starpu_task_list_push_front ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  528. Push a task at the front of a list
  529. @end deftypefun
  530. @deftypefun void starpu_task_list_push_back ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  531. Push a task at the back of a list
  532. @end deftypefun
  533. @deftypefun {struct starpu_task *} starpu_task_list_front ({struct starpu_task_list *}@var{list})
  534. Get the front of the list (without removing it)
  535. @end deftypefun
  536. @deftypefun {struct starpu_task *} starpu_task_list_back ({struct starpu_task_list *}@var{list})
  537. Get the back of the list (without removing it)
  538. @end deftypefun
  539. @deftypefun int starpu_task_list_empty ({struct starpu_task_list *}@var{list})
  540. Test if a list is empty
  541. @end deftypefun
  542. @deftypefun void starpu_task_list_erase ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  543. Remove an element from the list
  544. @end deftypefun
  545. @deftypefun {struct starpu_task *} starpu_task_list_pop_front ({struct starpu_task_list *}@var{list})
  546. Remove the element at the front of the list
  547. @end deftypefun
  548. @deftypefun {struct starpu_task *} starpu_task_list_pop_back ({struct starpu_task_list *}@var{list})
  549. Remove the element at the back of the list
  550. @end deftypefun
  551. @deftypefun {struct starpu_task *} starpu_task_list_begin ({struct starpu_task_list *}@var{list})
  552. Get the first task of the list.
  553. @end deftypefun
  554. @deftypefun {struct starpu_task *} starpu_task_list_end ({struct starpu_task_list *}@var{list})
  555. Get the end of the list.
  556. @end deftypefun
  557. @deftypefun {struct starpu_task *} starpu_task_list_next ({struct starpu_task *}@var{task})
  558. Get the next task of the list. This is not erase-safe.
  559. @end deftypefun
  560. @node Using Parallel Tasks
  561. @section Using Parallel Tasks
  562. These are used by parallel tasks:
  563. @deftypefun int starpu_combined_worker_get_size (void)
  564. Return the size of the current combined worker, i.e. the total number of cpus
  565. running the same task in the case of SPMD parallel tasks, or the total number
  566. of threads that the task is allowed to start in the case of FORKJOIN parallel
  567. tasks.
  568. @end deftypefun
  569. @deftypefun int starpu_combined_worker_get_rank (void)
  570. Return the rank of the current thread within the combined worker. Can only be
  571. used in FORKJOIN parallel tasks, to know which part of the task to work on.
  572. @end deftypefun
  573. Most of these are used for schedulers which support parallel tasks.
  574. @deftypefun unsigned starpu_combined_worker_get_count (void)
  575. Return the number of different combined workers.
  576. @end deftypefun
  577. @deftypefun int starpu_combined_worker_get_id (void)
  578. Return the identifier of the current combined worker.
  579. @end deftypefun
  580. @deftypefun int starpu_combined_worker_assign_workerid (int @var{nworkers}, int @var{workerid_array}[])
  581. Register a new combined worker and get its identifier
  582. @end deftypefun
  583. @deftypefun int starpu_combined_worker_get_description (int @var{workerid}, {int *}@var{worker_size}, {int **}@var{combined_workerid})
  584. Get the description of a combined worker
  585. @end deftypefun
  586. @deftypefun int starpu_combined_worker_can_execute_task (unsigned @var{workerid}, {struct starpu_task *}@var{task}, unsigned @var{nimpl})
  587. Variant of starpu_worker_can_execute_task compatible with combined workers
  588. @end deftypefun
  589. @deftp {Data Type} {struct starpu_machine_topology}
  590. @table @asis
  591. @item @code{unsigned nworkers}
  592. Total number of workers.
  593. @item @code{unsigned ncombinedworkers}
  594. Total number of combined workers.
  595. @item @code{hwloc_topology_t hwtopology}
  596. Topology as detected by hwloc.
  597. To maintain ABI compatibility when hwloc is not available, the field
  598. is replaced with @code{void *dummy}
  599. @item @code{unsigned nhwcpus}
  600. Total number of CPUs, as detected by the topology code. May be different from
  601. the actual number of CPU workers.
  602. @item @code{unsigned nhwcudagpus}
  603. Total number of CUDA devices, as detected. May be different from the actual
  604. number of CUDA workers.
  605. @item @code{unsigned nhwopenclgpus}
  606. Total number of OpenCL devices, as detected. May be different from the actual
  607. number of CUDA workers.
  608. @item @code{unsigned ncpus}
  609. Actual number of CPU workers used by StarPU.
  610. @item @code{unsigned ncudagpus}
  611. Actual number of CUDA workers used by StarPU.
  612. @item @code{unsigned nopenclgpus}
  613. Actual number of OpenCL workers used by StarPU.
  614. @item @code{unsigned workers_bindid[STARPU_NMAXWORKERS]}
  615. Indicates the successive cpu identifier that should be used to bind the
  616. workers. It is either filled according to the user's explicit
  617. parameters (from starpu_conf) or according to the STARPU_WORKERS_CPUID env.
  618. variable. Otherwise, a round-robin policy is used to distributed the workers
  619. over the cpus.
  620. @item @code{unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  621. Indicates the successive cpu identifier that should be used by the CUDA
  622. driver. It is either filled according to the user's explicit parameters (from
  623. starpu_conf) or according to the STARPU_WORKERS_CUDAID env. variable. Otherwise,
  624. they are taken in ID order.
  625. @item @code{unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS]}
  626. Indicates the successive cpu identifier that should be used by the OpenCL
  627. driver. It is either filled according to the user's explicit parameters (from
  628. starpu_conf) or according to the STARPU_WORKERS_OPENCLID env. variable. Otherwise,
  629. they are taken in ID order.
  630. @end table
  631. @end deftp
  632. @node Scheduling Contexts
  633. @section Scheduling Contexts
  634. 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.
  635. 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.
  636. Scheduling contexts can be created, deleted and modified dynamically.
  637. @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})
  638. 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.
  639. 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}.
  640. @end deftypefun
  641. @deftypefun void starpu_sched_ctx_delete (unsigned @var{sched_ctx_id})
  642. Delete scheduling context @var{sched_ctx_id} and transfer remaining workers to the inheritor scheduling context.
  643. @end deftypefun
  644. @deftypefun void starpu_sched_ctx_add_workers ({int *}@var{workerids_ctx}, int @var{nworkers_ctx}, unsigned @var{sched_ctx_id})
  645. 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}.
  646. @end deftypefun
  647. @deftypefun void starpu_sched_ctx_remove_workers ({int *}@var{workerids_ctx}, int @var{nworkers_ctx}, unsigned @var{sched_ctx_id})
  648. 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}.
  649. @end deftypefun
  650. 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.
  651. Only the list data structure is available but further data structures(like tree) implementations are foreseen.
  652. @deftp {Data Type} {struct starpu_sched_ctx_worker_collection}
  653. @table @asis
  654. @item @code{void *workerids}
  655. The workerids managed by the collection
  656. @item @code{unsigned nworkers}
  657. The number of workerids
  658. @item @code{pthread_key_t cursor_key} (optional)
  659. The cursor needed to iterate the collection (depending on the data structure)
  660. @item @code{int type}
  661. The type of structure (currently STARPU_SCHED_CTX_WORKER_LIST is the only one available)
  662. @item @code{unsigned (*has_next)(struct starpu_sched_ctx_worker_collection *workers)}
  663. Checks if there is a next worker
  664. @item @code{int (*get_next)(struct starpu_sched_ctx_worker_collection *workers)}
  665. Gets the next worker
  666. @item @code{int (*add)(struct starpu_sched_ctx_worker_collection *workers, int worker)}
  667. Adds a worker to the collection
  668. @item @code{int (*remove)(struct starpu_sched_ctx_worker_collection *workers, int worker)}
  669. Removes a worker from the collection
  670. @item @code{void* (*init)(struct starpu_sched_ctx_worker_collection *workers)}
  671. Initialize the collection
  672. @item @code{void (*deinit)(struct starpu_sched_ctx_worker_collection *workers)}
  673. Deinitialize the colection
  674. @item @code{void (*init_cursor)(struct starpu_sched_ctx_worker_collection *workers)} (optional)
  675. Initialize the cursor if there is one
  676. @item @code{void (*deinit_cursor)(struct starpu_sched_ctx_worker_collection *workers)} (optional)
  677. Deinitialize the cursor if there is one
  678. @end table
  679. @end deftp
  680. @deftypefun struct starpu_sched_ctx_worker_collection* starpu_sched_ctx_create_worker_collection (unsigned @var{sched_ctx_id}, int @var{type})
  681. Create a worker collection of the type indicated by the last parameter for the context specified through the first parameter.
  682. @end deftypefun
  683. @deftypefun void starpu_sched_ctx_delete_worker_collection (unsigned @var{sched_ctx_id})
  684. Delete the worker collection of the specified scheduling context
  685. @end deftypefun
  686. @deftypefun struct starpu_sched_ctx_worker_collection* starpu_sched_ctx_get_worker_collection (unsigned @var{sched_ctx_id})
  687. Return the worker collection managed by the indicated context
  688. @end deftypefun
  689. @deftypefun pthread_mutex_t* starpu_sched_ctx_get_changing_ctx_mutex (unsigned @var{sched_ctx_id})
  690. TODO
  691. @end deftypefun
  692. @deftypefun void starpu_sched_ctx_set_context (unsigned *@var{sched_ctx_id})
  693. Set the scheduling context the subsequent tasks will be submitted to
  694. @end deftypefun
  695. @deftypefun unsigned starpu_sched_ctx_get_context (void)
  696. Return the scheduling context the tasks are currently submitted to
  697. @end deftypefun
  698. @deftypefun unsigned starpu_sched_ctx_get_nworkers (unsigned @var{sched_ctx_id})
  699. Return the number of workers managed by the specified contexts
  700. (Usually needed to verify if it manages any workers or if it should be blocked)
  701. @end deftypefun
  702. @deftypefun unsigned starpu_sched_ctx_get_nshared_workers (unsigned @var{sched_ctx_id}, unsigned @var{sched_ctx_id2})
  703. Return the number of workers shared by two contexts
  704. @end deftypefun
  705. @node Defining a new scheduling policy
  706. @section Defining a new scheduling policy
  707. TODO
  708. A full example showing how to define a new scheduling policy is available in
  709. the StarPU sources in the directory @code{examples/scheduler/}.
  710. @menu
  711. * Scheduling Policy API:: Scheduling Policy API
  712. * Source code::
  713. @end menu
  714. @node Scheduling Policy API
  715. @subsection Scheduling Policy API
  716. While StarPU comes with a variety of scheduling policies (@pxref{Task
  717. scheduling policy}), it may sometimes be desirable to implement custom
  718. policies to address specific problems. The API described below allows
  719. users to write their own scheduling policy.
  720. @deftp {Data Type} {struct starpu_sched_policy}
  721. This structure contains all the methods that implement a scheduling policy. An
  722. application may specify which scheduling strategy in the @code{sched_policy}
  723. field of the @code{starpu_conf} structure passed to the @code{starpu_init}
  724. function. The different fields are:
  725. @table @asis
  726. @item @code{void (*init_sched)(unsigned sched_ctx_id)}
  727. Initialize the scheduling policy.
  728. @item @code{void (*deinit_sched)(unsigned sched_ctx_id)}
  729. Cleanup the scheduling policy.
  730. @item @code{int (*push_task)(struct starpu_task *)}
  731. Insert a task into the scheduler.
  732. @item @code{void (*push_task_notify)(struct starpu_task *, int workerid)}
  733. Notify the scheduler that a task was pushed on a given worker. This method is
  734. called when a task that was explicitely assigned to a worker becomes ready and
  735. is about to be executed by the worker. This method therefore permits to keep
  736. the state of of the scheduler coherent even when StarPU bypasses the scheduling
  737. strategy.
  738. @item @code{struct starpu_task *(*pop_task)(unsigned sched_ctx_id)} (optional)
  739. Get a task from the scheduler. The mutex associated to the worker is already
  740. taken when this method is called. If this method is defined as @code{NULL}, the
  741. worker will only execute tasks from its local queue. In this case, the
  742. @code{push_task} method should use the @code{starpu_push_local_task} method to
  743. assign tasks to the different workers.
  744. @item @code{struct starpu_task *(*pop_every_task)(unsigned sched_ctx_id)}
  745. Remove all available tasks from the scheduler (tasks are chained by the means
  746. of the prev and next fields of the starpu_task structure). The mutex associated
  747. to the worker is already taken when this method is called. This is currently
  748. not used.
  749. @item @code{void (*pre_exec_hook)(struct starpu_task *)} (optional)
  750. This method is called every time a task is starting.
  751. @item @code{void (*post_exec_hook)(struct starpu_task *)} (optional)
  752. This method is called every time a task has been executed.
  753. @item @code{void (*add_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)}
  754. Initialize scheduling structures corresponding to each worker used by the policy.
  755. @item @code{void (*remove_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)}
  756. Deinitialize scheduling structures corresponding to each worker used by the policy.
  757. @item @code{const char *policy_name} (optional)
  758. Name of the policy.
  759. @item @code{const char *policy_description} (optional)
  760. Description of the policy.
  761. @end table
  762. @end deftp
  763. @deftypefun {struct starpu_sched_policy **} starpu_sched_get_predefined_policies ()
  764. Return an NULL-terminated array of all the predefined scheduling policies.
  765. @end deftypefun
  766. @deftypefun void starpu_sched_ctx_set_worker_mutex_and_cond (unsigned @var{sched_ctx_id}, int @var{workerid}, pthread_mutex_t *@var{sched_mutex}, {pthread_cond_t *}@var{sched_cond})
  767. This function specifies the condition variable associated to a worker per context
  768. When there is no available task for a worker, StarPU blocks this worker on a
  769. condition variable. This function specifies which condition variable (and the
  770. associated mutex) should be used to block (and to wake up) a worker. Note that
  771. multiple workers may use the same condition variable. For instance, in the case
  772. of a scheduling strategy with a single task queue, the same condition variable
  773. would be used to block and wake up all workers.
  774. The initialization method of a scheduling strategy (@code{init_sched}) must
  775. call this function once per worker.
  776. @end deftypefun
  777. @deftypefun void starpu_sched_ctx_get_worker_mutex_and_cond (unsigned @var{sched_ctx_id}, int @var{workerid}, {pthread_mutex_t **}@var{sched_mutex}, {pthread_cond_t **}@var{sched_cond})
  778. This function returns the condition variables associated to a worker in a context
  779. It is used in the policy to access to the local queue of the worker
  780. @end deftypefun
  781. @deftypefun void starpu_sched_ctx_set_policy_data (unsigned @var{sched_ctx_id}, {void *} @var{policy_data})
  782. Each scheduling policy uses some specific data (queues, variables, additional condition variables).
  783. It is memorize through a local structure. This function assigns it to a scheduling context.
  784. @end deftypefun
  785. @deftypefun void* starpu_sched_ctx_get_policy_data (unsigned @var{sched_ctx_id})
  786. Returns the policy data previously assigned to a context
  787. @end deftypefun
  788. @deftypefun void starpu_sched_set_min_priority (int @var{min_prio})
  789. Defines the minimum priority level supported by the scheduling policy. The
  790. default minimum priority level is the same as the default priority level which
  791. is 0 by convention. The application may access that value by calling the
  792. @code{starpu_sched_get_min_priority} function. This function should only be
  793. called from the initialization method of the scheduling policy, and should not
  794. be used directly from the application.
  795. @end deftypefun
  796. @deftypefun void starpu_sched_set_max_priority (int @var{max_prio})
  797. Defines the maximum priority level supported by the scheduling policy. The
  798. default maximum priority level is 1. The application may access that value by
  799. calling the @code{starpu_sched_get_max_priority} function. This function should
  800. only be called from the initialization method of the scheduling policy, and
  801. should not be used directly from the application.
  802. @end deftypefun
  803. @deftypefun int starpu_sched_get_min_priority (void)
  804. Returns the current minimum priority level supported by the
  805. scheduling policy
  806. @end deftypefun
  807. @deftypefun int starpu_sched_get_max_priority (void)
  808. Returns the current maximum priority level supported by the
  809. scheduling policy
  810. @end deftypefun
  811. @deftypefun int starpu_push_local_task (int @var{workerid}, {struct starpu_task} *@var{task}, int @var{back})
  812. The scheduling policy may put tasks directly into a worker's local queue so
  813. that it is not always necessary to create its own queue when the local queue
  814. is sufficient. If @var{back} not null, @var{task} is put at the back of the queue
  815. where the worker will pop tasks first. Setting @var{back} to 0 therefore ensures
  816. a FIFO ordering.
  817. @end deftypefun
  818. @deftypefun int starpu_worker_can_execute_task (unsigned @var{workerid}, {struct starpu_task *}@var{task}, unsigned {nimpl})
  819. 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.
  820. @end deftypefun
  821. @deftypefun double starpu_timing_now (void)
  822. Return the current date in µs
  823. @end deftypefun
  824. @deftypefun double starpu_task_expected_length ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  825. Returns expected task duration in µs
  826. @end deftypefun
  827. @deftypefun double starpu_worker_get_relative_speedup ({enum starpu_perf_archtype} @var{perf_archtype})
  828. Returns an estimated speedup factor relative to CPU speed
  829. @end deftypefun
  830. @deftypefun double starpu_task_expected_data_transfer_time (unsigned @var{memory_node}, {struct starpu_task *}@var{task})
  831. Returns expected data transfer time in µs
  832. @end deftypefun
  833. @deftypefun double starpu_data_expected_transfer_time (starpu_data_handle_t @var{handle}, unsigned @var{memory_node}, {enum starpu_access_mode} @var{mode})
  834. Predict the transfer time (in µs) to move a handle to a memory node
  835. @end deftypefun
  836. @deftypefun double starpu_task_expected_power ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  837. Returns expected power consumption in J
  838. @end deftypefun
  839. @deftypefun double starpu_task_expected_conversion_time ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned {nimpl})
  840. Returns expected conversion time in ms (multiformat interface only)
  841. @end deftypefun
  842. @node Source code
  843. @subsection Source code
  844. @cartouche
  845. @smallexample
  846. static struct starpu_sched_policy dummy_sched_policy = @{
  847. .init_sched = init_dummy_sched,
  848. .deinit_sched = deinit_dummy_sched,
  849. .add_workers = dummy_sched_add_workers,
  850. .remove_workers = dummy_sched_remove_workers,
  851. .push_task = push_task_dummy,
  852. .push_prio_task = NULL,
  853. .pop_task = pop_task_dummy,
  854. .post_exec_hook = NULL,
  855. .pop_every_task = NULL,
  856. .policy_name = "dummy",
  857. .policy_description = "dummy scheduling strategy"
  858. @};
  859. @end smallexample
  860. @end cartouche
  861. @node Running drivers
  862. @section Running drivers
  863. @menu
  864. * Driver API::
  865. * Example::
  866. @end menu
  867. @node Driver API
  868. @subsection Driver API
  869. @deftypefun int starpu_driver_run ({struct starpu_driver *}@var{d})
  870. Initialize the given driver, run it until it receives a request to terminate,
  871. deinitialize it and return 0 on success. It returns -EINVAL if @code{d->type}
  872. is not a valid StarPU device type (STARPU_CPU_WORKER, STARPU_CUDA_WORKER or
  873. STARPU_OPENCL_WORKER). This is the same as using the following
  874. functions: calling @code{starpu_driver_init()}, then calling
  875. @code{starpu_driver_run_once()} in a loop, and eventually
  876. @code{starpu_driver_deinit()}.
  877. @end deftypefun
  878. @deftypefun int starpu_driver_init (struct starpu_driver *@var{d})
  879. Initialize the given driver. Returns 0 on success, -EINVAL if
  880. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  881. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  882. @end deftypefun
  883. @deftypefun int starpu_driver_run_once (struct starpu_driver *@var{d})
  884. Run the driver once, then returns 0 on success, -EINVAL if
  885. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  886. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  887. @end deftypefun
  888. @deftypefun int starpu_driver_deinit (struct starpu_driver *@var{d})
  889. Deinitialize the given driver. Returns 0 on success, -EINVAL if
  890. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  891. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  892. @end deftypefun
  893. @deftypefun void starpu_drivers_request_termination (void)
  894. Notify all running drivers they should terminate.
  895. @end deftypefun
  896. @node Example
  897. @subsection Example
  898. @cartouche
  899. @smallexample
  900. int ret;
  901. struct starpu_driver = @{
  902. .type = STARPU_CUDA_WORKER,
  903. .id.cuda_id = 0
  904. @};
  905. ret = starpu_driver_init(&d);
  906. if (ret != 0)
  907. error();
  908. while (some_condition) @{
  909. ret = starpu_driver_run_once(&d);
  910. if (ret != 0)
  911. error();
  912. @}
  913. ret = starpu_driver_deinit(&d);
  914. if (ret != 0)
  915. error();
  916. @end smallexample
  917. @end cartouche
  918. @node Expert mode
  919. @section Expert mode
  920. @deftypefun void starpu_wake_all_blocked_workers (void)
  921. Wake all the workers, so they can inspect data requests and task submissions
  922. again.
  923. @end deftypefun
  924. @deftypefun int starpu_progression_hook_register (unsigned (*@var{func})(void *arg), void *@var{arg})
  925. Register a progression hook, to be called when workers are idle.
  926. @end deftypefun
  927. @deftypefun void starpu_progression_hook_deregister (int @var{hook_id})
  928. Unregister a given progression hook.
  929. @end deftypefun