starpu_data_interfaces.h 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2019 Université de Bordeaux
  4. * Copyright (C) 2011-2014,2016,2017 Inria
  5. * Copyright (C) 2010-2015,2017,2019 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_DATA_INTERFACES_H__
  19. #define __STARPU_DATA_INTERFACES_H__
  20. #include <starpu.h>
  21. #ifdef STARPU_USE_CUDA
  22. /* to use CUDA streams */
  23. # ifdef STARPU_DONT_INCLUDE_CUDA_HEADERS
  24. typedef void *starpu_cudaStream_t;
  25. # else
  26. # include <cuda_runtime.h>
  27. typedef cudaStream_t starpu_cudaStream_t;
  28. # endif
  29. #endif
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /**
  35. @defgroup API_Data_Interfaces Data Interfaces
  36. @brief Data management is done at a high-level in StarPU: rather than
  37. accessing a mere list of contiguous buffers, the tasks may manipulate
  38. data that are described by a high-level construct which we call data
  39. interface.
  40. An example of data interface is the "vector" interface which describes
  41. a contiguous data array on a spefic memory node. This interface is a
  42. simple structure containing the number of elements in the array, the
  43. size of the elements, and the address of the array in the appropriate
  44. address space (this address may be invalid if there is no valid copy
  45. of the array in the memory node). More informations on the data
  46. interfaces provided by StarPU are given in \ref API_Data_Interfaces.
  47. When a piece of data managed by StarPU is used by a task, the task
  48. implementation is given a pointer to an interface describing a valid
  49. copy of the data that is accessible from the current processing unit.
  50. Every worker is associated to a memory node which is a logical
  51. abstraction of the address space from which the processing unit gets
  52. its data. For instance, the memory node associated to the different
  53. CPU workers represents main memory (RAM), the memory node associated
  54. to a GPU is DRAM embedded on the device. Every memory node is
  55. identified by a logical index which is accessible from the
  56. function starpu_worker_get_memory_node(). When registering a piece of
  57. data to StarPU, the specified memory node indicates where the piece of
  58. data initially resides (we also call this memory node the home node of
  59. a piece of data).
  60. In the case of NUMA systems, functions starpu_memory_nodes_numa_devid_to_id()
  61. and starpu_memory_nodes_numa_id_to_devid() can be used to convert from NUMA node
  62. numbers as seen by the Operating System and NUMA node numbers as seen by StarPU.
  63. There are several ways to register a memory region so that it can be
  64. managed by StarPU. StarPU provides data interfaces for vectors, 2D
  65. matrices, 3D matrices as well as BCSR and CSR sparse matrices.
  66. Each data interface is provided with a set of field access functions.
  67. The ones using a <c>void *</c> parameter aimed to be used in codelet
  68. implementations (see for example the code in
  69. \ref VectorScalingUsingStarPUAPI).
  70. Applications can provide their own interface as shown in \ref DefiningANewDataInterface.
  71. @{
  72. */
  73. /**
  74. Define the per-interface methods. If the
  75. starpu_data_copy_methods::any_to_any method is provided, it will be
  76. used by default if no specific method is provided. It can still be
  77. useful to provide more specific method in case of e.g. available
  78. particular CUDA or OpenCL support.
  79. */
  80. struct starpu_data_copy_methods
  81. {
  82. /**
  83. If defined, allow the interface to declare whether it supports
  84. transferring from \p src_interface on node \p src_node to \p
  85. dst_interface on node \p dst_node, run from node \p handling_node.
  86. If not defined, it is assumed that the interface supports all
  87. transfers.
  88. */
  89. int (*can_copy)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, unsigned handling_node);
  90. /**
  91. Define how to copy data from the \p src_interface interface on the
  92. \p src_node CPU node to the \p dst_interface interface on the \p
  93. dst_node CPU node. Return 0 on success.
  94. */
  95. int (*ram_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  96. /**
  97. Define how to copy data from the \p src_interface interface on the
  98. \p src_node CPU node to the \p dst_interface interface on the \p
  99. dst_node CUDA node. Return 0 on success.
  100. */
  101. int (*ram_to_cuda)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  102. /**
  103. Define how to copy data from the \p src_interface interface on the
  104. \p src_node CPU node to the \p dst_interface interface on the \p
  105. dst_node OpenCL node. Return 0 on success.
  106. */
  107. int (*ram_to_opencl)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  108. /**
  109. Define how to copy data from the \p src_interface interface on the
  110. \p src_node CPU node to the \p dst_interface interface on the \p
  111. dst_node MIC node. Return 0 on success.
  112. */
  113. int (*ram_to_mic)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  114. /**
  115. Define how to copy data from the \p src_interface interface on the
  116. \p src_node CUDA node to the \p dst_interface interface on the \p
  117. dst_node CPU node. Return 0 on success.
  118. */
  119. int (*cuda_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  120. /**
  121. Define how to copy data from the \p src_interface interface on the
  122. \p src_node CUDA node to the \p dst_interface interface on the \p
  123. dst_node CUDA node. Return 0 on success.
  124. */
  125. int (*cuda_to_cuda)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  126. /**
  127. Define how to copy data from the \p src_interface interface on the
  128. \p src_node CUDA node to the \p dst_interface interface on the \p
  129. dst_node OpenCL node. Return 0 on success.
  130. */
  131. int (*cuda_to_opencl)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  132. /**
  133. Define how to copy data from the \p src_interface interface on the
  134. \p src_node OpenCL node to the \p dst_interface interface on the
  135. \p dst_node CPU node. Return 0 on success.
  136. */
  137. int (*opencl_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  138. /**
  139. Define how to copy data from the \p src_interface interface on the
  140. \p src_node OpenCL node to the \p dst_interface interface on the
  141. \p dst_node CUDA node. Return 0 on success.
  142. */
  143. int (*opencl_to_cuda)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  144. /**
  145. Define how to copy data from the \p src_interface interface on the
  146. \p src_node OpenCL node to the \p dst_interface interface on the
  147. \p dst_node OpenCL node. Return 0 on success.
  148. */
  149. int (*opencl_to_opencl)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  150. /**
  151. Define how to copy data from the \p src_interface interface on the
  152. \p src_node MIC node to the \p dst_interface interface on the \p
  153. dst_node CPU node. Return 0 on success.
  154. */
  155. int (*mic_to_ram)(void *src_interface, unsigned srd_node, void *dst_interface, unsigned dst_node);
  156. /**
  157. Define how to copy data from the \p src_interface interface on the
  158. \p src_node node to the \p dst_interface interface on the \p
  159. dst_node node. Must return 0 if the transfer was actually
  160. completed completely synchronously, or <c>-EAGAIN</c> if at least
  161. some transfers are still ongoing and should be awaited for by the
  162. core.
  163. */
  164. int (*scc_src_to_sink)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  165. /**
  166. Define how to copy data from the \p src_interface interface on the
  167. \p src_node node to the \p dst_interface interface on the \p
  168. dst_node node. Must return 0 if the transfer was actually
  169. completed completely synchronously, or <c>-EAGAIN</c> if at least
  170. some transfers are still ongoing and should be awaited for by the core.
  171. */
  172. int (*scc_sink_to_src)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  173. /**
  174. Define how to copy data from the \p src_interface interface on the
  175. \p src_node node to the \p dst_interface interface on the \p
  176. dst_node node. Must return 0 if the transfer was actually
  177. completed completely synchronously, or <c>-EAGAIN</c> if at least
  178. some transfers are still ongoing and should be awaited for by the
  179. core.
  180. */
  181. int (*scc_sink_to_sink)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  182. /**
  183. Define how to copy data from the \p src_interface interface on the
  184. \p src_node CPU node to the \p dst_interface interface on the \p
  185. dst_node MPI Slave node. Return 0 on success.
  186. */
  187. int (*ram_to_mpi_ms)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  188. /**
  189. Define how to copy data from the \p src_interface interface on the
  190. \p src_node MPI Slave node to the \p dst_interface interface on
  191. the \p dst_node CPU node. Return 0 on success.
  192. */
  193. int (*mpi_ms_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  194. /**
  195. Define how to copy data from the \p src_interface interface on the
  196. \p src_node MPI Slave node to the \p dst_interface interface on
  197. the \p dst_node MPI Slave node. Return 0 on success.
  198. */
  199. int (*mpi_ms_to_mpi_ms)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  200. #ifdef STARPU_USE_CUDA
  201. /**
  202. Define how to copy data from the \p src_interface interface on the
  203. \p src_node CPU node to the \p dst_interface interface on the \p
  204. dst_node CUDA node, using the given stream. Must return 0 if the
  205. transfer was actually completed completely synchronously, or
  206. <c>-EAGAIN</c> if at least some transfers are still ongoing and
  207. should be awaited for by the core.
  208. */
  209. int (*ram_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, starpu_cudaStream_t stream);
  210. /**
  211. Define how to copy data from the \p src_interface interface on the
  212. \p src_node CUDA node to the \p dst_interface interface on the \p
  213. dst_node CPU node, using the given stream. Must return 0 if the
  214. transfer was actually completed completely synchronously, or
  215. <c>-EAGAIN</c> if at least some transfers are still ongoing and
  216. should be awaited for by the core.
  217. */
  218. int (*cuda_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, starpu_cudaStream_t stream);
  219. /**
  220. Define how to copy data from the \p src_interface interface on the
  221. \p src_node CUDA node to the \p dst_interface interface on the \p
  222. dst_node CUDA node, using the given stream. Must return 0 if the
  223. transfer was actually completed completely synchronously, or
  224. <c>-EAGAIN</c> if at least some transfers are still ongoing and
  225. should be awaited for by the core.
  226. */
  227. int (*cuda_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, starpu_cudaStream_t stream);
  228. #else
  229. int (*ram_to_cuda_async)();
  230. int (*cuda_to_ram_async)();
  231. int (*cuda_to_cuda_async)();
  232. #endif
  233. #if defined(STARPU_USE_OPENCL) && !defined(__CUDACC__)
  234. /**
  235. Define how to copy data from the \p src_interface interface on the
  236. \p src_node CPU node to the \p dst_interface interface on the \p
  237. dst_node OpenCL node, by recording in \p event, a pointer to a
  238. <c>cl_event</c>, the event of the last submitted transfer. Must
  239. return 0 if the transfer was actually completed completely
  240. synchronously, or <c>-EAGAIN</c> if at least some transfers are
  241. still ongoing and should be awaited for by the core.
  242. */
  243. int (*ram_to_opencl_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cl_event *event);
  244. /**
  245. Define how to copy data from the \p src_interface interface on the
  246. \p src_node OpenCL node to the \p dst_interface interface on the
  247. \p dst_node CPU node, by recording in \p event, a pointer to a
  248. <c>cl_event</c>, the event of the last submitted transfer. Must
  249. return 0 if the transfer was actually completed completely
  250. synchronously, or <c>-EAGAIN</c> if at least some transfers are
  251. still ongoing and should be awaited for by the core.
  252. */
  253. int (*opencl_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cl_event *event);
  254. /**
  255. Define how to copy data from the \p src_interface interface on the
  256. \p src_node OpenCL node to the \p dst_interface interface on the
  257. \p dst_node OpenCL node, by recording in \p event, a pointer to a
  258. <c>cl_event</c>, the event of the last submitted transfer. Must
  259. return 0 if the transfer was actually completed completely
  260. synchronously, or <c>-EAGAIN</c> if at least some transfers are
  261. still ongoing and should be awaited for by the core.
  262. */
  263. int (*opencl_to_opencl_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cl_event *event);
  264. #else
  265. int (*ram_to_opencl_async)();
  266. int (*opencl_to_ram_async)();
  267. int (*opencl_to_opencl_async)();
  268. #endif
  269. /**
  270. Define how to copy data from the \p src_interface interface on the
  271. \p src_node CPU node to the \p dst_interface interface on the \p
  272. dst_node MPI Slave node, with the given even. Must return 0 if the
  273. transfer was actually completed completely synchronously, or
  274. <c>-EAGAIN</c> if at least some transfers are still ongoing and
  275. should be awaited for by the core.
  276. */
  277. int (*ram_to_mpi_ms_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, void * event);
  278. /**
  279. Define how to copy data from the \p src_interface interface on the
  280. \p src_node MPI Slave node to the \p dst_interface interface on
  281. the \p dst_node CPU node, with the given event. Must return 0 if
  282. the transfer was actually completed completely synchronously, or
  283. <c>-EAGAIN</c> if at least some transfers are still ongoing and
  284. should be awaited for by the core.
  285. */
  286. int (*mpi_ms_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, void * event);
  287. /**
  288. Define how to copy data from the \p src_interface interface on the
  289. \p src_node MPI Slave node to the \p dst_interface interface on
  290. the \p dst_node MPI Slave node, using the given stream. Must
  291. return 0 if the transfer was actually completed completely
  292. synchronously, or <c>-EAGAIN</c> if at least some transfers are
  293. still ongoing and should be awaited for by the core.
  294. */
  295. int (*mpi_ms_to_mpi_ms_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, void * event);
  296. /**
  297. Define how to copy data from the \p src_interface interface on the
  298. \p src_node CPU node to the \p dst_interface interface on the \p
  299. dst_node MIC node. Must return 0 if the transfer was actually
  300. completed completely synchronously, or <c>-EAGAIN</c> if at least
  301. some transfers are still ongoing and should be awaited for by the
  302. core.
  303. */
  304. int (*ram_to_mic_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  305. /**
  306. Define how to copy data from the \p src_interface interface on the
  307. \p src_node MIC node to the \p dst_interface interface on the \p
  308. dst_node CPU node. Must return 0 if the transfer was actually
  309. completed completely synchronously, or <c>-EAGAIN</c> if at least
  310. some transfers are still ongoing and should be awaited for by the
  311. core.
  312. */
  313. int (*mic_to_ram_async)(void *src_interface, unsigned srd_node, void *dst_interface, unsigned dst_node);
  314. /**
  315. Define how to copy data from the \p src_interface interface on the
  316. \p src_node node to the \p dst_interface interface on the \p
  317. dst_node node. This is meant to be implemented through the
  318. starpu_interface_copy() helper, to which async_data should be
  319. passed as such, and will be used to manage asynchronicity. This
  320. must return <c>-EAGAIN</c> if any of the starpu_interface_copy()
  321. calls has returned <c>-EAGAIN</c> (i.e. at least some transfer is
  322. still ongoing), and return 0 otherwise.
  323. */
  324. int (*any_to_any)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, void *async_data);
  325. };
  326. /**
  327. Identifier for all predefined StarPU data interfaces
  328. */
  329. enum starpu_data_interface_id
  330. {
  331. STARPU_UNKNOWN_INTERFACE_ID = -1, /**< Unknown interface */
  332. STARPU_MATRIX_INTERFACE_ID=0, /**< Identifier for the matrix data interface */
  333. STARPU_BLOCK_INTERFACE_ID=1, /**< Identifier for the block data interface*/
  334. STARPU_VECTOR_INTERFACE_ID=2, /**< Identifier for the vector data interface*/
  335. STARPU_CSR_INTERFACE_ID=3, /**< Identifier for the CSR data interface*/
  336. STARPU_BCSR_INTERFACE_ID=4, /**< Identifier for the BCSR data interface*/
  337. STARPU_VARIABLE_INTERFACE_ID=5, /**< Identifier for the variable data interface*/
  338. STARPU_VOID_INTERFACE_ID=6, /**< Identifier for the void data interface*/
  339. STARPU_MULTIFORMAT_INTERFACE_ID=7, /**< Identifier for the multiformat data interface*/
  340. STARPU_COO_INTERFACE_ID=8, /**< Identifier for the COO data interface*/
  341. STARPU_MAX_INTERFACE_ID=9 /**< Maximum number of data interfaces */
  342. };
  343. /**
  344. Per-interface data management methods.
  345. */
  346. struct starpu_data_interface_ops
  347. {
  348. /**
  349. Register an existing interface into a data handle.
  350. This iterates over all memory nodes to initialize all fields of the data
  351. interface on each of them. Since data is not allocated yet except on the
  352. home node, pointers should be left as NULL except on the \p home_node, for
  353. which the pointers should be copied from the given \p data_interface, which
  354. was filled with the application's pointers.
  355. */
  356. void (*register_data_handle) (starpu_data_handle_t handle, unsigned home_node, void *data_interface);
  357. /**
  358. Allocate data for the interface on a given node. This should use
  359. starpu_malloc_on_node to perform the allocation(s), and fill the pointers
  360. in the data interface. It should return the size of the allocated memory, or
  361. -ENOMEM if memory could not be allocated.
  362. */
  363. starpu_ssize_t (*allocate_data_on_node) (void *data_interface, unsigned node);
  364. /**
  365. Free data of the interface on a given node.
  366. */
  367. void (*free_data_on_node) (void *data_interface, unsigned node);
  368. /**
  369. Struct with pointer to functions for performing ram/cuda/opencl synchronous and asynchronous transfers.
  370. */
  371. const struct starpu_data_copy_methods *copy_methods;
  372. /**
  373. @deprecated
  374. Use starpu_data_interface_ops::to_pointer instead.
  375. Return the current pointer (if any) for the handle on the given node.
  376. */
  377. void * (*handle_to_pointer) (starpu_data_handle_t handle, unsigned node);
  378. /**
  379. Return the current pointer (if any) for the given interface on the given node.
  380. */
  381. void * (*to_pointer) (void *data_interface, unsigned node);
  382. /**
  383. Return whether the given \p ptr is within the data for the given interface on the given node.
  384. */
  385. int (*pointer_is_inside) (void *data_interface, unsigned node, void *ptr);
  386. /**
  387. Return an estimation of the size of data, for performance models.
  388. */
  389. size_t (*get_size) (starpu_data_handle_t handle);
  390. /**
  391. Return an estimation of the size of allocated data, for allocation
  392. management.
  393. If not specified, the starpu_data_interface_ops::get_size method is
  394. used instead.
  395. */
  396. size_t (*get_alloc_size) (starpu_data_handle_t handle);
  397. /**
  398. Return a 32bit footprint which characterizes the data size and layout (nx, ny, ld, elemsize, etc.), to be used for indexing performance models.
  399. */
  400. uint32_t (*footprint) (starpu_data_handle_t handle);
  401. /**
  402. Return a 32bit footprint which characterizes the data allocation, to be used
  403. for indexing allocation cache.
  404. If not specified, the starpu_data_interface_ops::footprint method is
  405. used instead.
  406. */
  407. uint32_t (*alloc_footprint) (starpu_data_handle_t handle);
  408. /**
  409. Compare the data size and layout of two interfaces (nx, ny, ld, elemsize,
  410. etc.), to be used for indexing performance models.. It should return 1 if
  411. the two interfaces size and layout match, and 0 otherwise.
  412. */
  413. int (*compare) (void *data_interface_a, void *data_interface_b);
  414. /**
  415. Compare the data allocation of two interfaces etc.), to be used for indexing
  416. allocation cache. It should return
  417. 1 if the two interfaces are allocation-compatible, and 0 otherwise.
  418. If not specified, the starpu_data_interface_ops::compare method is
  419. used instead.
  420. */
  421. int (*alloc_compare) (void *data_interface_a, void *data_interface_b);
  422. /**
  423. Dump the sizes of a handle to a file.
  424. */
  425. void (*display) (starpu_data_handle_t handle, FILE *f);
  426. /**
  427. Describe the data into a string in a brief way, such as one
  428. letter to describe the type of data, and the data
  429. dimensions.
  430. */
  431. starpu_ssize_t (*describe) (void *data_interface, char *buf, size_t size);
  432. /**
  433. An identifier that is unique to each interface.
  434. */
  435. enum starpu_data_interface_id interfaceid;
  436. /**
  437. Size of the interface data descriptor.
  438. */
  439. size_t interface_size;
  440. /**
  441. */
  442. char is_multiformat;
  443. /**
  444. If set to non-zero, StarPU will never try to reuse an allocated
  445. buffer for a different handle. This can be notably useful for
  446. application-defined interfaces which have a dynamic size, and for
  447. which it thus does not make sense to reuse the buffer since will
  448. probably not have the proper size.
  449. */
  450. char dontcache;
  451. /**
  452. */
  453. struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface);
  454. /**
  455. Pack the data handle into a contiguous buffer at the address
  456. allocated with <c>starpu_malloc_flags(ptr, size, 0)</c> (and thus
  457. returned in \p ptr) and set the size of the newly created buffer
  458. in \p count. If \p ptr is <c>NULL</c>, the function should not
  459. copy the data in the buffer but just set count to the size of the
  460. buffer which would have been allocated. The special value -1
  461. indicates the size is yet unknown.
  462. */
  463. int (*pack_data) (starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count);
  464. /**
  465. Unpack the data handle from the contiguous buffer at the address
  466. \p ptr of size \p count
  467. */
  468. int (*unpack_data) (starpu_data_handle_t handle, unsigned node, void *ptr, size_t count);
  469. /**
  470. Name of the interface
  471. */
  472. char *name;
  473. };
  474. /**
  475. @name Basic API
  476. @{
  477. */
  478. /**
  479. Register a piece of data into the handle located at the
  480. \p handleptr address. The \p data_interface buffer contains the initial
  481. description of the data in the \p home_node. The \p ops argument is a
  482. pointer to a structure describing the different methods used to
  483. manipulate this type of interface. See starpu_data_interface_ops for
  484. more details on this structure.
  485. If \p home_node is -1, StarPU will automatically allocate the memory when
  486. it is used for the first time in write-only mode. Once such data
  487. handle has been automatically allocated, it is possible to access it
  488. using any access mode.
  489. Note that StarPU supplies a set of predefined types of interface (e.g.
  490. vector or matrix) which can be registered by the means of helper
  491. functions (e.g. starpu_vector_data_register() or
  492. starpu_matrix_data_register()).
  493. */
  494. void starpu_data_register(starpu_data_handle_t *handleptr, int home_node, void *data_interface, struct starpu_data_interface_ops *ops);
  495. /**
  496. Register that a buffer for \p handle on \p node will be set. This is typically
  497. used by starpu_*_ptr_register helpers before setting the interface pointers for
  498. this node, to tell the core that that is now allocated.
  499. */
  500. void starpu_data_ptr_register(starpu_data_handle_t handle, unsigned node);
  501. /**
  502. Register a new piece of data into the handle \p handledst with the
  503. same interface as the handle \p handlesrc.
  504. */
  505. void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc);
  506. /**
  507. Return the pointer associated with \p handle on node \p node or <c>NULL</c>
  508. if handle’s interface does not support this operation or data for this
  509. \p handle is not allocated on that \p node.
  510. */
  511. void *starpu_data_handle_to_pointer(starpu_data_handle_t handle, unsigned node);
  512. /**
  513. Return whether the given \p ptr is within the data for \p handle on node \p
  514. node (1) or not (0). If the handle interface does not support this operation,
  515. and thus the result is unknown, -1 is returned.
  516. */
  517. int starpu_data_pointer_is_inside(starpu_data_handle_t handle, unsigned node, void *ptr);
  518. /**
  519. Return the local pointer associated with \p handle or <c>NULL</c> if
  520. \p handle’s interface does not have any data allocated locally.
  521. */
  522. void *starpu_data_get_local_ptr(starpu_data_handle_t handle);
  523. /**
  524. Return the interface associated with \p handle on \p memory_node.
  525. */
  526. void *starpu_data_get_interface_on_node(starpu_data_handle_t handle, unsigned memory_node);
  527. /**
  528. Return the unique identifier of the interface associated with
  529. the given \p handle.
  530. */
  531. enum starpu_data_interface_id starpu_data_get_interface_id(starpu_data_handle_t handle);
  532. /**
  533. Execute the packing operation of the interface of the data
  534. registered at \p handle (see starpu_data_interface_ops). This
  535. packing operation must allocate a buffer large enough at \p ptr and copy
  536. into the newly allocated buffer the data associated to \p handle. \p count
  537. will be set to the size of the allocated buffer. If \p ptr is <c>NULL</c>, the
  538. function should not copy the data in the buffer but just set \p count to
  539. the size of the buffer which would have been allocated. The special
  540. value -1 indicates the size is yet unknown.
  541. */
  542. int starpu_data_pack(starpu_data_handle_t handle, void **ptr, starpu_ssize_t *count);
  543. /**
  544. Unpack in handle the data located at \p ptr of size \p count as
  545. described by the interface of the data. The interface registered at
  546. \p handle must define a unpacking operation (see
  547. starpu_data_interface_ops). The memory at the address \p ptr is freed
  548. after calling the data unpacking operation.
  549. */
  550. int starpu_data_unpack(starpu_data_handle_t handle, void *ptr, size_t count);
  551. /**
  552. Return the size of the data associated with \p handle.
  553. */
  554. size_t starpu_data_get_size(starpu_data_handle_t handle);
  555. /**
  556. Return the size of the allocated data associated with \p handle.
  557. */
  558. size_t starpu_data_get_alloc_size(starpu_data_handle_t handle);
  559. /**
  560. Return the handle corresponding to the data pointed to by the \p ptr host pointer.
  561. */
  562. starpu_data_handle_t starpu_data_lookup(const void *ptr);
  563. int starpu_data_get_home_node(starpu_data_handle_t handle);
  564. /**
  565. Return the next available id for a newly created data interface
  566. (\ref DefiningANewDataInterface).
  567. */
  568. int starpu_data_interface_get_next_id(void);
  569. /**
  570. Copy \p size bytes from byte offset \p src_offset of \p src on \p src_node
  571. to byte offset \p dst_offset of \p dst on \p dst_node. This is to be used in
  572. the starpu_data_copy_methods::any_to_any copy method, which is provided with \p async_data to
  573. be passed to starpu_interface_copy(). this returns <c>-EAGAIN</c> if the
  574. transfer is still ongoing, or 0 if the transfer is already completed.
  575. */
  576. int starpu_interface_copy(uintptr_t src, size_t src_offset, unsigned src_node, uintptr_t dst, size_t dst_offset, unsigned dst_node, size_t size, void *async_data);
  577. /**
  578. When an asynchonous implementation of the data transfer is implemented, the call
  579. to the underlying CUDA, OpenCL, etc. call should be surrounded
  580. by calls to starpu_interface_start_driver_copy_async() and
  581. starpu_interface_end_driver_copy_async(), so that it is recorded in offline
  582. execution traces, and the timing of the submission is checked. \p start must
  583. point to a variable whose value will be passed unchanged to
  584. starpu_interface_end_driver_copy_async().
  585. */
  586. void starpu_interface_start_driver_copy_async(unsigned src_node, unsigned dst_node, double *start);
  587. /**
  588. See starpu_interface_start_driver_copy_async().
  589. */
  590. void starpu_interface_end_driver_copy_async(unsigned src_node, unsigned dst_node, double start);
  591. /**
  592. Allocate \p size bytes on node \p dst_node with the given allocation \p flags. This returns 0 if
  593. allocation failed, the allocation method should then return <c>-ENOMEM</c> as
  594. allocated size. Deallocation must be done with starpu_free_on_node_flags().
  595. */
  596. uintptr_t starpu_malloc_on_node_flags(unsigned dst_node, size_t size, int flags);
  597. /**
  598. Allocate \p size bytes on node \p dst_node with the default allocation flags. This returns 0 if
  599. allocation failed, the allocation method should then return <c>-ENOMEM</c> as
  600. allocated size. Deallocation must be done with starpu_free_on_node().
  601. */
  602. uintptr_t starpu_malloc_on_node(unsigned dst_node, size_t size);
  603. /**
  604. Free \p addr of \p size bytes on node \p dst_node which was previously allocated
  605. with starpu_malloc_on_node_flags() with the given allocation \p flags.
  606. */
  607. void starpu_free_on_node_flags(unsigned dst_node, uintptr_t addr, size_t size, int flags);
  608. /**
  609. Free \p addr of \p size bytes on node \p dst_node which was previously allocated
  610. with starpu_malloc_on_node().
  611. */
  612. void starpu_free_on_node(unsigned dst_node, uintptr_t addr, size_t size);
  613. /**
  614. Define the default flags for allocations performed by starpu_malloc_on_node() and
  615. starpu_free_on_node(). The default is \ref STARPU_MALLOC_PINNED | \ref STARPU_MALLOC_COUNT.
  616. */
  617. void starpu_malloc_on_node_set_default_flags(unsigned node, int flags);
  618. /** @} */
  619. /**
  620. @name Accessing Matrix Data Interfaces
  621. @{
  622. */
  623. extern struct starpu_data_interface_ops starpu_interface_matrix_ops;
  624. /**
  625. Matrix interface for dense matrices
  626. */
  627. struct starpu_matrix_interface
  628. {
  629. enum starpu_data_interface_id id; /**< Identifier of the interface */
  630. uintptr_t ptr; /**< local pointer of the matrix */
  631. uintptr_t dev_handle; /**< device handle of the matrix */
  632. size_t offset; /**< offset in the matrix */
  633. uint32_t nx; /**< number of elements on the x-axis of the matrix */
  634. uint32_t ny; /**< number of elements on the y-axis of the matrix */
  635. uint32_t ld; /**< number of elements between each row of the
  636. matrix. Maybe be equal to starpu_matrix_interface::nx
  637. when there is no padding.
  638. */
  639. size_t elemsize; /**< size of the elements of the matrix */
  640. size_t allocsize; /**< size actually currently allocated */
  641. };
  642. /**
  643. Register the \p nx x \p ny 2D matrix of \p elemsize-byte elements pointed
  644. by \p ptr and initialize \p handle to represent it. \p ld specifies the number
  645. of elements between rows. a value greater than \p nx adds padding, which
  646. can be useful for alignment purposes.
  647. Here an example of how to use the function.
  648. \code{.c}
  649. float *matrix;
  650. starpu_data_handle_t matrix_handle;
  651. matrix = (float*)malloc(width * height * sizeof(float));
  652. starpu_matrix_data_register(&matrix_handle, STARPU_MAIN_RAM, (uintptr_t)matrix, width, width, height, sizeof(float));
  653. \endcode
  654. */
  655. void starpu_matrix_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, uint32_t ld, uint32_t nx, uint32_t ny, size_t elemsize);
  656. /**
  657. Similar to starpu_matrix_data_register, but additionally specifies which
  658. allocation size should be used instead of the initial nx*ny*elemsize.
  659. */
  660. void starpu_matrix_data_register_allocsize(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, uint32_t ld, uint32_t nx, uint32_t ny, size_t elemsize, size_t allocsize);
  661. /**
  662. Register into the \p handle that to store data on node \p node it should use the
  663. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  664. (for OpenCL, notably), with \p ld elements between rows.
  665. */
  666. void starpu_matrix_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset, uint32_t ld);
  667. /**
  668. Return the number of elements on the x-axis of the matrix
  669. designated by \p handle.
  670. */
  671. uint32_t starpu_matrix_get_nx(starpu_data_handle_t handle);
  672. /**
  673. Return the number of elements on the y-axis of the matrix
  674. designated by \p handle.
  675. */
  676. uint32_t starpu_matrix_get_ny(starpu_data_handle_t handle);
  677. /**
  678. Return the number of elements between each row of the matrix
  679. designated by \p handle. Maybe be equal to nx when there is no padding.
  680. */
  681. uint32_t starpu_matrix_get_local_ld(starpu_data_handle_t handle);
  682. /**
  683. Return the local pointer associated with \p handle.
  684. */
  685. uintptr_t starpu_matrix_get_local_ptr(starpu_data_handle_t handle);
  686. /**
  687. Return the size of the elements registered into the matrix
  688. designated by \p handle.
  689. */
  690. size_t starpu_matrix_get_elemsize(starpu_data_handle_t handle);
  691. /**
  692. Return the allocated size of the matrix designated by \p handle.
  693. */
  694. size_t starpu_matrix_get_allocsize(starpu_data_handle_t handle);
  695. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  696. #define STARPU_MATRIX_CHECK(interface) STARPU_ASSERT_MSG((((struct starpu_matrix_interface *)(interface))->id) == STARPU_MATRIX_INTERFACE_ID, "Error. The given data is not a matrix.")
  697. #define STARPU_MATRIX_GET_PTR(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ptr) ; })
  698. #define STARPU_MATRIX_GET_DEV_HANDLE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->dev_handle) ; })
  699. #define STARPU_MATRIX_GET_OFFSET(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->offset) ; })
  700. #define STARPU_MATRIX_GET_NX(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->nx) ; })
  701. #define STARPU_MATRIX_GET_NY(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ny) ; })
  702. #define STARPU_MATRIX_GET_LD(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ld) ; })
  703. #define STARPU_MATRIX_GET_ELEMSIZE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->elemsize) ; })
  704. #define STARPU_MATRIX_GET_ALLOCSIZE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->allocsize) ; })
  705. #else
  706. /**
  707. Return a pointer to the matrix designated by \p interface, valid
  708. on CPUs and CUDA devices only. For OpenCL devices, the device handle
  709. and offset need to be used instead.
  710. */
  711. #define STARPU_MATRIX_GET_PTR(interface) (((struct starpu_matrix_interface *)(interface))->ptr)
  712. /**
  713. Return a device handle for the matrix designated by \p interface,
  714. to be used with OpenCL. The offset returned by
  715. ::STARPU_MATRIX_GET_OFFSET has to be used in
  716. addition to this.
  717. */
  718. #define STARPU_MATRIX_GET_DEV_HANDLE(interface) (((struct starpu_matrix_interface *)(interface))->dev_handle)
  719. /**
  720. Return the offset in the matrix designated by \p interface, to be
  721. used with the device handle.
  722. */
  723. #define STARPU_MATRIX_GET_OFFSET(interface) (((struct starpu_matrix_interface *)(interface))->offset)
  724. /**
  725. Return the number of elements on the x-axis of the matrix
  726. designated by \p interface.
  727. */
  728. #define STARPU_MATRIX_GET_NX(interface) (((struct starpu_matrix_interface *)(interface))->nx)
  729. /**
  730. Return the number of elements on the y-axis of the matrix
  731. designated by \p interface.
  732. */
  733. #define STARPU_MATRIX_GET_NY(interface) (((struct starpu_matrix_interface *)(interface))->ny)
  734. /**
  735. Return the number of elements between each row of the matrix
  736. designated by \p interface. May be equal to nx when there is no padding.
  737. */
  738. #define STARPU_MATRIX_GET_LD(interface) (((struct starpu_matrix_interface *)(interface))->ld)
  739. /**
  740. Return the size of the elements registered into the matrix
  741. designated by \p interface.
  742. */
  743. #define STARPU_MATRIX_GET_ELEMSIZE(interface) (((struct starpu_matrix_interface *)(interface))->elemsize)
  744. /**
  745. Return the allocated size of the matrix designated by \p interface.
  746. */
  747. #define STARPU_MATRIX_GET_ALLOCSIZE(interface) (((struct starpu_matrix_interface *)(interface))->allocsize)
  748. #endif
  749. /**
  750. Set the number of elements on the x-axis of the matrix
  751. designated by \p interface.
  752. */
  753. #define STARPU_MATRIX_SET_NX(interface, newnx) do { \
  754. STARPU_MATRIX_CHECK(interface); \
  755. (((struct starpu_matrix_interface *)(interface))->nx) = (newnx); \
  756. } while (0)
  757. /**
  758. Set the number of elements on the y-axis of the matrix
  759. designated by \p interface.
  760. */
  761. #define STARPU_MATRIX_SET_NY(interface, newny) do { \
  762. STARPU_MATRIX_CHECK(interface); \
  763. (((struct starpu_matrix_interface *)(interface))->ny) = (newny); \
  764. } while(0)
  765. /**
  766. Set the number of elements between each row of the matrix
  767. designated by \p interface. May be set to the same value as nx when there is
  768. no padding.
  769. */
  770. #define STARPU_MATRIX_SET_LD(interface, newld) do { \
  771. STARPU_MATRIX_CHECK(interface); \
  772. (((struct starpu_matrix_interface *)(interface))->ld) = (newld); \
  773. } while(0)
  774. /** @} */
  775. /**
  776. @name Accessing COO Data Interfaces
  777. @{
  778. */
  779. extern struct starpu_data_interface_ops starpu_interface_coo_ops;
  780. /**
  781. COO Matrices
  782. */
  783. struct starpu_coo_interface
  784. {
  785. enum starpu_data_interface_id id; /**< identifier of the interface */
  786. uint32_t *columns; /**< column array of the matrix */
  787. uint32_t *rows; /**< row array of the matrix */
  788. uintptr_t values; /**< values of the matrix */
  789. uint32_t nx; /**< number of elements on the x-axis of the matrix */
  790. uint32_t ny; /**< number of elements on the y-axis of the matrix */
  791. uint32_t n_values; /**< number of values registered in the matrix */
  792. size_t elemsize; /**< size of the elements of the matrix */
  793. };
  794. /**
  795. Register the \p nx x \p ny 2D matrix given in the COO format, using the
  796. \p columns, \p rows, \p values arrays, which must have \p n_values elements of
  797. size \p elemsize. Initialize \p handleptr.
  798. */
  799. void starpu_coo_data_register(starpu_data_handle_t *handleptr, int home_node, uint32_t nx, uint32_t ny, uint32_t n_values, uint32_t *columns, uint32_t *rows, uintptr_t values, size_t elemsize);
  800. /**
  801. Return a pointer to the column array of the matrix designated
  802. by \p interface.
  803. */
  804. #define STARPU_COO_GET_COLUMNS(interface) (((struct starpu_coo_interface *)(interface))->columns)
  805. /**
  806. Return a device handle for the column array of the matrix
  807. designated by \p interface, to be used with OpenCL. The offset
  808. returned by ::STARPU_COO_GET_OFFSET has to be used in addition to
  809. this.
  810. */
  811. #define STARPU_COO_GET_COLUMNS_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->columns)
  812. /**
  813. Return a pointer to the rows array of the matrix designated by
  814. \p interface.
  815. */
  816. #define STARPU_COO_GET_ROWS(interface) (((struct starpu_coo_interface *)(interface))->rows)
  817. /**
  818. Return a device handle for the row array of the matrix
  819. designated by \p interface, to be used on OpenCL. The offset returned
  820. by ::STARPU_COO_GET_OFFSET has to be used in addition to this.
  821. */
  822. #define STARPU_COO_GET_ROWS_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->rows)
  823. /**
  824. Return a pointer to the values array of the matrix designated
  825. by \p interface.
  826. */
  827. #define STARPU_COO_GET_VALUES(interface) (((struct starpu_coo_interface *)(interface))->values)
  828. /**
  829. Return a device handle for the value array of the matrix
  830. designated by \p interface, to be used on OpenCL. The offset returned
  831. by ::STARPU_COO_GET_OFFSET has to be used in addition to this.
  832. */
  833. #define STARPU_COO_GET_VALUES_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->values)
  834. /**
  835. Return the offset in the arrays of the COO matrix designated by
  836. \p interface.
  837. */
  838. #define STARPU_COO_GET_OFFSET 0
  839. /**
  840. Return the number of elements on the x-axis of the matrix
  841. designated by \p interface.
  842. */
  843. #define STARPU_COO_GET_NX(interface) (((struct starpu_coo_interface *)(interface))->nx)
  844. /**
  845. Return the number of elements on the y-axis of the matrix
  846. designated by \p interface.
  847. */
  848. #define STARPU_COO_GET_NY(interface) (((struct starpu_coo_interface *)(interface))->ny)
  849. /**
  850. Return the number of values registered in the matrix designated
  851. by \p interface.
  852. */
  853. #define STARPU_COO_GET_NVALUES(interface) (((struct starpu_coo_interface *)(interface))->n_values)
  854. /**
  855. Return the size of the elements registered into the matrix
  856. designated by \p interface.
  857. */
  858. #define STARPU_COO_GET_ELEMSIZE(interface) (((struct starpu_coo_interface *)(interface))->elemsize)
  859. /** @} */
  860. /**
  861. @name Block Data Interface
  862. @{
  863. */
  864. extern struct starpu_data_interface_ops starpu_interface_block_ops;
  865. /* TODO: rename to 3dmatrix? */
  866. /* TODO: add allocsize support */
  867. /**
  868. Block interface for 3D dense blocks
  869. */
  870. struct starpu_block_interface
  871. {
  872. enum starpu_data_interface_id id; /**< identifier of the interface */
  873. uintptr_t ptr; /**< local pointer of the block */
  874. uintptr_t dev_handle; /**< device handle of the block. */
  875. size_t offset; /**< offset in the block. */
  876. uint32_t nx; /**< number of elements on the x-axis of the block. */
  877. uint32_t ny; /**< number of elements on the y-axis of the block. */
  878. uint32_t nz; /**< number of elements on the z-axis of the block. */
  879. uint32_t ldy; /**< number of elements between two lines */
  880. uint32_t ldz; /**< number of elements between two planes */
  881. size_t elemsize; /**< size of the elements of the block. */
  882. };
  883. /**
  884. Register the \p nx x \p ny x \p nz 3D matrix of \p elemsize byte elements
  885. pointed by \p ptr and initialize \p handle to represent it. Again, \p ldy and
  886. \p ldz specify the number of elements between rows and between z planes.
  887. Here an example of how to use the function.
  888. \code{.c}
  889. float *block;
  890. starpu_data_handle_t block_handle;
  891. block = (float*)malloc(nx*ny*nz*sizeof(float));
  892. starpu_block_data_register(&block_handle, STARPU_MAIN_RAM, (uintptr_t)block, nx, nx*ny, nx, ny, nz, sizeof(float));
  893. \endcode
  894. */
  895. void starpu_block_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx, uint32_t ny, uint32_t nz, size_t elemsize);
  896. /**
  897. Register into the \p handle that to store data on node \p node it should use the
  898. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  899. (for OpenCL, notably), with \p ldy elements between rows and \p ldz
  900. elements between z planes.
  901. */
  902. void starpu_block_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset, uint32_t ldy, uint32_t ldz);
  903. /**
  904. Return the number of elements on the x-axis of the block
  905. designated by \p handle.
  906. */
  907. uint32_t starpu_block_get_nx(starpu_data_handle_t handle);
  908. /**
  909. Return the number of elements on the y-axis of the block
  910. designated by \p handle.
  911. */
  912. uint32_t starpu_block_get_ny(starpu_data_handle_t handle);
  913. /**
  914. Return the number of elements on the z-axis of the block
  915. designated by \p handle.
  916. */
  917. uint32_t starpu_block_get_nz(starpu_data_handle_t handle);
  918. /**
  919. Return the number of elements between each row of the block
  920. designated by \p handle, in the format of the current memory node.
  921. */
  922. uint32_t starpu_block_get_local_ldy(starpu_data_handle_t handle);
  923. /**
  924. Return the number of elements between each z plane of the block
  925. designated by \p handle, in the format of the current memory node.
  926. */
  927. uint32_t starpu_block_get_local_ldz(starpu_data_handle_t handle);
  928. /**
  929. Return the local pointer associated with \p handle.
  930. */
  931. uintptr_t starpu_block_get_local_ptr(starpu_data_handle_t handle);
  932. /**
  933. Return the size of the elements of the block designated by
  934. \p handle.
  935. */
  936. size_t starpu_block_get_elemsize(starpu_data_handle_t handle);
  937. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  938. #define STARPU_BLOCK_CHECK(interface) STARPU_ASSERT_MSG((((struct starpu_block_interface *)(interface))->id) == STARPU_BLOCK_INTERFACE_ID, "Error. The given data is not a block.")
  939. #define STARPU_BLOCK_GET_PTR(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ptr) ; })
  940. #define STARPU_BLOCK_GET_DEV_HANDLE(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->dev_handle) ; })
  941. #define STARPU_BLOCK_GET_OFFSET(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->offset) ; })
  942. #define STARPU_BLOCK_GET_NX(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->nx) ; })
  943. #define STARPU_BLOCK_GET_NY(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ny) ; })
  944. #define STARPU_BLOCK_GET_NZ(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->nz) ; })
  945. #define STARPU_BLOCK_GET_LDY(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ldy) ; })
  946. #define STARPU_BLOCK_GET_LDZ(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ldz) ; })
  947. #define STARPU_BLOCK_GET_ELEMSIZE(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->elemsize) ; })
  948. #else
  949. /**
  950. Return a pointer to the block designated by \p interface.
  951. */
  952. #define STARPU_BLOCK_GET_PTR(interface) (((struct starpu_block_interface *)(interface))->ptr)
  953. /**
  954. Return a device handle for the block designated by \p interface,
  955. to be used on OpenCL. The offset returned by
  956. ::STARPU_BLOCK_GET_OFFSET has to be used in
  957. addition to this.
  958. */
  959. #define STARPU_BLOCK_GET_DEV_HANDLE(interface) (((struct starpu_block_interface *)(interface))->dev_handle)
  960. /**
  961. Return the offset in the block designated by \p interface, to be
  962. used with the device handle.
  963. */
  964. #define STARPU_BLOCK_GET_OFFSET(interface) (((struct starpu_block_interface *)(interface))->offset)
  965. /**
  966. Return the number of elements on the x-axis of the block
  967. designated by \p interface.
  968. */
  969. #define STARPU_BLOCK_GET_NX(interface) (((struct starpu_block_interface *)(interface))->nx)
  970. /**
  971. Return the number of elements on the y-axis of the block
  972. designated by \p interface.
  973. */
  974. #define STARPU_BLOCK_GET_NY(interface) (((struct starpu_block_interface *)(interface))->ny)
  975. /**
  976. Return the number of elements on the z-axis of the block
  977. designated by \p interface.
  978. */
  979. #define STARPU_BLOCK_GET_NZ(interface) (((struct starpu_block_interface *)(interface))->nz)
  980. /**
  981. Return the number of elements between each row of the block
  982. designated by \p interface. May be equal to nx when there is no padding.
  983. */
  984. #define STARPU_BLOCK_GET_LDY(interface) (((struct starpu_block_interface *)(interface))->ldy)
  985. /**
  986. Return the number of elements between each z plane of the block
  987. designated by \p interface. May be equal to nx*ny when there is no
  988. padding.
  989. */
  990. #define STARPU_BLOCK_GET_LDZ(interface) (((struct starpu_block_interface *)(interface))->ldz)
  991. /**
  992. Return the size of the elements of the block designated by
  993. \p interface.
  994. */
  995. #define STARPU_BLOCK_GET_ELEMSIZE(interface) (((struct starpu_block_interface *)(interface))->elemsize)
  996. #endif
  997. /** @} */
  998. /**
  999. @name Vector Data Interface
  1000. @{
  1001. */
  1002. extern struct starpu_data_interface_ops starpu_interface_vector_ops;
  1003. /**
  1004. */
  1005. struct starpu_vector_interface
  1006. {
  1007. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1008. uintptr_t ptr; /**< local pointer of the vector */
  1009. uintptr_t dev_handle; /**< device handle of the vector. */
  1010. size_t offset; /**< offset in the vector */
  1011. uint32_t nx; /**< number of elements on the x-axis of the vector */
  1012. size_t elemsize; /**< size of the elements of the vector */
  1013. uint32_t slice_base; /**< vector slice base, used by the StarPU OpenMP runtime support */
  1014. size_t allocsize; /**< size actually currently allocated */
  1015. };
  1016. /**
  1017. Register the \p nx \p elemsize-byte elements pointed to by \p ptr and initialize \p handle to represent it.
  1018. Here an example of how to use the function.
  1019. \code{.c}
  1020. float vector[NX];
  1021. starpu_data_handle_t vector_handle;
  1022. starpu_vector_data_register(&vector_handle, STARPU_MAIN_RAM, (uintptr_t)vector, NX, sizeof(vector[0]));
  1023. \endcode
  1024. */
  1025. void starpu_vector_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, uint32_t nx, size_t elemsize);
  1026. /**
  1027. Similar to starpu_matrix_data_register, but additionally specifies which
  1028. allocation size should be used instead of the initial nx*elemsize.
  1029. */
  1030. void starpu_vector_data_register_allocsize(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, uint32_t nx, size_t elemsize, size_t allocsize);
  1031. /**
  1032. Register into the \p handle that to store data on node \p node it should use the
  1033. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  1034. (for OpenCL, notably)
  1035. */
  1036. void starpu_vector_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset);
  1037. /**
  1038. Return the number of elements registered into the array designated by \p handle.
  1039. */
  1040. uint32_t starpu_vector_get_nx(starpu_data_handle_t handle);
  1041. /**
  1042. Return the size of each element of the array designated by \p handle.
  1043. */
  1044. size_t starpu_vector_get_elemsize(starpu_data_handle_t handle);
  1045. /**
  1046. Return the allocated size of the array designated by \p handle.
  1047. */
  1048. size_t starpu_vector_get_allocsize(starpu_data_handle_t handle);
  1049. /**
  1050. Return the local pointer associated with \p handle.
  1051. */
  1052. uintptr_t starpu_vector_get_local_ptr(starpu_data_handle_t handle);
  1053. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  1054. #define STARPU_VECTOR_CHECK(interface) STARPU_ASSERT_MSG((((struct starpu_vector_interface *)(interface))->id) == STARPU_VECTOR_INTERFACE_ID, "Error. The given data is not a vector.")
  1055. #define STARPU_VECTOR_GET_PTR(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->ptr); })
  1056. #define STARPU_VECTOR_GET_DEV_HANDLE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->dev_handle); })
  1057. #define STARPU_VECTOR_GET_OFFSET(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->offset); })
  1058. #define STARPU_VECTOR_GET_NX(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->nx); })
  1059. #define STARPU_VECTOR_GET_ELEMSIZE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->elemsize); })
  1060. #define STARPU_VECTOR_GET_ALLOCSIZE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->allocsize); })
  1061. #define STARPU_VECTOR_GET_SLICE_BASE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->slice_base); })
  1062. #else
  1063. /**
  1064. Return a pointer to the array designated by \p interface, valid on
  1065. CPUs and CUDA only. For OpenCL, the device handle and offset need to
  1066. be used instead.
  1067. */
  1068. #define STARPU_VECTOR_GET_PTR(interface) (((struct starpu_vector_interface *)(interface))->ptr)
  1069. /**
  1070. Return a device handle for the array designated by \p interface,
  1071. to be used with OpenCL. the offset returned by ::STARPU_VECTOR_GET_OFFSET has to be used in
  1072. addition to this.
  1073. */
  1074. #define STARPU_VECTOR_GET_DEV_HANDLE(interface) (((struct starpu_vector_interface *)(interface))->dev_handle)
  1075. /**
  1076. Return the offset in the array designated by \p interface, to be
  1077. used with the device handle.
  1078. */
  1079. #define STARPU_VECTOR_GET_OFFSET(interface) (((struct starpu_vector_interface *)(interface))->offset)
  1080. /**
  1081. Return the number of elements registered into the array
  1082. designated by \p interface.
  1083. */
  1084. #define STARPU_VECTOR_GET_NX(interface) (((struct starpu_vector_interface *)(interface))->nx)
  1085. /**
  1086. Return the size of each element of the array designated by
  1087. \p interface.
  1088. */
  1089. #define STARPU_VECTOR_GET_ELEMSIZE(interface) (((struct starpu_vector_interface *)(interface))->elemsize)
  1090. /**
  1091. Return the size of each element of the array designated by
  1092. \p interface.
  1093. */
  1094. #define STARPU_VECTOR_GET_ALLOCSIZE(interface) (((struct starpu_vector_interface *)(interface))->allocsize)
  1095. /**
  1096. Return the OpenMP slice base annotation of each element of the array designated by
  1097. \p interface.
  1098. */
  1099. #define STARPU_VECTOR_GET_SLICE_BASE(interface) (((struct starpu_vector_interface *)(interface))->slice_base)
  1100. #endif
  1101. /**
  1102. Set the number of elements registered into the array designated by \p
  1103. interface.
  1104. */
  1105. #define STARPU_VECTOR_SET_NX(interface, newnx) do { \
  1106. STARPU_VECTOR_CHECK(interface); \
  1107. (((struct starpu_vector_interface *)(interface))->nx) = (newnx); \
  1108. } while(0)
  1109. /** @} */
  1110. /**
  1111. @name Variable Data Interface
  1112. @{
  1113. */
  1114. extern struct starpu_data_interface_ops starpu_interface_variable_ops;
  1115. /**
  1116. Variable interface for a single data (not a vector, a matrix, a list,
  1117. ...)
  1118. */
  1119. struct starpu_variable_interface
  1120. {
  1121. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1122. uintptr_t ptr; /**< local pointer of the variable */
  1123. uintptr_t dev_handle; /**< device handle of the variable. */
  1124. size_t offset; /**< offset in the variable */
  1125. size_t elemsize; /**< size of the variable */
  1126. };
  1127. /**
  1128. Register the \p size byte element pointed to by \p ptr, which is
  1129. typically a scalar, and initialize \p handle to represent this data item.
  1130. Here an example of how to use the function.
  1131. \code{.c}
  1132. float var = 42.0;
  1133. starpu_data_handle_t var_handle;
  1134. starpu_variable_data_register(&var_handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  1135. \endcode
  1136. */
  1137. void starpu_variable_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, size_t size);
  1138. /**
  1139. Register into the \p handle that to store data on node \p node it should use the
  1140. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  1141. (for OpenCL, notably)
  1142. */
  1143. void starpu_variable_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset);
  1144. /**
  1145. Return the size of the variable designated by \p handle.
  1146. */
  1147. size_t starpu_variable_get_elemsize(starpu_data_handle_t handle);
  1148. /**
  1149. Return a pointer to the variable designated by \p handle.
  1150. */
  1151. uintptr_t starpu_variable_get_local_ptr(starpu_data_handle_t handle);
  1152. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  1153. #define STARPU_VARIABLE_CHECK(interface) STARPU_ASSERT_MSG((((struct starpu_variable_interface *)(interface))->id) == STARPU_VARIABLE_INTERFACE_ID, "Error. The given data is not a variable.")
  1154. #define STARPU_VARIABLE_GET_PTR(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->ptr) ; })
  1155. #define STARPU_VARIABLE_GET_OFFSET(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->offset) ; })
  1156. #define STARPU_VARIABLE_GET_ELEMSIZE(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->elemsize) ; })
  1157. #define STARPU_VARIABLE_GET_DEV_HANDLE(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->ptr) ; })
  1158. #else
  1159. /**
  1160. Return a pointer to the variable designated by \p interface.
  1161. */
  1162. #define STARPU_VARIABLE_GET_PTR(interface) (((struct starpu_variable_interface *)(interface))->ptr)
  1163. /**
  1164. Return the offset in the variable designated by \p interface, to
  1165. be used with the device handle.
  1166. */
  1167. #define STARPU_VARIABLE_GET_OFFSET(interface) (((struct starpu_variable_interface *)(interface))->offset)
  1168. /**
  1169. Return the size of the variable designated by \p interface.
  1170. */
  1171. #define STARPU_VARIABLE_GET_ELEMSIZE(interface) (((struct starpu_variable_interface *)(interface))->elemsize)
  1172. /**
  1173. Return a device handle for the variable designated by
  1174. \p interface, to be used with OpenCL. The offset returned by
  1175. ::STARPU_VARIABLE_GET_OFFSET has to be
  1176. used in addition to this.
  1177. */
  1178. #define STARPU_VARIABLE_GET_DEV_HANDLE(interface) (((struct starpu_variable_interface *)(interface))->ptr)
  1179. #endif
  1180. /** @} */
  1181. /**
  1182. @name Void Data Interface
  1183. @{
  1184. */
  1185. extern struct starpu_data_interface_ops starpu_interface_void_ops;
  1186. /**
  1187. Register a void interface. There is no data really associated
  1188. to that interface, but it may be used as a synchronization mechanism.
  1189. It also permits to express an abstract piece of data that is managed
  1190. by the application internally: this makes it possible to forbid the
  1191. concurrent execution of different tasks accessing the same <c>void</c>
  1192. data in read-write concurrently.
  1193. */
  1194. void starpu_void_data_register(starpu_data_handle_t *handle);
  1195. /** @} */
  1196. /**
  1197. @name CSR Data Interface
  1198. @{
  1199. */
  1200. extern struct starpu_data_interface_ops starpu_interface_csr_ops;
  1201. /**
  1202. CSR interface for sparse matrices (compressed sparse row
  1203. representation)
  1204. */
  1205. struct starpu_csr_interface
  1206. {
  1207. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1208. uint32_t nnz; /**< number of non-zero entries */
  1209. uint32_t nrow; /**< number of rows */
  1210. uintptr_t nzval; /**< non-zero values */
  1211. uint32_t *colind; /**< position of non-zero entries on the row */
  1212. uint32_t *rowptr; /**< index (in nzval) of the first entry of the row */
  1213. uint32_t firstentry; /**< k for k-based indexing (0 or 1 usually). also useful when partitionning the matrix. */
  1214. size_t elemsize; /**< size of the elements of the matrix */
  1215. };
  1216. /**
  1217. Register a CSR (Compressed Sparse Row Representation) sparse matrix.
  1218. */
  1219. void starpu_csr_data_register(starpu_data_handle_t *handle, int home_node, uint32_t nnz, uint32_t nrow, uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);
  1220. /**
  1221. Return the number of non-zero values in the matrix designated
  1222. by \p handle.
  1223. */
  1224. uint32_t starpu_csr_get_nnz(starpu_data_handle_t handle);
  1225. /**
  1226. Return the size of the row pointer array of the matrix
  1227. designated by \p handle.
  1228. */
  1229. uint32_t starpu_csr_get_nrow(starpu_data_handle_t handle);
  1230. /**
  1231. Return the index at which all arrays (the column indexes, the
  1232. row pointers...) of the matrix designated by \p handle.
  1233. */
  1234. uint32_t starpu_csr_get_firstentry(starpu_data_handle_t handle);
  1235. /**
  1236. Return a local pointer to the non-zero values of the matrix
  1237. designated by \p handle.
  1238. */
  1239. uintptr_t starpu_csr_get_local_nzval(starpu_data_handle_t handle);
  1240. /**
  1241. Return a local pointer to the column index of the matrix
  1242. designated by \p handle.
  1243. */
  1244. uint32_t *starpu_csr_get_local_colind(starpu_data_handle_t handle);
  1245. /**
  1246. Return a local pointer to the row pointer array of the matrix
  1247. designated by \p handle.
  1248. */
  1249. uint32_t *starpu_csr_get_local_rowptr(starpu_data_handle_t handle);
  1250. /**
  1251. Return the size of the elements registered into the matrix
  1252. designated by \p handle.
  1253. */
  1254. size_t starpu_csr_get_elemsize(starpu_data_handle_t handle);
  1255. /**
  1256. Return the number of non-zero values in the matrix designated
  1257. by \p interface.
  1258. */
  1259. #define STARPU_CSR_GET_NNZ(interface) (((struct starpu_csr_interface *)(interface))->nnz)
  1260. /**
  1261. Return the size of the row pointer array of the matrix
  1262. designated by \p interface.
  1263. */
  1264. #define STARPU_CSR_GET_NROW(interface) (((struct starpu_csr_interface *)(interface))->nrow)
  1265. /**
  1266. Return a pointer to the non-zero values of the matrix
  1267. designated by \p interface.
  1268. */
  1269. #define STARPU_CSR_GET_NZVAL(interface) (((struct starpu_csr_interface *)(interface))->nzval)
  1270. /**
  1271. Return a device handle for the array of non-zero values in the
  1272. matrix designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET
  1273. has to used in addition to this.
  1274. */
  1275. #define STARPU_CSR_GET_NZVAL_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->nnz)
  1276. /**
  1277. Return a pointer to the column index of the matrix designated
  1278. by \p interface.
  1279. */
  1280. #define STARPU_CSR_GET_COLIND(interface) (((struct starpu_csr_interface *)(interface))->colind)
  1281. /**
  1282. Return a device handle for the column index of the matrix
  1283. designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET has to be used in
  1284. addition to this.
  1285. */
  1286. #define STARPU_CSR_GET_COLIND_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->colind)
  1287. /**
  1288. Return a pointer to the row pointer array of the matrix
  1289. designated by \p interface.
  1290. */
  1291. #define STARPU_CSR_GET_ROWPTR(interface) (((struct starpu_csr_interface *)(interface))->rowptr)
  1292. /**
  1293. Return a device handle for the row pointer array of the matrix
  1294. designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET has to be used in
  1295. addition to this.
  1296. */
  1297. #define STARPU_CSR_GET_ROWPTR_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->rowptr)
  1298. /**
  1299. Return the offset in the arrays (colind, rowptr, nzval) of the
  1300. matrix designated by \p interface, to be used with the device handles.
  1301. */
  1302. #define STARPU_CSR_GET_OFFSET 0
  1303. /**
  1304. Return the index at which all arrays (the column indexes, the
  1305. row pointers...) of the \p interface start.
  1306. */
  1307. #define STARPU_CSR_GET_FIRSTENTRY(interface) (((struct starpu_csr_interface *)(interface))->firstentry)
  1308. /**
  1309. Return the size of the elements registered into the matrix
  1310. designated by \p interface.
  1311. */
  1312. #define STARPU_CSR_GET_ELEMSIZE(interface) (((struct starpu_csr_interface *)(interface))->elemsize)
  1313. /** @} */
  1314. /**
  1315. @name BCSR Data Interface
  1316. @{
  1317. */
  1318. extern struct starpu_data_interface_ops starpu_interface_bcsr_ops;
  1319. /**
  1320. BCSR interface for sparse matrices (blocked compressed sparse
  1321. row representation)
  1322. */
  1323. struct starpu_bcsr_interface
  1324. {
  1325. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1326. uint32_t nnz; /**< number of non-zero BLOCKS */
  1327. uint32_t nrow; /**< number of rows (in terms of BLOCKS) */
  1328. uintptr_t nzval; /**< non-zero values */
  1329. uint32_t *colind; /**< array of nnz elements, colind[i] is the block-column index for block i in nzval */
  1330. uint32_t *rowptr; /**< array of nrow+1
  1331. * elements, rowptr[i] is
  1332. * the block-index (in
  1333. * nzval) of the first block
  1334. * of row i. By convention,
  1335. * rowptr[nrow] is the
  1336. * number of blocks, this
  1337. * allows an easier access
  1338. * of the matrix's elements
  1339. * for the kernels. */
  1340. uint32_t firstentry; /**< k for k-based indexing (0 or 1 usually). Also useful when partitionning the matrix. */
  1341. uint32_t r; /**< height of the blocks */
  1342. uint32_t c; /**< width of the blocks */
  1343. size_t elemsize; /**< size of the elements of the matrix */
  1344. };
  1345. /**
  1346. This variant of starpu_data_register() uses the BCSR (Blocked
  1347. Compressed Sparse Row Representation) sparse matrix interface.
  1348. Register the sparse matrix made of \p nnz non-zero blocks of elements of
  1349. size \p elemsize stored in \p nzval and initializes \p handle to represent it.
  1350. Blocks have size \p r * \p c. \p nrow is the number of rows (in terms of
  1351. blocks), \p colind is an array of nnz elements, colind[i] is the block-column index for block i in \p nzval,
  1352. \p rowptr is an array of nrow+1 elements, rowptr[i] is the block-index (in \p nzval) of the first block of row i. By convention, rowptr[nrow] is the number of blocks, this allows an easier access of the matrix's elements for the kernels.
  1353. \p firstentry is the index of the first entry of the given arrays
  1354. (usually 0 or 1).
  1355. Here an example with the following matrix:
  1356. \code | 0 1 0 0 | \endcode
  1357. \code | 2 3 0 0 | \endcode
  1358. \code | 4 5 8 9 | \endcode
  1359. \code | 6 7 10 11 | \endcode
  1360. \code nzval = [0, 1, 2, 3] ++ [4, 5, 6, 7] ++ [8, 9, 10, 11] \endcode
  1361. \code colind = [0, 0, 1] \endcode
  1362. \code rowptr = [0, 1, 3] \endcode
  1363. \code r = c = 2 \endcode
  1364. which translates into the following code
  1365. \code{.c}
  1366. int R = 2; // Size of the blocks
  1367. int C = 2;
  1368. int NROWS = 2;
  1369. int NNZ_BLOCKS = 3; // out of 4
  1370. int NZVAL_SIZE = (R*C*NNZ_BLOCKS);
  1371. int nzval[NZVAL_SIZE] =
  1372. {
  1373. 0, 1, 2, 3, // First block
  1374. 4, 5, 6, 7, // Second block
  1375. 8, 9, 10, 11 // Third block
  1376. };
  1377. uint32_t colind[NNZ_BLOCKS] =
  1378. {
  1379. 0, // block-column index for first block in nzval
  1380. 0, // block-column index for second block in nzval
  1381. 1 // block-column index for third block in nzval
  1382. };
  1383. uint32_t rowptr[NROWS+1] =
  1384. {
  1385. 0, // block-index in nzval of the first block of the first row.
  1386. 1, // block-index in nzval of the first block of the second row.
  1387. NNZ_BLOCKS // number of blocks, to allow an easier element's access for the kernels
  1388. };
  1389. starpu_data_handle_t bcsr_handle;
  1390. starpu_bcsr_data_register(&bcsr_handle,
  1391. STARPU_MAIN_RAM,
  1392. NNZ_BLOCKS,
  1393. NROWS,
  1394. (uintptr_t) nzval,
  1395. colind,
  1396. rowptr,
  1397. 0, // firstentry
  1398. R,
  1399. C,
  1400. sizeof(nzval[0]));
  1401. \endcode
  1402. */
  1403. void starpu_bcsr_data_register(starpu_data_handle_t *handle, int home_node, uint32_t nnz, uint32_t nrow, uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);
  1404. /**
  1405. Return the number of non-zero elements in the matrix designated
  1406. by \p handle.
  1407. */
  1408. uint32_t starpu_bcsr_get_nnz(starpu_data_handle_t handle);
  1409. /**
  1410. Return the number of rows (in terms of blocks of size r*c) in
  1411. the matrix designated by \p handle.
  1412. */
  1413. uint32_t starpu_bcsr_get_nrow(starpu_data_handle_t handle);
  1414. /**
  1415. Return the index at which all arrays (the column indexes, the
  1416. row pointers...) of the matrix desginated by \p handle.
  1417. */
  1418. uint32_t starpu_bcsr_get_firstentry(starpu_data_handle_t handle);
  1419. /**
  1420. Return a pointer to the non-zero values of the matrix
  1421. designated by \p handle.
  1422. */
  1423. uintptr_t starpu_bcsr_get_local_nzval(starpu_data_handle_t handle);
  1424. /**
  1425. Return a pointer to the column index, which holds the positions
  1426. of the non-zero entries in the matrix designated by \p handle.
  1427. */
  1428. uint32_t *starpu_bcsr_get_local_colind(starpu_data_handle_t handle);
  1429. /**
  1430. Return the row pointer array of the matrix designated by
  1431. \p handle.
  1432. */
  1433. uint32_t *starpu_bcsr_get_local_rowptr(starpu_data_handle_t handle);
  1434. /**
  1435. Return the number of rows in a block.
  1436. */
  1437. uint32_t starpu_bcsr_get_r(starpu_data_handle_t handle);
  1438. /**
  1439. Return the number of columns in a block.
  1440. */
  1441. uint32_t starpu_bcsr_get_c(starpu_data_handle_t handle);
  1442. /**
  1443. Return the size of the elements in the matrix designated by
  1444. \p handle.
  1445. */
  1446. size_t starpu_bcsr_get_elemsize(starpu_data_handle_t handle);
  1447. /**
  1448. Return the number of non-zero values in the matrix designated
  1449. by \p interface.
  1450. */
  1451. #define STARPU_BCSR_GET_NNZ(interface) (((struct starpu_bcsr_interface *)(interface))->nnz)
  1452. /**
  1453. Return a pointer to the non-zero values of the matrix
  1454. designated by \p interface.
  1455. */
  1456. #define STARPU_BCSR_GET_NZVAL(interface) (((struct starpu_bcsr_interface *)(interface))->nzval)
  1457. /**
  1458. Return a device handle for the array of non-zero values in the
  1459. matrix designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be
  1460. used in addition to this.
  1461. */
  1462. #define STARPU_BCSR_GET_NZVAL_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->nnz)
  1463. /**
  1464. Return a pointer to the column index of the matrix designated
  1465. by \p interface.
  1466. */
  1467. #define STARPU_BCSR_GET_COLIND(interface) (((struct starpu_bcsr_interface *)(interface))->colind)
  1468. /**
  1469. Return a device handle for the column index of the matrix
  1470. designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be used in
  1471. addition to this.
  1472. */
  1473. #define STARPU_BCSR_GET_COLIND_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->colind)
  1474. /**
  1475. Return a pointer to the row pointer array of the matrix
  1476. designated by \p interface.
  1477. */
  1478. #define STARPU_BCSR_GET_ROWPTR(interface) (((struct starpu_bcsr_interface *)(interface))->rowptr)
  1479. /**
  1480. Return a device handle for the row pointer array of the matrix
  1481. designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be used in
  1482. addition to this.
  1483. */
  1484. #define STARPU_BCSR_GET_ROWPTR_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->rowptr)
  1485. /**
  1486. Return the offset in the arrays (coling, rowptr, nzval) of the
  1487. matrix designated by \p interface, to be used with the device handles.
  1488. */
  1489. #define STARPU_BCSR_GET_OFFSET 0
  1490. /** @} */
  1491. /**
  1492. @name Multiformat Data Interface
  1493. @{
  1494. */
  1495. /**
  1496. Multiformat operations
  1497. */
  1498. struct starpu_multiformat_data_interface_ops
  1499. {
  1500. size_t cpu_elemsize; /**< size of each element on CPUs */
  1501. size_t opencl_elemsize; /**< size of each element on OpenCL devices */
  1502. struct starpu_codelet *cpu_to_opencl_cl; /**< pointer to a codelet which converts from CPU to OpenCL */
  1503. struct starpu_codelet *opencl_to_cpu_cl; /**< pointer to a codelet which converts from OpenCL to CPU */
  1504. size_t cuda_elemsize; /**< size of each element on CUDA devices */
  1505. struct starpu_codelet *cpu_to_cuda_cl; /**< pointer to a codelet which converts from CPU to CUDA */
  1506. struct starpu_codelet *cuda_to_cpu_cl; /**< pointer to a codelet which converts from CUDA to CPU */
  1507. size_t mic_elemsize; /**< size of each element on MIC devices */
  1508. struct starpu_codelet *cpu_to_mic_cl; /**< pointer to a codelet which converts from CPU to MIC */
  1509. struct starpu_codelet *mic_to_cpu_cl; /**< pointer to a codelet which converts from MIC to CPU */
  1510. };
  1511. struct starpu_multiformat_interface
  1512. {
  1513. enum starpu_data_interface_id id;
  1514. void *cpu_ptr;
  1515. void *cuda_ptr;
  1516. void *opencl_ptr;
  1517. void *mic_ptr;
  1518. uint32_t nx;
  1519. struct starpu_multiformat_data_interface_ops *ops;
  1520. };
  1521. /**
  1522. Register a piece of data that can be represented in different
  1523. ways, depending upon the processing unit that manipulates it. It
  1524. allows the programmer, for instance, to use an array of structures
  1525. when working on a CPU, and a structure of arrays when working on a
  1526. GPU. \p nobjects is the number of elements in the data. \p format_ops
  1527. describes the format.
  1528. */
  1529. void starpu_multiformat_data_register(starpu_data_handle_t *handle, int home_node, void *ptr, uint32_t nobjects, struct starpu_multiformat_data_interface_ops *format_ops);
  1530. /**
  1531. Return the local pointer to the data with CPU format.
  1532. */
  1533. #define STARPU_MULTIFORMAT_GET_CPU_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->cpu_ptr)
  1534. /**
  1535. Return the local pointer to the data with CUDA format.
  1536. */
  1537. #define STARPU_MULTIFORMAT_GET_CUDA_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->cuda_ptr)
  1538. /**
  1539. Return the local pointer to the data with OpenCL format.
  1540. */
  1541. #define STARPU_MULTIFORMAT_GET_OPENCL_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->opencl_ptr)
  1542. /**
  1543. Return the local pointer to the data with MIC format.
  1544. */
  1545. #define STARPU_MULTIFORMAT_GET_MIC_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->mic_ptr)
  1546. /**
  1547. Return the number of elements in the data.
  1548. */
  1549. #define STARPU_MULTIFORMAT_GET_NX(interface) (((struct starpu_multiformat_interface *)(interface))->nx)
  1550. /** @} */
  1551. /** @} */
  1552. #ifdef __cplusplus
  1553. }
  1554. #endif
  1555. #endif /* __STARPU_DATA_INTERFACES_H__ */