starpu_data_interfaces.h 84 KB

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