advanced-api.texi 15 KB

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