starpu_data_interfaces.h 72 KB

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