advanced-api.texi 47 KB

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