starpu_data_interfaces.h 67 KB

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