advanced-api.texi 49 KB

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