csr_interface.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  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. #include <starpu.h>
  19. #include <common/config.h>
  20. #include <datawizard/coherency.h>
  21. #include <datawizard/copy_driver.h>
  22. #include <datawizard/filters.h>
  23. #include <starpu_hash.h>
  24. #include <starpu_cuda.h>
  25. #include <starpu_opencl.h>
  26. #include <drivers/opencl/driver_opencl.h>
  27. static int copy_ram_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  28. #ifdef STARPU_USE_CUDA
  29. static int copy_ram_to_cuda(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  30. static int copy_cuda_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  31. static int copy_cuda_to_cuda(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  32. static int copy_cuda_to_ram_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  33. static int copy_ram_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  34. static int copy_cuda_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  35. #endif
  36. #ifdef STARPU_USE_OPENCL
  37. static int copy_ram_to_opencl(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  38. static int copy_opencl_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  39. #endif
  40. static struct starpu_data_copy_methods csr_copy_data_methods_s =
  41. {
  42. .ram_to_ram = copy_ram_to_ram,
  43. .ram_to_spu = NULL,
  44. #ifdef STARPU_USE_CUDA
  45. .ram_to_cuda = copy_ram_to_cuda,
  46. .cuda_to_ram = copy_cuda_to_ram,
  47. .cuda_to_cuda = copy_cuda_to_cuda,
  48. .ram_to_cuda_async = copy_ram_to_cuda_async,
  49. .cuda_to_ram_async = copy_cuda_to_ram_async,
  50. .cuda_to_cuda_async = copy_cuda_to_cuda_async,
  51. #endif
  52. #ifdef STARPU_USE_OPENCL
  53. .ram_to_opencl = copy_ram_to_opencl,
  54. .opencl_to_ram = copy_opencl_to_ram,
  55. #endif
  56. .cuda_to_spu = NULL,
  57. .spu_to_ram = NULL,
  58. .spu_to_cuda = NULL,
  59. .spu_to_spu = NULL
  60. };
  61. static void register_csr_handle(starpu_data_handle_t handle, uint32_t home_node, void *data_interface);
  62. static ssize_t allocate_csr_buffer_on_node(void *data_interface_, uint32_t dst_node);
  63. static void free_csr_buffer_on_node(void *data_interface, uint32_t node);
  64. static size_t csr_interface_get_size(starpu_data_handle_t handle);
  65. static int csr_compare(void *data_interface_a, void *data_interface_b);
  66. static uint32_t footprint_csr_interface_crc32(starpu_data_handle_t handle);
  67. static struct starpu_data_interface_ops interface_csr_ops =
  68. {
  69. .register_data_handle = register_csr_handle,
  70. .allocate_data_on_node = allocate_csr_buffer_on_node,
  71. .free_data_on_node = free_csr_buffer_on_node,
  72. .copy_methods = &csr_copy_data_methods_s,
  73. .get_size = csr_interface_get_size,
  74. .interfaceid = STARPU_CSR_INTERFACE_ID,
  75. .interface_size = sizeof(struct starpu_csr_interface),
  76. .footprint = footprint_csr_interface_crc32,
  77. .compare = csr_compare,
  78. };
  79. static void register_csr_handle(starpu_data_handle_t handle, uint32_t home_node, void *data_interface)
  80. {
  81. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *) data_interface;
  82. unsigned node;
  83. for (node = 0; node < STARPU_MAXNODES; node++)
  84. {
  85. struct starpu_csr_interface *local_interface = (struct starpu_csr_interface *)
  86. starpu_data_get_interface_on_node(handle, node);
  87. if (node == home_node)
  88. {
  89. local_interface->nzval = csr_interface->nzval;
  90. local_interface->colind = csr_interface->colind;
  91. }
  92. else
  93. {
  94. local_interface->nzval = 0;
  95. local_interface->colind = NULL;
  96. }
  97. local_interface->rowptr = csr_interface->rowptr;
  98. local_interface->nnz = csr_interface->nnz;
  99. local_interface->nrow = csr_interface->nrow;
  100. local_interface->firstentry = csr_interface->firstentry;
  101. local_interface->elemsize = csr_interface->elemsize;
  102. }
  103. }
  104. /* declare a new data with the BLAS interface */
  105. void starpu_csr_data_register(starpu_data_handle_t *handleptr, uint32_t home_node,
  106. uint32_t nnz, uint32_t nrow, uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize)
  107. {
  108. struct starpu_csr_interface csr_interface =
  109. {
  110. .nnz = nnz,
  111. .nrow = nrow,
  112. .nzval = nzval,
  113. .colind = colind,
  114. .rowptr = rowptr,
  115. .firstentry = firstentry,
  116. .elemsize = elemsize
  117. };
  118. starpu_data_register(handleptr, home_node, &csr_interface, &interface_csr_ops);
  119. }
  120. static uint32_t footprint_csr_interface_crc32(starpu_data_handle_t handle)
  121. {
  122. return starpu_crc32_be(starpu_csr_get_nnz(handle), 0);
  123. }
  124. static int csr_compare(void *data_interface_a, void *data_interface_b)
  125. {
  126. struct starpu_csr_interface *csr_a = (struct starpu_csr_interface *) data_interface_a;
  127. struct starpu_csr_interface *csr_b = (struct starpu_csr_interface *) data_interface_b;
  128. /* Two matricess are considered compatible if they have the same size */
  129. return ((csr_a->nnz == csr_b->nnz)
  130. && (csr_a->nrow == csr_b->nrow)
  131. && (csr_a->elemsize == csr_b->elemsize));
  132. }
  133. /* offer an access to the data parameters */
  134. uint32_t starpu_csr_get_nnz(starpu_data_handle_t handle)
  135. {
  136. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)
  137. starpu_data_get_interface_on_node(handle, 0);
  138. return csr_interface->nnz;
  139. }
  140. uint32_t starpu_csr_get_nrow(starpu_data_handle_t handle)
  141. {
  142. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)
  143. starpu_data_get_interface_on_node(handle, 0);
  144. return csr_interface->nrow;
  145. }
  146. uint32_t starpu_csr_get_firstentry(starpu_data_handle_t handle)
  147. {
  148. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)
  149. starpu_data_get_interface_on_node(handle, 0);
  150. return csr_interface->firstentry;
  151. }
  152. size_t starpu_csr_get_elemsize(starpu_data_handle_t handle)
  153. {
  154. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)
  155. starpu_data_get_interface_on_node(handle, 0);
  156. return csr_interface->elemsize;
  157. }
  158. uintptr_t starpu_csr_get_local_nzval(starpu_data_handle_t handle)
  159. {
  160. unsigned node;
  161. node = _starpu_get_local_memory_node();
  162. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  163. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)
  164. starpu_data_get_interface_on_node(handle, node);
  165. return csr_interface->nzval;
  166. }
  167. uint32_t *starpu_csr_get_local_colind(starpu_data_handle_t handle)
  168. {
  169. unsigned node;
  170. node = _starpu_get_local_memory_node();
  171. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  172. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)
  173. starpu_data_get_interface_on_node(handle, node);
  174. return csr_interface->colind;
  175. }
  176. uint32_t *starpu_csr_get_local_rowptr(starpu_data_handle_t handle)
  177. {
  178. unsigned node;
  179. node = _starpu_get_local_memory_node();
  180. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  181. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)
  182. starpu_data_get_interface_on_node(handle, node);
  183. return csr_interface->rowptr;
  184. }
  185. static size_t csr_interface_get_size(starpu_data_handle_t handle)
  186. {
  187. size_t size;
  188. uint32_t nnz = starpu_csr_get_nnz(handle);
  189. uint32_t nrow = starpu_csr_get_nrow(handle);
  190. size_t elemsize = starpu_csr_get_elemsize(handle);
  191. size = nnz*elemsize + nnz*sizeof(uint32_t) + (nrow+1)*sizeof(uint32_t);
  192. return size;
  193. }
  194. /* memory allocation/deallocation primitives for the BLAS interface */
  195. /* returns the size of the allocated area */
  196. static ssize_t allocate_csr_buffer_on_node(void *data_interface_, uint32_t dst_node)
  197. {
  198. uintptr_t addr_nzval = 0;
  199. uint32_t *addr_colind = NULL, *addr_rowptr = NULL;
  200. ssize_t allocated_memory;
  201. /* we need the 3 arrays to be allocated */
  202. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *) data_interface_;
  203. uint32_t nnz = csr_interface->nnz;
  204. uint32_t nrow = csr_interface->nrow;
  205. size_t elemsize = csr_interface->elemsize;
  206. addr_nzval = starpu_allocate_buffer_on_node(dst_node, nnz*elemsize);
  207. if (!addr_nzval)
  208. goto fail_nzval;
  209. addr_colind = (uint32_t*) starpu_allocate_buffer_on_node(dst_node, nnz*sizeof(uint32_t));
  210. if (!addr_colind)
  211. goto fail_colind;
  212. addr_rowptr = (uint32_t*) starpu_allocate_buffer_on_node(dst_node, (nrow+1)*sizeof(uint32_t));
  213. if (!addr_rowptr)
  214. goto fail_rowptr;
  215. /* allocation succeeded */
  216. allocated_memory =
  217. nnz*elemsize + nnz*sizeof(uint32_t) + (nrow+1)*sizeof(uint32_t);
  218. /* update the data properly in consequence */
  219. csr_interface->nzval = addr_nzval;
  220. csr_interface->colind = addr_colind;
  221. csr_interface->rowptr = addr_rowptr;
  222. return allocated_memory;
  223. fail_rowptr:
  224. starpu_free_buffer_on_node(dst_node, (uintptr_t) addr_colind);
  225. fail_colind:
  226. starpu_free_buffer_on_node(dst_node, addr_nzval);
  227. fail_nzval:
  228. /* allocation failed */
  229. return -ENOMEM;
  230. }
  231. static void free_csr_buffer_on_node(void *data_interface, uint32_t node)
  232. {
  233. struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *) data_interface;
  234. starpu_free_buffer_on_node(node, csr_interface->nzval);
  235. starpu_free_buffer_on_node(node, (uintptr_t) csr_interface->colind);
  236. starpu_free_buffer_on_node(node, (uintptr_t) csr_interface->rowptr);
  237. }
  238. #ifdef STARPU_USE_CUDA
  239. static int copy_cuda_async_sync(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind, cudaStream_t stream)
  240. {
  241. struct starpu_csr_interface *src_csr = src_interface;
  242. struct starpu_csr_interface *dst_csr = dst_interface;
  243. uint32_t nnz = src_csr->nnz;
  244. uint32_t nrow = src_csr->nrow;
  245. size_t elemsize = src_csr->elemsize;
  246. cudaStream_t sstream = stream;
  247. int ret;
  248. ret = starpu_cuda_copy_async_sync((void *)src_csr->nzval, src_node, (void *)dst_csr->nzval, dst_node, nnz*elemsize, sstream, kind);
  249. if (ret == 0) sstream = NULL;
  250. ret = starpu_cuda_copy_async_sync((void *)src_csr->colind, src_node, (void *)dst_csr->colind, dst_node, nnz*sizeof(uint32_t), sstream, kind);
  251. if (ret == 0) sstream = NULL;
  252. ret = starpu_cuda_copy_async_sync((void *)src_csr->rowptr, src_node, (void *)dst_csr->rowptr, dst_node, (nrow+1)*sizeof(uint32_t), sstream, kind);
  253. _STARPU_TRACE_DATA_COPY(src_node, dst_node, nnz*elemsize + (nnz+nrow+1)*sizeof(uint32_t));
  254. return ret;
  255. }
  256. static int copy_cuda_peer(void *src_interface STARPU_ATTRIBUTE_UNUSED, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface STARPU_ATTRIBUTE_UNUSED, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  257. {
  258. #ifdef HAVE_CUDA_MEMCPY_PEER
  259. struct starpu_csr_interface *src_csr = src_interface;
  260. struct starpu_csr_interface *dst_csr = dst_interface;
  261. uint32_t nnz = src_csr->nnz;
  262. uint32_t nrow = src_csr->nrow;
  263. size_t elemsize = src_csr->elemsize;
  264. int src_dev = _starpu_memory_node_to_devid(src_node);
  265. int dst_dev = _starpu_memory_node_to_devid(dst_node);
  266. cudaError_t cures;
  267. cures = cudaMemcpyPeer((char *)dst_csr->nzval, dst_dev, (char *)src_csr->nzval, src_dev, nnz*elemsize);
  268. if (STARPU_UNLIKELY(cures))
  269. STARPU_CUDA_REPORT_ERROR(cures);
  270. cures = cudaMemcpyPeer((char *)dst_csr->colind, dst_dev, (char *)src_csr->colind, src_dev, nnz*sizeof(uint32_t));
  271. if (STARPU_UNLIKELY(cures))
  272. STARPU_CUDA_REPORT_ERROR(cures);
  273. cures = cudaMemcpyPeer((char *)dst_csr->rowptr, dst_dev, (char *)src_csr->rowptr, src_dev, (nrow+1)*sizeof(uint32_t));
  274. if (STARPU_UNLIKELY(cures))
  275. STARPU_CUDA_REPORT_ERROR(cures);
  276. _STARPU_TRACE_DATA_COPY(src_node, dst_node, nnz*elemsize + (nnz+nrow+1)*sizeof(uint32_t));
  277. return 0;
  278. #else
  279. STARPU_ABORT();
  280. return 0;
  281. #endif
  282. }
  283. static int copy_cuda_peer_async(void *src_interface STARPU_ATTRIBUTE_UNUSED, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  284. void *dst_interface STARPU_ATTRIBUTE_UNUSED, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream STARPU_ATTRIBUTE_UNUSED)
  285. {
  286. #ifdef HAVE_CUDA_MEMCPY_PEER
  287. struct starpu_csr_interface *src_csr = src_interface;
  288. struct starpu_csr_interface *dst_csr = dst_interface;
  289. uint32_t nnz = src_csr->nnz;
  290. uint32_t nrow = src_csr->nrow;
  291. size_t elemsize = src_csr->elemsize;
  292. cudaError_t cures;
  293. int src_dev = _starpu_memory_node_to_devid(src_node);
  294. int dst_dev = _starpu_memory_node_to_devid(dst_node);
  295. int synchronous_fallback = 0;
  296. _STARPU_TRACE_START_DRIVER_COPY_ASYNC(src_node, dst_node);
  297. cures = cudaMemcpyPeerAsync((char *)dst_csr->nzval, dst_dev, (char *)src_csr->nzval, src_dev, nnz*elemsize, stream);
  298. if (cures)
  299. {
  300. synchronous_fallback = 1;
  301. _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
  302. cures = cudaMemcpyPeer((char *)dst_csr->nzval, dst_dev, (char *)src_csr->nzval, src_dev, nnz*elemsize);
  303. if (STARPU_UNLIKELY(cures))
  304. STARPU_CUDA_REPORT_ERROR(cures);
  305. }
  306. if (!synchronous_fallback)
  307. {
  308. cures = cudaMemcpyPeerAsync((char *)dst_csr->colind, dst_dev, (char *)src_csr->colind, src_dev, nnz*sizeof(uint32_t), stream);
  309. }
  310. if (synchronous_fallback || cures != cudaSuccess)
  311. {
  312. synchronous_fallback = 1;
  313. _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
  314. cures = cudaMemcpyPeer((char *)dst_csr->colind, dst_dev, (char *)src_csr->colind, src_dev, nnz*sizeof(uint32_t));
  315. if (STARPU_UNLIKELY(cures))
  316. STARPU_CUDA_REPORT_ERROR(cures);
  317. }
  318. if (!synchronous_fallback)
  319. {
  320. cures = cudaMemcpyPeerAsync((char *)dst_csr->rowptr, dst_dev, (char *)src_csr->rowptr, src_dev, (nrow+1)*sizeof(uint32_t), stream);
  321. }
  322. if (synchronous_fallback || cures != cudaSuccess)
  323. {
  324. synchronous_fallback = 1;
  325. _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
  326. cures = cudaMemcpyPeer((char *)dst_csr->rowptr, dst_dev, (char *)src_csr->rowptr, src_dev, (nrow+1)*sizeof(uint32_t));
  327. if (STARPU_UNLIKELY(cures))
  328. STARPU_CUDA_REPORT_ERROR(cures);
  329. }
  330. if (synchronous_fallback)
  331. {
  332. _STARPU_TRACE_DATA_COPY(src_node, dst_node, nnz*elemsize + (nnz+nrow+1)*sizeof(uint32_t));
  333. return 0;
  334. }
  335. else
  336. {
  337. _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
  338. return -EAGAIN;
  339. }
  340. #else
  341. /* Illegal without Peer tranfers */
  342. STARPU_ABORT();
  343. return 0;
  344. #endif
  345. }
  346. static int copy_cuda_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)
  347. {
  348. return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToHost, NULL);
  349. }
  350. static int copy_ram_to_cuda(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)
  351. {
  352. return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyHostToDevice, NULL);
  353. }
  354. static int copy_cuda_to_cuda(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)
  355. {
  356. if (src_node == dst_node)
  357. return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToDevice, NULL);
  358. else
  359. return copy_cuda_peer(src_interface, src_node, dst_interface, dst_node);
  360. }
  361. static int copy_cuda_to_ram_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)
  362. {
  363. return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToHost, stream);
  364. }
  365. static int copy_ram_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)
  366. {
  367. return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyHostToDevice, stream);
  368. }
  369. static int copy_cuda_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)
  370. {
  371. if (src_node == dst_node)
  372. return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToDevice, stream);
  373. else
  374. return copy_cuda_peer_async(src_interface, src_node, dst_interface, dst_node, stream);
  375. }
  376. #endif // STARPU_USE_CUDA
  377. #ifdef STARPU_USE_OPENCL
  378. static int copy_opencl_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  379. {
  380. struct starpu_csr_interface *src_csr = src_interface;
  381. struct starpu_csr_interface *dst_csr = dst_interface;
  382. uint32_t nnz = src_csr->nnz;
  383. uint32_t nrow = src_csr->nrow;
  384. size_t elemsize = src_csr->elemsize;
  385. int err;
  386. err = starpu_opencl_copy_opencl_to_ram((cl_mem)src_csr->nzval, src_node, (void *)dst_csr->nzval, dst_node, nnz*elemsize, 0, NULL, NULL);
  387. if (STARPU_UNLIKELY(err))
  388. STARPU_OPENCL_REPORT_ERROR(err);
  389. err = starpu_opencl_copy_opencl_to_ram((cl_mem)src_csr->colind, src_node, (void *)dst_csr->colind, dst_node, nnz*sizeof(uint32_t), 0, NULL, NULL);
  390. if (STARPU_UNLIKELY(err))
  391. STARPU_OPENCL_REPORT_ERROR(err);
  392. err = starpu_opencl_copy_opencl_to_ram((cl_mem)src_csr->rowptr, src_node, (void *)dst_csr->rowptr, dst_node, (nrow+1)*sizeof(uint32_t), 0, NULL, NULL);
  393. if (STARPU_UNLIKELY(err))
  394. STARPU_OPENCL_REPORT_ERROR(err);
  395. _STARPU_TRACE_DATA_COPY(src_node, dst_node, nnz*elemsize + (nnz+nrow+1)*sizeof(uint32_t));
  396. return 0;
  397. }
  398. static int copy_ram_to_opencl(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  399. {
  400. struct starpu_csr_interface *src_csr = src_interface;
  401. struct starpu_csr_interface *dst_csr = dst_interface;
  402. uint32_t nnz = src_csr->nnz;
  403. uint32_t nrow = src_csr->nrow;
  404. size_t elemsize = src_csr->elemsize;
  405. int err;
  406. err = starpu_opencl_copy_ram_to_opencl((void *)src_csr->nzval, src_node, (cl_mem)dst_csr->nzval, dst_node, nnz*elemsize, 0, NULL, NULL);
  407. if (STARPU_UNLIKELY(err))
  408. STARPU_OPENCL_REPORT_ERROR(err);
  409. err = starpu_opencl_copy_ram_to_opencl((void *)src_csr->colind, src_node, (cl_mem)dst_csr->colind, dst_node, nnz*sizeof(uint32_t), 0, NULL, NULL);
  410. if (STARPU_UNLIKELY(err))
  411. STARPU_OPENCL_REPORT_ERROR(err);
  412. err = starpu_opencl_copy_ram_to_opencl((void *)src_csr->rowptr, src_node, (cl_mem)dst_csr->rowptr, dst_node, (nrow+1)*sizeof(uint32_t), 0, NULL, NULL);
  413. if (STARPU_UNLIKELY(err))
  414. STARPU_OPENCL_REPORT_ERROR(err);
  415. _STARPU_TRACE_DATA_COPY(src_node, dst_node, nnz*elemsize + (nnz+nrow+1)*sizeof(uint32_t));
  416. return 0;
  417. }
  418. #endif // STARPU_USE_OPENCL
  419. /* as not all platform easily have a BLAS lib installed ... */
  420. static int copy_ram_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  421. {
  422. struct starpu_csr_interface *src_csr = (struct starpu_csr_interface *) src_interface;
  423. struct starpu_csr_interface *dst_csr = (struct starpu_csr_interface *) dst_interface;
  424. uint32_t nnz = src_csr->nnz;
  425. uint32_t nrow = src_csr->nrow;
  426. size_t elemsize = src_csr->elemsize;
  427. memcpy((void *)dst_csr->nzval, (void *)src_csr->nzval, nnz*elemsize);
  428. memcpy((void *)dst_csr->colind, (void *)src_csr->colind, nnz*sizeof(uint32_t));
  429. memcpy((void *)dst_csr->rowptr, (void *)src_csr->rowptr, (nrow+1)*sizeof(uint32_t));
  430. _STARPU_TRACE_DATA_COPY(src_node, dst_node, nnz*elemsize + (nnz+nrow+1)*sizeof(uint32_t));
  431. return 0;
  432. }