starpu_data_interfaces.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  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. This method is optional, as it is only used for coherency checks.
  385. */
  386. int (*pointer_is_inside) (void *data_interface, unsigned node, void *ptr);
  387. /**
  388. Return an estimation of the size of data, for performance models.
  389. */
  390. size_t (*get_size) (starpu_data_handle_t handle);
  391. /**
  392. Return an estimation of the size of allocated data, for allocation
  393. management.
  394. If not specified, the starpu_data_interface_ops::get_size method is
  395. used instead.
  396. */
  397. size_t (*get_alloc_size) (starpu_data_handle_t handle);
  398. /**
  399. Return a 32bit footprint which characterizes the data size and layout (nx, ny, ld, elemsize, etc.), to be used for indexing performance models.
  400. */
  401. uint32_t (*footprint) (starpu_data_handle_t handle);
  402. /**
  403. Return a 32bit footprint which characterizes the data allocation, to be used
  404. for indexing allocation cache.
  405. If not specified, the starpu_data_interface_ops::footprint method is
  406. used instead.
  407. */
  408. uint32_t (*alloc_footprint) (starpu_data_handle_t handle);
  409. /**
  410. Compare the data size and layout of two interfaces (nx, ny, ld, elemsize,
  411. etc.), to be used for indexing performance models.. It should return 1 if
  412. the two interfaces size and layout match, and 0 otherwise.
  413. */
  414. int (*compare) (void *data_interface_a, void *data_interface_b);
  415. /**
  416. Compare the data allocation of two interfaces etc.), to be used for indexing
  417. allocation cache. It should return
  418. 1 if the two interfaces are allocation-compatible, and 0 otherwise.
  419. If not specified, the starpu_data_interface_ops::compare method is
  420. used instead.
  421. */
  422. int (*alloc_compare) (void *data_interface_a, void *data_interface_b);
  423. /**
  424. Dump the sizes of a handle to a file.
  425. */
  426. void (*display) (starpu_data_handle_t handle, FILE *f);
  427. /**
  428. Describe the data into a string in a brief way, such as one
  429. letter to describe the type of data, and the data
  430. dimensions.
  431. */
  432. starpu_ssize_t (*describe) (void *data_interface, char *buf, size_t size);
  433. /**
  434. An identifier that is unique to each interface.
  435. */
  436. enum starpu_data_interface_id interfaceid;
  437. /**
  438. Size of the interface data descriptor.
  439. */
  440. size_t interface_size;
  441. /**
  442. */
  443. char is_multiformat;
  444. /**
  445. If set to non-zero, StarPU will never try to reuse an allocated
  446. buffer for a different handle. This can be notably useful for
  447. application-defined interfaces which have a dynamic size, and for
  448. which it thus does not make sense to reuse the buffer since will
  449. probably not have the proper size.
  450. */
  451. char dontcache;
  452. /**
  453. */
  454. struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface);
  455. /**
  456. Pack the data handle into a contiguous buffer at the address
  457. allocated with <c>starpu_malloc_flags(ptr, size, 0)</c> (and thus
  458. returned in \p ptr) and set the size of the newly created buffer
  459. in \p count. If \p ptr is <c>NULL</c>, the function should not
  460. copy the data in the buffer but just set count to the size of the
  461. buffer which would have been allocated. The special value -1
  462. indicates the size is yet unknown.
  463. */
  464. int (*pack_data) (starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count);
  465. /**
  466. Unpack the data handle from the contiguous buffer at the address
  467. \p ptr of size \p count
  468. */
  469. int (*unpack_data) (starpu_data_handle_t handle, unsigned node, void *ptr, size_t count);
  470. /**
  471. Name of the interface
  472. */
  473. char *name;
  474. };
  475. /**
  476. @name Basic API
  477. @{
  478. */
  479. /**
  480. Register a piece of data into the handle located at the
  481. \p handleptr address. The \p data_interface buffer contains the initial
  482. description of the data in the \p home_node. The \p ops argument is a
  483. pointer to a structure describing the different methods used to
  484. manipulate this type of interface. See starpu_data_interface_ops for
  485. more details on this structure.
  486. If \p home_node is -1, StarPU will automatically allocate the memory when
  487. it is used for the first time in write-only mode. Once such data
  488. handle has been automatically allocated, it is possible to access it
  489. using any access mode.
  490. Note that StarPU supplies a set of predefined types of interface (e.g.
  491. vector or matrix) which can be registered by the means of helper
  492. functions (e.g. starpu_vector_data_register() or
  493. starpu_matrix_data_register()).
  494. */
  495. void starpu_data_register(starpu_data_handle_t *handleptr, int home_node, void *data_interface, struct starpu_data_interface_ops *ops);
  496. /**
  497. Register that a buffer for \p handle on \p node will be set. This is typically
  498. used by starpu_*_ptr_register helpers before setting the interface pointers for
  499. this node, to tell the core that that is now allocated.
  500. */
  501. void starpu_data_ptr_register(starpu_data_handle_t handle, unsigned node);
  502. /**
  503. Register a new piece of data into the handle \p handledst with the
  504. same interface as the handle \p handlesrc.
  505. */
  506. void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc);
  507. /**
  508. Return the pointer associated with \p handle on node \p node or <c>NULL</c>
  509. if handle’s interface does not support this operation or data for this
  510. \p handle is not allocated on that \p node.
  511. */
  512. void *starpu_data_handle_to_pointer(starpu_data_handle_t handle, unsigned node);
  513. /**
  514. Return whether the given \p ptr is within the data for \p handle on node \p
  515. node (1) or not (0). If the handle interface does not support this operation,
  516. and thus the result is unknown, -1 is returned.
  517. */
  518. int starpu_data_pointer_is_inside(starpu_data_handle_t handle, unsigned node, void *ptr);
  519. /**
  520. Return the local pointer associated with \p handle or <c>NULL</c> if
  521. \p handle’s interface does not have any data allocated locally.
  522. */
  523. void *starpu_data_get_local_ptr(starpu_data_handle_t handle);
  524. /**
  525. Return the interface associated with \p handle on \p memory_node.
  526. */
  527. void *starpu_data_get_interface_on_node(starpu_data_handle_t handle, unsigned memory_node);
  528. /**
  529. Return the unique identifier of the interface associated with
  530. the given \p handle.
  531. */
  532. enum starpu_data_interface_id starpu_data_get_interface_id(starpu_data_handle_t handle);
  533. /**
  534. Execute the packing operation of the interface of the data
  535. registered at \p handle (see starpu_data_interface_ops). This
  536. packing operation must allocate a buffer large enough at \p ptr and copy
  537. into the newly allocated buffer the data associated to \p handle. \p count
  538. will be set to the size of the allocated buffer. If \p ptr is <c>NULL</c>, the
  539. function should not copy the data in the buffer but just set \p count to
  540. the size of the buffer which would have been allocated. The special
  541. value -1 indicates the size is yet unknown.
  542. */
  543. int starpu_data_pack(starpu_data_handle_t handle, void **ptr, starpu_ssize_t *count);
  544. /**
  545. Unpack in handle the data located at \p ptr of size \p count as
  546. described by the interface of the data. The interface registered at
  547. \p handle must define a unpacking operation (see
  548. starpu_data_interface_ops). The memory at the address \p ptr is freed
  549. after calling the data unpacking operation.
  550. */
  551. int starpu_data_unpack(starpu_data_handle_t handle, void *ptr, size_t count);
  552. /**
  553. Return the size of the data associated with \p handle.
  554. */
  555. size_t starpu_data_get_size(starpu_data_handle_t handle);
  556. /**
  557. Return the size of the allocated data associated with \p handle.
  558. */
  559. size_t starpu_data_get_alloc_size(starpu_data_handle_t handle);
  560. /**
  561. Return the handle corresponding to the data pointed to by the \p ptr host pointer.
  562. */
  563. starpu_data_handle_t starpu_data_lookup(const void *ptr);
  564. int starpu_data_get_home_node(starpu_data_handle_t handle);
  565. /**
  566. Return the next available id for a newly created data interface
  567. (\ref DefiningANewDataInterface).
  568. */
  569. int starpu_data_interface_get_next_id(void);
  570. /**
  571. Copy \p size bytes from byte offset \p src_offset of \p src on \p src_node
  572. to byte offset \p dst_offset of \p dst on \p dst_node. This is to be used in
  573. the starpu_data_copy_methods::any_to_any copy method, which is provided with \p async_data to
  574. be passed to starpu_interface_copy(). this returns <c>-EAGAIN</c> if the
  575. transfer is still ongoing, or 0 if the transfer is already completed.
  576. */
  577. 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);
  578. /**
  579. When an asynchonous implementation of the data transfer is implemented, the call
  580. to the underlying CUDA, OpenCL, etc. call should be surrounded
  581. by calls to starpu_interface_start_driver_copy_async() and
  582. starpu_interface_end_driver_copy_async(), so that it is recorded in offline
  583. execution traces, and the timing of the submission is checked. \p start must
  584. point to a variable whose value will be passed unchanged to
  585. starpu_interface_end_driver_copy_async().
  586. */
  587. void starpu_interface_start_driver_copy_async(unsigned src_node, unsigned dst_node, double *start);
  588. /**
  589. See starpu_interface_start_driver_copy_async().
  590. */
  591. void starpu_interface_end_driver_copy_async(unsigned src_node, unsigned dst_node, double start);
  592. /**
  593. Allocate \p size bytes on node \p dst_node with the given allocation \p flags. This returns 0 if
  594. allocation failed, the allocation method should then return <c>-ENOMEM</c> as
  595. allocated size. Deallocation must be done with starpu_free_on_node_flags().
  596. */
  597. uintptr_t starpu_malloc_on_node_flags(unsigned dst_node, size_t size, int flags);
  598. /**
  599. Allocate \p size bytes on node \p dst_node with the default allocation flags. This returns 0 if
  600. allocation failed, the allocation method should then return <c>-ENOMEM</c> as
  601. allocated size. Deallocation must be done with starpu_free_on_node().
  602. */
  603. uintptr_t starpu_malloc_on_node(unsigned dst_node, size_t size);
  604. /**
  605. Free \p addr of \p size bytes on node \p dst_node which was previously allocated
  606. with starpu_malloc_on_node_flags() with the given allocation \p flags.
  607. */
  608. void starpu_free_on_node_flags(unsigned dst_node, uintptr_t addr, size_t size, int flags);
  609. /**
  610. Free \p addr of \p size bytes on node \p dst_node which was previously allocated
  611. with starpu_malloc_on_node().
  612. */
  613. void starpu_free_on_node(unsigned dst_node, uintptr_t addr, size_t size);
  614. /**
  615. Define the default flags for allocations performed by starpu_malloc_on_node() and
  616. starpu_free_on_node(). The default is \ref STARPU_MALLOC_PINNED | \ref STARPU_MALLOC_COUNT.
  617. */
  618. void starpu_malloc_on_node_set_default_flags(unsigned node, int flags);
  619. /** @} */
  620. /**
  621. @name Accessing Matrix Data Interfaces
  622. @{
  623. */
  624. extern struct starpu_data_interface_ops starpu_interface_matrix_ops;
  625. /**
  626. Matrix interface for dense matrices
  627. */
  628. struct starpu_matrix_interface
  629. {
  630. enum starpu_data_interface_id id; /**< Identifier of the interface */
  631. uintptr_t ptr; /**< local pointer of the matrix */
  632. uintptr_t dev_handle; /**< device handle of the matrix */
  633. size_t offset; /**< offset in the matrix */
  634. uint32_t nx; /**< number of elements on the x-axis of the matrix */
  635. uint32_t ny; /**< number of elements on the y-axis of the matrix */
  636. uint32_t ld; /**< number of elements between each row of the
  637. matrix. Maybe be equal to starpu_matrix_interface::nx
  638. when there is no padding.
  639. */
  640. size_t elemsize; /**< size of the elements of the matrix */
  641. size_t allocsize; /**< size actually currently allocated */
  642. };
  643. /**
  644. Register the \p nx x \p ny 2D matrix of \p elemsize-byte elements pointed
  645. by \p ptr and initialize \p handle to represent it. \p ld specifies the number
  646. of elements between rows. a value greater than \p nx adds padding, which
  647. can be useful for alignment purposes.
  648. Here an example of how to use the function.
  649. \code{.c}
  650. float *matrix;
  651. starpu_data_handle_t matrix_handle;
  652. matrix = (float*)malloc(width * height * sizeof(float));
  653. starpu_matrix_data_register(&matrix_handle, STARPU_MAIN_RAM, (uintptr_t)matrix, width, width, height, sizeof(float));
  654. \endcode
  655. */
  656. 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);
  657. /**
  658. Similar to starpu_matrix_data_register, but additionally specifies which
  659. allocation size should be used instead of the initial nx*ny*elemsize.
  660. */
  661. 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);
  662. /**
  663. Register into the \p handle that to store data on node \p node it should use the
  664. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  665. (for OpenCL, notably), with \p ld elements between rows.
  666. */
  667. 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);
  668. /**
  669. Return the number of elements on the x-axis of the matrix
  670. designated by \p handle.
  671. */
  672. uint32_t starpu_matrix_get_nx(starpu_data_handle_t handle);
  673. /**
  674. Return the number of elements on the y-axis of the matrix
  675. designated by \p handle.
  676. */
  677. uint32_t starpu_matrix_get_ny(starpu_data_handle_t handle);
  678. /**
  679. Return the number of elements between each row of the matrix
  680. designated by \p handle. Maybe be equal to nx when there is no padding.
  681. */
  682. uint32_t starpu_matrix_get_local_ld(starpu_data_handle_t handle);
  683. /**
  684. Return the local pointer associated with \p handle.
  685. */
  686. uintptr_t starpu_matrix_get_local_ptr(starpu_data_handle_t handle);
  687. /**
  688. Return the size of the elements registered into the matrix
  689. designated by \p handle.
  690. */
  691. size_t starpu_matrix_get_elemsize(starpu_data_handle_t handle);
  692. /**
  693. Return the allocated size of the matrix designated by \p handle.
  694. */
  695. size_t starpu_matrix_get_allocsize(starpu_data_handle_t handle);
  696. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  697. #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.")
  698. #define STARPU_MATRIX_GET_PTR(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ptr) ; })
  699. #define STARPU_MATRIX_GET_DEV_HANDLE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->dev_handle) ; })
  700. #define STARPU_MATRIX_GET_OFFSET(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->offset) ; })
  701. #define STARPU_MATRIX_GET_NX(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->nx) ; })
  702. #define STARPU_MATRIX_GET_NY(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ny) ; })
  703. #define STARPU_MATRIX_GET_LD(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ld) ; })
  704. #define STARPU_MATRIX_GET_ELEMSIZE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->elemsize) ; })
  705. #define STARPU_MATRIX_GET_ALLOCSIZE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->allocsize) ; })
  706. #else
  707. /**
  708. Return a pointer to the matrix designated by \p interface, valid
  709. on CPUs and CUDA devices only. For OpenCL devices, the device handle
  710. and offset need to be used instead.
  711. */
  712. #define STARPU_MATRIX_GET_PTR(interface) (((struct starpu_matrix_interface *)(interface))->ptr)
  713. /**
  714. Return a device handle for the matrix designated by \p interface,
  715. to be used with OpenCL. The offset returned by
  716. ::STARPU_MATRIX_GET_OFFSET has to be used in
  717. addition to this.
  718. */
  719. #define STARPU_MATRIX_GET_DEV_HANDLE(interface) (((struct starpu_matrix_interface *)(interface))->dev_handle)
  720. /**
  721. Return the offset in the matrix designated by \p interface, to be
  722. used with the device handle.
  723. */
  724. #define STARPU_MATRIX_GET_OFFSET(interface) (((struct starpu_matrix_interface *)(interface))->offset)
  725. /**
  726. Return the number of elements on the x-axis of the matrix
  727. designated by \p interface.
  728. */
  729. #define STARPU_MATRIX_GET_NX(interface) (((struct starpu_matrix_interface *)(interface))->nx)
  730. /**
  731. Return the number of elements on the y-axis of the matrix
  732. designated by \p interface.
  733. */
  734. #define STARPU_MATRIX_GET_NY(interface) (((struct starpu_matrix_interface *)(interface))->ny)
  735. /**
  736. Return the number of elements between each row of the matrix
  737. designated by \p interface. May be equal to nx when there is no padding.
  738. */
  739. #define STARPU_MATRIX_GET_LD(interface) (((struct starpu_matrix_interface *)(interface))->ld)
  740. /**
  741. Return the size of the elements registered into the matrix
  742. designated by \p interface.
  743. */
  744. #define STARPU_MATRIX_GET_ELEMSIZE(interface) (((struct starpu_matrix_interface *)(interface))->elemsize)
  745. /**
  746. Return the allocated size of the matrix designated by \p interface.
  747. */
  748. #define STARPU_MATRIX_GET_ALLOCSIZE(interface) (((struct starpu_matrix_interface *)(interface))->allocsize)
  749. #endif
  750. /**
  751. Set the number of elements on the x-axis of the matrix
  752. designated by \p interface.
  753. */
  754. #define STARPU_MATRIX_SET_NX(interface, newnx) do { \
  755. STARPU_MATRIX_CHECK(interface); \
  756. (((struct starpu_matrix_interface *)(interface))->nx) = (newnx); \
  757. } while (0)
  758. /**
  759. Set the number of elements on the y-axis of the matrix
  760. designated by \p interface.
  761. */
  762. #define STARPU_MATRIX_SET_NY(interface, newny) do { \
  763. STARPU_MATRIX_CHECK(interface); \
  764. (((struct starpu_matrix_interface *)(interface))->ny) = (newny); \
  765. } while(0)
  766. /**
  767. Set the number of elements between each row of the matrix
  768. designated by \p interface. May be set to the same value as nx when there is
  769. no padding.
  770. */
  771. #define STARPU_MATRIX_SET_LD(interface, newld) do { \
  772. STARPU_MATRIX_CHECK(interface); \
  773. (((struct starpu_matrix_interface *)(interface))->ld) = (newld); \
  774. } while(0)
  775. /** @} */
  776. /**
  777. @name Accessing COO Data Interfaces
  778. @{
  779. */
  780. extern struct starpu_data_interface_ops starpu_interface_coo_ops;
  781. /**
  782. COO Matrices
  783. */
  784. struct starpu_coo_interface
  785. {
  786. enum starpu_data_interface_id id; /**< identifier of the interface */
  787. uint32_t *columns; /**< column array of the matrix */
  788. uint32_t *rows; /**< row array of the matrix */
  789. uintptr_t values; /**< values of the matrix */
  790. uint32_t nx; /**< number of elements on the x-axis of the matrix */
  791. uint32_t ny; /**< number of elements on the y-axis of the matrix */
  792. uint32_t n_values; /**< number of values registered in the matrix */
  793. size_t elemsize; /**< size of the elements of the matrix */
  794. };
  795. /**
  796. Register the \p nx x \p ny 2D matrix given in the COO format, using the
  797. \p columns, \p rows, \p values arrays, which must have \p n_values elements of
  798. size \p elemsize. Initialize \p handleptr.
  799. */
  800. 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);
  801. /**
  802. Return a pointer to the column array of the matrix designated
  803. by \p interface.
  804. */
  805. #define STARPU_COO_GET_COLUMNS(interface) (((struct starpu_coo_interface *)(interface))->columns)
  806. /**
  807. Return a device handle for the column array of the matrix
  808. designated by \p interface, to be used with OpenCL. The offset
  809. returned by ::STARPU_COO_GET_OFFSET has to be used in addition to
  810. this.
  811. */
  812. #define STARPU_COO_GET_COLUMNS_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->columns)
  813. /**
  814. Return a pointer to the rows array of the matrix designated by
  815. \p interface.
  816. */
  817. #define STARPU_COO_GET_ROWS(interface) (((struct starpu_coo_interface *)(interface))->rows)
  818. /**
  819. Return a device handle for the row array of the matrix
  820. designated by \p interface, to be used on OpenCL. The offset returned
  821. by ::STARPU_COO_GET_OFFSET has to be used in addition to this.
  822. */
  823. #define STARPU_COO_GET_ROWS_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->rows)
  824. /**
  825. Return a pointer to the values array of the matrix designated
  826. by \p interface.
  827. */
  828. #define STARPU_COO_GET_VALUES(interface) (((struct starpu_coo_interface *)(interface))->values)
  829. /**
  830. Return a device handle for the value array of the matrix
  831. designated by \p interface, to be used on OpenCL. The offset returned
  832. by ::STARPU_COO_GET_OFFSET has to be used in addition to this.
  833. */
  834. #define STARPU_COO_GET_VALUES_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->values)
  835. /**
  836. Return the offset in the arrays of the COO matrix designated by
  837. \p interface.
  838. */
  839. #define STARPU_COO_GET_OFFSET 0
  840. /**
  841. Return the number of elements on the x-axis of the matrix
  842. designated by \p interface.
  843. */
  844. #define STARPU_COO_GET_NX(interface) (((struct starpu_coo_interface *)(interface))->nx)
  845. /**
  846. Return the number of elements on the y-axis of the matrix
  847. designated by \p interface.
  848. */
  849. #define STARPU_COO_GET_NY(interface) (((struct starpu_coo_interface *)(interface))->ny)
  850. /**
  851. Return the number of values registered in the matrix designated
  852. by \p interface.
  853. */
  854. #define STARPU_COO_GET_NVALUES(interface) (((struct starpu_coo_interface *)(interface))->n_values)
  855. /**
  856. Return the size of the elements registered into the matrix
  857. designated by \p interface.
  858. */
  859. #define STARPU_COO_GET_ELEMSIZE(interface) (((struct starpu_coo_interface *)(interface))->elemsize)
  860. /** @} */
  861. /**
  862. @name Block Data Interface
  863. @{
  864. */
  865. extern struct starpu_data_interface_ops starpu_interface_block_ops;
  866. /* TODO: rename to 3dmatrix? */
  867. /* TODO: add allocsize support */
  868. /**
  869. Block interface for 3D dense blocks
  870. */
  871. struct starpu_block_interface
  872. {
  873. enum starpu_data_interface_id id; /**< identifier of the interface */
  874. uintptr_t ptr; /**< local pointer of the block */
  875. uintptr_t dev_handle; /**< device handle of the block. */
  876. size_t offset; /**< offset in the block. */
  877. uint32_t nx; /**< number of elements on the x-axis of the block. */
  878. uint32_t ny; /**< number of elements on the y-axis of the block. */
  879. uint32_t nz; /**< number of elements on the z-axis of the block. */
  880. uint32_t ldy; /**< number of elements between two lines */
  881. uint32_t ldz; /**< number of elements between two planes */
  882. size_t elemsize; /**< size of the elements of the block. */
  883. };
  884. /**
  885. Register the \p nx x \p ny x \p nz 3D matrix of \p elemsize byte elements
  886. pointed by \p ptr and initialize \p handle to represent it. Again, \p ldy and
  887. \p ldz specify the number of elements between rows and between z planes.
  888. Here an example of how to use the function.
  889. \code{.c}
  890. float *block;
  891. starpu_data_handle_t block_handle;
  892. block = (float*)malloc(nx*ny*nz*sizeof(float));
  893. starpu_block_data_register(&block_handle, STARPU_MAIN_RAM, (uintptr_t)block, nx, nx*ny, nx, ny, nz, sizeof(float));
  894. \endcode
  895. */
  896. 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);
  897. /**
  898. Register into the \p handle that to store data on node \p node it should use the
  899. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  900. (for OpenCL, notably), with \p ldy elements between rows and \p ldz
  901. elements between z planes.
  902. */
  903. 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);
  904. /**
  905. Return the number of elements on the x-axis of the block
  906. designated by \p handle.
  907. */
  908. uint32_t starpu_block_get_nx(starpu_data_handle_t handle);
  909. /**
  910. Return the number of elements on the y-axis of the block
  911. designated by \p handle.
  912. */
  913. uint32_t starpu_block_get_ny(starpu_data_handle_t handle);
  914. /**
  915. Return the number of elements on the z-axis of the block
  916. designated by \p handle.
  917. */
  918. uint32_t starpu_block_get_nz(starpu_data_handle_t handle);
  919. /**
  920. Return the number of elements between each row of the block
  921. designated by \p handle, in the format of the current memory node.
  922. */
  923. uint32_t starpu_block_get_local_ldy(starpu_data_handle_t handle);
  924. /**
  925. Return the number of elements between each z plane of the block
  926. designated by \p handle, in the format of the current memory node.
  927. */
  928. uint32_t starpu_block_get_local_ldz(starpu_data_handle_t handle);
  929. /**
  930. Return the local pointer associated with \p handle.
  931. */
  932. uintptr_t starpu_block_get_local_ptr(starpu_data_handle_t handle);
  933. /**
  934. Return the size of the elements of the block designated by
  935. \p handle.
  936. */
  937. size_t starpu_block_get_elemsize(starpu_data_handle_t handle);
  938. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  939. #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.")
  940. #define STARPU_BLOCK_GET_PTR(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ptr) ; })
  941. #define STARPU_BLOCK_GET_DEV_HANDLE(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->dev_handle) ; })
  942. #define STARPU_BLOCK_GET_OFFSET(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->offset) ; })
  943. #define STARPU_BLOCK_GET_NX(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->nx) ; })
  944. #define STARPU_BLOCK_GET_NY(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ny) ; })
  945. #define STARPU_BLOCK_GET_NZ(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->nz) ; })
  946. #define STARPU_BLOCK_GET_LDY(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ldy) ; })
  947. #define STARPU_BLOCK_GET_LDZ(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ldz) ; })
  948. #define STARPU_BLOCK_GET_ELEMSIZE(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->elemsize) ; })
  949. #else
  950. /**
  951. Return a pointer to the block designated by \p interface.
  952. */
  953. #define STARPU_BLOCK_GET_PTR(interface) (((struct starpu_block_interface *)(interface))->ptr)
  954. /**
  955. Return a device handle for the block designated by \p interface,
  956. to be used on OpenCL. The offset returned by
  957. ::STARPU_BLOCK_GET_OFFSET has to be used in
  958. addition to this.
  959. */
  960. #define STARPU_BLOCK_GET_DEV_HANDLE(interface) (((struct starpu_block_interface *)(interface))->dev_handle)
  961. /**
  962. Return the offset in the block designated by \p interface, to be
  963. used with the device handle.
  964. */
  965. #define STARPU_BLOCK_GET_OFFSET(interface) (((struct starpu_block_interface *)(interface))->offset)
  966. /**
  967. Return the number of elements on the x-axis of the block
  968. designated by \p interface.
  969. */
  970. #define STARPU_BLOCK_GET_NX(interface) (((struct starpu_block_interface *)(interface))->nx)
  971. /**
  972. Return the number of elements on the y-axis of the block
  973. designated by \p interface.
  974. */
  975. #define STARPU_BLOCK_GET_NY(interface) (((struct starpu_block_interface *)(interface))->ny)
  976. /**
  977. Return the number of elements on the z-axis of the block
  978. designated by \p interface.
  979. */
  980. #define STARPU_BLOCK_GET_NZ(interface) (((struct starpu_block_interface *)(interface))->nz)
  981. /**
  982. Return the number of elements between each row of the block
  983. designated by \p interface. May be equal to nx when there is no padding.
  984. */
  985. #define STARPU_BLOCK_GET_LDY(interface) (((struct starpu_block_interface *)(interface))->ldy)
  986. /**
  987. Return the number of elements between each z plane of the block
  988. designated by \p interface. May be equal to nx*ny when there is no
  989. padding.
  990. */
  991. #define STARPU_BLOCK_GET_LDZ(interface) (((struct starpu_block_interface *)(interface))->ldz)
  992. /**
  993. Return the size of the elements of the block designated by
  994. \p interface.
  995. */
  996. #define STARPU_BLOCK_GET_ELEMSIZE(interface) (((struct starpu_block_interface *)(interface))->elemsize)
  997. #endif
  998. /** @} */
  999. /**
  1000. @name Vector Data Interface
  1001. @{
  1002. */
  1003. extern struct starpu_data_interface_ops starpu_interface_vector_ops;
  1004. /**
  1005. */
  1006. struct starpu_vector_interface
  1007. {
  1008. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1009. uintptr_t ptr; /**< local pointer of the vector */
  1010. uintptr_t dev_handle; /**< device handle of the vector. */
  1011. size_t offset; /**< offset in the vector */
  1012. uint32_t nx; /**< number of elements on the x-axis of the vector */
  1013. size_t elemsize; /**< size of the elements of the vector */
  1014. uint32_t slice_base; /**< vector slice base, used by the StarPU OpenMP runtime support */
  1015. size_t allocsize; /**< size actually currently allocated */
  1016. };
  1017. /**
  1018. Register the \p nx \p elemsize-byte elements pointed to by \p ptr and initialize \p handle to represent it.
  1019. Here an example of how to use the function.
  1020. \code{.c}
  1021. float vector[NX];
  1022. starpu_data_handle_t vector_handle;
  1023. starpu_vector_data_register(&vector_handle, STARPU_MAIN_RAM, (uintptr_t)vector, NX, sizeof(vector[0]));
  1024. \endcode
  1025. */
  1026. void starpu_vector_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, uint32_t nx, size_t elemsize);
  1027. /**
  1028. Similar to starpu_matrix_data_register, but additionally specifies which
  1029. allocation size should be used instead of the initial nx*elemsize.
  1030. */
  1031. 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);
  1032. /**
  1033. Register into the \p handle that to store data on node \p node it should use the
  1034. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  1035. (for OpenCL, notably)
  1036. */
  1037. void starpu_vector_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset);
  1038. /**
  1039. Return the number of elements registered into the array designated by \p handle.
  1040. */
  1041. uint32_t starpu_vector_get_nx(starpu_data_handle_t handle);
  1042. /**
  1043. Return the size of each element of the array designated by \p handle.
  1044. */
  1045. size_t starpu_vector_get_elemsize(starpu_data_handle_t handle);
  1046. /**
  1047. Return the allocated size of the array designated by \p handle.
  1048. */
  1049. size_t starpu_vector_get_allocsize(starpu_data_handle_t handle);
  1050. /**
  1051. Return the local pointer associated with \p handle.
  1052. */
  1053. uintptr_t starpu_vector_get_local_ptr(starpu_data_handle_t handle);
  1054. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  1055. #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.")
  1056. #define STARPU_VECTOR_GET_PTR(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->ptr); })
  1057. #define STARPU_VECTOR_GET_DEV_HANDLE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->dev_handle); })
  1058. #define STARPU_VECTOR_GET_OFFSET(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->offset); })
  1059. #define STARPU_VECTOR_GET_NX(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->nx); })
  1060. #define STARPU_VECTOR_GET_ELEMSIZE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->elemsize); })
  1061. #define STARPU_VECTOR_GET_ALLOCSIZE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->allocsize); })
  1062. #define STARPU_VECTOR_GET_SLICE_BASE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->slice_base); })
  1063. #else
  1064. /**
  1065. Return a pointer to the array designated by \p interface, valid on
  1066. CPUs and CUDA only. For OpenCL, the device handle and offset need to
  1067. be used instead.
  1068. */
  1069. #define STARPU_VECTOR_GET_PTR(interface) (((struct starpu_vector_interface *)(interface))->ptr)
  1070. /**
  1071. Return a device handle for the array designated by \p interface,
  1072. to be used with OpenCL. the offset returned by ::STARPU_VECTOR_GET_OFFSET has to be used in
  1073. addition to this.
  1074. */
  1075. #define STARPU_VECTOR_GET_DEV_HANDLE(interface) (((struct starpu_vector_interface *)(interface))->dev_handle)
  1076. /**
  1077. Return the offset in the array designated by \p interface, to be
  1078. used with the device handle.
  1079. */
  1080. #define STARPU_VECTOR_GET_OFFSET(interface) (((struct starpu_vector_interface *)(interface))->offset)
  1081. /**
  1082. Return the number of elements registered into the array
  1083. designated by \p interface.
  1084. */
  1085. #define STARPU_VECTOR_GET_NX(interface) (((struct starpu_vector_interface *)(interface))->nx)
  1086. /**
  1087. Return the size of each element of the array designated by
  1088. \p interface.
  1089. */
  1090. #define STARPU_VECTOR_GET_ELEMSIZE(interface) (((struct starpu_vector_interface *)(interface))->elemsize)
  1091. /**
  1092. Return the size of each element of the array designated by
  1093. \p interface.
  1094. */
  1095. #define STARPU_VECTOR_GET_ALLOCSIZE(interface) (((struct starpu_vector_interface *)(interface))->allocsize)
  1096. /**
  1097. Return the OpenMP slice base annotation of each element of the array designated by
  1098. \p interface.
  1099. */
  1100. #define STARPU_VECTOR_GET_SLICE_BASE(interface) (((struct starpu_vector_interface *)(interface))->slice_base)
  1101. #endif
  1102. /**
  1103. Set the number of elements registered into the array designated by \p
  1104. interface.
  1105. */
  1106. #define STARPU_VECTOR_SET_NX(interface, newnx) do { \
  1107. STARPU_VECTOR_CHECK(interface); \
  1108. (((struct starpu_vector_interface *)(interface))->nx) = (newnx); \
  1109. } while(0)
  1110. /** @} */
  1111. /**
  1112. @name Variable Data Interface
  1113. @{
  1114. */
  1115. extern struct starpu_data_interface_ops starpu_interface_variable_ops;
  1116. /**
  1117. Variable interface for a single data (not a vector, a matrix, a list,
  1118. ...)
  1119. */
  1120. struct starpu_variable_interface
  1121. {
  1122. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1123. uintptr_t ptr; /**< local pointer of the variable */
  1124. uintptr_t dev_handle; /**< device handle of the variable. */
  1125. size_t offset; /**< offset in the variable */
  1126. size_t elemsize; /**< size of the variable */
  1127. };
  1128. /**
  1129. Register the \p size byte element pointed to by \p ptr, which is
  1130. typically a scalar, and initialize \p handle to represent this data item.
  1131. Here an example of how to use the function.
  1132. \code{.c}
  1133. float var = 42.0;
  1134. starpu_data_handle_t var_handle;
  1135. starpu_variable_data_register(&var_handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  1136. \endcode
  1137. */
  1138. void starpu_variable_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, size_t size);
  1139. /**
  1140. Register into the \p handle that to store data on node \p node it should use the
  1141. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  1142. (for OpenCL, notably)
  1143. */
  1144. void starpu_variable_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset);
  1145. /**
  1146. Return the size of the variable designated by \p handle.
  1147. */
  1148. size_t starpu_variable_get_elemsize(starpu_data_handle_t handle);
  1149. /**
  1150. Return a pointer to the variable designated by \p handle.
  1151. */
  1152. uintptr_t starpu_variable_get_local_ptr(starpu_data_handle_t handle);
  1153. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  1154. #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.")
  1155. #define STARPU_VARIABLE_GET_PTR(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->ptr) ; })
  1156. #define STARPU_VARIABLE_GET_OFFSET(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->offset) ; })
  1157. #define STARPU_VARIABLE_GET_ELEMSIZE(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->elemsize) ; })
  1158. #define STARPU_VARIABLE_GET_DEV_HANDLE(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->ptr) ; })
  1159. #else
  1160. /**
  1161. Return a pointer to the variable designated by \p interface.
  1162. */
  1163. #define STARPU_VARIABLE_GET_PTR(interface) (((struct starpu_variable_interface *)(interface))->ptr)
  1164. /**
  1165. Return the offset in the variable designated by \p interface, to
  1166. be used with the device handle.
  1167. */
  1168. #define STARPU_VARIABLE_GET_OFFSET(interface) (((struct starpu_variable_interface *)(interface))->offset)
  1169. /**
  1170. Return the size of the variable designated by \p interface.
  1171. */
  1172. #define STARPU_VARIABLE_GET_ELEMSIZE(interface) (((struct starpu_variable_interface *)(interface))->elemsize)
  1173. /**
  1174. Return a device handle for the variable designated by
  1175. \p interface, to be used with OpenCL. The offset returned by
  1176. ::STARPU_VARIABLE_GET_OFFSET has to be
  1177. used in addition to this.
  1178. */
  1179. #define STARPU_VARIABLE_GET_DEV_HANDLE(interface) (((struct starpu_variable_interface *)(interface))->ptr)
  1180. #endif
  1181. /** @} */
  1182. /**
  1183. @name Void Data Interface
  1184. @{
  1185. */
  1186. extern struct starpu_data_interface_ops starpu_interface_void_ops;
  1187. /**
  1188. Register a void interface. There is no data really associated
  1189. to that interface, but it may be used as a synchronization mechanism.
  1190. It also permits to express an abstract piece of data that is managed
  1191. by the application internally: this makes it possible to forbid the
  1192. concurrent execution of different tasks accessing the same <c>void</c>
  1193. data in read-write concurrently.
  1194. */
  1195. void starpu_void_data_register(starpu_data_handle_t *handle);
  1196. /** @} */
  1197. /**
  1198. @name CSR Data Interface
  1199. @{
  1200. */
  1201. extern struct starpu_data_interface_ops starpu_interface_csr_ops;
  1202. /**
  1203. CSR interface for sparse matrices (compressed sparse row
  1204. representation)
  1205. */
  1206. struct starpu_csr_interface
  1207. {
  1208. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1209. uint32_t nnz; /**< number of non-zero entries */
  1210. uint32_t nrow; /**< number of rows */
  1211. uintptr_t nzval; /**< non-zero values */
  1212. uint32_t *colind; /**< position of non-zero entries on the row */
  1213. uint32_t *rowptr; /**< index (in nzval) of the first entry of the row */
  1214. uint32_t firstentry; /**< k for k-based indexing (0 or 1 usually). also useful when partitionning the matrix. */
  1215. size_t elemsize; /**< size of the elements of the matrix */
  1216. };
  1217. /**
  1218. Register a CSR (Compressed Sparse Row Representation) sparse matrix.
  1219. */
  1220. 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);
  1221. /**
  1222. Return the number of non-zero values in the matrix designated
  1223. by \p handle.
  1224. */
  1225. uint32_t starpu_csr_get_nnz(starpu_data_handle_t handle);
  1226. /**
  1227. Return the size of the row pointer array of the matrix
  1228. designated by \p handle.
  1229. */
  1230. uint32_t starpu_csr_get_nrow(starpu_data_handle_t handle);
  1231. /**
  1232. Return the index at which all arrays (the column indexes, the
  1233. row pointers...) of the matrix designated by \p handle.
  1234. */
  1235. uint32_t starpu_csr_get_firstentry(starpu_data_handle_t handle);
  1236. /**
  1237. Return a local pointer to the non-zero values of the matrix
  1238. designated by \p handle.
  1239. */
  1240. uintptr_t starpu_csr_get_local_nzval(starpu_data_handle_t handle);
  1241. /**
  1242. Return a local pointer to the column index of the matrix
  1243. designated by \p handle.
  1244. */
  1245. uint32_t *starpu_csr_get_local_colind(starpu_data_handle_t handle);
  1246. /**
  1247. Return a local pointer to the row pointer array of the matrix
  1248. designated by \p handle.
  1249. */
  1250. uint32_t *starpu_csr_get_local_rowptr(starpu_data_handle_t handle);
  1251. /**
  1252. Return the size of the elements registered into the matrix
  1253. designated by \p handle.
  1254. */
  1255. size_t starpu_csr_get_elemsize(starpu_data_handle_t handle);
  1256. /**
  1257. Return the number of non-zero values in the matrix designated
  1258. by \p interface.
  1259. */
  1260. #define STARPU_CSR_GET_NNZ(interface) (((struct starpu_csr_interface *)(interface))->nnz)
  1261. /**
  1262. Return the size of the row pointer array of the matrix
  1263. designated by \p interface.
  1264. */
  1265. #define STARPU_CSR_GET_NROW(interface) (((struct starpu_csr_interface *)(interface))->nrow)
  1266. /**
  1267. Return a pointer to the non-zero values of the matrix
  1268. designated by \p interface.
  1269. */
  1270. #define STARPU_CSR_GET_NZVAL(interface) (((struct starpu_csr_interface *)(interface))->nzval)
  1271. /**
  1272. Return a device handle for the array of non-zero values in the
  1273. matrix designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET
  1274. has to used in addition to this.
  1275. */
  1276. #define STARPU_CSR_GET_NZVAL_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->nnz)
  1277. /**
  1278. Return a pointer to the column index of the matrix designated
  1279. by \p interface.
  1280. */
  1281. #define STARPU_CSR_GET_COLIND(interface) (((struct starpu_csr_interface *)(interface))->colind)
  1282. /**
  1283. Return a device handle for the column index of the matrix
  1284. designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET has to be used in
  1285. addition to this.
  1286. */
  1287. #define STARPU_CSR_GET_COLIND_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->colind)
  1288. /**
  1289. Return a pointer to the row pointer array of the matrix
  1290. designated by \p interface.
  1291. */
  1292. #define STARPU_CSR_GET_ROWPTR(interface) (((struct starpu_csr_interface *)(interface))->rowptr)
  1293. /**
  1294. Return a device handle for the row pointer array of the matrix
  1295. designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET has to be used in
  1296. addition to this.
  1297. */
  1298. #define STARPU_CSR_GET_ROWPTR_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->rowptr)
  1299. /**
  1300. Return the offset in the arrays (colind, rowptr, nzval) of the
  1301. matrix designated by \p interface, to be used with the device handles.
  1302. */
  1303. #define STARPU_CSR_GET_OFFSET 0
  1304. /**
  1305. Return the index at which all arrays (the column indexes, the
  1306. row pointers...) of the \p interface start.
  1307. */
  1308. #define STARPU_CSR_GET_FIRSTENTRY(interface) (((struct starpu_csr_interface *)(interface))->firstentry)
  1309. /**
  1310. Return the size of the elements registered into the matrix
  1311. designated by \p interface.
  1312. */
  1313. #define STARPU_CSR_GET_ELEMSIZE(interface) (((struct starpu_csr_interface *)(interface))->elemsize)
  1314. /** @} */
  1315. /**
  1316. @name BCSR Data Interface
  1317. @{
  1318. */
  1319. extern struct starpu_data_interface_ops starpu_interface_bcsr_ops;
  1320. /**
  1321. BCSR interface for sparse matrices (blocked compressed sparse
  1322. row representation)
  1323. */
  1324. struct starpu_bcsr_interface
  1325. {
  1326. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1327. uint32_t nnz; /**< number of non-zero BLOCKS */
  1328. uint32_t nrow; /**< number of rows (in terms of BLOCKS) */
  1329. uintptr_t nzval; /**< non-zero values */
  1330. uint32_t *colind; /**< array of nnz elements, colind[i] is the block-column index for block i in nzval */
  1331. uint32_t *rowptr; /**< array of nrow+1
  1332. * elements, rowptr[i] is
  1333. * the block-index (in
  1334. * nzval) of the first block
  1335. * of row i. By convention,
  1336. * rowptr[nrow] is the
  1337. * number of blocks, this
  1338. * allows an easier access
  1339. * of the matrix's elements
  1340. * for the kernels. */
  1341. uint32_t firstentry; /**< k for k-based indexing (0 or 1 usually). Also useful when partitionning the matrix. */
  1342. uint32_t r; /**< height of the blocks */
  1343. uint32_t c; /**< width of the blocks */
  1344. size_t elemsize; /**< size of the elements of the matrix */
  1345. };
  1346. /**
  1347. This variant of starpu_data_register() uses the BCSR (Blocked
  1348. Compressed Sparse Row Representation) sparse matrix interface.
  1349. Register the sparse matrix made of \p nnz non-zero blocks of elements of
  1350. size \p elemsize stored in \p nzval and initializes \p handle to represent it.
  1351. Blocks have size \p r * \p c. \p nrow is the number of rows (in terms of
  1352. blocks), \p colind is an array of nnz elements, colind[i] is the block-column index for block i in \p nzval,
  1353. \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.
  1354. \p firstentry is the index of the first entry of the given arrays
  1355. (usually 0 or 1).
  1356. Here an example with the following matrix:
  1357. \code | 0 1 0 0 | \endcode
  1358. \code | 2 3 0 0 | \endcode
  1359. \code | 4 5 8 9 | \endcode
  1360. \code | 6 7 10 11 | \endcode
  1361. \code nzval = [0, 1, 2, 3] ++ [4, 5, 6, 7] ++ [8, 9, 10, 11] \endcode
  1362. \code colind = [0, 0, 1] \endcode
  1363. \code rowptr = [0, 1, 3] \endcode
  1364. \code r = c = 2 \endcode
  1365. which translates into the following code
  1366. \code{.c}
  1367. int R = 2; // Size of the blocks
  1368. int C = 2;
  1369. int NROWS = 2;
  1370. int NNZ_BLOCKS = 3; // out of 4
  1371. int NZVAL_SIZE = (R*C*NNZ_BLOCKS);
  1372. int nzval[NZVAL_SIZE] =
  1373. {
  1374. 0, 1, 2, 3, // First block
  1375. 4, 5, 6, 7, // Second block
  1376. 8, 9, 10, 11 // Third block
  1377. };
  1378. uint32_t colind[NNZ_BLOCKS] =
  1379. {
  1380. 0, // block-column index for first block in nzval
  1381. 0, // block-column index for second block in nzval
  1382. 1 // block-column index for third block in nzval
  1383. };
  1384. uint32_t rowptr[NROWS+1] =
  1385. {
  1386. 0, // block-index in nzval of the first block of the first row.
  1387. 1, // block-index in nzval of the first block of the second row.
  1388. NNZ_BLOCKS // number of blocks, to allow an easier element's access for the kernels
  1389. };
  1390. starpu_data_handle_t bcsr_handle;
  1391. starpu_bcsr_data_register(&bcsr_handle,
  1392. STARPU_MAIN_RAM,
  1393. NNZ_BLOCKS,
  1394. NROWS,
  1395. (uintptr_t) nzval,
  1396. colind,
  1397. rowptr,
  1398. 0, // firstentry
  1399. R,
  1400. C,
  1401. sizeof(nzval[0]));
  1402. \endcode
  1403. */
  1404. 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);
  1405. /**
  1406. Return the number of non-zero elements in the matrix designated
  1407. by \p handle.
  1408. */
  1409. uint32_t starpu_bcsr_get_nnz(starpu_data_handle_t handle);
  1410. /**
  1411. Return the number of rows (in terms of blocks of size r*c) in
  1412. the matrix designated by \p handle.
  1413. */
  1414. uint32_t starpu_bcsr_get_nrow(starpu_data_handle_t handle);
  1415. /**
  1416. Return the index at which all arrays (the column indexes, the
  1417. row pointers...) of the matrix desginated by \p handle.
  1418. */
  1419. uint32_t starpu_bcsr_get_firstentry(starpu_data_handle_t handle);
  1420. /**
  1421. Return a pointer to the non-zero values of the matrix
  1422. designated by \p handle.
  1423. */
  1424. uintptr_t starpu_bcsr_get_local_nzval(starpu_data_handle_t handle);
  1425. /**
  1426. Return a pointer to the column index, which holds the positions
  1427. of the non-zero entries in the matrix designated by \p handle.
  1428. */
  1429. uint32_t *starpu_bcsr_get_local_colind(starpu_data_handle_t handle);
  1430. /**
  1431. Return the row pointer array of the matrix designated by
  1432. \p handle.
  1433. */
  1434. uint32_t *starpu_bcsr_get_local_rowptr(starpu_data_handle_t handle);
  1435. /**
  1436. Return the number of rows in a block.
  1437. */
  1438. uint32_t starpu_bcsr_get_r(starpu_data_handle_t handle);
  1439. /**
  1440. Return the number of columns in a block.
  1441. */
  1442. uint32_t starpu_bcsr_get_c(starpu_data_handle_t handle);
  1443. /**
  1444. Return the size of the elements in the matrix designated by
  1445. \p handle.
  1446. */
  1447. size_t starpu_bcsr_get_elemsize(starpu_data_handle_t handle);
  1448. /**
  1449. Return the number of non-zero values in the matrix designated
  1450. by \p interface.
  1451. */
  1452. #define STARPU_BCSR_GET_NNZ(interface) (((struct starpu_bcsr_interface *)(interface))->nnz)
  1453. /**
  1454. Return a pointer to the non-zero values of the matrix
  1455. designated by \p interface.
  1456. */
  1457. #define STARPU_BCSR_GET_NZVAL(interface) (((struct starpu_bcsr_interface *)(interface))->nzval)
  1458. /**
  1459. Return a device handle for the array of non-zero values in the
  1460. matrix designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be
  1461. used in addition to this.
  1462. */
  1463. #define STARPU_BCSR_GET_NZVAL_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->nnz)
  1464. /**
  1465. Return a pointer to the column index of the matrix designated
  1466. by \p interface.
  1467. */
  1468. #define STARPU_BCSR_GET_COLIND(interface) (((struct starpu_bcsr_interface *)(interface))->colind)
  1469. /**
  1470. Return a device handle for the column index of the matrix
  1471. designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be used in
  1472. addition to this.
  1473. */
  1474. #define STARPU_BCSR_GET_COLIND_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->colind)
  1475. /**
  1476. Return a pointer to the row pointer array of the matrix
  1477. designated by \p interface.
  1478. */
  1479. #define STARPU_BCSR_GET_ROWPTR(interface) (((struct starpu_bcsr_interface *)(interface))->rowptr)
  1480. /**
  1481. Return a device handle for the row pointer array of the matrix
  1482. designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be used in
  1483. addition to this.
  1484. */
  1485. #define STARPU_BCSR_GET_ROWPTR_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->rowptr)
  1486. /**
  1487. Return the offset in the arrays (coling, rowptr, nzval) of the
  1488. matrix designated by \p interface, to be used with the device handles.
  1489. */
  1490. #define STARPU_BCSR_GET_OFFSET 0
  1491. /** @} */
  1492. /**
  1493. @name Multiformat Data Interface
  1494. @{
  1495. */
  1496. /**
  1497. Multiformat operations
  1498. */
  1499. struct starpu_multiformat_data_interface_ops
  1500. {
  1501. size_t cpu_elemsize; /**< size of each element on CPUs */
  1502. size_t opencl_elemsize; /**< size of each element on OpenCL devices */
  1503. struct starpu_codelet *cpu_to_opencl_cl; /**< pointer to a codelet which converts from CPU to OpenCL */
  1504. struct starpu_codelet *opencl_to_cpu_cl; /**< pointer to a codelet which converts from OpenCL to CPU */
  1505. size_t cuda_elemsize; /**< size of each element on CUDA devices */
  1506. struct starpu_codelet *cpu_to_cuda_cl; /**< pointer to a codelet which converts from CPU to CUDA */
  1507. struct starpu_codelet *cuda_to_cpu_cl; /**< pointer to a codelet which converts from CUDA to CPU */
  1508. size_t mic_elemsize; /**< size of each element on MIC devices */
  1509. struct starpu_codelet *cpu_to_mic_cl; /**< pointer to a codelet which converts from CPU to MIC */
  1510. struct starpu_codelet *mic_to_cpu_cl; /**< pointer to a codelet which converts from MIC to CPU */
  1511. };
  1512. struct starpu_multiformat_interface
  1513. {
  1514. enum starpu_data_interface_id id;
  1515. void *cpu_ptr;
  1516. void *cuda_ptr;
  1517. void *opencl_ptr;
  1518. void *mic_ptr;
  1519. uint32_t nx;
  1520. struct starpu_multiformat_data_interface_ops *ops;
  1521. };
  1522. /**
  1523. Register a piece of data that can be represented in different
  1524. ways, depending upon the processing unit that manipulates it. It
  1525. allows the programmer, for instance, to use an array of structures
  1526. when working on a CPU, and a structure of arrays when working on a
  1527. GPU. \p nobjects is the number of elements in the data. \p format_ops
  1528. describes the format.
  1529. */
  1530. 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);
  1531. /**
  1532. Return the local pointer to the data with CPU format.
  1533. */
  1534. #define STARPU_MULTIFORMAT_GET_CPU_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->cpu_ptr)
  1535. /**
  1536. Return the local pointer to the data with CUDA format.
  1537. */
  1538. #define STARPU_MULTIFORMAT_GET_CUDA_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->cuda_ptr)
  1539. /**
  1540. Return the local pointer to the data with OpenCL format.
  1541. */
  1542. #define STARPU_MULTIFORMAT_GET_OPENCL_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->opencl_ptr)
  1543. /**
  1544. Return the local pointer to the data with MIC format.
  1545. */
  1546. #define STARPU_MULTIFORMAT_GET_MIC_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->mic_ptr)
  1547. /**
  1548. Return the number of elements in the data.
  1549. */
  1550. #define STARPU_MULTIFORMAT_GET_NX(interface) (((struct starpu_multiformat_interface *)(interface))->nx)
  1551. /** @} */
  1552. /** @} */
  1553. #ifdef __cplusplus
  1554. }
  1555. #endif
  1556. #endif /* __STARPU_DATA_INTERFACES_H__ */