starpu.texi 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename starpu.info
  4. @settitle StarPU
  5. @c %**end of header
  6. @setchapternewpage odd
  7. @titlepage
  8. @title StarPU
  9. @page
  10. @vskip 0pt plus 1filll
  11. @comment For the @value{version-GCC} Version*
  12. @end titlepage
  13. @summarycontents
  14. @contents
  15. @page
  16. @node Top
  17. @top Preface
  18. @cindex Preface
  19. This manual documents the usage of StarPU
  20. @comment
  21. @comment When you add a new menu item, please keep the right hand
  22. @comment aligned to the same column. Do not use tabs. This provides
  23. @comment better formatting.
  24. @comment
  25. @menu
  26. * Introduction:: A basic introduction to using StarPU.
  27. * Installing StarPU:: How to configure, build and install StarPU
  28. * StarPU API:: The API to use StarPU
  29. * Basic Examples:: Basic examples of the use of StarPU
  30. @end menu
  31. @c ---------------------------------------------------------------------
  32. @c Introduction to StarPU
  33. @c ---------------------------------------------------------------------
  34. @node Introduction
  35. @chapter Introduction to StarPU
  36. @section Motivation
  37. @c DSM
  38. @c explain the notion of codelet and task (ie. g(A, B)
  39. @c ---------------------------------------------------------------------
  40. @c Installing StarPU
  41. @c ---------------------------------------------------------------------
  42. @node Installing StarPU
  43. @chapter Installing StarPU
  44. StarPU can be built and install by the standard means of the GNU autotools. The
  45. following chapter is intended to briefly remind how these tools can be used to
  46. install StarPU.
  47. @section Configuring StarPU
  48. @subsection Generating Makefiles and configuration scripts
  49. This step is not necessary when using the tarball releases of StarPU. If you
  50. are using the source code from the svn repository, you first need to generate
  51. the configure scripts and the Makefiles.
  52. @example
  53. $ autoreconf -i
  54. @end example
  55. @subsection Configuring StarPU
  56. @example
  57. $ configure
  58. @end example
  59. @c TODO enumerate the list of interesting options
  60. @section Building and Installing StarPU
  61. @subsection Building
  62. @example
  63. $ make
  64. @end example
  65. @subsection Sanity Checks
  66. In order to make sure that StarPU is working properly on the system, it is also
  67. possible to run a test suite.
  68. @example
  69. $ make check
  70. @end example
  71. @subsection Installing
  72. In order to install StarPU at the location that was specified during
  73. configuration:
  74. @example
  75. $ make install
  76. @end example
  77. @subsection pkg-config configuration
  78. It is possible that compiling and linking an application against StarPU
  79. requires to use specific flags or libraries (for instance @code{CUDA} or
  80. @code{libspe2}). Therefore, it is possible to use the @code{pkg-config} tool.
  81. If StarPU was not installed at some standard location, the path of StarPU's
  82. library must be specified in the @code{PKG_CONFIG_PATH} environment variable so
  83. that @code{pkg-config} can find it. So if StarPU was installed in
  84. @code{$(prefix_dir)}:
  85. @example
  86. $ PKG_CONFIG_PATH = @{PKG_CONFIG_PATH@}:$(prefix_dir)/lib/
  87. @end example
  88. The flags required to compiled or linked against StarPU are then
  89. accessible with the following commands:
  90. @example
  91. $ pkg-config --cflags libstarpu # options for the compiler
  92. $ pkg-config --libs libstarpu # options for the linker
  93. @end example
  94. @c ---------------------------------------------------------------------
  95. @c StarPU API
  96. @c ---------------------------------------------------------------------
  97. @node StarPU API
  98. @chapter StarPU API
  99. @menu
  100. * Initialization and Termination:: Initialization and Termination methods
  101. * Data Library:: Methods to manipulate data
  102. * Codelets and Tasks:: Methods to construct tasks
  103. @end menu
  104. @node Initialization and Termination
  105. @section Initialization and Termination
  106. @menu
  107. * starpu_init:: Initialize StarPU
  108. * starpu_shutdown:: Terminate StarPU
  109. @end menu
  110. @node starpu_init
  111. @subsection @code{starpu_init} -- Initialize StarPU
  112. @table @asis
  113. @item @emph{Description}:
  114. This is StarPU initialization method, which must be called prior to any other
  115. StarPU call. It is possible to specify StarPU's configuration (eg. scheduling
  116. policy, number of cores, ...) by passing a non-null argument. Default
  117. configuration is used if the passed argument is @code{NULL}.
  118. @item @emph{Prototype}:
  119. @code{void starpu_init(struct starpu_conf *conf);}
  120. @end table
  121. @node starpu_shutdown
  122. @subsection @code{starpu_shutdown} -- Terminate StarPU
  123. @table @asis
  124. @item @emph{Description}:
  125. This is StarPU termination method. It must be called at the end of the
  126. application: statistics and other post-mortem debugging information are not
  127. garanteed to be available until this method has been called.
  128. @item @emph{Prototype}:
  129. @code{void starpu_shutdown(void);}
  130. @end table
  131. @node Data Library
  132. @section Data Library
  133. @node Codelets and Tasks
  134. @section Codelets and Tasks
  135. @c TODO
  136. @node starpu_task_create
  137. @c Callbacks : what can we put in callbacks ?
  138. @section Extensions
  139. @subsection CUDA extensions
  140. @subsection Cell extensions
  141. @c ---------------------------------------------------------------------
  142. @c Basic Examples
  143. @c ---------------------------------------------------------------------
  144. @node Basic Examples
  145. @chapter Basic Examples
  146. @section Compiling and linking options
  147. The Makefile could for instance contain the following lines to define which
  148. options must be given to the compiler and to the linker:
  149. @example
  150. @cartouche
  151. CFLAGS+=$$(pkg-config --cflags libstarpu)
  152. LIBS+=$$(pkg-config --libs libstarpu)
  153. @end cartouche
  154. @end example
  155. @section Hello World
  156. In this section, we show how to implement a simple program that submits a task to StarPU.
  157. @subsection Required Headers
  158. The @code{starpu.h} header should be included in any code using StarPU.
  159. @example
  160. @cartouche
  161. #include <starpu.h>
  162. @end cartouche
  163. @end example
  164. @subsection Defining a Codelet
  165. @example
  166. @cartouche
  167. void cpu_func(starpu_data_interface_t *buffers, void *func_arg)
  168. @{
  169. float *array = func_arg;
  170. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  171. @}
  172. starpu_codelet cl =
  173. @{
  174. .where = CORE,
  175. .core_func = cpu_func,
  176. .nbuffers = 0
  177. @};
  178. @end cartouche
  179. @end example
  180. A codelet is a structure that represents a computational kernel. Such a codelet
  181. may contain an implementation of the same kernel on different architectures
  182. (eg. CUDA, Cell's SPU, x86, ...).
  183. The ''@code{.nbuffers}'' field specifies the number of data buffers that are
  184. manipulated by the codelet: here the codelet does not access or modify any data
  185. that is controlled by our data management library. Note that the argument
  186. passed to the codelet (the ''@code{.cl_arg}'' field of the @code{starpu_task}
  187. structure) does not count as a buffer since it is not managed by our data
  188. management library.
  189. @c TODO need a crossref to the proper description of "where" see bla for more ...
  190. We create a codelet which may only be executed on the CPUs. The ''@code{.where}''
  191. field is a bitmask that defines where the codelet may be executed. Here, the
  192. @code{CORE} value means that only CPUs can execute this codelet
  193. (@pxref{Codelets and Tasks} for more details on that field).
  194. When a CPU core executes a codelet, it calls the @code{.core_func} function,
  195. which @emph{must} have the following prototype:
  196. @code{void (*core_func)(starpu_data_interface_t *, void *)}
  197. In this example, we can ignore the first argument of this function gives a
  198. description of the input and output buffers (eg. the size and the location of
  199. the matrices). The second argument is a pointer to a buffer passed as an
  200. argument to the codelet by the means of the ''@code{.cl_arg}'' field of the
  201. @code{starpu_task} structure. Be aware that this may be a pointer to a
  202. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  203. if the codelet modifies this buffer, there is no garantee that the initial
  204. buffer will be modified as well: this for instance implies that the buffer
  205. cannot be used as a synchronization medium.
  206. @subsection Submitting a Task
  207. @example
  208. @cartouche
  209. void callback_func(void *callback_arg)
  210. @{
  211. printf("Callback function (arg %x)\n", callback_arg);
  212. @}
  213. int main(int argc, char **argv)
  214. @{
  215. /* initialize StarPU */
  216. starpu_init(NULL);
  217. struct starpu_task *task = starpu_task_create();
  218. task->cl = &cl;
  219. float array[2] = @{1.0f, -1.0f@};
  220. task->cl_arg = &array;
  221. task->cl_arg_size = 2*sizeof(float);
  222. task->callback_func = callback_func;
  223. task->callback_arg = 0x42;
  224. /* starpu_submit_task will be a blocking call */
  225. task->synchronous = 1;
  226. /* submit the task to StarPU */
  227. starpu_submit_task(task);
  228. /* terminate StarPU */
  229. starpu_shutdown();
  230. return 0;
  231. @}
  232. @end cartouche
  233. @end example
  234. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  235. @code{NULL} arguments specifies that we use default configuration. Tasks cannot
  236. be submitted after the termination of StarPU by a call to
  237. @code{starpu_shutdown}.
  238. In the example above, a task structure is allocated by a call to
  239. @code{starpu_task_create}. This function only allocate and fills the
  240. corresponding structure with the default settings (@pxref{starpu_task_create}),
  241. but it does not submit the task to StarPU.
  242. @c not really clear ;)
  243. The ''@code{.cl}'' field is a pointer to the codelet which the task will
  244. execute: in other words, the codelet structure describes which computational
  245. kernel should be offloaded on the different architectures, and the task
  246. structure is a wrapper containing a codelet and the piece of data on which the
  247. codelet should operate.
  248. The optional ''@code{.cl_arg}'' field is a pointer to a buffer (of size
  249. @code{.cl_arg_size}) with some parameters for some parameters for the kernel
  250. described by the codelet. For instance, if a codelet implements a computational
  251. kernel that multiplies its input vector by a constant, the constant could be
  252. specified by the means of this buffer.
  253. Once a task has been executed, an optional callback function can be called.
  254. While the computational kernel could be offloaded on various architectures, the
  255. callback function is always executed on a CPU. The ''@code{.callback_arg}''
  256. pointer is passed as an argument of the callback. The prototype of a callback
  257. function must be:
  258. @example
  259. void (*callback_function)(void *);
  260. @end example
  261. If the @code{.synchronous} field is non-null, task submission will be
  262. synchronous: the @code{starpu_submit_task} function will not return until the
  263. task was executed. Note that the @code{starpu_shutdown} method does not
  264. guaranty that asynchronous tasks have been executed before it returns.
  265. @bye