starpu_data_interfaces.h 84 KB

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