advanced-examples.texi 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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 Institut National de Recherche en Informatique et Automatique
  6. @c See the file starpu.texi for copying conditions.
  7. @menu
  8. * Using multiple implementations of a codelet::
  9. * Enabling implementation according to capabilities::
  10. * Task and Worker Profiling::
  11. * Partitioning Data::
  12. * Performance model example::
  13. * Theoretical lower bound on execution time::
  14. * Insert Task Utility::
  15. * Data reduction::
  16. * Temporary buffers::
  17. * Parallel Tasks::
  18. * Debugging::
  19. * The multiformat interface::
  20. * On-GPU rendering::
  21. * More examples:: More examples shipped with StarPU
  22. @end menu
  23. @node Using multiple implementations of a codelet
  24. @section Using multiple implementations of a codelet
  25. One may want to write multiple implementations of a codelet for a single type of
  26. device and let StarPU choose which one to run. As an example, we will show how
  27. to use SSE to scale a vector. The codelet can be written as follows:
  28. @cartouche
  29. @smallexample
  30. #include <xmmintrin.h>
  31. void scal_sse_func(void *buffers[], void *cl_arg)
  32. @{
  33. float *vector = (float *) STARPU_VECTOR_GET_PTR(buffers[0]);
  34. unsigned int n = STARPU_VECTOR_GET_NX(buffers[0]);
  35. unsigned int n_iterations = n/4;
  36. if (n % 4 != 0)
  37. n_iterations++;
  38. __m128 *VECTOR = (__m128*) vector;
  39. __m128 factor __attribute__((aligned(16)));
  40. factor = _mm_set1_ps(*(float *) cl_arg);
  41. unsigned int i;
  42. for (i = 0; i < n_iterations; i++)
  43. VECTOR[i] = _mm_mul_ps(factor, VECTOR[i]);
  44. @}
  45. @end smallexample
  46. @end cartouche
  47. @cartouche
  48. @smallexample
  49. struct starpu_codelet cl = @{
  50. .where = STARPU_CPU,
  51. .cpu_funcs = @{ scal_cpu_func, scal_sse_func, NULL @},
  52. .nbuffers = 1,
  53. .modes = @{ STARPU_RW @}
  54. @};
  55. @end smallexample
  56. @end cartouche
  57. Schedulers which are multi-implementation aware (only @code{dmda} and
  58. @code{pheft} for now) will use the performance models of all the
  59. implementations it was given, and pick the one that seems to be the fastest.
  60. @node Enabling implementation according to capabilities
  61. @section Enabling implementation according to capabilities
  62. Some implementations may not run on some devices. For instance, some CUDA
  63. devices do not support double floating point precision, and thus the kernel
  64. execution would just fail; or the device may not have enough shared memory for
  65. the implementation being used. The @code{can_execute} field of the @code{struct
  66. starpu_codelet} structure permits to express this. For instance:
  67. @cartouche
  68. @smallexample
  69. static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  70. @{
  71. const struct cudaDeviceProp *props;
  72. if (starpu_worker_get_type(workerid) == STARPU_CPU_WORKER)
  73. return 1;
  74. /* Cuda device */
  75. props = starpu_cuda_get_device_properties(workerid);
  76. if (props->major >= 2 || props->minor >= 3)
  77. /* At least compute capability 1.3, supports doubles */
  78. return 1;
  79. /* Old card, does not support doubles */
  80. return 0;
  81. @}
  82. struct starpu_codelet cl = @{
  83. .where = STARPU_CPU|STARPU_CUDA,
  84. .can_execute = can_execute,
  85. .cpu_funcs = @{ cpu_func, NULL @},
  86. .cuda_funcs = @{ gpu_func, NULL @}
  87. .nbuffers = 1,
  88. .modes = @{ STARPU_RW @}
  89. @};
  90. @end smallexample
  91. @end cartouche
  92. This can be essential e.g. when running on a machine which mixes various models
  93. of CUDA devices, to take benefit from the new models without crashing on old models.
  94. Note: the @code{can_execute} function is called by the scheduler each time it
  95. tries to match a task with a worker, and should thus be very fast. The
  96. @code{starpu_cuda_get_device_properties} provides a quick access to CUDA
  97. properties of CUDA devices to achieve such efficiency.
  98. Another example is compiling CUDA code for various compute capabilities,
  99. resulting with two CUDA functions, e.g. @code{scal_gpu_13} for compute capability
  100. 1.3, and @code{scal_gpu_20} for compute capability 2.0. Both functions can be
  101. provided to StarPU by using @code{cuda_funcs}, and @code{can_execute} can then be
  102. used to rule out the @code{scal_gpu_20} variant on a CUDA device which
  103. will not be able to execute it:
  104. @cartouche
  105. @smallexample
  106. static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  107. @{
  108. const struct cudaDeviceProp *props;
  109. if (starpu_worker_get_type(workerid) == STARPU_CPU_WORKER)
  110. return 1;
  111. /* Cuda device */
  112. if (nimpl == 0)
  113. /* Trying to execute the 1.3 capability variant, we assume it is ok in all cases. */
  114. return 1;
  115. /* Trying to execute the 2.0 capability variant, check that the card can do it. */
  116. props = starpu_cuda_get_device_properties(workerid);
  117. if (props->major >= 2 || props->minor >= 0)
  118. /* At least compute capability 2.0, can run it */
  119. return 1;
  120. /* Old card, does not support 2.0, will not be able to execute the 2.0 variant. */
  121. return 0;
  122. @}
  123. struct starpu_codelet cl = @{
  124. .where = STARPU_CPU|STARPU_CUDA,
  125. .can_execute = can_execute,
  126. .cpu_funcs = @{ cpu_func, NULL @},
  127. .cuda_funcs = @{ scal_gpu_13, scal_gpu_20, NULL @},
  128. .nbuffers = 1,
  129. .modes = @{ STARPU_RW @}
  130. @};
  131. @end smallexample
  132. @end cartouche
  133. Note: the most generic variant should be provided first, as some schedulers are
  134. not able to try the different variants.
  135. @node Task and Worker Profiling
  136. @section Task and Worker Profiling
  137. A full example showing how to use the profiling API is available in
  138. the StarPU sources in the directory @code{examples/profiling/}.
  139. @cartouche
  140. @smallexample
  141. struct starpu_task *task = starpu_task_create();
  142. task->cl = &cl;
  143. task->synchronous = 1;
  144. /* We will destroy the task structure by hand so that we can
  145. * query the profiling info before the task is destroyed. */
  146. task->destroy = 0;
  147. /* Submit and wait for completion (since synchronous was set to 1) */
  148. starpu_task_submit(task);
  149. /* The task is finished, get profiling information */
  150. struct starpu_task_profiling_info *info = task->profiling_info;
  151. /* How much time did it take before the task started ? */
  152. double delay += starpu_timing_timespec_delay_us(&info->submit_time, &info->start_time);
  153. /* How long was the task execution ? */
  154. double length += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  155. /* We don't need the task structure anymore */
  156. starpu_task_destroy(task);
  157. @end smallexample
  158. @end cartouche
  159. @cartouche
  160. @smallexample
  161. /* Display the occupancy of all workers during the test */
  162. int worker;
  163. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  164. @{
  165. struct starpu_worker_profiling_info worker_info;
  166. int ret = starpu_worker_get_profiling_info(worker, &worker_info);
  167. STARPU_ASSERT(!ret);
  168. double total_time = starpu_timing_timespec_to_us(&worker_info.total_time);
  169. double executing_time = starpu_timing_timespec_to_us(&worker_info.executing_time);
  170. double sleeping_time = starpu_timing_timespec_to_us(&worker_info.sleeping_time);
  171. double overhead_time = total_time - executing_time - sleeping_time;
  172. float executing_ratio = 100.0*executing_time/total_time;
  173. float sleeping_ratio = 100.0*sleeping_time/total_time;
  174. float overhead_ratio = 100.0 - executing_ratio - sleeping_ratio;
  175. char workername[128];
  176. starpu_worker_get_name(worker, workername, 128);
  177. fprintf(stderr, "Worker %s:\n", workername);
  178. fprintf(stderr, "\ttotal time: %.2lf ms\n", total_time*1e-3);
  179. fprintf(stderr, "\texec time: %.2lf ms (%.2f %%)\n", executing_time*1e-3,
  180. executing_ratio);
  181. fprintf(stderr, "\tblocked time: %.2lf ms (%.2f %%)\n", sleeping_time*1e-3,
  182. sleeping_ratio);
  183. fprintf(stderr, "\toverhead time: %.2lf ms (%.2f %%)\n", overhead_time*1e-3,
  184. overhead_ratio);
  185. @}
  186. @end smallexample
  187. @end cartouche
  188. @node Partitioning Data
  189. @section Partitioning Data
  190. An existing piece of data can be partitioned in sub parts to be used by different tasks, for instance:
  191. @cartouche
  192. @smallexample
  193. int vector[NX];
  194. starpu_data_handle_t handle;
  195. /* Declare data to StarPU */
  196. starpu_vector_data_register(&handle, 0, (uintptr_t)vector,
  197. NX, sizeof(vector[0]));
  198. /* Partition the vector in PARTS sub-vectors */
  199. starpu_data_filter f =
  200. @{
  201. .filter_func = starpu_block_filter_func_vector,
  202. .nchildren = PARTS
  203. @};
  204. starpu_data_partition(handle, &f);
  205. @end smallexample
  206. @end cartouche
  207. The task submission then uses @code{starpu_data_get_sub_data} to retrieve the
  208. sub-handles to be passed as tasks parameters.
  209. @cartouche
  210. @smallexample
  211. /* Submit a task on each sub-vector */
  212. for (i=0; i<starpu_data_get_nb_children(handle); i++) @{
  213. /* Get subdata number i (there is only 1 dimension) */
  214. starpu_data_handle_t sub_handle = starpu_data_get_sub_data(handle, 1, i);
  215. struct starpu_task *task = starpu_task_create();
  216. task->handles[0] = sub_handle;
  217. task->cl = &cl;
  218. task->synchronous = 1;
  219. task->cl_arg = &factor;
  220. task->cl_arg_size = sizeof(factor);
  221. starpu_task_submit(task);
  222. @}
  223. @end smallexample
  224. @end cartouche
  225. Partitioning can be applied several times, see
  226. @code{examples/basic_examples/mult.c} and @code{examples/filters/}.
  227. Wherever the whole piece of data is already available, the partitioning will
  228. be done in-place, i.e. without allocating new buffers but just using pointers
  229. inside the existing copy. This is particularly important to be aware of when
  230. using OpenCL, where the kernel parameters are not pointers, but handles. The
  231. kernel thus needs to be also passed the offset within the OpenCL buffer:
  232. @cartouche
  233. @smallexample
  234. void opencl_func(void *buffers[], void *cl_arg)
  235. @{
  236. cl_mem vector = (cl_mem) STARPU_VECTOR_GET_DEV_HANDLE(buffers[0]);
  237. unsigned offset = STARPU_BLOCK_GET_OFFSET(buffers[0]);
  238. ...
  239. clSetKernelArg(kernel, 0, sizeof(vector), &vector);
  240. clSetKernelArg(kernel, 1, sizeof(offset), &offset);
  241. ...
  242. @}
  243. @end smallexample
  244. @end cartouche
  245. And the kernel has to shift from the pointer passed by the OpenCL driver:
  246. @cartouche
  247. @smallexample
  248. __kernel void opencl_kernel(__global int *vector, unsigned offset)
  249. @{
  250. block = (__global void *)block + offset;
  251. ...
  252. @}
  253. @end smallexample
  254. @end cartouche
  255. StarPU provides various interfaces and filters for matrices, vectors, etc.,
  256. but applications can also write their own data interfaces and filters, see
  257. @code{examples/interface} and @code{examples/filters/custom_mf} for an example.
  258. @node Performance model example
  259. @section Performance model example
  260. To achieve good scheduling, StarPU scheduling policies need to be able to
  261. estimate in advance the duration of a task. This is done by giving to codelets
  262. a performance model, by defining a @code{starpu_perfmodel} structure and
  263. providing its address in the @code{model} field of the @code{struct starpu_codelet}
  264. structure. The @code{symbol} and @code{type} fields of @code{starpu_perfmodel}
  265. are mandatory, to give a name to the model, and the type of the model, since
  266. there are several kinds of performance models. For compatibility, make sure to
  267. initialize the whole structure to zero, either by using explicit memset, or by
  268. letting the compiler implicitly do it as examplified below.
  269. @itemize
  270. @item
  271. Measured at runtime (@code{STARPU_HISTORY_BASED} model type). This assumes that for a
  272. given set of data input/output sizes, the performance will always be about the
  273. same. This is very true for regular kernels on GPUs for instance (<0.1% error),
  274. and just a bit less true on CPUs (~=1% error). This also assumes that there are
  275. few different sets of data input/output sizes. StarPU will then keep record of
  276. the average time of previous executions on the various processing units, and use
  277. it as an estimation. History is done per task size, by using a hash of the input
  278. and ouput sizes as an index.
  279. It will also save it in @code{$STARPU_HOME/.starpu/sampling/codelets}
  280. for further executions, and can be observed by using the
  281. @code{starpu_perfmodel_display} command, or drawn by using
  282. the @code{starpu_perfmodel_plot} (@pxref{Performance model calibration}). The
  283. models are indexed by machine name. To
  284. share the models between machines (e.g. for a homogeneous cluster), use
  285. @code{export STARPU_HOSTNAME=some_global_name}. Measurements are only done
  286. when using a task scheduler which makes use of it, such as
  287. @code{dmda}. Measurements can also be provided explicitly by the application, by
  288. using the @code{starpu_perfmodel_update_history} function.
  289. The following is a small code example.
  290. If e.g. the code is recompiled with other compilation options, or several
  291. variants of the code are used, the symbol string should be changed to reflect
  292. that, in order to recalibrate a new model from zero. The symbol string can even
  293. be constructed dynamically at execution time, as long as this is done before
  294. submitting any task using it.
  295. @cartouche
  296. @smallexample
  297. static struct starpu_perfmodel mult_perf_model = @{
  298. .type = STARPU_HISTORY_BASED,
  299. .symbol = "mult_perf_model"
  300. @};
  301. struct starpu_codelet cl = @{
  302. .where = STARPU_CPU,
  303. .cpu_funcs = @{ cpu_mult, NULL @},
  304. .nbuffers = 3,
  305. .modes = @{ STARPU_R, STARPU_R, STARPU_W @},
  306. /* for the scheduling policy to be able to use performance models */
  307. .model = &mult_perf_model
  308. @};
  309. @end smallexample
  310. @end cartouche
  311. @item
  312. Measured at runtime and refined by regression (@code{STARPU_*REGRESSION_BASED}
  313. model type). This still assumes performance regularity, but works
  314. with various data input sizes, by applying regression over observed
  315. execution times. STARPU_REGRESSION_BASED uses an a*n^b regression
  316. form, STARPU_NL_REGRESSION_BASED uses an a*n^b+c (more precise than
  317. STARPU_REGRESSION_BASED, but costs a lot more to compute).
  318. For instance,
  319. @code{tests/perfmodels/regression_based.c} uses a regression-based performance
  320. model for the @code{memset} operation.
  321. Of course, the application has to issue
  322. tasks with varying size so that the regression can be computed. StarPU will not
  323. trust the regression unless there is at least 10% difference between the minimum
  324. and maximum observed input size. It can be useful to set the
  325. @code{STARPU_CALIBRATE} environment variable to @code{1} and run the application
  326. on varying input sizes with @code{STARPU_SCHED} set to @code{eager} scheduler,
  327. so as to feed the performance model for a variety of
  328. inputs. The application can also provide the measurements explictly by using
  329. @code{starpu_perfmodel_update_history}. The @code{starpu_perfmodel_display} and
  330. @code{starpu_perfmodel_plot}
  331. tools can be used to observe how much the performance model is calibrated (@pxref{Performance model calibration}); when
  332. their output look good, @code{STARPU_CALIBRATE} can be reset to @code{0} to let
  333. StarPU use the resulting performance model without recording new measures, and
  334. @code{STARPU_SCHED} can be set to @code{dmda} to benefit from the performance models. If
  335. the data input sizes vary a lot, it is really important to set
  336. @code{STARPU_CALIBRATE} to @code{0}, otherwise StarPU will continue adding the
  337. measures, and result with a very big performance model, which will take time a
  338. lot of time to load and save.
  339. For non-linear regression, since computing it
  340. is quite expensive, it is only done at termination of the application. This
  341. means that the first execution of the application will use only history-based
  342. performance model to perform scheduling, without using regression.
  343. @item
  344. Provided as an estimation from the application itself (@code{STARPU_COMMON} model type and @code{cost_function} field),
  345. see for instance
  346. @code{examples/common/blas_model.h} and @code{examples/common/blas_model.c}.
  347. @item
  348. Provided explicitly by the application (@code{STARPU_PER_ARCH} model type): the
  349. @code{.per_arch[arch][nimpl].cost_function} fields have to be filled with pointers to
  350. functions which return the expected duration of the task in micro-seconds, one
  351. per architecture.
  352. @end itemize
  353. For the @code{STARPU_HISTORY_BASED} and @code{STARPU_*REGRESSION_BASE},
  354. the total size of task data (both input and output) is used as an index by
  355. default. The @code{size_base} field of @code{struct starpu_perfmodel} however
  356. permits the application to override that, when for instance some of the data
  357. do not matter for task cost (e.g. mere reference table), or when using sparse
  358. structures (in which case it is the number of non-zeros which matter), or when
  359. there is some hidden parameter such as the number of iterations, etc.
  360. How to use schedulers which can benefit from such performance model is explained
  361. in @ref{Task scheduling policy}.
  362. The same can be done for task power consumption estimation, by setting the
  363. @code{power_model} field the same way as the @code{model} field. Note: for
  364. now, the application has to give to the power consumption performance model
  365. a name which is different from the execution time performance model.
  366. The application can request time estimations from the StarPU performance
  367. models by filling a task structure as usual without actually submitting
  368. it. The data handles can be created by calling @code{starpu_data_register}
  369. functions with a @code{NULL} pointer (and need to be unregistered as usual)
  370. and the desired data sizes. The @code{starpu_task_expected_length} and
  371. @code{starpu_task_expected_power} functions can then be called to get an
  372. estimation of the task duration on a given arch. @code{starpu_task_destroy}
  373. needs to be called to destroy the dummy task afterwards. See
  374. @code{tests/perfmodels/regression_based.c} for an example.
  375. @node Theoretical lower bound on execution time
  376. @section Theoretical lower bound on execution time
  377. For kernels with history-based performance models (and provided that they are completely calibrated), StarPU can very easily provide a theoretical lower
  378. bound for the execution time of a whole set of tasks. See for
  379. instance @code{examples/lu/lu_example.c}: before submitting tasks,
  380. call @code{starpu_bound_start}, and after complete execution, call
  381. @code{starpu_bound_stop}. @code{starpu_bound_print_lp} or
  382. @code{starpu_bound_print_mps} can then be used to output a Linear Programming
  383. problem corresponding to the schedule of your tasks. Run it through
  384. @code{lp_solve} or any other linear programming solver, and that will give you a
  385. lower bound for the total execution time of your tasks. If StarPU was compiled
  386. with the glpk library installed, @code{starpu_bound_compute} can be used to
  387. solve it immediately and get the optimized minimum, in ms. Its @code{integer}
  388. parameter allows to decide whether integer resolution should be computed
  389. and returned too.
  390. The @code{deps} parameter tells StarPU whether to take tasks, implicit data, and tag
  391. dependencies into account. Tags released in a callback or similar
  392. are not taken into account, only tags associated with a task are.
  393. It must be understood that the linear programming
  394. problem size is quadratic with the number of tasks and thus the time to solve it
  395. will be very long, it could be minutes for just a few dozen tasks. You should
  396. probably use @code{lp_solve -timeout 1 test.pl -wmps test.mps} to convert the
  397. problem to MPS format and then use a better solver, @code{glpsol} might be
  398. better than @code{lp_solve} for instance (the @code{--pcost} option may be
  399. useful), but sometimes doesn't manage to converge. @code{cbc} might look
  400. slower, but it is parallel. Be sure to try at least all the @code{-B} options
  401. of @code{lp_solve}. For instance, we often just use
  402. @code{lp_solve -cc -B1 -Bb -Bg -Bp -Bf -Br -BG -Bd -Bs -BB -Bo -Bc -Bi} , and
  403. the @code{-gr} option can also be quite useful.
  404. Data transfer time can only be taken into account when @code{deps} is set. Only
  405. data transfers inferred from implicit data dependencies between tasks are taken
  406. into account.
  407. Setting @code{deps} to 0 will only take into account the actual computations
  408. on processing units. It however still properly takes into account the varying
  409. performances of kernels and processing units, which is quite more accurate than
  410. just comparing StarPU performances with the fastest of the kernels being used.
  411. The @code{prio} parameter tells StarPU whether to simulate taking into account
  412. the priorities as the StarPU scheduler would, i.e. schedule prioritized
  413. tasks before less prioritized tasks, to check to which extend this results
  414. to a less optimal solution. This increases even more computation time.
  415. Note that for simplicity, all this however doesn't take into account data
  416. transfers, which are assumed to be completely overlapped.
  417. @node Insert Task Utility
  418. @section Insert Task Utility
  419. StarPU provides the wrapper function @code{starpu_insert_task} to ease
  420. the creation and submission of tasks. See the definition of the
  421. functions in @ref{Insert Task}.
  422. Here the implementation of the codelet:
  423. @cartouche
  424. @smallexample
  425. void func_cpu(void *descr[], void *_args)
  426. @{
  427. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  428. float *x1 = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
  429. int ifactor;
  430. float ffactor;
  431. starpu_codelet_unpack_args(_args, &ifactor, &ffactor);
  432. *x0 = *x0 * ifactor;
  433. *x1 = *x1 * ffactor;
  434. @}
  435. struct starpu_codelet mycodelet = @{
  436. .where = STARPU_CPU,
  437. .cpu_funcs = @{ func_cpu, NULL @},
  438. .nbuffers = 2,
  439. .modes = @{ STARPU_RW, STARPU_RW @}
  440. @};
  441. @end smallexample
  442. @end cartouche
  443. And the call to the @code{starpu_insert_task} wrapper:
  444. @cartouche
  445. @smallexample
  446. starpu_insert_task(&mycodelet,
  447. STARPU_VALUE, &ifactor, sizeof(ifactor),
  448. STARPU_VALUE, &ffactor, sizeof(ffactor),
  449. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  450. 0);
  451. @end smallexample
  452. @end cartouche
  453. The call to @code{starpu_insert_task} is equivalent to the following
  454. code:
  455. @cartouche
  456. @smallexample
  457. struct starpu_task *task = starpu_task_create();
  458. task->cl = &mycodelet;
  459. task->handles[0] = data_handles[0];
  460. task->handles[1] = data_handles[1];
  461. char *arg_buffer;
  462. size_t arg_buffer_size;
  463. starpu_codelet_pack_args(&arg_buffer, &arg_buffer_size,
  464. STARPU_VALUE, &ifactor, sizeof(ifactor),
  465. STARPU_VALUE, &ffactor, sizeof(ffactor),
  466. 0);
  467. task->cl_arg = arg_buffer;
  468. task->cl_arg_size = arg_buffer_size;
  469. int ret = starpu_task_submit(task);
  470. @end smallexample
  471. @end cartouche
  472. Here a similar call using @code{STARPU_DATA_ARRAY}.
  473. @cartouche
  474. @smallexample
  475. starpu_insert_task(&mycodelet,
  476. STARPU_DATA_ARRAY, data_handles, 2,
  477. STARPU_VALUE, &ifactor, sizeof(ifactor),
  478. STARPU_VALUE, &ffactor, sizeof(ffactor),
  479. 0);
  480. @end smallexample
  481. @end cartouche
  482. If some part of the task insertion depends on the value of some computation,
  483. the @code{STARPU_DATA_ACQUIRE_CB} macro can be very convenient. For
  484. instance, assuming that the index variable @code{i} was registered as handle
  485. @code{i_handle}:
  486. @cartouche
  487. @smallexample
  488. /* Compute which portion we will work on, e.g. pivot */
  489. starpu_insert_task(&which_index, STARPU_W, i_handle, 0);
  490. /* And submit the corresponding task */
  491. STARPU_DATA_ACQUIRE_CB(i_handle, STARPU_R,
  492. starpu_insert_task(&work, STARPU_RW, A_handle[i], 0));
  493. @end smallexample
  494. @end cartouche
  495. The @code{STARPU_DATA_ACQUIRE_CB} macro submits an asynchronous request for
  496. acquiring data @code{i} for the main application, and will execute the code
  497. given as third parameter when it is acquired. In other words, as soon as the
  498. value of @code{i} computed by the @code{which_index} codelet can be read, the
  499. portion of code passed as third parameter of @code{STARPU_DATA_ACQUIRE_CB} will
  500. be executed, and is allowed to read from @code{i} to use it e.g. as an
  501. index. Note that this macro is only avaible when compiling StarPU with
  502. the compiler @code{gcc}.
  503. @node Data reduction
  504. @section Data reduction
  505. In various cases, some piece of data is used to accumulate intermediate
  506. results. For instances, the dot product of a vector, maximum/minimum finding,
  507. the histogram of a photograph, etc. When these results are produced along the
  508. whole machine, it would not be efficient to accumulate them in only one place,
  509. incurring data transmission each and access concurrency.
  510. StarPU provides a @code{STARPU_REDUX} mode, which permits to optimize
  511. that case: it will allocate a buffer on each memory node, and accumulate
  512. intermediate results there. When the data is eventually accessed in the normal
  513. @code{STARPU_R} mode, StarPU will collect the intermediate results in just one
  514. buffer.
  515. For this to work, the user has to use the
  516. @code{starpu_data_set_reduction_methods} to declare how to initialize these
  517. buffers, and how to assemble partial results.
  518. For instance, @code{cg} uses that to optimize its dot product: it first defines
  519. the codelets for initialization and reduction:
  520. @cartouche
  521. @smallexample
  522. struct starpu_codelet bzero_variable_cl =
  523. @{
  524. .cpu_funcs = @{ bzero_variable_cpu, NULL @},
  525. .cuda_funcs = @{ bzero_variable_cuda, NULL @},
  526. .nbuffers = 1,
  527. @}
  528. static void accumulate_variable_cpu(void *descr[], void *cl_arg)
  529. @{
  530. double *v_dst = (double *)STARPU_VARIABLE_GET_PTR(descr[0]);
  531. double *v_src = (double *)STARPU_VARIABLE_GET_PTR(descr[1]);
  532. *v_dst = *v_dst + *v_src;
  533. @}
  534. static void accumulate_variable_cuda(void *descr[], void *cl_arg)
  535. @{
  536. double *v_dst = (double *)STARPU_VARIABLE_GET_PTR(descr[0]);
  537. double *v_src = (double *)STARPU_VARIABLE_GET_PTR(descr[1]);
  538. cublasaxpy(1, (double)1.0, v_src, 1, v_dst, 1);
  539. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  540. @}
  541. struct starpu_codelet accumulate_variable_cl =
  542. @{
  543. .cpu_funcs = @{ accumulate_variable_cpu, NULL @},
  544. .cuda_funcs = @{ accumulate_variable_cuda, NULL @},
  545. .nbuffers = 1,
  546. @}
  547. @end smallexample
  548. @end cartouche
  549. and attaches them as reduction methods for its dtq handle:
  550. @cartouche
  551. @smallexample
  552. starpu_variable_data_register(&dtq_handle, -1, NULL, sizeof(type));
  553. starpu_data_set_reduction_methods(dtq_handle,
  554. &accumulate_variable_cl, &bzero_variable_cl);
  555. @end smallexample
  556. @end cartouche
  557. and @code{dtq_handle} can now be used in @code{STARPU_REDUX} mode for the dot products
  558. with partitioned vectors:
  559. @cartouche
  560. @smallexample
  561. for (b = 0; b < nblocks; b++)
  562. starpu_insert_task(&dot_kernel_cl,
  563. STARPU_REDUX, dtq_handle,
  564. STARPU_R, starpu_data_get_sub_data(v1, 1, b),
  565. STARPU_R, starpu_data_get_sub_data(v2, 1, b),
  566. 0);
  567. @end smallexample
  568. @end cartouche
  569. During registration, we have here provided NULL, i.e. there is no initial value
  570. to be taken into account during reduction. StarPU will thus only take into
  571. account the contributions from the @code{dot_kernel_cl} tasks. Also, it will not
  572. allocate any memory for @code{dtq_handle} before @code{dot_kernel_cl} tasks are
  573. ready to run.
  574. If another dot product has to be performed, one could unregister
  575. @code{dtq_handle}, and re-register it. But one can also use
  576. @code{starpu_data_invalidate_submit(dtq_handle)}, which will clear all data from the handle,
  577. thus resetting it back to the initial @code{register(NULL)} state.
  578. The @code{cg} example also uses reduction for the blocked gemv kernel, leading
  579. to yet more relaxed dependencies and more parallelism.
  580. STARPU_REDUX can also be passed to @code{starpu_mpi_insert_task} in the MPI
  581. case. That will however not produce any MPI communication, but just pass
  582. STARPU_REDUX to the underlying @code{starpu_insert_task}. It is up to the
  583. application to call @code{starpu_mpi_redux_data}, which posts tasks that will
  584. reduce the partial results among MPI nodes into the MPI node which owns the
  585. data. For instance, some hypothetical application which collects partial results
  586. into data @code{res}, then uses it for other computation, before looping again
  587. with a new reduction:
  588. @cartouche
  589. @smallexample
  590. for (i = 0; i < 100; i++) @{
  591. starpu_mpi_insert_task(MPI_COMM_WORLD, &init_res, STARPU_W, res, 0);
  592. starpu_mpi_insert_task(MPI_COMM_WORLD, &work, STARPU_RW, A,
  593. STARPU_R, B, STARPU_REDUX, res, 0);
  594. starpu_mpi_redux_data(MPI_COMM_WORLD, res);
  595. starpu_mpi_insert_task(MPI_COMM_WORLD, &work2, STARPU_RW, B, STARPU_R, res, 0);
  596. @}
  597. @end smallexample
  598. @end cartouche
  599. @node Temporary buffers
  600. @section Temporary buffers
  601. There are two kinds of temporary buffers: temporary data which just pass results
  602. from a task to another, and scratch data which are needed only internally by
  603. tasks.
  604. @subsection Temporary data
  605. Data can sometimes be entirely produced by a task, and entirely consumed by
  606. another task, without the need for other parts of the application to access
  607. it. In such case, registration can be done without prior allocation, by using
  608. the special -1 memory node number, and passing a zero pointer. StarPU will
  609. actually allocate memory only when the task creating the content gets scheduled,
  610. and destroy it on unregistration.
  611. In addition to that, it can be tedious for the application to have to unregister
  612. the data, since it will not use its content anyway. The unregistration can be
  613. done lazily by using the @code{starpu_data_unregister_submit(handle)} function,
  614. which will record that no more tasks accessing the handle will be submitted, so
  615. that it can be freed as soon as the last task accessing it is over.
  616. The following code examplifies both points: it registers the temporary
  617. data, submits three tasks accessing it, and records the data for automatic
  618. unregistration.
  619. @cartouche
  620. @smallexample
  621. starpu_vector_data_register(&handle, -1, 0, n, sizeof(float));
  622. starpu_insert_task(&produce_data, STARPU_W, handle, 0);
  623. starpu_insert_task(&compute_data, STARPU_RW, handle, 0);
  624. starpu_insert_task(&summarize_data, STARPU_R, handle, STARPU_W, result_handle, 0);
  625. starpu_data_unregister_submit(handle);
  626. @end smallexample
  627. @end cartouche
  628. @subsection Scratch data
  629. Some kernels sometimes need temporary data to achieve the computations, i.e. a
  630. workspace. The application could allocate it at the start of the codelet
  631. function, and free it at the end, but that would be costly. It could also
  632. allocate one buffer per worker (similarly to @ref{Per-worker library
  633. initialization}), but that would make them systematic and permanent. A more
  634. optimized way is to use the SCRATCH data access mode, as examplified below,
  635. which provides per-worker buffers without content consistency.
  636. @cartouche
  637. @smallexample
  638. starpu_vector_data_register(&workspace, -1, 0, sizeof(float));
  639. for (i = 0; i < N; i++)
  640. starpu_insert_task(&compute, STARPU_R, input[i],
  641. STARPU_SCRATCH, workspace, STARPU_W, output[i], 0);
  642. @end smallexample
  643. @end cartouche
  644. StarPU will make sure that the buffer is allocated before executing the task,
  645. and make this allocation per-worker: for CPU workers, notably, each worker has
  646. its own buffer. This means that each task submitted above will actually have its
  647. own workspace, which will actually be the same for all tasks running one after
  648. the other on the same worker. Also, if for instance GPU memory becomes scarce,
  649. StarPU will notice that it can free such buffers easily, since the content does
  650. not matter.
  651. @node Parallel Tasks
  652. @section Parallel Tasks
  653. StarPU can leverage existing parallel computation libraries by the means of
  654. parallel tasks. A parallel task is a task which gets worked on by a set of CPUs
  655. (called a parallel or combined worker) at the same time, by using an existing
  656. parallel CPU implementation of the computation to be achieved. This can also be
  657. useful to improve the load balance between slow CPUs and fast GPUs: since CPUs
  658. work collectively on a single task, the completion time of tasks on CPUs become
  659. comparable to the completion time on GPUs, thus relieving from granularity
  660. discrepancy concerns. Hwloc support needs to be enabled to get good performance,
  661. otherwise StarPU will not know how to better group cores.
  662. Two modes of execution exist to accomodate with existing usages.
  663. @subsection Fork-mode parallel tasks
  664. In the Fork mode, StarPU will call the codelet function on one
  665. of the CPUs of the combined worker. The codelet function can use
  666. @code{starpu_combined_worker_get_size()} to get the number of threads it is
  667. allowed to start to achieve the computation. The CPU binding mask for the whole
  668. set of CPUs is already enforced, so that threads created by the function will
  669. inherit the mask, and thus execute where StarPU expected, the OS being in charge
  670. of choosing how to schedule threads on the corresponding CPUs. The application
  671. can also choose to bind threads by hand, using e.g. sched_getaffinity to know
  672. the CPU binding mask that StarPU chose.
  673. For instance, using OpenMP (full source is available in
  674. @code{examples/openmp/vector_scal.c}):
  675. @cartouche
  676. @smallexample
  677. void scal_cpu_func(void *buffers[], void *_args)
  678. @{
  679. unsigned i;
  680. float *factor = _args;
  681. struct starpu_vector_interface *vector = buffers[0];
  682. unsigned n = STARPU_VECTOR_GET_NX(vector);
  683. float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
  684. #pragma omp parallel for num_threads(starpu_combined_worker_get_size())
  685. for (i = 0; i < n; i++)
  686. val[i] *= *factor;
  687. @}
  688. static struct starpu_codelet cl =
  689. @{
  690. .modes = @{ STARPU_RW @},
  691. .where = STARPU_CPU,
  692. .type = STARPU_FORKJOIN,
  693. .max_parallelism = INT_MAX,
  694. .cpu_funcs = @{scal_cpu_func, NULL@},
  695. .nbuffers = 1,
  696. @};
  697. @end smallexample
  698. @end cartouche
  699. Other examples include for instance calling a BLAS parallel CPU implementation
  700. (see @code{examples/mult/xgemm.c}).
  701. @subsection SPMD-mode parallel tasks
  702. In the SPMD mode, StarPU will call the codelet function on
  703. each CPU of the combined worker. The codelet function can use
  704. @code{starpu_combined_worker_get_size()} to get the total number of CPUs
  705. involved in the combined worker, and thus the number of calls that are made in
  706. parallel to the function, and @code{starpu_combined_worker_get_rank()} to get
  707. the rank of the current CPU within the combined worker. For instance:
  708. @cartouche
  709. @smallexample
  710. static void func(void *buffers[], void *args)
  711. @{
  712. unsigned i;
  713. float *factor = _args;
  714. struct starpu_vector_interface *vector = buffers[0];
  715. unsigned n = STARPU_VECTOR_GET_NX(vector);
  716. float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
  717. /* Compute slice to compute */
  718. unsigned m = starpu_combined_worker_get_size();
  719. unsigned j = starpu_combined_worker_get_rank();
  720. unsigned slice = (n+m-1)/m;
  721. for (i = j * slice; i < (j+1) * slice && i < n; i++)
  722. val[i] *= *factor;
  723. @}
  724. static struct starpu_codelet cl =
  725. @{
  726. .modes = @{ STARPU_RW @},
  727. .where = STARP_CPU,
  728. .type = STARPU_SPMD,
  729. .max_parallelism = INT_MAX,
  730. .cpu_funcs = @{ func, NULL @},
  731. .nbuffers = 1,
  732. @}
  733. @end smallexample
  734. @end cartouche
  735. Of course, this trivial example will not really benefit from parallel task
  736. execution, and was only meant to be simple to understand. The benefit comes
  737. when the computation to be done is so that threads have to e.g. exchange
  738. intermediate results, or write to the data in a complex but safe way in the same
  739. buffer.
  740. @subsection Parallel tasks performance
  741. To benefit from parallel tasks, a parallel-task-aware StarPU scheduler has to
  742. be used. When exposed to codelets with a Fork or SPMD flag, the @code{pheft}
  743. (parallel-heft) and @code{peager} (parallel eager) schedulers will indeed also
  744. try to execute tasks with several CPUs. It will automatically try the various
  745. available combined worker sizes and thus be able to avoid choosing a large
  746. combined worker if the codelet does not actually scale so much.
  747. @subsection Combined workers
  748. By default, StarPU creates combined workers according to the architecture
  749. structure as detected by hwloc. It means that for each object of the hwloc
  750. topology (NUMA node, socket, cache, ...) a combined worker will be created. If
  751. some nodes of the hierarchy have a big arity (e.g. many cores in a socket
  752. without a hierarchy of shared caches), StarPU will create combined workers of
  753. intermediate sizes. The @code{STARPU_SYNTHESIZE_ARITY_COMBINED_WORKER} variable
  754. permits to tune the maximum arity between levels of combined workers.
  755. The combined workers actually produced can be seen in the output of the
  756. @code{starpu_machine_display} tool (the @code{STARPU_SCHED} environment variable
  757. has to be set to a combined worker-aware scheduler such as @code{pheft} or
  758. @code{peager}).
  759. @subsection Concurrent parallel tasks
  760. Unfortunately, many environments and librairies do not support concurrent
  761. calls.
  762. For instance, most OpenMP implementations (including the main ones) do not
  763. support concurrent @code{pragma omp parallel} statements without nesting them in
  764. another @code{pragma omp parallel} statement, but StarPU does not yet support
  765. creating its CPU workers by using such pragma.
  766. Other parallel libraries are also not safe when being invoked concurrently
  767. from different threads, due to the use of global variables in their sequential
  768. sections for instance.
  769. The solution is then to use only one combined worker at a time. This can be
  770. done by setting @code{single_combined_worker} to 1 in the @code{starpu_conf}
  771. structure, or setting the @code{STARPU_SINGLE_COMBINED_WORKER} environment
  772. variable to 1. StarPU will then run only one parallel task at a time (but other
  773. CPU and GPU tasks are not affected and can be run concurrently). The parallel
  774. task scheduler will however still however still try varying combined worker
  775. sizes to look for the most efficient ones.
  776. @node Debugging
  777. @section Debugging
  778. StarPU provides several tools to help debugging aplications. Execution traces
  779. can be generated and displayed graphically, see @ref{Generating traces}. Some
  780. gdb helpers are also provided to show the whole StarPU state:
  781. @smallexample
  782. (gdb) source tools/gdbinit
  783. (gdb) help starpu
  784. @end smallexample
  785. The Temanejo task debugger can also be used, see @ref{Task debugger}.
  786. @node The multiformat interface
  787. @section The multiformat interface
  788. It may be interesting to represent the same piece of data using two different
  789. data structures: one that would only be used on CPUs, and one that would only
  790. be used on GPUs. This can be done by using the multiformat interface. StarPU
  791. will be able to convert data from one data structure to the other when needed.
  792. Note that the dmda scheduler is the only one optimized for this interface. The
  793. user must provide StarPU with conversion codelets:
  794. @cartouche
  795. @smallexample
  796. #define NX 1024
  797. struct point array_of_structs[NX];
  798. starpu_data_handle_t handle;
  799. /*
  800. * The conversion of a piece of data is itself a task, though it is created,
  801. * submitted and destroyed by StarPU internals and not by the user. Therefore,
  802. * we have to define two codelets.
  803. * Note that for now the conversion from the CPU format to the GPU format has to
  804. * be executed on the GPU, and the conversion from the GPU to the CPU has to be
  805. * executed on the CPU.
  806. */
  807. #ifdef STARPU_USE_OPENCL
  808. void cpu_to_opencl_opencl_func(void *buffers[], void *args);
  809. struct starpu_codelet cpu_to_opencl_cl = @{
  810. .where = STARPU_OPENCL,
  811. .opencl_funcs = @{ cpu_to_opencl_opencl_func, NULL @},
  812. .nbuffers = 1,
  813. .modes = @{ STARPU_RW @}
  814. @};
  815. void opencl_to_cpu_func(void *buffers[], void *args);
  816. struct starpu_codelet opencl_to_cpu_cl = @{
  817. .where = STARPU_CPU,
  818. .cpu_funcs = @{ opencl_to_cpu_func, NULL @},
  819. .nbuffers = 1,
  820. .modes = @{ STARPU_RW @}
  821. @};
  822. #endif
  823. struct starpu_multiformat_data_interface_ops format_ops = @{
  824. #ifdef STARPU_USE_OPENCL
  825. .opencl_elemsize = 2 * sizeof(float),
  826. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  827. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  828. #endif
  829. .cpu_elemsize = 2 * sizeof(float),
  830. ...
  831. @};
  832. starpu_multiformat_data_register(handle, 0, &array_of_structs, NX, &format_ops);
  833. @end smallexample
  834. @end cartouche
  835. Kernels can be written almost as for any other interface. Note that
  836. STARPU_MULTIFORMAT_GET_CPU_PTR shall only be used for CPU kernels. CUDA kernels
  837. must use STARPU_MULTIFORMAT_GET_CUDA_PTR, and OpenCL kernels must use
  838. STARPU_MULTIFORMAT_GET_OPENCL_PTR. STARPU_MULTIFORMAT_GET_NX may be used in any
  839. kind of kernel.
  840. @cartouche
  841. @smallexample
  842. static void
  843. multiformat_scal_cpu_func(void *buffers[], void *args)
  844. @{
  845. struct point *aos;
  846. unsigned int n;
  847. aos = STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
  848. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  849. ...
  850. @}
  851. extern "C" void multiformat_scal_cuda_func(void *buffers[], void *_args)
  852. @{
  853. unsigned int n;
  854. struct struct_of_arrays *soa;
  855. soa = (struct struct_of_arrays *) STARPU_MULTIFORMAT_GET_CUDA_PTR(buffers[0]);
  856. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  857. ...
  858. @}
  859. @end smallexample
  860. @end cartouche
  861. A full example may be found in @code{examples/basic_examples/multiformat.c}.
  862. @node On-GPU rendering
  863. @section On-GPU rendering
  864. Graphical-oriented applications need to draw the result of their computations,
  865. typically on the very GPU where these happened. Technologies such as OpenGL/CUDA
  866. interoperability permit to let CUDA directly work on the OpenGL buffers, making
  867. them thus immediately ready for drawing, by mapping OpenGL buffer, textures or
  868. renderbuffer objects into CUDA. CUDA however imposes some technical
  869. constraints: peer memcpy has to be disabled, and the thread that runs OpenGL has
  870. to be the one that runs CUDA computations for that GPU.
  871. To achieve this with StarPU, pass the @code{--disable-cuda-memcpy-peer} option
  872. to @code{./configure} (TODO: make it dynamic), OpenGL/GLUT has to be initialized
  873. first, and the interoperability mode has to
  874. be enabled by using the @code{cuda_opengl_interoperability} field of the
  875. @code{starpu_conf} structure, and the driver loop has to be run by
  876. the application, by using the @code{not_launched_drivers} field of
  877. @code{starpu_conf} to prevent StarPU from running it in a separate thread, and
  878. by using @code{starpu_driver_run} to run the loop. The @code{gl_interop} and
  879. @code{gl_interop_idle} examples shows how it articulates in a simple case, where
  880. rendering is done in task callbacks. The former uses @code{glutMainLoopEvent}
  881. to make GLUT progress from the StarPU driver loop, while the latter uses
  882. @code{glutIdleFunc} to make StarPU progress from the GLUT main loop.
  883. Then, to use an OpenGL buffer as a CUDA data, StarPU simply needs to be given
  884. the CUDA pointer at registration, for instance:
  885. @cartouche
  886. @smallexample
  887. /* Get the CUDA worker id */
  888. for (workerid = 0; workerid < starpu_worker_get_count(); workerid++)
  889. if (starpu_worker_get_type(workerid) == STARPU_CUDA_WORKER)
  890. break;
  891. /* Build a CUDA pointer pointing at the OpenGL buffer */
  892. cudaGraphicsResourceGetMappedPointer((void**)&output, &num_bytes, resource);
  893. /* And register it to StarPU */
  894. starpu_vector_data_register(&handle, starpu_worker_get_memory_node(workerid),
  895. output, num_bytes / sizeof(float4), sizeof(float4));
  896. /* The handle can now be used as usual */
  897. starpu_insert_task(&cl, STARPU_RW, handle, 0);
  898. /* ... */
  899. /* This gets back data into the OpenGL buffer */
  900. starpu_data_unregister(handle);
  901. @end smallexample
  902. @end cartouche
  903. and display it e.g. in the callback function.
  904. @node More examples
  905. @section More examples
  906. More examples are available in the StarPU sources in the @code{examples/}
  907. directory. Simple examples include:
  908. @table @asis
  909. @item @code{incrementer/}:
  910. Trivial incrementation test.
  911. @item @code{basic_examples/}:
  912. Simple documented Hello world and vector/scalar product (as
  913. shown in @ref{Basic Examples}), matrix
  914. product examples (as shown in @ref{Performance model example}), an example using the blocked matrix data
  915. interface, an example using the variable data interface, and an example
  916. using different formats on CPUs and GPUs.
  917. @item @code{matvecmult/}:
  918. OpenCL example from NVidia, adapted to StarPU.
  919. @item @code{axpy/}:
  920. AXPY CUBLAS operation adapted to StarPU.
  921. @item @code{fortran/}:
  922. Example of Fortran bindings.
  923. @end table
  924. More advanced examples include:
  925. @table @asis
  926. @item @code{filters/}:
  927. Examples using filters, as shown in @ref{Partitioning Data}.
  928. @item @code{lu/}:
  929. LU matrix factorization, see for instance @code{xlu_implicit.c}
  930. @item @code{cholesky/}:
  931. Cholesky matrix factorization, see for instance @code{cholesky_implicit.c}.
  932. @end table