starpu_data_interfaces.h 84 KB

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