advanced-api.texi 47 KB

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