starpu_data_interfaces.h 86 KB

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