advanced-api.texi 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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 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. * Defining a new data interface::
  9. * Multiformat Data Interface::
  10. * Task Bundles::
  11. * Task Lists::
  12. * Using Parallel Tasks::
  13. * Defining a new scheduling policy::
  14. * Running drivers::
  15. * Expert mode::
  16. @end menu
  17. @node Defining a new data interface
  18. @section Defining a new data interface
  19. @menu
  20. * Data Interface API:: Data Interface API
  21. * An example of data interface:: An example of data interface
  22. @end menu
  23. @node Data Interface API
  24. @subsection Data Interface API
  25. @deftp {Data Type} {struct starpu_data_interface_ops}
  26. @anchor{struct starpu_data_interface_ops}
  27. Per-interface data transfer methods.
  28. @table @asis
  29. @item @code{void (*register_data_handle)(starpu_data_handle_t handle, uint32_t home_node, void *data_interface)}
  30. Register an existing interface into a data handle.
  31. @item @code{starpu_ssize_t (*allocate_data_on_node)(void *data_interface, uint32_t node)}
  32. Allocate data for the interface on a given node.
  33. @item @code{ void (*free_data_on_node)(void *data_interface, uint32_t node)}
  34. Free data of the interface on a given node.
  35. @item @code{ const struct starpu_data_copy_methods *copy_methods}
  36. ram/cuda/spu/opencl synchronous and asynchronous transfer methods.
  37. @item @code{ void * (*handle_to_pointer)(starpu_data_handle_t handle, uint32_t node)}
  38. Return the current pointer (if any) for the handle on the given node.
  39. @item @code{ size_t (*get_size)(starpu_data_handle_t handle)}
  40. Return an estimation of the size of data, for performance models.
  41. @item @code{ uint32_t (*footprint)(starpu_data_handle_t handle)}
  42. Return a 32bit footprint which characterizes the data size.
  43. @item @code{ int (*compare)(void *data_interface_a, void *data_interface_b)}
  44. Compare the data size of two interfaces.
  45. @item @code{ void (*display)(starpu_data_handle_t handle, FILE *f)}
  46. Dump the sizes of a handle to a file.
  47. @item @code{ int (*convert_to_gordon)(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss)}
  48. Convert the data size to the spu size format. If no SPUs are used, this field can be seto NULL.
  49. @item @code{enum starpu_data_interface_id interfaceid}
  50. An identifier that is unique to each interface.
  51. @item @code{size_t interface_size}
  52. The size of the interface data descriptor.
  53. @item @code{int is_multiformat}
  54. todo
  55. @item @code{struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface)}
  56. todo
  57. @item @code{int (*pack_data)(starpu_data_handle_t handle, uint32_t node, void **ptr)}
  58. Pack the data handle into a contiguous buffer at the address @code{ptr}
  59. @item @code{int (*unpack_data)(starpu_data_handle_t handle, uint32_t node, void *ptr)}
  60. Unpack the data handle from the contiguous buffer at the address @code{ptr}
  61. @end table
  62. @end deftp
  63. @deftp {Data Type} {struct starpu_data_copy_methods}
  64. Defines the per-interface methods.
  65. @table @asis
  66. @item @code{int @{ram,cuda,opencl,spu@}_to_@{ram,cuda,opencl,spu@}(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)}
  67. These 16 functions define how to copy data from the @var{src_interface}
  68. interface on the @var{src_node} node to the @var{dst_interface} interface
  69. on the @var{dst_node} node. They return 0 on success.
  70. @item @code{int (*ram_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)}
  71. Define how to copy data from the @var{src_interface} interface on the
  72. @var{src_node} node (in RAM) to the @var{dst_interface} interface on the
  73. @var{dst_node} node (on a CUDA device), using the given @var{stream}. Return 0
  74. on success.
  75. @item @code{int (*cuda_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)}
  76. Define how to copy data from the @var{src_interface} interface on the
  77. @var{src_node} node (on a CUDA device) to the @var{dst_interface} interface on the
  78. @var{dst_node} node (in RAM), using the given @var{stream}. Return 0
  79. on success.
  80. @item @code{int (*cuda_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)}
  81. Define how to copy data from the @var{src_interface} interface on the
  82. @var{src_node} node (on a CUDA device) to the @var{dst_interface} interface on
  83. the @var{dst_node} node (on another CUDA device), using the given @var{stream}.
  84. Return 0 on success.
  85. @item @code{int (*ram_to_opencl_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, /* cl_event * */ void *event)}
  86. Define how to copy data from the @var{src_interface} interface on the
  87. @var{src_node} node (in RAM) to the @var{dst_interface} interface on the
  88. @var{dst_node} node (on an OpenCL device), using @var{event}, a pointer to a
  89. cl_event. Return 0 on success.
  90. @item @code{int (*opencl_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, /* cl_event * */ void *event)}
  91. Define how to copy data from the @var{src_interface} interface on the
  92. @var{src_node} node (on an OpenCL device) to the @var{dst_interface} interface
  93. on the @var{dst_node} node (in RAM), using the given @var{event}, a pointer to
  94. a cl_event. Return 0 on success.
  95. @item @code{int (*opencl_to_opencl_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, /* cl_event * */ void *event)}
  96. Define how to copy data from the @var{src_interface} interface on the
  97. @var{src_node} node (on an OpenCL device) to the @var{dst_interface} interface
  98. on the @var{dst_node} node (on another OpenCL device), using the given
  99. @var{event}, a pointer to a cl_event. Return 0 on success.
  100. @end table
  101. @end deftp
  102. @deftypefun uint32_t starpu_crc32_be_n ({void *}@var{input}, size_t @var{n}, uint32_t @var{inputcrc})
  103. Compute the CRC of a byte buffer seeded by the inputcrc "current
  104. state". The return value should be considered as the new "current
  105. state" for future CRC computation. This is used for computing data size
  106. footprint.
  107. @end deftypefun
  108. @deftypefun uint32_t starpu_crc32_be (uint32_t @var{input}, uint32_t @var{inputcrc})
  109. Compute the CRC of a 32bit number seeded by the inputcrc "current
  110. state". The return value should be considered as the new "current
  111. state" for future CRC computation. This is used for computing data size
  112. footprint.
  113. @end deftypefun
  114. @deftypefun uint32_t starpu_crc32_string ({char *}@var{str}, uint32_t @var{inputcrc})
  115. Compute the CRC of a string seeded by the inputcrc "current state".
  116. The return value should be considered as the new "current state" for
  117. future CRC computation. This is used for computing data size footprint.
  118. @end deftypefun
  119. @node An example of data interface
  120. @subsection An example of data interface
  121. @deftypefun int starpu_data_interface_get_next_id (void)
  122. Returns the next available id for a newly created data interface.
  123. @end deftypefun
  124. Let's define a new data interface to manage complex numbers.
  125. @cartouche
  126. @smallexample
  127. /* interface for complex numbers */
  128. struct starpu_complex_interface
  129. @{
  130. double *real;
  131. double *imaginary;
  132. int nx;
  133. @};
  134. @end smallexample
  135. @end cartouche
  136. Registering such a data to StarPU is easily done using the function
  137. @code{starpu_data_register} (@pxref{Basic Data Management API}). The last
  138. parameter of the function, @code{interface_complex_ops}, will be
  139. described below.
  140. @cartouche
  141. @smallexample
  142. void starpu_complex_data_register(starpu_data_handle_t *handle,
  143. uint32_t home_node, double *real, double *imaginary, int nx)
  144. @{
  145. struct starpu_complex_interface complex =
  146. @{
  147. .real = real,
  148. .imaginary = imaginary,
  149. .nx = nx
  150. @};
  151. if (interface_complex_ops.interfaceid == -1)
  152. @{
  153. interface_complex_ops.interfaceid = starpu_data_interface_get_next_id();
  154. @}
  155. starpu_data_register(handleptr, home_node, &complex, &interface_complex_ops);
  156. @}
  157. @end smallexample
  158. @end cartouche
  159. Different operations need to be defined for a data interface through
  160. the type @code{struct starpu_data_interface_ops} (@pxref{Data
  161. Interface API}). We only define here the basic operations needed to
  162. run simple applications. The source code for the different functions
  163. can be found in the file
  164. @code{examples/interface/complex_interface.c}.
  165. @cartouche
  166. @smallexample
  167. static struct starpu_data_interface_ops interface_complex_ops =
  168. @{
  169. .register_data_handle = complex_register_data_handle,
  170. .allocate_data_on_node = complex_allocate_data_on_node,
  171. .copy_methods = &complex_copy_methods,
  172. .get_size = complex_get_size,
  173. .footprint = complex_footprint,
  174. .interfaceid = -1,
  175. .interface_size = sizeof(struct starpu_complex_interface),
  176. @};
  177. @end smallexample
  178. @end cartouche
  179. Functions need to be defined to access the different fields of the
  180. complex interface from a StarPU data handle.
  181. @cartouche
  182. @smallexample
  183. double *starpu_complex_get_real(starpu_data_handle_t handle)
  184. @{
  185. struct starpu_complex_interface *complex_interface =
  186. (struct starpu_complex_interface *) starpu_data_get_interface_on_node(handle, 0);
  187. return complex_interface->real;
  188. @}
  189. double *starpu_complex_get_imaginary(starpu_data_handle_t handle);
  190. int starpu_complex_get_nx(starpu_data_handle_t handle);
  191. @end smallexample
  192. @end cartouche
  193. Similar functions need to be defined to access the different fields of the
  194. complex interface from a @code{void *} pointer to be used within codelet
  195. implemetations.
  196. @cartouche
  197. @smallexample
  198. #define STARPU_COMPLEX_GET_REAL(interface) \
  199. (((struct starpu_complex_interface *)(interface))->real)
  200. #define STARPU_COMPLEX_GET_IMAGINARY(interface) \
  201. (((struct starpu_complex_interface *)(interface))->imaginary)
  202. #define STARPU_COMPLEX_GET_NX(interface) \
  203. (((struct starpu_complex_interface *)(interface))->nx)
  204. @end smallexample
  205. @end cartouche
  206. Complex data interfaces can then be registered to StarPU.
  207. @cartouche
  208. @smallexample
  209. double real = 45.0;
  210. double imaginary = 12.0;
  211. starpu_complex_data_register(&handle1, 0, &real, &imaginary, 1);
  212. starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
  213. @end smallexample
  214. @end cartouche
  215. and used by codelets.
  216. @cartouche
  217. @smallexample
  218. void display_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args)
  219. @{
  220. int nx = STARPU_COMPLEX_GET_NX(descr[0]);
  221. double *real = STARPU_COMPLEX_GET_REAL(descr[0]);
  222. double *imaginary = STARPU_COMPLEX_GET_IMAGINARY(descr[0]);
  223. int i;
  224. for(i=0 ; i<nx ; i++)
  225. @{
  226. fprintf(stderr, "Complex[%d] = %3.2f + %3.2f i\n", i, real[i], imaginary[i]);
  227. @}
  228. @}
  229. @end smallexample
  230. @end cartouche
  231. The whole code for this complex data interface is available in the
  232. directory @code{examples/interface/}.
  233. @node Multiformat Data Interface
  234. @section Multiformat Data Interface
  235. @deftp {Data Type} {struct starpu_multiformat_data_interface_ops}
  236. The different fields are:
  237. @table @asis
  238. @item @code{size_t cpu_elemsize}
  239. the size of each element on CPUs,
  240. @item @code{size_t opencl_elemsize}
  241. the size of each element on OpenCL devices,
  242. @item @code{struct starpu_codelet *cpu_to_opencl_cl}
  243. pointer to a codelet which converts from CPU to OpenCL
  244. @item @code{struct starpu_codelet *opencl_to_cpu_cl}
  245. pointer to a codelet which converts from OpenCL to CPU
  246. @item @code{size_t cuda_elemsize}
  247. the size of each element on CUDA devices,
  248. @item @code{struct starpu_codelet *cpu_to_cuda_cl}
  249. pointer to a codelet which converts from CPU to CUDA
  250. @item @code{struct starpu_codelet *cuda_to_cpu_cl}
  251. pointer to a codelet which converts from CUDA to CPU
  252. @end table
  253. @end deftp
  254. @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})
  255. Register a piece of data that can be represented in different ways, depending upon
  256. the processing unit that manipulates it. It allows the programmer, for instance, to
  257. use an array of structures when working on a CPU, and a structure of arrays when
  258. working on a GPU.
  259. @var{nobjects} is the number of elements in the data. @var{format_ops} describes
  260. the format.
  261. @end deftypefun
  262. @defmac STARPU_MULTIFORMAT_GET_CPU_PTR ({void *}@var{interface})
  263. returns the local pointer to the data with CPU format.
  264. @end defmac
  265. @defmac STARPU_MULTIFORMAT_GET_CUDA_PTR ({void *}@var{interface})
  266. returns the local pointer to the data with CUDA format.
  267. @end defmac
  268. @defmac STARPU_MULTIFORMAT_GET_OPENCL_PTR ({void *}@var{interface})
  269. returns the local pointer to the data with OpenCL format.
  270. @end defmac
  271. @defmac STARPU_MULTIFORMAT_GET_NX ({void *}@var{interface})
  272. returns the number of elements in the data.
  273. @end defmac
  274. @node Task Bundles
  275. @section Task Bundles
  276. @deftp {Data Type} {starpu_task_bundle_t}
  277. Opaque structure describing a list of tasks that should be scheduled
  278. on the same worker whenever it's possible. It must be considered as a
  279. hint given to the scheduler as there is no guarantee that they will be
  280. executed on the same worker.
  281. @end deftp
  282. @deftypefun void starpu_task_bundle_create ({starpu_task_bundle_t *}@var{bundle})
  283. Factory function creating and initializing @var{bundle}, when the call returns, memory needed is allocated and @var{bundle} is ready to use.
  284. @end deftypefun
  285. @deftypefun int starpu_task_bundle_insert (starpu_task_bundle_t @var{bundle}, {struct starpu_task *}@var{task})
  286. 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}.
  287. This function mustn't be called if @var{bundle} is already closed and/or @var{task} is already submitted.
  288. @end deftypefun
  289. @deftypefun int starpu_task_bundle_remove (starpu_task_bundle_t @var{bundle}, {struct starpu_task *}@var{task})
  290. Remove @var{task} from @var{bundle}.
  291. Of course @var{task} must have been previously inserted @var{bundle}.
  292. 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.
  293. @end deftypefun
  294. @deftypefun void starpu_task_bundle_close (starpu_task_bundle_t @var{bundle})
  295. 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.
  296. @end deftypefun
  297. @deftypefun double starpu_task_bundle_expected_length (starpu_task_bundle_t @var{bundle}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  298. Return the expected duration of the entire task bundle in µs.
  299. @end deftypefun
  300. @deftypefun double starpu_task_bundle_expected_power (starpu_task_bundle_t @var{bundle}, enum starpu_perf_archtype @var{arch}, unsigned @var{nimpl})
  301. Return the expected power consumption of the entire task bundle in J.
  302. @end deftypefun
  303. @deftypefun double starpu_task_bundle_expected_data_transfer_time (starpu_task_bundle_t @var{bundle}, unsigned @var{memory_node})
  304. Return the time (in µs) expected to transfer all data used within the bundle.
  305. @end deftypefun
  306. @node Task Lists
  307. @section Task Lists
  308. @deftp {Data Type} {struct starpu_task_list}
  309. Stores a double-chained list of tasks
  310. @end deftp
  311. @deftypefun void starpu_task_list_init ({struct starpu_task_list *}@var{list})
  312. Initialize a list structure
  313. @end deftypefun
  314. @deftypefun void starpu_task_list_push_front ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  315. Push a task at the front of a list
  316. @end deftypefun
  317. @deftypefun void starpu_task_list_push_back ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  318. Push a task at the back of a list
  319. @end deftypefun
  320. @deftypefun {struct starpu_task *} starpu_task_list_front ({struct starpu_task_list *}@var{list})
  321. Get the front of the list (without removing it)
  322. @end deftypefun
  323. @deftypefun {struct starpu_task *} starpu_task_list_back ({struct starpu_task_list *}@var{list})
  324. Get the back of the list (without removing it)
  325. @end deftypefun
  326. @deftypefun int starpu_task_list_empty ({struct starpu_task_list *}@var{list})
  327. Test if a list is empty
  328. @end deftypefun
  329. @deftypefun void starpu_task_list_erase ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  330. Remove an element from the list
  331. @end deftypefun
  332. @deftypefun {struct starpu_task *} starpu_task_list_pop_front ({struct starpu_task_list *}@var{list})
  333. Remove the element at the front of the list
  334. @end deftypefun
  335. @deftypefun {struct starpu_task *} starpu_task_list_pop_back ({struct starpu_task_list *}@var{list})
  336. Remove the element at the back of the list
  337. @end deftypefun
  338. @deftypefun {struct starpu_task *} starpu_task_list_begin ({struct starpu_task_list *}@var{list})
  339. Get the first task of the list.
  340. @end deftypefun
  341. @deftypefun {struct starpu_task *} starpu_task_list_end ({struct starpu_task_list *}@var{list})
  342. Get the end of the list.
  343. @end deftypefun
  344. @deftypefun {struct starpu_task *} starpu_task_list_next ({struct starpu_task *}@var{task})
  345. Get the next task of the list. This is not erase-safe.
  346. @end deftypefun
  347. @node Using Parallel Tasks
  348. @section Using Parallel Tasks
  349. These are used by parallel tasks:
  350. @deftypefun int starpu_combined_worker_get_size (void)
  351. Return the size of the current combined worker, i.e. the total number of cpus
  352. running the same task in the case of SPMD parallel tasks, or the total number
  353. of threads that the task is allowed to start in the case of FORKJOIN parallel
  354. tasks.
  355. @end deftypefun
  356. @deftypefun int starpu_combined_worker_get_rank (void)
  357. Return the rank of the current thread within the combined worker. Can only be
  358. used in FORKJOIN parallel tasks, to know which part of the task to work on.
  359. @end deftypefun
  360. Most of these are used for schedulers which support parallel tasks.
  361. @deftypefun unsigned starpu_combined_worker_get_count (void)
  362. Return the number of different combined workers.
  363. @end deftypefun
  364. @deftypefun int starpu_combined_worker_get_id (void)
  365. Return the identifier of the current combined worker.
  366. @end deftypefun
  367. @deftypefun int starpu_combined_worker_assign_workerid (int @var{nworkers}, int @var{workerid_array}[])
  368. Register a new combined worker and get its identifier
  369. @end deftypefun
  370. @deftypefun int starpu_combined_worker_get_description (int @var{workerid}, {int *}@var{worker_size}, {int **}@var{combined_workerid})
  371. Get the description of a combined worker
  372. @end deftypefun
  373. @deftypefun int starpu_combined_worker_can_execute_task (unsigned @var{workerid}, {struct starpu_task *}@var{task}, unsigned @var{nimpl})
  374. Variant of starpu_worker_can_execute_task compatible with combined workers
  375. @end deftypefun
  376. @node Defining a new scheduling policy
  377. @section Defining a new scheduling policy
  378. TODO
  379. A full example showing how to define a new scheduling policy is available in
  380. the StarPU sources in the directory @code{examples/scheduler/}.
  381. @menu
  382. * Scheduling Policy API:: Scheduling Policy API
  383. * Source code::
  384. @end menu
  385. @node Scheduling Policy API
  386. @subsection Scheduling Policy API
  387. While StarPU comes with a variety of scheduling policies (@pxref{Task
  388. scheduling policy}), it may sometimes be desirable to implement custom
  389. policies to address specific problems. The API described below allows
  390. users to write their own scheduling policy.
  391. @deftp {Data Type} {struct starpu_machine_topology}
  392. @table @asis
  393. @item @code{unsigned nworkers}
  394. Total number of workers.
  395. @item @code{unsigned ncombinedworkers}
  396. Total number of combined workers.
  397. @item @code{hwloc_topology_t hwtopology}
  398. Topology as detected by hwloc.
  399. To maintain ABI compatibility when hwloc is not available, the field
  400. is replaced with @code{void *dummy}
  401. @item @code{unsigned nhwcpus}
  402. Total number of CPUs, as detected by the topology code. May be different from
  403. the actual number of CPU workers.
  404. @item @code{unsigned nhwcudagpus}
  405. Total number of CUDA devices, as detected. May be different from the actual
  406. number of CUDA workers.
  407. @item @code{unsigned nhwopenclgpus}
  408. Total number of OpenCL devices, as detected. May be different from the actual
  409. number of CUDA workers.
  410. @item @code{unsigned ncpus}
  411. Actual number of CPU workers used by StarPU.
  412. @item @code{unsigned ncudagpus}
  413. Actual number of CUDA workers used by StarPU.
  414. @item @code{unsigned nopenclgpus}
  415. Actual number of OpenCL workers used by StarPU.
  416. @item @code{unsigned ngordon_spus}
  417. Actual number of Gordon workers used by StarPU.
  418. @item @code{unsigned workers_bindid[STARPU_NMAXWORKERS]}
  419. Indicates the successive cpu identifier that should be used to bind the
  420. workers. It is either filled according to the user's explicit
  421. parameters (from starpu_conf) or according to the STARPU_WORKERS_CPUID env.
  422. variable. Otherwise, a round-robin policy is used to distributed the workers
  423. over the cpus.
  424. @item @code{unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  425. Indicates the successive cpu identifier that should be used by the CUDA
  426. driver. It is either filled according to the user's explicit parameters (from
  427. starpu_conf) or according to the STARPU_WORKERS_CUDAID env. variable. Otherwise,
  428. they are taken in ID order.
  429. @item @code{unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS]}
  430. Indicates the successive cpu identifier that should be used by the OpenCL
  431. driver. It is either filled according to the user's explicit parameters (from
  432. starpu_conf) or according to the STARPU_WORKERS_OPENCLID env. variable. Otherwise,
  433. they are taken in ID order.
  434. @end table
  435. @end deftp
  436. @deftp {Data Type} {struct starpu_sched_policy}
  437. This structure contains all the methods that implement a scheduling policy. An
  438. application may specify which scheduling strategy in the @code{sched_policy}
  439. field of the @code{starpu_conf} structure passed to the @code{starpu_init}
  440. function. The different fields are:
  441. @table @asis
  442. @item @code{void (*init_sched)(struct starpu_machine_topology *, struct starpu_sched_policy *)}
  443. Initialize the scheduling policy.
  444. @item @code{void (*deinit_sched)(struct starpu_machine_topology *, struct starpu_sched_policy *)}
  445. Cleanup the scheduling policy.
  446. @item @code{int (*push_task)(struct starpu_task *)}
  447. Insert a task into the scheduler.
  448. @item @code{void (*push_task_notify)(struct starpu_task *, int workerid)}
  449. Notify the scheduler that a task was pushed on a given worker. This method is
  450. called when a task that was explicitely assigned to a worker becomes ready and
  451. is about to be executed by the worker. This method therefore permits to keep
  452. the state of of the scheduler coherent even when StarPU bypasses the scheduling
  453. strategy.
  454. @item @code{struct starpu_task *(*pop_task)(void)} (optional)
  455. Get a task from the scheduler. The mutex associated to the worker is already
  456. taken when this method is called. If this method is defined as @code{NULL}, the
  457. worker will only execute tasks from its local queue. In this case, the
  458. @code{push_task} method should use the @code{starpu_push_local_task} method to
  459. assign tasks to the different workers.
  460. @item @code{struct starpu_task *(*pop_every_task)(void)}
  461. Remove all available tasks from the scheduler (tasks are chained by the means
  462. of the prev and next fields of the starpu_task structure). The mutex associated
  463. to the worker is already taken when this method is called. This is currently
  464. only used by the Gordon driver.
  465. @item @code{void (*pre_exec_hook)(struct starpu_task *)} (optional)
  466. This method is called every time a task is starting.
  467. @item @code{void (*post_exec_hook)(struct starpu_task *)} (optional)
  468. This method is called every time a task has been executed.
  469. @item @code{const char *policy_name} (optional)
  470. Name of the policy.
  471. @item @code{const char *policy_description} (optional)
  472. Description of the policy.
  473. @end table
  474. @end deftp
  475. @deftypefun void starpu_worker_set_sched_condition (int @var{workerid}, pthread_cond_t *@var{sched_cond}, pthread_mutex_t *@var{sched_mutex})
  476. This function specifies the condition variable associated to a worker
  477. When there is no available task for a worker, StarPU blocks this worker on a
  478. condition variable. This function specifies which condition variable (and the
  479. associated mutex) should be used to block (and to wake up) a worker. Note that
  480. multiple workers may use the same condition variable. For instance, in the case
  481. of a scheduling strategy with a single task queue, the same condition variable
  482. would be used to block and wake up all workers.
  483. The initialization method of a scheduling strategy (@code{init_sched}) must
  484. call this function once per worker.
  485. @end deftypefun
  486. @deftypefun void starpu_sched_set_min_priority (int @var{min_prio})
  487. Defines the minimum priority level supported by the scheduling policy. The
  488. default minimum priority level is the same as the default priority level which
  489. is 0 by convention. The application may access that value by calling the
  490. @code{starpu_sched_get_min_priority} function. This function should only be
  491. called from the initialization method of the scheduling policy, and should not
  492. be used directly from the application.
  493. @end deftypefun
  494. @deftypefun void starpu_sched_set_max_priority (int @var{max_prio})
  495. Defines the maximum priority level supported by the scheduling policy. The
  496. default maximum priority level is 1. The application may access that value by
  497. calling the @code{starpu_sched_get_max_priority} function. This function should
  498. only be called from the initialization method of the scheduling policy, and
  499. should not be used directly from the application.
  500. @end deftypefun
  501. @deftypefun int starpu_sched_get_min_priority (void)
  502. Returns the current minimum priority level supported by the
  503. scheduling policy
  504. @end deftypefun
  505. @deftypefun int starpu_sched_get_max_priority (void)
  506. Returns the current maximum priority level supported by the
  507. scheduling policy
  508. @end deftypefun
  509. @deftypefun int starpu_push_local_task (int @var{workerid}, {struct starpu_task} *@var{task}, int @var{back})
  510. The scheduling policy may put tasks directly into a worker's local queue so
  511. that it is not always necessary to create its own queue when the local queue
  512. is sufficient. If @var{back} not null, @var{task} is put at the back of the queue
  513. where the worker will pop tasks first. Setting @var{back} to 0 therefore ensures
  514. a FIFO ordering.
  515. @end deftypefun
  516. @deftypefun int starpu_worker_can_execute_task (unsigned @var{workerid}, {struct starpu_task *}@var{task}, unsigned {nimpl})
  517. 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.
  518. @end deftypefun
  519. @deftypefun double starpu_timing_now (void)
  520. Return the current date in µs
  521. @end deftypefun
  522. @deftypefun double starpu_task_expected_length ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  523. Returns expected task duration in µs
  524. @end deftypefun
  525. @deftypefun double starpu_worker_get_relative_speedup ({enum starpu_perf_archtype} @var{perf_archtype})
  526. Returns an estimated speedup factor relative to CPU speed
  527. @end deftypefun
  528. @deftypefun double starpu_task_expected_data_transfer_time (uint32_t @var{memory_node}, {struct starpu_task *}@var{task})
  529. Returns expected data transfer time in µs
  530. @end deftypefun
  531. @deftypefun double starpu_data_expected_transfer_time (starpu_data_handle_t @var{handle}, unsigned @var{memory_node}, {enum starpu_access_mode} @var{mode})
  532. Predict the transfer time (in µs) to move a handle to a memory node
  533. @end deftypefun
  534. @deftypefun double starpu_task_expected_power ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  535. Returns expected power consumption in J
  536. @end deftypefun
  537. @deftypefun double starpu_task_expected_conversion_time ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned {nimpl})
  538. Returns expected conversion time in ms (multiformat interface only)
  539. @end deftypefun
  540. @node Source code
  541. @subsection Source code
  542. @cartouche
  543. @smallexample
  544. static struct starpu_sched_policy dummy_sched_policy = @{
  545. .init_sched = init_dummy_sched,
  546. .deinit_sched = deinit_dummy_sched,
  547. .push_task = push_task_dummy,
  548. .push_prio_task = NULL,
  549. .pop_task = pop_task_dummy,
  550. .post_exec_hook = NULL,
  551. .pop_every_task = NULL,
  552. .policy_name = "dummy",
  553. .policy_description = "dummy scheduling strategy"
  554. @};
  555. @end smallexample
  556. @end cartouche
  557. @node Running drivers
  558. @section Running drivers
  559. @menu
  560. * Driver API::
  561. * Example::
  562. @end menu
  563. @node Driver API
  564. @subsection Driver API
  565. @deftypefun int starpu_driver_run ({struct starpu_driver *}@var{d})
  566. Initialize the given driver, run it until it receives a request to terminate,
  567. deinitialize it and return 0 on success. It returns -EINVAL if @code{d->type}
  568. is not a valid StarPU device type (STARPU_CPU_WORKER, STARPU_CUDA_WORKER or
  569. STARPU_OPENCL_WORKER). This is the same as using the following
  570. functions: calling @code{starpu_driver_init()}, then calling
  571. @code{starpu_driver_run_once()} in a loop, and eventually
  572. @code{starpu_driver_deinit()}.
  573. @end deftypefun
  574. @deftypefun int starpu_driver_init (struct starpu_driver *@var{d})
  575. Initialize the given driver. Returns 0 on success, -EINVAL if
  576. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  577. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  578. @end deftypefun
  579. @deftypefun int starpu_driver_run_once (struct starpu_driver *@var{d})
  580. Run the driver once, then returns 0 on success, -EINVAL if
  581. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  582. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  583. @end deftypefun
  584. @deftypefun int starpu_driver_deinit (struct starpu_driver *@var{d})
  585. Deinitialize the given driver. Returns 0 on success, -EINVAL if
  586. @code{d->type} is not a valid StarPU device type (STARPU_CPU_WORKER,
  587. STARPU_CUDA_WORKER or STARPU_OPENCL_WORKER).
  588. @end deftypefun
  589. @deftypefun void starpu_drivers_request_termination (void)
  590. Notify all running drivers they should terminate.
  591. @end deftypefun
  592. @node Example
  593. @subsection Example
  594. @cartouche
  595. @smallexample
  596. int ret;
  597. struct starpu_driver = @{
  598. .type = STARPU_CUDA_WORKER,
  599. .id.cuda_id = 0
  600. @};
  601. ret = starpu_driver_init(&d);
  602. if (ret != 0)
  603. error();
  604. while (some_condition) @{
  605. ret = starpu_driver_run_once(&d);
  606. if (ret != 0)
  607. error();
  608. @}
  609. ret = starpu_driver_deinit(&d);
  610. if (ret != 0)
  611. error();
  612. @end smallexample
  613. @end cartouche
  614. @node Expert mode
  615. @section Expert mode
  616. @deftypefun void starpu_wake_all_blocked_workers (void)
  617. Wake all the workers, so they can inspect data requests and task submissions
  618. again.
  619. @end deftypefun
  620. @deftypefun int starpu_progression_hook_register (unsigned (*@var{func})(void *arg), void *@var{arg})
  621. Register a progression hook, to be called when workers are idle.
  622. @end deftypefun
  623. @deftypefun void starpu_progression_hook_deregister (int @var{hook_id})
  624. Unregister a given progression hook.
  625. @end deftypefun