vector_interface.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <common/config.h>
  19. #include <datawizard/coherency.h>
  20. #include <datawizard/copy_driver.h>
  21. #include <datawizard/filters.h>
  22. #include <common/hash.h>
  23. #include <starpu_cuda.h>
  24. #include <starpu_opencl.h>
  25. #include <drivers/opencl/driver_opencl.h>
  26. static int copy_ram_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node);
  27. #ifdef STARPU_USE_CUDA
  28. static int copy_ram_to_cuda(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node);
  29. static int copy_cuda_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node);
  30. static int copy_ram_to_cuda_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  31. static int copy_cuda_to_ram_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  32. static int copy_cuda_to_cuda(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  33. static int copy_cuda_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  34. #endif
  35. #ifdef STARPU_USE_OPENCL
  36. static int copy_ram_to_opencl(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node);
  37. static int copy_opencl_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node);
  38. static int copy_opencl_to_opencl(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node);
  39. static int copy_ram_to_opencl_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node, void *_event);
  40. static int copy_opencl_to_ram_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node, void *_event);
  41. #endif
  42. static const struct starpu_data_copy_methods vector_copy_data_methods_s = {
  43. .ram_to_ram = copy_ram_to_ram,
  44. .ram_to_spu = NULL,
  45. #ifdef STARPU_USE_CUDA
  46. .ram_to_cuda = copy_ram_to_cuda,
  47. .cuda_to_ram = copy_cuda_to_ram,
  48. .ram_to_cuda_async = copy_ram_to_cuda_async,
  49. .cuda_to_ram_async = copy_cuda_to_ram_async,
  50. .cuda_to_cuda = copy_cuda_to_cuda,
  51. .cuda_to_cuda_async = copy_cuda_to_cuda_async,
  52. #endif
  53. #ifdef STARPU_USE_OPENCL
  54. .ram_to_opencl = copy_ram_to_opencl,
  55. .opencl_to_ram = copy_opencl_to_ram,
  56. .opencl_to_opencl = copy_opencl_to_opencl,
  57. .ram_to_opencl_async = copy_ram_to_opencl_async,
  58. .opencl_to_ram_async = copy_opencl_to_ram_async,
  59. #endif
  60. .cuda_to_spu = NULL,
  61. .spu_to_ram = NULL,
  62. .spu_to_cuda = NULL,
  63. .spu_to_spu = NULL
  64. };
  65. static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface);
  66. static ssize_t allocate_vector_buffer_on_node(void *data_interface_, uint32_t dst_node);
  67. static void *vector_handle_to_pointer(starpu_data_handle data_handle, uint32_t node);
  68. static void free_vector_buffer_on_node(void *data_interface, uint32_t node);
  69. static size_t vector_interface_get_size(starpu_data_handle handle);
  70. static uint32_t footprint_vector_interface_crc32(starpu_data_handle handle);
  71. static int vector_compare(void *data_interface_a, void *data_interface_b);
  72. static void display_vector_interface(starpu_data_handle handle, FILE *f);
  73. #ifdef STARPU_USE_GORDON
  74. static int convert_vector_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss);
  75. #endif
  76. static struct starpu_data_interface_ops_t interface_vector_ops = {
  77. .register_data_handle = register_vector_handle,
  78. .allocate_data_on_node = allocate_vector_buffer_on_node,
  79. .handle_to_pointer = vector_handle_to_pointer,
  80. .free_data_on_node = free_vector_buffer_on_node,
  81. .copy_methods = &vector_copy_data_methods_s,
  82. .get_size = vector_interface_get_size,
  83. .footprint = footprint_vector_interface_crc32,
  84. .compare = vector_compare,
  85. #ifdef STARPU_USE_GORDON
  86. .convert_to_gordon = convert_vector_to_gordon,
  87. #endif
  88. .interfaceid = STARPU_VECTOR_INTERFACE_ID,
  89. .interface_size = sizeof(starpu_vector_interface_t),
  90. .display = display_vector_interface
  91. };
  92. static void *vector_handle_to_pointer(starpu_data_handle handle, uint32_t node)
  93. {
  94. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  95. starpu_vector_interface_t *vector_interface =
  96. starpu_data_get_interface_on_node(handle, node);
  97. return (void*) vector_interface->ptr;
  98. }
  99. static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)
  100. {
  101. starpu_vector_interface_t *vector_interface = data_interface;
  102. unsigned node;
  103. for (node = 0; node < STARPU_MAXNODES; node++)
  104. {
  105. starpu_vector_interface_t *local_interface =
  106. starpu_data_get_interface_on_node(handle, node);
  107. if (node == home_node) {
  108. local_interface->ptr = vector_interface->ptr;
  109. local_interface->dev_handle = vector_interface->dev_handle;
  110. local_interface->offset = vector_interface->offset;
  111. }
  112. else {
  113. local_interface->ptr = 0;
  114. local_interface->dev_handle = 0;
  115. local_interface->offset = 0;
  116. }
  117. local_interface->nx = vector_interface->nx;
  118. local_interface->elemsize = vector_interface->elemsize;
  119. }
  120. }
  121. #ifdef STARPU_USE_GORDON
  122. int convert_vector_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss)
  123. {
  124. starpu_vector_interface_t *vector_interface = interface;
  125. *ptr = vector_interface->ptr;
  126. (*ss).size = vector_interface->nx * vector_interface->elemsize;
  127. return 0;
  128. }
  129. #endif
  130. /* declare a new data with the vector interface */
  131. void starpu_vector_data_register(starpu_data_handle *handleptr, uint32_t home_node,
  132. uintptr_t ptr, uint32_t nx, size_t elemsize)
  133. {
  134. starpu_vector_interface_t vector = {
  135. .ptr = ptr,
  136. .nx = nx,
  137. .elemsize = elemsize,
  138. .dev_handle = ptr,
  139. .offset = 0
  140. };
  141. starpu_data_register(handleptr, home_node, &vector, &interface_vector_ops);
  142. }
  143. static uint32_t footprint_vector_interface_crc32(starpu_data_handle handle)
  144. {
  145. return _starpu_crc32_be(starpu_vector_get_nx(handle), 0);
  146. }
  147. static int vector_compare(void *data_interface_a, void *data_interface_b)
  148. {
  149. starpu_vector_interface_t *vector_a = data_interface_a;
  150. starpu_vector_interface_t *vector_b = data_interface_b;
  151. /* Two vectors are considered compatible if they have the same size */
  152. return ((vector_a->nx == vector_b->nx)
  153. && (vector_a->elemsize == vector_b->elemsize));
  154. }
  155. static void display_vector_interface(starpu_data_handle handle, FILE *f)
  156. {
  157. starpu_vector_interface_t *vector_interface =
  158. starpu_data_get_interface_on_node(handle, 0);
  159. fprintf(f, "%u\t", vector_interface->nx);
  160. }
  161. static size_t vector_interface_get_size(starpu_data_handle handle)
  162. {
  163. size_t size;
  164. starpu_vector_interface_t *vector_interface =
  165. starpu_data_get_interface_on_node(handle, 0);
  166. size = vector_interface->nx*vector_interface->elemsize;
  167. return size;
  168. }
  169. /* offer an access to the data parameters */
  170. uint32_t starpu_vector_get_nx(starpu_data_handle handle)
  171. {
  172. starpu_vector_interface_t *vector_interface =
  173. starpu_data_get_interface_on_node(handle, 0);
  174. return vector_interface->nx;
  175. }
  176. uintptr_t starpu_vector_get_local_ptr(starpu_data_handle 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. starpu_vector_interface_t *vector_interface =
  182. starpu_data_get_interface_on_node(handle, node);
  183. return vector_interface->ptr;
  184. }
  185. size_t starpu_vector_get_elemsize(starpu_data_handle handle)
  186. {
  187. starpu_vector_interface_t *vector_interface =
  188. starpu_data_get_interface_on_node(handle, 0);
  189. return vector_interface->elemsize;
  190. }
  191. /* memory allocation/deallocation primitives for the vector interface */
  192. /* returns the size of the allocated area */
  193. static ssize_t allocate_vector_buffer_on_node(void *data_interface_, uint32_t dst_node)
  194. {
  195. starpu_vector_interface_t *vector_interface = data_interface_;
  196. unsigned fail = 0;
  197. uintptr_t addr = 0;
  198. ssize_t allocated_memory;
  199. uint32_t nx = vector_interface->nx;
  200. size_t elemsize = vector_interface->elemsize;
  201. starpu_node_kind kind = _starpu_get_node_kind(dst_node);
  202. #ifdef STARPU_USE_CUDA
  203. cudaError_t status;
  204. #endif
  205. switch(kind) {
  206. case STARPU_CPU_RAM:
  207. addr = (uintptr_t)malloc(nx*elemsize);
  208. if (!addr)
  209. fail = 1;
  210. break;
  211. #ifdef STARPU_USE_CUDA
  212. case STARPU_CUDA_RAM:
  213. status = cudaMalloc((void **)&addr, nx*elemsize);
  214. if (!addr || (status != cudaSuccess))
  215. {
  216. if (STARPU_UNLIKELY(status != cudaErrorMemoryAllocation))
  217. STARPU_CUDA_REPORT_ERROR(status);
  218. fail = 1;
  219. }
  220. break;
  221. #endif
  222. #ifdef STARPU_USE_OPENCL
  223. case STARPU_OPENCL_RAM:
  224. {
  225. int ret;
  226. void *ptr;
  227. ret = _starpu_opencl_allocate_memory(&ptr, nx*elemsize, CL_MEM_READ_WRITE);
  228. addr = (uintptr_t)ptr;
  229. if (ret) {
  230. fail = 1;
  231. }
  232. break;
  233. }
  234. #endif
  235. default:
  236. assert(0);
  237. }
  238. if (fail)
  239. return -ENOMEM;
  240. /* allocation succeeded */
  241. allocated_memory = nx*elemsize;
  242. /* update the data properly in consequence */
  243. vector_interface->ptr = addr;
  244. vector_interface->dev_handle = addr;
  245. vector_interface->offset = 0;
  246. return allocated_memory;
  247. }
  248. static void free_vector_buffer_on_node(void *data_interface, uint32_t node)
  249. {
  250. starpu_vector_interface_t *vector_interface = data_interface;
  251. #ifdef STARPU_USE_CUDA
  252. cudaError_t cures;
  253. #endif
  254. starpu_node_kind kind = _starpu_get_node_kind(node);
  255. switch(kind) {
  256. case STARPU_CPU_RAM:
  257. free((void*)vector_interface->ptr);
  258. break;
  259. #ifdef STARPU_USE_CUDA
  260. case STARPU_CUDA_RAM:
  261. cures = cudaFree((void*)vector_interface->ptr);
  262. STARPU_ASSERT(cures == cudaSuccess);
  263. break;
  264. #endif
  265. #ifdef STARPU_USE_OPENCL
  266. case STARPU_OPENCL_RAM:
  267. clReleaseMemObject((void *)vector_interface->ptr);
  268. break;
  269. #endif
  270. default:
  271. assert(0);
  272. }
  273. }
  274. #ifdef STARPU_USE_CUDA
  275. static int copy_cuda_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  276. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind)
  277. {
  278. starpu_vector_interface_t *src_vector = src_interface;
  279. starpu_vector_interface_t *dst_vector = dst_interface;
  280. cudaError_t cures;
  281. cures = cudaMemcpy((char *)dst_vector->ptr, (char *)src_vector->ptr, src_vector->nx*src_vector->elemsize, kind);
  282. if (STARPU_UNLIKELY(cures))
  283. STARPU_CUDA_REPORT_ERROR(cures);
  284. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_vector->nx*src_vector->elemsize);
  285. return 0;
  286. }
  287. #ifdef HAVE_CUDA_MEMCPY_PEER
  288. static int copy_cuda_peer_common(void *src_interface, unsigned src_node,
  289. void *dst_interface, unsigned dst_node,
  290. int is_async, cudaStream_t stream)
  291. {
  292. cudaError_t cures;
  293. starpu_vector_interface_t *src_vector = src_interface;
  294. starpu_vector_interface_t *dst_vector = dst_interface;
  295. size_t length = src_vector->nx*src_vector->elemsize;
  296. int src_dev = starpu_memory_node_to_devid(src_node);
  297. int dst_dev = starpu_memory_node_to_devid(dst_node);
  298. if (is_async)
  299. {
  300. cures = cudaMemcpyPeerAsync((char *)dst_vector->ptr, dst_dev,
  301. (char *)src_vector->ptr, src_dev,
  302. length, stream);
  303. if (!cures)
  304. return -EAGAIN;
  305. }
  306. cures = cudaMemcpyPeer((char *)dst_vector->ptr, dst_dev,
  307. (char *)src_vector->ptr, src_dev, length);
  308. if (STARPU_UNLIKELY(cures))
  309. STARPU_CUDA_REPORT_ERROR(cures);
  310. STARPU_TRACE_DATA_COPY(src_node, dst_node, length);
  311. return 0;
  312. }
  313. #endif
  314. static int copy_cuda_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  315. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  316. {
  317. return copy_cuda_common(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToHost);
  318. }
  319. static int copy_ram_to_cuda(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  320. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  321. {
  322. return copy_cuda_common(src_interface, src_node, dst_interface, dst_node, cudaMemcpyHostToDevice);
  323. }
  324. static int copy_cuda_to_cuda(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  325. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  326. {
  327. if (src_node == dst_node)
  328. {
  329. return copy_cuda_common(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToDevice);
  330. }
  331. else {
  332. #ifdef HAVE_CUDA_MEMCPY_PEER
  333. return copy_cuda_peer_common(src_interface, src_node, dst_interface, dst_node, 0, 0);
  334. #else
  335. /* This is illegal without cudaMemcpyPeer */
  336. STARPU_ABORT();
  337. return 0;
  338. #endif
  339. }
  340. }
  341. static int copy_cuda_async_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  342. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED,
  343. cudaStream_t stream, enum cudaMemcpyKind kind)
  344. {
  345. starpu_vector_interface_t *src_vector = src_interface;
  346. starpu_vector_interface_t *dst_vector = dst_interface;
  347. cudaError_t cures;
  348. cures = cudaMemcpyAsync((char *)dst_vector->ptr, (char *)src_vector->ptr, src_vector->nx*src_vector->elemsize, kind, stream);
  349. if (cures)
  350. {
  351. /* do it in a synchronous fashion */
  352. cures = cudaMemcpy((char *)dst_vector->ptr, (char *)src_vector->ptr, src_vector->nx*src_vector->elemsize, kind);
  353. if (STARPU_UNLIKELY(cures))
  354. STARPU_CUDA_REPORT_ERROR(cures);
  355. return 0;
  356. }
  357. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_vector->nx*src_vector->elemsize);
  358. return -EAGAIN;
  359. }
  360. static int copy_cuda_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)
  361. {
  362. if (src_node == dst_node)
  363. {
  364. return copy_cuda_async_common(src_interface, src_node, dst_interface, dst_node, stream, cudaMemcpyDeviceToDevice);
  365. }
  366. else {
  367. #ifdef HAVE_CUDA_MEMCPY_PEER
  368. return copy_cuda_peer_common(src_interface, src_node, dst_interface, dst_node, 1, stream);
  369. #else
  370. /* This is illegal without cudaMemcpyPeer */
  371. STARPU_ABORT();
  372. return 0;
  373. #endif
  374. }
  375. }
  376. static int copy_cuda_to_ram_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  377. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream)
  378. {
  379. return copy_cuda_async_common(src_interface, src_node, dst_interface, dst_node, stream, cudaMemcpyDeviceToHost);
  380. }
  381. static int copy_ram_to_cuda_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  382. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream)
  383. {
  384. return copy_cuda_async_common(src_interface, src_node, dst_interface, dst_node, stream, cudaMemcpyHostToDevice);
  385. }
  386. #endif // STARPU_USE_CUDA
  387. #ifdef STARPU_USE_OPENCL
  388. static int copy_ram_to_opencl_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  389. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, void *_event)
  390. {
  391. starpu_vector_interface_t *src_vector = src_interface;
  392. starpu_vector_interface_t *dst_vector = dst_interface;
  393. int err, ret;
  394. err = _starpu_opencl_copy_ram_to_opencl_async_sync((void*)src_vector->ptr, (cl_mem)dst_vector->dev_handle,
  395. src_vector->nx*src_vector->elemsize,
  396. dst_vector->offset, (cl_event*)_event, &ret);
  397. if (STARPU_UNLIKELY(err))
  398. STARPU_OPENCL_REPORT_ERROR(err);
  399. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_vector->nx*src_vector->elemsize);
  400. return ret;
  401. }
  402. static int copy_opencl_to_ram_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  403. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, void *_event)
  404. {
  405. starpu_vector_interface_t *src_vector = src_interface;
  406. starpu_vector_interface_t *dst_vector = dst_interface;
  407. int err, ret;
  408. err = _starpu_opencl_copy_opencl_to_ram_async_sync((cl_mem)src_vector->dev_handle, (void*)dst_vector->ptr, src_vector->nx*src_vector->elemsize,
  409. src_vector->offset, (cl_event *)_event, &ret);
  410. if (STARPU_UNLIKELY(err))
  411. STARPU_OPENCL_REPORT_ERROR(err);
  412. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_vector->nx*src_vector->elemsize);
  413. return ret;
  414. }
  415. static int copy_ram_to_opencl(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  416. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  417. {
  418. return copy_ram_to_opencl_async(src_interface, src_node, dst_interface, dst_node, NULL);
  419. }
  420. static int copy_opencl_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  421. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  422. {
  423. return copy_opencl_to_ram_async(src_interface, src_node, dst_interface, dst_node, NULL);
  424. }
  425. static int copy_opencl_to_opencl(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  426. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  427. {
  428. int err;
  429. starpu_vector_interface_t *src_vector = src_interface;
  430. starpu_vector_interface_t *dst_vector = dst_interface;
  431. cl_command_queue cq;
  432. starpu_opencl_get_current_queue(&cq);
  433. size_t size = src_vector->nx*src_vector->elemsize;
  434. err = clEnqueueCopyBuffer(cq, (cl_mem)src_vector->dev_handle, (cl_mem)dst_vector->dev_handle, src_vector->offset, dst_vector->offset, size, 0, NULL, NULL);
  435. if (STARPU_UNLIKELY(err))
  436. STARPU_OPENCL_REPORT_ERROR(err);
  437. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_vector->nx*src_vector->elemsize);
  438. return 0;
  439. }
  440. #endif // STARPU_USE_OPENCL
  441. static int copy_ram_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  442. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  443. {
  444. starpu_vector_interface_t *src_vector = src_interface;
  445. starpu_vector_interface_t *dst_vector = dst_interface;
  446. uint32_t nx = dst_vector->nx;
  447. size_t elemsize = dst_vector->elemsize;
  448. uintptr_t ptr_src = src_vector->ptr;
  449. uintptr_t ptr_dst = dst_vector->ptr;
  450. memcpy((void *)ptr_dst, (void *)ptr_src, nx*elemsize);
  451. STARPU_TRACE_DATA_COPY(src_node, dst_node, nx*elemsize);
  452. return 0;
  453. }