advanced-api.texi 47 KB

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