advanced-api.texi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 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. * Defining a new scheduling policy::
  13. * Expert mode::
  14. @end menu
  15. @node Defining a new data interface
  16. @section Defining a new data interface
  17. @menu
  18. * Data Interface API:: Data Interface API
  19. * An example of data interface:: An example of data interface
  20. @end menu
  21. @node Data Interface API
  22. @subsection Data Interface API
  23. @deftp {Data Type} {struct starpu_data_interface_ops}
  24. @anchor{struct starpu_data_interface_ops}
  25. Defines the per-interface methods. TODO describe all the different fields
  26. @end deftp
  27. @deftp {Data Type} {struct starpu_data_copy_methods}
  28. Per-interface data transfer methods. TODO describe all the different fields
  29. @end deftp
  30. @node An example of data interface
  31. @subsection An example of data interface
  32. TODO
  33. See @code{src/datawizard/interfaces/vector_interface.c} for now.
  34. @node Multiformat Data Interface
  35. @section Multiformat Data Interface
  36. @deftp {Data Type} {struct starpu_multiformat_data_interface_ops}
  37. todo. The different fields are:
  38. @table @asis
  39. @item @code{cpu_elemsize}
  40. the size of each element on CPUs,
  41. @item @code{opencl_elemsize}
  42. the size of each element on OpenCL devices,
  43. @item @code{cuda_elemsize}
  44. the size of each element on CUDA devices,
  45. @item @code{cpu_to_opencl_cl}
  46. pointer to a codelet which converts from CPU to OpenCL
  47. @item @code{opencl_to_cpu_cl}
  48. pointer to a codelet which converts from OpenCL to CPU
  49. @item @code{cpu_to_cuda_cl}
  50. pointer to a codelet which converts from CPU to CUDA
  51. @item @code{cuda_to_cpu_cl}
  52. pointer to a codelet which converts from CUDA to CPU
  53. @end table
  54. @end deftp
  55. @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});
  56. Register a piece of data that can be represented in different ways, depending upon
  57. the processing unit that manipulates it. It allows the programmer, for instance, to
  58. use an array of structures when working on a CPU, and a structure of arrays when
  59. working on a GPU.
  60. @var{nobjects} is the number of elements in the data. @var{format_ops} describes
  61. the format.
  62. @end deftypefun
  63. @node Task Bundles
  64. @section Task Bundles
  65. @deftp {DataType} {struct starpu_task_bundle}
  66. The task bundle structure describes a list of tasks that should be
  67. scheduled together whenever possible. The different fields are:
  68. @table @asis
  69. @item @code{mutex}
  70. Mutex protecting the bundle
  71. @item @code{int previous_workerid}
  72. last worker previously assigned a task from the bundle (-1 if none)
  73. @item @code{struct starpu_task_bundle_entry *list}
  74. list of tasks
  75. @item @code{int destroy}
  76. If this flag is set, the bundle structure is automatically free'd when the bundle is deinitialized.
  77. @item @code{int closed}
  78. Is the bundle closed ?
  79. @end table
  80. @end deftp
  81. @deftypefun void starpu_task_bundle_init ({struct starpu_task_bundle *}@var{bundle})
  82. Initialize a task bundle
  83. @end deftypefun
  84. @deftypefun void starpu_task_bundle_deinit ({struct starpu_task_bundle *}@var{bundle})
  85. Deinitialize a bundle. In case the destroy flag is set, the bundle
  86. structure is freed too.
  87. @end deftypefun
  88. @deftypefun int starpu_task_bundle_insert ({struct starpu_task_bundle *}@var{bundle}, {struct starpu_task *}@var{task})
  89. Insert a task into a bundle.
  90. @end deftypefun
  91. @deftypefun int starpu_task_bundle_remove ({struct starpu_task_bundle *}@var{bundle}, {struct starpu_task *}@var{task})
  92. Remove a task from a bundle. This method must be called with
  93. bundle->mutex hold. This function returns 0 if the task was found,
  94. -ENOENT if the element was not found, 1 if the element is found and if
  95. the list was deinitialized because it became empty.
  96. @end deftypefun
  97. @deftypefun void starpu_task_bundle_close ({struct starpu_task_bundle *}@var{bundle});
  98. Close a bundle. No task can be added to a closed bundle. A closed
  99. bundle automatically gets deinitialized when it becomes empty.
  100. @end deftypefun
  101. @deftypefun double starpu_task_bundle_expected_length ({struct starpu_task_bundle *}@var{bundle}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  102. Return the expected duration of the entire task bundle in µs.
  103. @end deftypefun
  104. @deftypefun double starpu_task_bundle_expected_data_transfer_time ({struct starpu_task_bundle *}@var{bundle}, unsigned {memory_node})
  105. Return the time (in µs) expected to transfer all data used within the bundle
  106. @end deftypefun
  107. @deftypefun double starpu_task_bundle_expected_power ({struct starpu_task_bundle *}@var{bundle}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  108. Return the expected power consumption of the entire task bundle in J.
  109. @end deftypefun
  110. @node Task Lists
  111. @section Task Lists
  112. @deftp {Data Type} {struct starpu_task_list}
  113. Stores a double-chained list of tasks
  114. @end deftp
  115. @deftypefun void starpu_task_list_init ({struct starpu_task_list *}@var{list})
  116. Initialize a list structure
  117. @end deftypefun
  118. @deftypefun void starpu_task_list_push_front ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  119. Push a task at the front of a list
  120. @end deftypefun
  121. @deftypefun void starpu_task_list_push_back ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  122. Push a task at the back of a list
  123. @end deftypefun
  124. @deftypefun {struct starpu_task *} starpu_task_list_front ({struct starpu_task_list *}@var{list})
  125. Get the front of the list (without removing it)
  126. @end deftypefun
  127. @deftypefun {struct starpu_task *} starpu_task_list_back ({struct starpu_task_list *}@var{list})
  128. Get the back of the list (without removing it)
  129. @end deftypefun
  130. @deftypefun int starpu_task_list_empty ({struct starpu_task_list *}@var{list})
  131. Test if a list is empty
  132. @end deftypefun
  133. @deftypefun void starpu_task_list_erase ({struct starpu_task_list *}@var{list}, {struct starpu_task *}@var{task})
  134. Remove an element from the list
  135. @end deftypefun
  136. @deftypefun {struct starpu_task *} starpu_task_list_pop_front ({struct starpu_task_list *}@var{list})
  137. Remove the element at the front of the list
  138. @end deftypefun
  139. @deftypefun {struct starpu_task *} starpu_task_list_pop_back ({struct starpu_task_list *}@var{list})
  140. Remove the element at the back of the list
  141. @end deftypefun
  142. @deftypefun {struct starpu_task *} starpu_task_list_begin ({struct starpu_task_list *}@var{list})
  143. Get the first task of the list.
  144. @end deftypefun
  145. @deftypefun {struct starpu_task *} starpu_task_list_end ({struct starpu_task_list *}@var{list})
  146. Get the end of the list.
  147. @end deftypefun
  148. @deftypefun {struct starpu_task *} starpu_task_list_next ({struct starpu_task *}@var{task})
  149. Get the next task of the list. This is not erase-safe.
  150. @end deftypefun
  151. @node Defining a new scheduling policy
  152. @section Defining a new scheduling policy
  153. TODO
  154. A full example showing how to define a new scheduling policy is available in
  155. the StarPU sources in the directory @code{examples/scheduler/}.
  156. @menu
  157. * Scheduling Policy API:: Scheduling Policy API
  158. * Source code::
  159. @end menu
  160. @node Scheduling Policy API
  161. @subsection Scheduling Policy API
  162. @deftp {Data Type} {struct starpu_sched_policy}
  163. This structure contains all the methods that implement a scheduling policy. An
  164. application may specify which scheduling strategy in the @code{sched_policy}
  165. field of the @code{starpu_conf} structure passed to the @code{starpu_init}
  166. function. The different fields are:
  167. @table @asis
  168. @item @code{init_sched}
  169. Initialize the scheduling policy.
  170. @item @code{deinit_sched}
  171. Cleanup the scheduling policy.
  172. @item @code{push_task}
  173. Insert a task into the scheduler.
  174. @item @code{push_task_notify}
  175. Notify the scheduler that a task was pushed on a given worker. This method is
  176. called when a task that was explicitely assigned to a worker becomes ready and
  177. is about to be executed by the worker. This method therefore permits to keep
  178. the state of of the scheduler coherent even when StarPU bypasses the scheduling
  179. strategy.
  180. @item @code{pop_task} (optional)
  181. Get a task from the scheduler. The mutex associated to the worker is already
  182. taken when this method is called. If this method is defined as @code{NULL}, the
  183. worker will only execute tasks from its local queue. In this case, the
  184. @code{push_task} method should use the @code{starpu_push_local_task} method to
  185. assign tasks to the different workers.
  186. @item @code{pop_every_task}
  187. Remove all available tasks from the scheduler (tasks are chained by the means
  188. of the prev and next fields of the starpu_task structure). The mutex associated
  189. to the worker is already taken when this method is called. This is currently
  190. only used by the Gordon driver.
  191. @item @code{post_exec_hook} (optional)
  192. This method is called every time a task has been executed.
  193. @item @code{policy_name}
  194. Name of the policy (optional).
  195. @item @code{policy_description}
  196. Description of the policy (optional).
  197. @end table
  198. @end deftp
  199. @deftypefun void starpu_worker_set_sched_condition (int @var{workerid}, pthread_cond_t *@var{sched_cond}, pthread_mutex_t *@var{sched_mutex})
  200. This function specifies the condition variable associated to a worker
  201. When there is no available task for a worker, StarPU blocks this worker on a
  202. condition variable. This function specifies which condition variable (and the
  203. associated mutex) should be used to block (and to wake up) a worker. Note that
  204. multiple workers may use the same condition variable. For instance, in the case
  205. of a scheduling strategy with a single task queue, the same condition variable
  206. would be used to block and wake up all workers.
  207. The initialization method of a scheduling strategy (@code{init_sched}) must
  208. call this function once per worker.
  209. @end deftypefun
  210. @deftypefun void starpu_sched_set_min_priority (int @var{min_prio})
  211. Defines the minimum priority level supported by the scheduling policy. The
  212. default minimum priority level is the same as the default priority level which
  213. is 0 by convention. The application may access that value by calling the
  214. @code{starpu_sched_get_min_priority} function. This function should only be
  215. called from the initialization method of the scheduling policy, and should not
  216. be used directly from the application.
  217. @end deftypefun
  218. @deftypefun void starpu_sched_set_max_priority (int @var{max_prio})
  219. Defines the maximum priority level supported by the scheduling policy. The
  220. default maximum priority level is 1. The application may access that value by
  221. calling the @code{starpu_sched_get_max_priority} function. This function should
  222. only be called from the initialization method of the scheduling policy, and
  223. should not be used directly from the application.
  224. @end deftypefun
  225. @deftypefun int starpu_sched_get_min_priority (void)
  226. Returns the current minimum priority level supported by the
  227. scheduling policy
  228. @end deftypefun
  229. @deftypefun int starpu_sched_get_max_priority (void)
  230. Returns the current maximum priority level supported by the
  231. scheduling policy
  232. @end deftypefun
  233. @deftypefun int starpu_push_local_task (int @var{workerid}, {struct starpu_task} *@var{task}, int @var{back})
  234. The scheduling policy may put tasks directly into a worker's local queue so
  235. that it is not always necessary to create its own queue when the local queue
  236. is sufficient. If @var{back} not null, @var{task} is put at the back of the queue
  237. where the worker will pop tasks first. Setting @var{back} to 0 therefore ensures
  238. a FIFO ordering.
  239. @end deftypefun
  240. @deftypefun int starpu_worker_may_run_task (unsigned @var{workerid}, {struct starpu_task *}@var{task}, unsigned {nimpl})
  241. 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.
  242. @end deftypefun
  243. @deftypefun double starpu_timing_now (void)
  244. Return the current date in µs
  245. @end deftypefun
  246. @deftypefun double starpu_task_expected_length ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  247. Returns expected task duration in µs
  248. @end deftypefun
  249. @deftypefun double starpu_worker_get_relative_speedup ({enum starpu_perf_archtype} @var{perf_archtype})
  250. Returns an estimated speedup factor relative to CPU speed
  251. @end deftypefun
  252. @deftypefun double starpu_task_expected_data_transfer_time (uint32_t @var{memory_node}, {struct starpu_task *}@var{task})
  253. Returns expected data transfer time in µs
  254. @end deftypefun
  255. @deftypefun double starpu_data_expected_transfer_time (starpu_data_handle_t @var{handle}, unsigned @var{memory_node}, {enum starpu_access_mode} @var{mode})
  256. Predict the transfer time (in µs) to move a handle to a memory node
  257. @end deftypefun
  258. @deftypefun double starpu_task_expected_power ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned @var{nimpl})
  259. Returns expected power consumption in J
  260. @end deftypefun
  261. @deftypefun double starpu_task_expected_conversion_time ({struct starpu_task *}@var{task}, {enum starpu_perf_archtype} @var{arch}, unsigned {nimpl})
  262. Returns expected conversion time in ms (multiformat interface only)
  263. @end deftypefun
  264. @node Source code
  265. @subsection Source code
  266. @cartouche
  267. @smallexample
  268. static struct starpu_sched_policy dummy_sched_policy = @{
  269. .init_sched = init_dummy_sched,
  270. .deinit_sched = deinit_dummy_sched,
  271. .push_task = push_task_dummy,
  272. .push_prio_task = NULL,
  273. .pop_task = pop_task_dummy,
  274. .post_exec_hook = NULL,
  275. .pop_every_task = NULL,
  276. .policy_name = "dummy",
  277. .policy_description = "dummy scheduling strategy"
  278. @};
  279. @end smallexample
  280. @end cartouche
  281. @node Expert mode
  282. @section Expert mode
  283. @deftypefun void starpu_wake_all_blocked_workers (void)
  284. todo
  285. @end deftypefun
  286. @deftypefun int starpu_progression_hook_register (unsigned (*@var{func})(void *arg), void *@var{arg})
  287. todo
  288. @end deftypefun
  289. @deftypefun void starpu_progression_hook_deregister (int @var{hook_id})
  290. todo
  291. @end deftypefun