starpu_data_interfaces.h 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  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. /** @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.), to be used for indexing performance models.
  391. */
  392. uint32_t (*footprint) (starpu_data_handle_t handle);
  393. /**
  394. Return a 32bit footprint which characterizes the data allocation, to be used
  395. for indexing allocation cache.
  396. If not specified, the starpu_data_interface_ops::footprint method is
  397. used instead.
  398. */
  399. uint32_t (*alloc_footprint) (starpu_data_handle_t handle);
  400. /**
  401. Compare the data size and layout of two interfaces (nx, ny, ld, elemsize,
  402. etc.), to be used for indexing performance models.. It should return 1 if
  403. the two interfaces size and layout match, and 0 otherwise.
  404. */
  405. int (*compare) (void *data_interface_a, void *data_interface_b);
  406. /**
  407. Compare the data allocation of two interfaces etc.), to be used for indexing
  408. allocation cache. It should return
  409. 1 if the two interfaces are allocation-compatible, and 0 otherwise.
  410. If not specified, the starpu_data_interface_ops::compare method is
  411. used instead.
  412. */
  413. int (*alloc_compare) (void *data_interface_a, void *data_interface_b);
  414. /**
  415. Dump the sizes of a handle to a file.
  416. */
  417. void (*display) (starpu_data_handle_t handle, FILE *f);
  418. /**
  419. Describe the data into a string in a brief way, such as one
  420. letter to describe the type of data, and the data
  421. dimensions.
  422. */
  423. starpu_ssize_t (*describe) (void *data_interface, char *buf, size_t size);
  424. /**
  425. An identifier that is unique to each interface.
  426. */
  427. enum starpu_data_interface_id interfaceid;
  428. /**
  429. Size of the interface data descriptor.
  430. */
  431. size_t interface_size;
  432. /**
  433. */
  434. char is_multiformat;
  435. /**
  436. If set to non-zero, StarPU will never try to reuse an allocated
  437. buffer for a different handle. This can be notably useful for
  438. application-defined interfaces which have a dynamic size, and for
  439. which it thus does not make sense to reuse the buffer since will
  440. probably not have the proper size.
  441. */
  442. char dontcache;
  443. /**
  444. */
  445. struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface);
  446. /**
  447. Pack the data handle into a contiguous buffer at the address
  448. allocated with <c>starpu_malloc_flags(ptr, size, 0)</c> (and thus
  449. returned in \p ptr) and set the size of the newly created buffer
  450. in \p count. If \p ptr is <c>NULL</c>, the function should not
  451. copy the data in the buffer but just set count to the size of the
  452. buffer which would have been allocated. The special value -1
  453. indicates the size is yet unknown.
  454. */
  455. int (*pack_data) (starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count);
  456. /**
  457. Unpack the data handle from the contiguous buffer at the address
  458. \p ptr of size \p count
  459. */
  460. int (*unpack_data) (starpu_data_handle_t handle, unsigned node, void *ptr, size_t count);
  461. /**
  462. Name of the interface
  463. */
  464. char *name;
  465. };
  466. /** @name Basic API
  467. @{
  468. */
  469. /**
  470. Register a piece of data into the handle located at the
  471. \p handleptr address. The \p data_interface buffer contains the initial
  472. description of the data in the \p home_node. The \p ops argument is a
  473. pointer to a structure describing the different methods used to
  474. manipulate this type of interface. See starpu_data_interface_ops for
  475. more details on this structure.
  476. If \p home_node is -1, StarPU will automatically allocate the memory when
  477. it is used for the first time in write-only mode. Once such data
  478. handle has been automatically allocated, it is possible to access it
  479. using any access mode.
  480. Note that StarPU supplies a set of predefined types of interface (e.g.
  481. vector or matrix) which can be registered by the means of helper
  482. functions (e.g. starpu_vector_data_register() or
  483. starpu_matrix_data_register()).
  484. */
  485. void starpu_data_register(starpu_data_handle_t *handleptr, int home_node, void *data_interface, struct starpu_data_interface_ops *ops);
  486. /**
  487. Register that a buffer for \p handle on \p node will be set. This is typically
  488. used by starpu_*_ptr_register helpers before setting the interface pointers for
  489. this node, to tell the core that that is now allocated.
  490. */
  491. void starpu_data_ptr_register(starpu_data_handle_t handle, unsigned node);
  492. /**
  493. Register a new piece of data into the handle \p handledst with the
  494. same interface as the handle \p handlesrc.
  495. */
  496. void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc);
  497. /**
  498. Return the pointer associated with \p handle on node \p node or <c>NULL</c>
  499. if handle’s interface does not support this operation or data for this
  500. \p handle is not allocated on that \p node.
  501. */
  502. void *starpu_data_handle_to_pointer(starpu_data_handle_t handle, unsigned node);
  503. /**
  504. Return whether the given \p ptr is within the data for \p handle on node \p
  505. node (1) or not (0). If the handle interface does not support this operation,
  506. and thus the result is unknown, -1 is returned.
  507. */
  508. int starpu_data_pointer_is_inside(starpu_data_handle_t handle, unsigned node, void *ptr);
  509. /**
  510. Return the local pointer associated with \p handle or <c>NULL</c> if
  511. \p handle’s interface does not have any data allocated locally.
  512. */
  513. void *starpu_data_get_local_ptr(starpu_data_handle_t handle);
  514. /**
  515. Return the interface associated with \p handle on \p memory_node.
  516. */
  517. void *starpu_data_get_interface_on_node(starpu_data_handle_t handle, unsigned memory_node);
  518. /**
  519. Return the unique identifier of the interface associated with
  520. the given \p handle.
  521. */
  522. enum starpu_data_interface_id starpu_data_get_interface_id(starpu_data_handle_t handle);
  523. /**
  524. Execute the packing operation of the interface of the data
  525. registered at \p handle (see starpu_data_interface_ops). This
  526. packing operation must allocate a buffer large enough at \p ptr and copy
  527. into the newly allocated buffer the data associated to \p handle. \p count
  528. will be set to the size of the allocated buffer. If \p ptr is <c>NULL</c>, the
  529. function should not copy the data in the buffer but just set \p count to
  530. the size of the buffer which would have been allocated. The special
  531. value -1 indicates the size is yet unknown.
  532. */
  533. int starpu_data_pack(starpu_data_handle_t handle, void **ptr, starpu_ssize_t *count);
  534. /**
  535. Unpack in handle the data located at \p ptr of size \p count as
  536. described by the interface of the data. The interface registered at
  537. \p handle must define a unpacking operation (see
  538. starpu_data_interface_ops). The memory at the address \p ptr is freed
  539. after calling the data unpacking operation.
  540. */
  541. int starpu_data_unpack(starpu_data_handle_t handle, void *ptr, size_t count);
  542. /**
  543. Return the size of the data associated with \p handle.
  544. */
  545. size_t starpu_data_get_size(starpu_data_handle_t handle);
  546. /**
  547. Return the handle corresponding to the data pointed to by the \p ptr host pointer.
  548. */
  549. starpu_data_handle_t starpu_data_lookup(const void *ptr);
  550. int starpu_data_get_home_node(starpu_data_handle_t handle);
  551. /**
  552. Return the next available id for a newly created data interface
  553. (\ref DefiningANewDataInterface).
  554. */
  555. int starpu_data_interface_get_next_id(void);
  556. /**
  557. Copy \p size bytes from byte offset \p src_offset of \p src on \p src_node
  558. to byte offset \p dst_offset of \p dst on \p dst_node. This is to be used in
  559. the starpu_data_copy_methods::any_to_any copy method, which is provided with \p async_data to
  560. be passed to starpu_interface_copy(). this returns <c>-EAGAIN</c> if the
  561. transfer is still ongoing, or 0 if the transfer is already completed.
  562. */
  563. 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);
  564. /**
  565. When an asynchonous implementation of the data transfer is implemented, the call
  566. to the underlying CUDA, OpenCL, etc. call should be surrounded
  567. by calls to starpu_interface_start_driver_copy_async() and
  568. starpu_interface_end_driver_copy_async(), so that it is recorded in offline
  569. execution traces, and the timing of the submission is checked. \p start must
  570. point to a variable whose value will be passed unchanged to
  571. starpu_interface_end_driver_copy_async().
  572. */
  573. void starpu_interface_start_driver_copy_async(unsigned src_node, unsigned dst_node, double *start);
  574. /**
  575. See starpu_interface_start_driver_copy_async().
  576. */
  577. void starpu_interface_end_driver_copy_async(unsigned src_node, unsigned dst_node, double start);
  578. /**
  579. Allocate \p size bytes on node \p dst_node with the given allocation \p flags. This returns 0 if
  580. allocation failed, the allocation method should then return <c>-ENOMEM</c> as
  581. allocated size. Deallocation must be done with starpu_free_on_node_flags().
  582. */
  583. uintptr_t starpu_malloc_on_node_flags(unsigned dst_node, size_t size, int flags);
  584. /**
  585. Allocate \p size bytes on node \p dst_node with the default allocation flags. This returns 0 if
  586. allocation failed, the allocation method should then return <c>-ENOMEM</c> as
  587. allocated size. Deallocation must be done with starpu_free_on_node().
  588. */
  589. uintptr_t starpu_malloc_on_node(unsigned dst_node, size_t size);
  590. /**
  591. Free \p addr of \p size bytes on node \p dst_node which was previously allocated
  592. with starpu_malloc_on_node_flags() with the given allocation \p flags.
  593. */
  594. void starpu_free_on_node_flags(unsigned dst_node, uintptr_t addr, size_t size, int flags);
  595. /**
  596. Free \p addr of \p size bytes on node \p dst_node which was previously allocated
  597. with starpu_malloc_on_node().
  598. */
  599. void starpu_free_on_node(unsigned dst_node, uintptr_t addr, size_t size);
  600. /**
  601. Define the default flags for allocations performed by starpu_malloc_on_node() and
  602. starpu_free_on_node(). The default is \ref STARPU_MALLOC_PINNED | \ref STARPU_MALLOC_COUNT.
  603. */
  604. void starpu_malloc_on_node_set_default_flags(unsigned node, int flags);
  605. /** @} */
  606. /** @name Accessing Matrix Data Interfaces
  607. @{
  608. */
  609. extern struct starpu_data_interface_ops starpu_interface_matrix_ops;
  610. /** Matrix interface for dense matrices */
  611. struct starpu_matrix_interface
  612. {
  613. enum starpu_data_interface_id id; /**< Identifier of the interface */
  614. uintptr_t ptr; /**< local pointer of the matrix */
  615. uintptr_t dev_handle; /**< device handle of the matrix */
  616. size_t offset; /**< offset in the matrix */
  617. uint32_t nx; /**< number of elements on the x-axis of the matrix */
  618. uint32_t ny; /**< number of elements on the y-axis of the matrix */
  619. uint32_t ld; /**< number of elements between each row of the
  620. matrix. Maybe be equal to starpu_matrix_interface::nx
  621. when there is no padding.
  622. */
  623. size_t elemsize; /**< size of the elements of the matrix */
  624. size_t allocsize; /**< size actually currently allocated */
  625. };
  626. /**
  627. Register the \p nx x \p ny 2D matrix of \p elemsize-byte elements pointed
  628. by \p ptr and initialize \p handle to represent it. \p ld specifies the number
  629. of elements between rows. a value greater than \p nx adds padding, which
  630. can be useful for alignment purposes.
  631. Here an example of how to use the function.
  632. \code{.c}
  633. float *matrix;
  634. starpu_data_handle_t matrix_handle;
  635. matrix = (float*)malloc(width * height * sizeof(float));
  636. starpu_matrix_data_register(&matrix_handle, STARPU_MAIN_RAM, (uintptr_t)matrix, width, width, height, sizeof(float));
  637. \endcode
  638. */
  639. 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);
  640. /**
  641. Similar to starpu_matrix_data_register, but additionally specifies which
  642. allocation size should be used instead of the initial nx*ny*elemsize.
  643. */
  644. 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);
  645. /**
  646. Register into the \p handle that to store data on node \p node it should use the
  647. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  648. (for OpenCL, notably), with \p ld elements between rows.
  649. */
  650. 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);
  651. /**
  652. Return the number of elements on the x-axis of the matrix
  653. designated by \p handle.
  654. */
  655. uint32_t starpu_matrix_get_nx(starpu_data_handle_t handle);
  656. /**
  657. Return the number of elements on the y-axis of the matrix
  658. designated by \p handle.
  659. */
  660. uint32_t starpu_matrix_get_ny(starpu_data_handle_t handle);
  661. /**
  662. Return the number of elements between each row of the matrix
  663. designated by \p handle. Maybe be equal to nx when there is no padding.
  664. */
  665. uint32_t starpu_matrix_get_local_ld(starpu_data_handle_t handle);
  666. /**
  667. Return the local pointer associated with \p handle.
  668. */
  669. uintptr_t starpu_matrix_get_local_ptr(starpu_data_handle_t handle);
  670. /**
  671. Return the size of the elements registered into the matrix
  672. designated by \p handle.
  673. */
  674. size_t starpu_matrix_get_elemsize(starpu_data_handle_t handle);
  675. /**
  676. Return the allocated size of the matrix designated by \p handle.
  677. */
  678. size_t starpu_matrix_get_allocsize(starpu_data_handle_t handle);
  679. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  680. #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.")
  681. #define STARPU_MATRIX_GET_PTR(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ptr) ; })
  682. #define STARPU_MATRIX_GET_DEV_HANDLE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->dev_handle) ; })
  683. #define STARPU_MATRIX_GET_OFFSET(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->offset) ; })
  684. #define STARPU_MATRIX_GET_NX(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->nx) ; })
  685. #define STARPU_MATRIX_GET_NY(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ny) ; })
  686. #define STARPU_MATRIX_GET_LD(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->ld) ; })
  687. #define STARPU_MATRIX_GET_ELEMSIZE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->elemsize) ; })
  688. #define STARPU_MATRIX_GET_ALLOCSIZE(interface) ({ STARPU_MATRIX_CHECK(interface); (((struct starpu_matrix_interface *)(interface))->allocsize) ; })
  689. #else
  690. /**
  691. Return a pointer to the matrix designated by \p interface, valid
  692. on CPUs and CUDA devices only. For OpenCL devices, the device handle
  693. and offset need to be used instead.
  694. */
  695. #define STARPU_MATRIX_GET_PTR(interface) (((struct starpu_matrix_interface *)(interface))->ptr)
  696. /**
  697. Return a device handle for the matrix designated by \p interface,
  698. to be used with OpenCL. The offset returned by
  699. ::STARPU_MATRIX_GET_OFFSET has to be used in
  700. addition to this.
  701. */
  702. #define STARPU_MATRIX_GET_DEV_HANDLE(interface) (((struct starpu_matrix_interface *)(interface))->dev_handle)
  703. /**
  704. Return the offset in the matrix designated by \p interface, to be
  705. used with the device handle.
  706. */
  707. #define STARPU_MATRIX_GET_OFFSET(interface) (((struct starpu_matrix_interface *)(interface))->offset)
  708. /**
  709. Return the number of elements on the x-axis of the matrix
  710. designated by \p interface.
  711. */
  712. #define STARPU_MATRIX_GET_NX(interface) (((struct starpu_matrix_interface *)(interface))->nx)
  713. /**
  714. Return the number of elements on the y-axis of the matrix
  715. designated by \p interface.
  716. */
  717. #define STARPU_MATRIX_GET_NY(interface) (((struct starpu_matrix_interface *)(interface))->ny)
  718. /**
  719. Return the number of elements between each row of the matrix
  720. designated by \p interface. May be equal to nx when there is no padding.
  721. */
  722. #define STARPU_MATRIX_GET_LD(interface) (((struct starpu_matrix_interface *)(interface))->ld)
  723. /**
  724. Return the size of the elements registered into the matrix
  725. designated by \p interface.
  726. */
  727. #define STARPU_MATRIX_GET_ELEMSIZE(interface) (((struct starpu_matrix_interface *)(interface))->elemsize)
  728. /**
  729. Return the allocated size of the matrix designated by \p interface.
  730. */
  731. #define STARPU_MATRIX_GET_ALLOCSIZE(interface) (((struct starpu_matrix_interface *)(interface))->allocsize)
  732. #endif
  733. /**
  734. Set the number of elements on the x-axis of the matrix
  735. designated by \p interface.
  736. */
  737. #define STARPU_MATRIX_SET_NX(interface, newnx) do { \
  738. (((struct starpu_matrix_interface *)(interface))->nx) = (newnx); \
  739. } while (0)
  740. /**
  741. Set the number of elements on the y-axis of the matrix
  742. designated by \p interface.
  743. */
  744. #define STARPU_MATRIX_SET_NY(interface, newny) do { \
  745. (((struct starpu_matrix_interface *)(interface))->ny) = (newny); \
  746. } while(0)
  747. /** @} */
  748. /** @name Accessing COO Data Interfaces
  749. @{
  750. */
  751. extern struct starpu_data_interface_ops starpu_interface_coo_ops;
  752. /** COO Matrices */
  753. struct starpu_coo_interface
  754. {
  755. enum starpu_data_interface_id id; /**< identifier of the interface */
  756. uint32_t *columns; /**< column array of the matrix */
  757. uint32_t *rows; /**< row array of the matrix */
  758. uintptr_t values; /**< values of the matrix */
  759. uint32_t nx; /**< number of elements on the x-axis of the matrix */
  760. uint32_t ny; /**< number of elements on the y-axis of the matrix */
  761. uint32_t n_values; /**< number of values registered in the matrix */
  762. size_t elemsize; /**< size of the elements of the matrix */
  763. };
  764. /**
  765. Register the \p nx x \p ny 2D matrix given in the COO format, using the
  766. \p columns, \p rows, \p values arrays, which must have \p n_values elements of
  767. size \p elemsize. Initialize \p handleptr.
  768. */
  769. 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);
  770. /**
  771. Return a pointer to the column array of the matrix designated
  772. by \p interface.
  773. */
  774. #define STARPU_COO_GET_COLUMNS(interface) (((struct starpu_coo_interface *)(interface))->columns)
  775. /**
  776. Return a device handle for the column array of the matrix
  777. designated by \p interface, to be used with OpenCL. The offset
  778. returned by ::STARPU_COO_GET_OFFSET has to be used in addition to
  779. this.
  780. */
  781. #define STARPU_COO_GET_COLUMNS_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->columns)
  782. /**
  783. Return a pointer to the rows array of the matrix designated by
  784. \p interface.
  785. */
  786. #define STARPU_COO_GET_ROWS(interface) (((struct starpu_coo_interface *)(interface))->rows)
  787. /**
  788. Return a device handle for the row array of the matrix
  789. designated by \p interface, to be used on OpenCL. The offset returned
  790. by ::STARPU_COO_GET_OFFSET has to be used in addition to this.
  791. */
  792. #define STARPU_COO_GET_ROWS_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->rows)
  793. /**
  794. Return a pointer to the values array of the matrix designated
  795. by \p interface.
  796. */
  797. #define STARPU_COO_GET_VALUES(interface) (((struct starpu_coo_interface *)(interface))->values)
  798. /**
  799. Return a device handle for the value array of the matrix
  800. designated by \p interface, to be used on OpenCL. The offset returned
  801. by ::STARPU_COO_GET_OFFSET has to be used in addition to this.
  802. */
  803. #define STARPU_COO_GET_VALUES_DEV_HANDLE(interface) (((struct starpu_coo_interface *)(interface))->values)
  804. /**
  805. Return the offset in the arrays of the COO matrix designated by
  806. \p interface.
  807. */
  808. #define STARPU_COO_GET_OFFSET 0
  809. /**
  810. Return the number of elements on the x-axis of the matrix
  811. designated by \p interface.
  812. */
  813. #define STARPU_COO_GET_NX(interface) (((struct starpu_coo_interface *)(interface))->nx)
  814. /**
  815. Return the number of elements on the y-axis of the matrix
  816. designated by \p interface.
  817. */
  818. #define STARPU_COO_GET_NY(interface) (((struct starpu_coo_interface *)(interface))->ny)
  819. /**
  820. Return the number of values registered in the matrix designated
  821. by \p interface.
  822. */
  823. #define STARPU_COO_GET_NVALUES(interface) (((struct starpu_coo_interface *)(interface))->n_values)
  824. /**
  825. Return the size of the elements registered into the matrix
  826. designated by \p interface.
  827. */
  828. #define STARPU_COO_GET_ELEMSIZE(interface) (((struct starpu_coo_interface *)(interface))->elemsize)
  829. /** @} */
  830. /** @name Block Data Interface
  831. @{
  832. */
  833. extern struct starpu_data_interface_ops starpu_interface_block_ops;
  834. /* TODO: rename to 3dmatrix? */
  835. /* TODO: add allocsize support */
  836. /** Block interface for 3D dense blocks */
  837. struct starpu_block_interface
  838. {
  839. enum starpu_data_interface_id id; /**< identifier of the interface */
  840. uintptr_t ptr; /**< local pointer of the block */
  841. uintptr_t dev_handle; /**< device handle of the block. */
  842. size_t offset; /**< offset in the block. */
  843. uint32_t nx; /**< number of elements on the x-axis of the block. */
  844. uint32_t ny; /**< number of elements on the y-axis of the block. */
  845. uint32_t nz; /**< number of elements on the z-axis of the block. */
  846. uint32_t ldy; /**< number of elements between two lines */
  847. uint32_t ldz; /**< number of elements between two planes */
  848. size_t elemsize; /**< size of the elements of the block. */
  849. };
  850. /**
  851. Register the \p nx x \p ny x \p nz 3D matrix of \p elemsize byte elements
  852. pointed by \p ptr and initialize \p handle to represent it. Again, \p ldy and
  853. \p ldz specify the number of elements between rows and between z planes.
  854. Here an example of how to use the function.
  855. \code{.c}
  856. float *block;
  857. starpu_data_handle_t block_handle;
  858. block = (float*)malloc(nx*ny*nz*sizeof(float));
  859. starpu_block_data_register(&block_handle, STARPU_MAIN_RAM, (uintptr_t)block, nx, nx*ny, nx, ny, nz, sizeof(float));
  860. \endcode
  861. */
  862. 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);
  863. /**
  864. Register into the \p handle that to store data on node \p node it should use the
  865. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  866. (for OpenCL, notably), with \p ldy elements between rows and \p ldz
  867. elements between z planes.
  868. */
  869. 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);
  870. /**
  871. Return the number of elements on the x-axis of the block
  872. designated by \p handle.
  873. */
  874. uint32_t starpu_block_get_nx(starpu_data_handle_t handle);
  875. /**
  876. Return the number of elements on the y-axis of the block
  877. designated by \p handle.
  878. */
  879. uint32_t starpu_block_get_ny(starpu_data_handle_t handle);
  880. /**
  881. Return the number of elements on the z-axis of the block
  882. designated by \p handle.
  883. */
  884. uint32_t starpu_block_get_nz(starpu_data_handle_t handle);
  885. /**
  886. Return the number of elements between each row of the block
  887. designated by \p handle, in the format of the current memory node.
  888. */
  889. uint32_t starpu_block_get_local_ldy(starpu_data_handle_t handle);
  890. /**
  891. Return the number of elements between each z plane of the block
  892. designated by \p handle, in the format of the current memory node.
  893. */
  894. uint32_t starpu_block_get_local_ldz(starpu_data_handle_t handle);
  895. /**
  896. Return the local pointer associated with \p handle.
  897. */
  898. uintptr_t starpu_block_get_local_ptr(starpu_data_handle_t handle);
  899. /**
  900. Return the size of the elements of the block designated by
  901. \p handle.
  902. */
  903. size_t starpu_block_get_elemsize(starpu_data_handle_t handle);
  904. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  905. #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.")
  906. #define STARPU_BLOCK_GET_PTR(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ptr) ; })
  907. #define STARPU_BLOCK_GET_DEV_HANDLE(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->dev_handle) ; })
  908. #define STARPU_BLOCK_GET_OFFSET(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->offset) ; })
  909. #define STARPU_BLOCK_GET_NX(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->nx) ; })
  910. #define STARPU_BLOCK_GET_NY(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ny) ; })
  911. #define STARPU_BLOCK_GET_NZ(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->nz) ; })
  912. #define STARPU_BLOCK_GET_LDY(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ldy) ; })
  913. #define STARPU_BLOCK_GET_LDZ(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->ldz) ; })
  914. #define STARPU_BLOCK_GET_ELEMSIZE(interface) ({ STARPU_BLOCK_CHECK(interface); (((struct starpu_block_interface *)(interface))->elemsize) ; })
  915. #else
  916. /**
  917. Return a pointer to the block designated by \p interface.
  918. */
  919. #define STARPU_BLOCK_GET_PTR(interface) (((struct starpu_block_interface *)(interface))->ptr)
  920. /**
  921. Return a device handle for the block designated by \p interface,
  922. to be used on OpenCL. The offset returned by
  923. ::STARPU_BLOCK_GET_OFFSET has to be used in
  924. addition to this.
  925. */
  926. #define STARPU_BLOCK_GET_DEV_HANDLE(interface) (((struct starpu_block_interface *)(interface))->dev_handle)
  927. /**
  928. Return the offset in the block designated by \p interface, to be
  929. used with the device handle.
  930. */
  931. #define STARPU_BLOCK_GET_OFFSET(interface) (((struct starpu_block_interface *)(interface))->offset)
  932. /**
  933. Return the number of elements on the x-axis of the block
  934. designated by \p interface.
  935. */
  936. #define STARPU_BLOCK_GET_NX(interface) (((struct starpu_block_interface *)(interface))->nx)
  937. /**
  938. Return the number of elements on the y-axis of the block
  939. designated by \p interface.
  940. */
  941. #define STARPU_BLOCK_GET_NY(interface) (((struct starpu_block_interface *)(interface))->ny)
  942. /**
  943. Return the number of elements on the z-axis of the block
  944. designated by \p interface.
  945. */
  946. #define STARPU_BLOCK_GET_NZ(interface) (((struct starpu_block_interface *)(interface))->nz)
  947. /**
  948. Return the number of elements between each row of the block
  949. designated by \p interface. May be equal to nx when there is no padding.
  950. */
  951. #define STARPU_BLOCK_GET_LDY(interface) (((struct starpu_block_interface *)(interface))->ldy)
  952. /**
  953. Return the number of elements between each z plane of the block
  954. designated by \p interface. May be equal to nx*ny when there is no
  955. padding.
  956. */
  957. #define STARPU_BLOCK_GET_LDZ(interface) (((struct starpu_block_interface *)(interface))->ldz)
  958. /**
  959. Return the size of the elements of the block designated by
  960. \p interface.
  961. */
  962. #define STARPU_BLOCK_GET_ELEMSIZE(interface) (((struct starpu_block_interface *)(interface))->elemsize)
  963. #endif
  964. /** @} */
  965. /** @name Vector Data Interface
  966. @{
  967. */
  968. extern struct starpu_data_interface_ops starpu_interface_vector_ops;
  969. /**
  970. */
  971. /* TODO: add allocsize support */
  972. struct starpu_vector_interface
  973. {
  974. enum starpu_data_interface_id id; /**< Identifier of the interface */
  975. uintptr_t ptr; /**< local pointer of the vector */
  976. uintptr_t dev_handle; /**< device handle of the vector. */
  977. size_t offset; /**< offset in the vector */
  978. uint32_t nx; /**< number of elements on the x-axis of the vector */
  979. size_t elemsize; /**< size of the elements of the vector */
  980. uint32_t slice_base; /**< vector slice base, used by the StarPU OpenMP runtime support */
  981. };
  982. /**
  983. Register the \p nx \p elemsize-byte elements pointed to by \p ptr and initialize \p handle to represent it.
  984. Here an example of how to use the function.
  985. \code{.c}
  986. float vector[NX];
  987. starpu_data_handle_t vector_handle;
  988. starpu_vector_data_register(&vector_handle, STARPU_MAIN_RAM, (uintptr_t)vector, NX, sizeof(vector[0]));
  989. \endcode
  990. */
  991. void starpu_vector_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, uint32_t nx, size_t elemsize);
  992. /**
  993. Register into the \p handle that to store data on node \p node it should use the
  994. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  995. (for OpenCL, notably)
  996. */
  997. void starpu_vector_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset);
  998. /**
  999. Return the number of elements registered into the array designated by \p handle.
  1000. */
  1001. uint32_t starpu_vector_get_nx(starpu_data_handle_t handle);
  1002. /**
  1003. Return the size of each element of the array designated by \p handle.
  1004. */
  1005. size_t starpu_vector_get_elemsize(starpu_data_handle_t handle);
  1006. /**
  1007. Return the local pointer associated with \p handle.
  1008. */
  1009. uintptr_t starpu_vector_get_local_ptr(starpu_data_handle_t handle);
  1010. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  1011. #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.")
  1012. #define STARPU_VECTOR_GET_PTR(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->ptr); })
  1013. #define STARPU_VECTOR_GET_DEV_HANDLE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->dev_handle); })
  1014. #define STARPU_VECTOR_GET_OFFSET(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->offset); })
  1015. #define STARPU_VECTOR_GET_NX(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->nx); })
  1016. #define STARPU_VECTOR_GET_ELEMSIZE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->elemsize); })
  1017. #define STARPU_VECTOR_GET_SLICE_BASE(interface) ({ STARPU_VECTOR_CHECK(interface); (((struct starpu_vector_interface *)(interface))->slice_base); })
  1018. #else
  1019. /**
  1020. Return a pointer to the array designated by \p interface, valid on
  1021. CPUs and CUDA only. For OpenCL, the device handle and offset need to
  1022. be used instead.
  1023. */
  1024. #define STARPU_VECTOR_GET_PTR(interface) (((struct starpu_vector_interface *)(interface))->ptr)
  1025. /**
  1026. Return a device handle for the array designated by \p interface,
  1027. to be used with OpenCL. the offset returned by ::STARPU_VECTOR_GET_OFFSET has to be used in
  1028. addition to this.
  1029. */
  1030. #define STARPU_VECTOR_GET_DEV_HANDLE(interface) (((struct starpu_vector_interface *)(interface))->dev_handle)
  1031. /**
  1032. Return the offset in the array designated by \p interface, to be
  1033. used with the device handle.
  1034. */
  1035. #define STARPU_VECTOR_GET_OFFSET(interface) (((struct starpu_vector_interface *)(interface))->offset)
  1036. /**
  1037. Return the number of elements registered into the array
  1038. designated by \p interface.
  1039. */
  1040. #define STARPU_VECTOR_GET_NX(interface) (((struct starpu_vector_interface *)(interface))->nx)
  1041. /**
  1042. Return the size of each element of the array designated by
  1043. \p interface.
  1044. */
  1045. #define STARPU_VECTOR_GET_ELEMSIZE(interface) (((struct starpu_vector_interface *)(interface))->elemsize)
  1046. /**
  1047. Return the OpenMP slice base annotation of each element of the array designated by
  1048. \p interface.
  1049. */
  1050. #define STARPU_VECTOR_GET_SLICE_BASE(interface) (((struct starpu_vector_interface *)(interface))->slice_base)
  1051. #endif
  1052. /** @} */
  1053. /** @name Variable Data Interface
  1054. @{
  1055. */
  1056. extern struct starpu_data_interface_ops starpu_interface_variable_ops;
  1057. /**
  1058. Variable interface for a single data (not a vector, a matrix, a list,
  1059. ...)
  1060. */
  1061. struct starpu_variable_interface
  1062. {
  1063. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1064. uintptr_t ptr; /**< local pointer of the variable */
  1065. uintptr_t dev_handle; /**< device handle of the variable. */
  1066. size_t offset; /**< offset in the variable */
  1067. size_t elemsize; /**< size of the variable */
  1068. };
  1069. /**
  1070. Register the \p size byte element pointed to by \p ptr, which is
  1071. typically a scalar, and initialize \p handle to represent this data item.
  1072. Here an example of how to use the function.
  1073. \code{.c}
  1074. float var = 42.0;
  1075. starpu_data_handle_t var_handle;
  1076. starpu_variable_data_register(&var_handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  1077. \endcode
  1078. */
  1079. void starpu_variable_data_register(starpu_data_handle_t *handle, int home_node, uintptr_t ptr, size_t size);
  1080. /**
  1081. Register into the \p handle that to store data on node \p node it should use the
  1082. buffer located at \p ptr, or device handle \p dev_handle and offset \p offset
  1083. (for OpenCL, notably)
  1084. */
  1085. void starpu_variable_ptr_register(starpu_data_handle_t handle, unsigned node, uintptr_t ptr, uintptr_t dev_handle, size_t offset);
  1086. /**
  1087. Return the size of the variable designated by \p handle.
  1088. */
  1089. size_t starpu_variable_get_elemsize(starpu_data_handle_t handle);
  1090. /**
  1091. Return a pointer to the variable designated by \p handle.
  1092. */
  1093. uintptr_t starpu_variable_get_local_ptr(starpu_data_handle_t handle);
  1094. #if defined(STARPU_HAVE_STATEMENT_EXPRESSIONS) && defined(STARPU_DEBUG)
  1095. #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.")
  1096. #define STARPU_VARIABLE_GET_PTR(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->ptr) ; })
  1097. #define STARPU_VARIABLE_GET_OFFSET(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->offset) ; })
  1098. #define STARPU_VARIABLE_GET_ELEMSIZE(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->elemsize) ; })
  1099. #define STARPU_VARIABLE_GET_DEV_HANDLE(interface) ({ STARPU_VARIABLE_CHECK(interface); (((struct starpu_variable_interface *)(interface))->ptr) ; })
  1100. #else
  1101. /**
  1102. Return a pointer to the variable designated by \p interface.
  1103. */
  1104. #define STARPU_VARIABLE_GET_PTR(interface) (((struct starpu_variable_interface *)(interface))->ptr)
  1105. /**
  1106. Return the offset in the variable designated by \p interface, to
  1107. be used with the device handle.
  1108. */
  1109. #define STARPU_VARIABLE_GET_OFFSET(interface) (((struct starpu_variable_interface *)(interface))->offset)
  1110. /**
  1111. Return the size of the variable designated by \p interface.
  1112. */
  1113. #define STARPU_VARIABLE_GET_ELEMSIZE(interface) (((struct starpu_variable_interface *)(interface))->elemsize)
  1114. /**
  1115. Return a device handle for the variable designated by
  1116. \p interface, to be used with OpenCL. The offset returned by
  1117. ::STARPU_VARIABLE_GET_OFFSET has to be
  1118. used in addition to this.
  1119. */
  1120. #define STARPU_VARIABLE_GET_DEV_HANDLE(interface) (((struct starpu_variable_interface *)(interface))->ptr)
  1121. #endif
  1122. /** @} */
  1123. /** @name Void Data Interface
  1124. @{
  1125. */
  1126. extern struct starpu_data_interface_ops starpu_interface_void_ops;
  1127. /**
  1128. Register a void interface. There is no data really associated
  1129. to that interface, but it may be used as a synchronization mechanism.
  1130. It also permits to express an abstract piece of data that is managed
  1131. by the application internally: this makes it possible to forbid the
  1132. concurrent execution of different tasks accessing the same <c>void</c>
  1133. data in read-write concurrently.
  1134. */
  1135. void starpu_void_data_register(starpu_data_handle_t *handle);
  1136. /** @} */
  1137. /** @name CSR Data Interface
  1138. @{
  1139. */
  1140. extern struct starpu_data_interface_ops starpu_interface_csr_ops;
  1141. /**
  1142. CSR interface for sparse matrices (compressed sparse row
  1143. representation)
  1144. */
  1145. struct starpu_csr_interface
  1146. {
  1147. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1148. uint32_t nnz; /**< number of non-zero entries */
  1149. uint32_t nrow; /**< number of rows */
  1150. uintptr_t nzval; /**< non-zero values */
  1151. uint32_t *colind; /**< position of non-zero entries on the row */
  1152. uint32_t *rowptr; /**< index (in nzval) of the first entry of the row */
  1153. uint32_t firstentry; /**< k for k-based indexing (0 or 1 usually). also useful when partitionning the matrix. */
  1154. size_t elemsize; /**< size of the elements of the matrix */
  1155. };
  1156. /**
  1157. Register a CSR (Compressed Sparse Row Representation) sparse matrix.
  1158. */
  1159. 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);
  1160. /**
  1161. Return the number of non-zero values in the matrix designated
  1162. by \p handle.
  1163. */
  1164. uint32_t starpu_csr_get_nnz(starpu_data_handle_t handle);
  1165. /**
  1166. Return the size of the row pointer array of the matrix
  1167. designated by \p handle.
  1168. */
  1169. uint32_t starpu_csr_get_nrow(starpu_data_handle_t handle);
  1170. /**
  1171. Return the index at which all arrays (the column indexes, the
  1172. row pointers...) of the matrix designated by \p handle.
  1173. */
  1174. uint32_t starpu_csr_get_firstentry(starpu_data_handle_t handle);
  1175. /**
  1176. Return a local pointer to the non-zero values of the matrix
  1177. designated by \p handle.
  1178. */
  1179. uintptr_t starpu_csr_get_local_nzval(starpu_data_handle_t handle);
  1180. /**
  1181. Return a local pointer to the column index of the matrix
  1182. designated by \p handle.
  1183. */
  1184. uint32_t *starpu_csr_get_local_colind(starpu_data_handle_t handle);
  1185. /**
  1186. Return a local pointer to the row pointer array of the matrix
  1187. designated by \p handle.
  1188. */
  1189. uint32_t *starpu_csr_get_local_rowptr(starpu_data_handle_t handle);
  1190. /**
  1191. Return the size of the elements registered into the matrix
  1192. designated by \p handle.
  1193. */
  1194. size_t starpu_csr_get_elemsize(starpu_data_handle_t handle);
  1195. /**
  1196. Return the number of non-zero values in the matrix designated
  1197. by \p interface.
  1198. */
  1199. #define STARPU_CSR_GET_NNZ(interface) (((struct starpu_csr_interface *)(interface))->nnz)
  1200. /**
  1201. Return the size of the row pointer array of the matrix
  1202. designated by \p interface.
  1203. */
  1204. #define STARPU_CSR_GET_NROW(interface) (((struct starpu_csr_interface *)(interface))->nrow)
  1205. /**
  1206. Return a pointer to the non-zero values of the matrix
  1207. designated by \p interface.
  1208. */
  1209. #define STARPU_CSR_GET_NZVAL(interface) (((struct starpu_csr_interface *)(interface))->nzval)
  1210. /**
  1211. Return a device handle for the array of non-zero values in the
  1212. matrix designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET
  1213. has to used in addition to this.
  1214. */
  1215. #define STARPU_CSR_GET_NZVAL_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->nnz)
  1216. /**
  1217. Return a pointer to the column index of the matrix designated
  1218. by \p interface.
  1219. */
  1220. #define STARPU_CSR_GET_COLIND(interface) (((struct starpu_csr_interface *)(interface))->colind)
  1221. /**
  1222. Return a device handle for the column index of the matrix
  1223. designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET has to be used in
  1224. addition to this.
  1225. */
  1226. #define STARPU_CSR_GET_COLIND_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->colind)
  1227. /**
  1228. Return a pointer to the row pointer array of the matrix
  1229. designated by \p interface.
  1230. */
  1231. #define STARPU_CSR_GET_ROWPTR(interface) (((struct starpu_csr_interface *)(interface))->rowptr)
  1232. /**
  1233. Return a device handle for the row pointer array of the matrix
  1234. designated by \p interface. The offset returned by ::STARPU_CSR_GET_OFFSET has to be used in
  1235. addition to this.
  1236. */
  1237. #define STARPU_CSR_GET_ROWPTR_DEV_HANDLE(interface) (((struct starpu_csr_interface *)(interface))->rowptr)
  1238. /**
  1239. Return the offset in the arrays (colind, rowptr, nzval) of the
  1240. matrix designated by \p interface, to be used with the device handles.
  1241. */
  1242. #define STARPU_CSR_GET_OFFSET 0
  1243. /**
  1244. Return the index at which all arrays (the column indexes, the
  1245. row pointers...) of the \p interface start.
  1246. */
  1247. #define STARPU_CSR_GET_FIRSTENTRY(interface) (((struct starpu_csr_interface *)(interface))->firstentry)
  1248. /**
  1249. Return the size of the elements registered into the matrix
  1250. designated by \p interface.
  1251. */
  1252. #define STARPU_CSR_GET_ELEMSIZE(interface) (((struct starpu_csr_interface *)(interface))->elemsize)
  1253. /** @} */
  1254. /** @name BCSR Data Interface
  1255. @{
  1256. */
  1257. extern struct starpu_data_interface_ops starpu_interface_bcsr_ops;
  1258. /**
  1259. BCSR interface for sparse matrices (blocked compressed sparse
  1260. row representation)
  1261. */
  1262. struct starpu_bcsr_interface
  1263. {
  1264. enum starpu_data_interface_id id; /**< Identifier of the interface */
  1265. uint32_t nnz; /**< number of non-zero BLOCKS */
  1266. uint32_t nrow; /**< number of rows (in terms of BLOCKS) */
  1267. uintptr_t nzval; /**< non-zero values */
  1268. uint32_t *colind; /**< array of nnz elements, colind[i] is the block-column index for block i in nzval */
  1269. uint32_t *rowptr; /**< array of nrow+1
  1270. * elements, rowptr[i] is
  1271. * the block-index (in
  1272. * nzval) of the first block
  1273. * of row i. By convention,
  1274. * rowptr[nrow] is the
  1275. * number of blocks, this
  1276. * allows an easier access
  1277. * of the matrix's elements
  1278. * for the kernels. */
  1279. uint32_t firstentry; /**< k for k-based indexing (0 or 1 usually). Also useful when partitionning the matrix. */
  1280. uint32_t r; /**< height of the blocks */
  1281. uint32_t c; /**< width of the blocks */
  1282. size_t elemsize; /**< size of the elements of the matrix */
  1283. };
  1284. /**
  1285. This variant of starpu_data_register() uses the BCSR (Blocked
  1286. Compressed Sparse Row Representation) sparse matrix interface.
  1287. Register the sparse matrix made of \p nnz non-zero blocks of elements of
  1288. size \p elemsize stored in \p nzval and initializes \p handle to represent it.
  1289. Blocks have size \p r * \p c. \p nrow is the number of rows (in terms of
  1290. blocks), \p colind is an array of nnz elements, colind[i] is the block-column index for block i in \p nzval,
  1291. \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.
  1292. \p firstentry is the index of the first entry of the given arrays
  1293. (usually 0 or 1).
  1294. Here an example with the following matrix:
  1295. \code | 0 1 0 0 | \endcode
  1296. \code | 2 3 0 0 | \endcode
  1297. \code | 4 5 8 9 | \endcode
  1298. \code | 6 7 10 11 | \endcode
  1299. \code nzval = [0, 1, 2, 3] ++ [4, 5, 6, 7] ++ [8, 9, 10, 11] \endcode
  1300. \code colind = [0, 0, 1] \endcode
  1301. \code rowptr = [0, 1, 3] \endcode
  1302. \code r = c = 2 \endcode
  1303. which translates into the following code
  1304. \code{.c}
  1305. int R = 2; // Size of the blocks
  1306. int C = 2;
  1307. int NROWS = 2;
  1308. int NNZ_BLOCKS = 3; // out of 4
  1309. int NZVAL_SIZE = (R*C*NNZ_BLOCKS);
  1310. int nzval[NZVAL_SIZE] =
  1311. {
  1312. 0, 1, 2, 3, // First block
  1313. 4, 5, 6, 7, // Second block
  1314. 8, 9, 10, 11 // Third block
  1315. };
  1316. uint32_t colind[NNZ_BLOCKS] =
  1317. {
  1318. 0, // block-column index for first block in nzval
  1319. 0, // block-column index for second block in nzval
  1320. 1 // block-column index for third block in nzval
  1321. };
  1322. uint32_t rowptr[NROWS+1] =
  1323. {
  1324. 0, // block-index in nzval of the first block of the first row.
  1325. 1, // block-index in nzval of the first block of the second row.
  1326. NNZ_BLOCKS // number of blocks, to allow an easier element's access for the kernels
  1327. };
  1328. starpu_data_handle_t bcsr_handle;
  1329. starpu_bcsr_data_register(&bcsr_handle,
  1330. STARPU_MAIN_RAM,
  1331. NNZ_BLOCKS,
  1332. NROWS,
  1333. (uintptr_t) nzval,
  1334. colind,
  1335. rowptr,
  1336. 0, // firstentry
  1337. R,
  1338. C,
  1339. sizeof(nzval[0]));
  1340. \endcode
  1341. */
  1342. 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);
  1343. /**
  1344. Return the number of non-zero elements in the matrix designated
  1345. by \p handle.
  1346. */
  1347. uint32_t starpu_bcsr_get_nnz(starpu_data_handle_t handle);
  1348. /**
  1349. Return the number of rows (in terms of blocks of size r*c) in
  1350. the matrix designated by \p handle.
  1351. */
  1352. uint32_t starpu_bcsr_get_nrow(starpu_data_handle_t handle);
  1353. /**
  1354. Return the index at which all arrays (the column indexes, the
  1355. row pointers...) of the matrix desginated by \p handle.
  1356. */
  1357. uint32_t starpu_bcsr_get_firstentry(starpu_data_handle_t handle);
  1358. /**
  1359. Return a pointer to the non-zero values of the matrix
  1360. designated by \p handle.
  1361. */
  1362. uintptr_t starpu_bcsr_get_local_nzval(starpu_data_handle_t handle);
  1363. /**
  1364. Return a pointer to the column index, which holds the positions
  1365. of the non-zero entries in the matrix designated by \p handle.
  1366. */
  1367. uint32_t *starpu_bcsr_get_local_colind(starpu_data_handle_t handle);
  1368. /**
  1369. Return the row pointer array of the matrix designated by
  1370. \p handle.
  1371. */
  1372. uint32_t *starpu_bcsr_get_local_rowptr(starpu_data_handle_t handle);
  1373. /**
  1374. Return the number of rows in a block.
  1375. */
  1376. uint32_t starpu_bcsr_get_r(starpu_data_handle_t handle);
  1377. /**
  1378. Return the number of columns in a block.
  1379. */
  1380. uint32_t starpu_bcsr_get_c(starpu_data_handle_t handle);
  1381. /**
  1382. Return the size of the elements in the matrix designated by
  1383. \p handle.
  1384. */
  1385. size_t starpu_bcsr_get_elemsize(starpu_data_handle_t handle);
  1386. /**
  1387. Return the number of non-zero values in the matrix designated
  1388. by \p interface.
  1389. */
  1390. #define STARPU_BCSR_GET_NNZ(interface) (((struct starpu_bcsr_interface *)(interface))->nnz)
  1391. /**
  1392. Return a pointer to the non-zero values of the matrix
  1393. designated by \p interface.
  1394. */
  1395. #define STARPU_BCSR_GET_NZVAL(interface) (((struct starpu_bcsr_interface *)(interface))->nzval)
  1396. /**
  1397. Return a device handle for the array of non-zero values in the
  1398. matrix designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be
  1399. used in addition to this.
  1400. */
  1401. #define STARPU_BCSR_GET_NZVAL_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->nnz)
  1402. /**
  1403. Return a pointer to the column index of the matrix designated
  1404. by \p interface.
  1405. */
  1406. #define STARPU_BCSR_GET_COLIND(interface) (((struct starpu_bcsr_interface *)(interface))->colind)
  1407. /**
  1408. Return a device handle for the column index of the matrix
  1409. designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be used in
  1410. addition to this.
  1411. */
  1412. #define STARPU_BCSR_GET_COLIND_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->colind)
  1413. /**
  1414. Return a pointer to the row pointer array of the matrix
  1415. designated by \p interface.
  1416. */
  1417. #define STARPU_BCSR_GET_ROWPTR(interface) (((struct starpu_bcsr_interface *)(interface))->rowptr)
  1418. /**
  1419. Return a device handle for the row pointer array of the matrix
  1420. designated by \p interface. The offset returned by ::STARPU_BCSR_GET_OFFSET has to be used in
  1421. addition to this.
  1422. */
  1423. #define STARPU_BCSR_GET_ROWPTR_DEV_HANDLE(interface) (((struct starpu_bcsr_interface *)(interface))->rowptr)
  1424. /**
  1425. Return the offset in the arrays (coling, rowptr, nzval) of the
  1426. matrix designated by \p interface, to be used with the device handles.
  1427. */
  1428. #define STARPU_BCSR_GET_OFFSET 0
  1429. /** @} */
  1430. /** @name Multiformat Data Interface
  1431. @{
  1432. */
  1433. /**
  1434. Multiformat operations
  1435. */
  1436. struct starpu_multiformat_data_interface_ops
  1437. {
  1438. size_t cpu_elemsize; /**< size of each element on CPUs */
  1439. size_t opencl_elemsize; /**< size of each element on OpenCL devices */
  1440. struct starpu_codelet *cpu_to_opencl_cl; /**< pointer to a codelet which converts from CPU to OpenCL */
  1441. struct starpu_codelet *opencl_to_cpu_cl; /**< pointer to a codelet which converts from OpenCL to CPU */
  1442. size_t cuda_elemsize; /**< size of each element on CUDA devices */
  1443. struct starpu_codelet *cpu_to_cuda_cl; /**< pointer to a codelet which converts from CPU to CUDA */
  1444. struct starpu_codelet *cuda_to_cpu_cl; /**< pointer to a codelet which converts from CUDA to CPU */
  1445. size_t mic_elemsize; /**< size of each element on MIC devices */
  1446. struct starpu_codelet *cpu_to_mic_cl; /**< pointer to a codelet which converts from CPU to MIC */
  1447. struct starpu_codelet *mic_to_cpu_cl; /**< pointer to a codelet which converts from MIC to CPU */
  1448. };
  1449. struct starpu_multiformat_interface
  1450. {
  1451. enum starpu_data_interface_id id;
  1452. void *cpu_ptr;
  1453. void *cuda_ptr;
  1454. void *opencl_ptr;
  1455. void *mic_ptr;
  1456. uint32_t nx;
  1457. struct starpu_multiformat_data_interface_ops *ops;
  1458. };
  1459. /**
  1460. Register a piece of data that can be represented in different
  1461. ways, depending upon the processing unit that manipulates it. It
  1462. allows the programmer, for instance, to use an array of structures
  1463. when working on a CPU, and a structure of arrays when working on a
  1464. GPU. \p nobjects is the number of elements in the data. \p format_ops
  1465. describes the format.
  1466. */
  1467. 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);
  1468. /**
  1469. Return the local pointer to the data with CPU format.
  1470. */
  1471. #define STARPU_MULTIFORMAT_GET_CPU_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->cpu_ptr)
  1472. /**
  1473. Return the local pointer to the data with CUDA format.
  1474. */
  1475. #define STARPU_MULTIFORMAT_GET_CUDA_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->cuda_ptr)
  1476. /**
  1477. Return the local pointer to the data with OpenCL format.
  1478. */
  1479. #define STARPU_MULTIFORMAT_GET_OPENCL_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->opencl_ptr)
  1480. /**
  1481. Return the local pointer to the data with MIC format.
  1482. */
  1483. #define STARPU_MULTIFORMAT_GET_MIC_PTR(interface) (((struct starpu_multiformat_interface *)(interface))->mic_ptr)
  1484. /**
  1485. Return the number of elements in the data.
  1486. */
  1487. #define STARPU_MULTIFORMAT_GET_NX(interface) (((struct starpu_multiformat_interface *)(interface))->nx)
  1488. /** @} */
  1489. #ifdef __cplusplus
  1490. }
  1491. #endif
  1492. /** @} */
  1493. #endif /* __STARPU_DATA_INTERFACES_H__ */