advanced-api.texi 46 KB

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