copy_driver.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2019 Université de Bordeaux
  4. * Copyright (C) 2011-2013,2016,2017 Inria
  5. * Copyright (C) 2010,2011,2013,2015-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. #include <starpu.h>
  19. #include <common/config.h>
  20. #include <common/utils.h>
  21. #include <core/sched_policy.h>
  22. #include <datawizard/datastats.h>
  23. #include <datawizard/memory_nodes.h>
  24. #include <drivers/disk/driver_disk.h>
  25. #include <drivers/mpi/driver_mpi_sink.h>
  26. #include <drivers/mpi/driver_mpi_source.h>
  27. #include <drivers/mpi/driver_mpi_common.h>
  28. #include <common/fxt.h>
  29. #include "copy_driver.h"
  30. #include "memalloc.h"
  31. #include <starpu_opencl.h>
  32. #include <starpu_cuda.h>
  33. #include <profiling/profiling.h>
  34. #include <core/disk.h>
  35. #ifdef STARPU_SIMGRID
  36. #include <core/simgrid.h>
  37. #endif
  38. void _starpu_wake_all_blocked_workers_on_node(unsigned nodeid)
  39. {
  40. /* wake up all workers on that memory node */
  41. struct _starpu_memory_node_descr * const descr = _starpu_memory_node_get_description();
  42. const int cur_workerid = starpu_worker_get_id();
  43. struct _starpu_worker *cur_worker = cur_workerid>=0?_starpu_get_worker_struct(cur_workerid):NULL;
  44. STARPU_PTHREAD_RWLOCK_RDLOCK(&descr->conditions_rwlock);
  45. unsigned nconds = descr->condition_count[nodeid];
  46. unsigned cond_id;
  47. for (cond_id = 0; cond_id < nconds; cond_id++)
  48. {
  49. struct _starpu_cond_and_worker *condition;
  50. condition = &descr->conditions_attached_to_node[nodeid][cond_id];
  51. if (condition->worker == cur_worker)
  52. {
  53. if (condition->cond == &condition->worker->sched_cond)
  54. {
  55. condition->worker->state_keep_awake = 1;
  56. }
  57. /* No need to wake myself, and I might be called from
  58. * the scheduler with mutex locked, through
  59. * starpu_prefetch_task_input_on_node */
  60. continue;
  61. }
  62. /* wake anybody waiting on that condition */
  63. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&condition->worker->sched_mutex);
  64. if (condition->cond == &condition->worker->sched_cond)
  65. {
  66. condition->worker->state_keep_awake = 1;
  67. }
  68. STARPU_PTHREAD_COND_BROADCAST(condition->cond);
  69. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&condition->worker->sched_mutex);
  70. }
  71. STARPU_PTHREAD_RWLOCK_UNLOCK(&descr->conditions_rwlock);
  72. #ifdef STARPU_SIMGRID
  73. starpu_pthread_queue_broadcast(&_starpu_simgrid_transfer_queue[nodeid]);
  74. #endif
  75. }
  76. void starpu_wake_all_blocked_workers(void)
  77. {
  78. /* workers may be blocked on the various queues' conditions */
  79. struct _starpu_memory_node_descr * const descr = _starpu_memory_node_get_description();
  80. const int cur_workerid = starpu_worker_get_id();
  81. struct _starpu_worker *cur_worker = cur_workerid>=0?_starpu_get_worker_struct(cur_workerid):NULL;
  82. STARPU_PTHREAD_RWLOCK_RDLOCK(&descr->conditions_rwlock);
  83. unsigned nconds = descr->total_condition_count;
  84. unsigned cond_id;
  85. for (cond_id = 0; cond_id < nconds; cond_id++)
  86. {
  87. struct _starpu_cond_and_worker *condition;
  88. condition = &descr->conditions_all[cond_id];
  89. if (condition->worker == cur_worker)
  90. {
  91. if (condition->cond == &condition->worker->sched_cond)
  92. {
  93. condition->worker->state_keep_awake = 1;
  94. }
  95. /* No need to wake myself, and I might be called from
  96. * the scheduler with mutex locked, through
  97. * starpu_prefetch_task_input_on_node */
  98. continue;
  99. }
  100. /* wake anybody waiting on that condition */
  101. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&condition->worker->sched_mutex);
  102. if (condition->cond == &condition->worker->sched_cond)
  103. {
  104. condition->worker->state_keep_awake = 1;
  105. }
  106. STARPU_PTHREAD_COND_BROADCAST(condition->cond);
  107. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&condition->worker->sched_mutex);
  108. }
  109. STARPU_PTHREAD_RWLOCK_UNLOCK(&descr->conditions_rwlock);
  110. #ifdef STARPU_SIMGRID
  111. unsigned workerid, nodeid;
  112. for (workerid = 0; workerid < starpu_worker_get_count(); workerid++)
  113. starpu_pthread_queue_broadcast(&_starpu_simgrid_task_queue[workerid]);
  114. for (nodeid = 0; nodeid < starpu_memory_nodes_get_count(); nodeid++)
  115. starpu_pthread_queue_broadcast(&_starpu_simgrid_transfer_queue[nodeid]);
  116. #endif
  117. }
  118. #ifdef STARPU_USE_FXT
  119. /* we need to identify each communication so that we can match the beginning
  120. * and the end of a communication in the trace, so we use a unique identifier
  121. * per communication */
  122. static unsigned long communication_cnt = 0;
  123. #endif
  124. static int copy_data_1_to_1_generic(starpu_data_handle_t handle,
  125. struct _starpu_data_replicate *src_replicate,
  126. struct _starpu_data_replicate *dst_replicate,
  127. struct _starpu_data_request *req)
  128. {
  129. unsigned src_node = src_replicate->memory_node;
  130. unsigned dst_node = dst_replicate->memory_node;
  131. STARPU_ASSERT(src_replicate->refcnt);
  132. STARPU_ASSERT(dst_replicate->refcnt);
  133. STARPU_ASSERT(src_replicate->allocated);
  134. STARPU_ASSERT(dst_replicate->allocated);
  135. #ifdef STARPU_SIMGRID
  136. if (src_node == STARPU_MAIN_RAM || dst_node == STARPU_MAIN_RAM)
  137. _starpu_simgrid_data_transfer(handle->ops->get_size(handle), src_node, dst_node);
  138. return _starpu_simgrid_transfer(handle->ops->get_size(handle), src_node, dst_node, req);
  139. #else /* !SIMGRID */
  140. int ret = 0;
  141. const struct starpu_data_copy_methods *copy_methods = handle->ops->copy_methods;
  142. enum starpu_node_kind src_kind = starpu_node_get_kind(src_node);
  143. enum starpu_node_kind dst_kind = starpu_node_get_kind(dst_node);
  144. #ifdef STARPU_USE_CUDA
  145. cudaError_t cures;
  146. cudaStream_t stream;
  147. #endif
  148. void *src_interface = src_replicate->data_interface;
  149. void *dst_interface = dst_replicate->data_interface;
  150. #if defined(STARPU_USE_CUDA) && defined(STARPU_HAVE_CUDA_MEMCPY_PEER) && !defined(STARPU_SIMGRID)
  151. if ((src_kind == STARPU_CUDA_RAM) || (dst_kind == STARPU_CUDA_RAM))
  152. {
  153. unsigned devid;
  154. if ((src_kind == STARPU_CUDA_RAM) && (dst_kind == STARPU_CUDA_RAM))
  155. {
  156. /* GPU-GPU transfer, issue it from the destination */
  157. devid = starpu_memory_node_get_devid(dst_node);
  158. }
  159. else
  160. {
  161. unsigned node = (dst_kind == STARPU_CUDA_RAM)?dst_node:src_node;
  162. devid = starpu_memory_node_get_devid(node);
  163. }
  164. starpu_cuda_set_device(devid);
  165. }
  166. #endif
  167. switch (_STARPU_MEMORY_NODE_TUPLE(src_kind,dst_kind))
  168. {
  169. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CPU_RAM):
  170. /* STARPU_CPU_RAM -> STARPU_CPU_RAM */
  171. if (copy_methods->ram_to_ram)
  172. copy_methods->ram_to_ram(src_interface, src_node, dst_interface, dst_node);
  173. else
  174. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, req ? &req->async_channel : NULL);
  175. break;
  176. #ifdef STARPU_USE_CUDA
  177. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CPU_RAM):
  178. /* only the proper CUBLAS thread can initiate this directly ! */
  179. #if !defined(STARPU_HAVE_CUDA_MEMCPY_PEER)
  180. STARPU_ASSERT(starpu_worker_get_local_memory_node() == src_node);
  181. #endif
  182. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_cuda_copy_disabled() ||
  183. !(copy_methods->cuda_to_ram_async || copy_methods->any_to_any))
  184. {
  185. /* this is not associated to a request so it's synchronous */
  186. STARPU_ASSERT(copy_methods->cuda_to_ram || copy_methods->any_to_any);
  187. if (copy_methods->cuda_to_ram)
  188. copy_methods->cuda_to_ram(src_interface, src_node, dst_interface, dst_node);
  189. else
  190. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  191. }
  192. else
  193. {
  194. req->async_channel.type = STARPU_CUDA_RAM;
  195. cures = cudaEventCreateWithFlags(&req->async_channel.event.cuda_event, cudaEventDisableTiming);
  196. if (STARPU_UNLIKELY(cures != cudaSuccess)) STARPU_CUDA_REPORT_ERROR(cures);
  197. stream = starpu_cuda_get_out_transfer_stream(src_node);
  198. if (copy_methods->cuda_to_ram_async)
  199. ret = copy_methods->cuda_to_ram_async(src_interface, src_node, dst_interface, dst_node, stream);
  200. else
  201. {
  202. STARPU_ASSERT(copy_methods->any_to_any);
  203. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  204. }
  205. cures = cudaEventRecord(req->async_channel.event.cuda_event, stream);
  206. if (STARPU_UNLIKELY(cures != cudaSuccess)) STARPU_CUDA_REPORT_ERROR(cures);
  207. }
  208. break;
  209. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CUDA_RAM):
  210. /* STARPU_CPU_RAM -> CUBLAS_RAM */
  211. /* only the proper CUBLAS thread can initiate this ! */
  212. #if !defined(STARPU_HAVE_CUDA_MEMCPY_PEER)
  213. STARPU_ASSERT(starpu_worker_get_local_memory_node() == dst_node);
  214. #endif
  215. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_cuda_copy_disabled() ||
  216. !(copy_methods->ram_to_cuda_async || copy_methods->any_to_any))
  217. {
  218. /* this is not associated to a request so it's synchronous */
  219. STARPU_ASSERT(copy_methods->ram_to_cuda || copy_methods->any_to_any);
  220. if (copy_methods->ram_to_cuda)
  221. copy_methods->ram_to_cuda(src_interface, src_node, dst_interface, dst_node);
  222. else
  223. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  224. }
  225. else
  226. {
  227. req->async_channel.type = STARPU_CUDA_RAM;
  228. cures = cudaEventCreateWithFlags(&req->async_channel.event.cuda_event, cudaEventDisableTiming);
  229. if (STARPU_UNLIKELY(cures != cudaSuccess))
  230. STARPU_CUDA_REPORT_ERROR(cures);
  231. stream = starpu_cuda_get_in_transfer_stream(dst_node);
  232. if (copy_methods->ram_to_cuda_async)
  233. ret = copy_methods->ram_to_cuda_async(src_interface, src_node, dst_interface, dst_node, stream);
  234. else
  235. {
  236. STARPU_ASSERT(copy_methods->any_to_any);
  237. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  238. }
  239. cures = cudaEventRecord(req->async_channel.event.cuda_event, stream);
  240. if (STARPU_UNLIKELY(cures != cudaSuccess))
  241. STARPU_CUDA_REPORT_ERROR(cures);
  242. }
  243. break;
  244. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CUDA_RAM):
  245. /* CUDA - CUDA transfer */
  246. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_cuda_copy_disabled() ||
  247. !(copy_methods->cuda_to_cuda_async || copy_methods->any_to_any))
  248. {
  249. STARPU_ASSERT(copy_methods->cuda_to_cuda || copy_methods->any_to_any);
  250. /* this is not associated to a request so it's synchronous */
  251. if (copy_methods->cuda_to_cuda)
  252. copy_methods->cuda_to_cuda(src_interface, src_node, dst_interface, dst_node);
  253. else
  254. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  255. }
  256. else
  257. {
  258. req->async_channel.type = STARPU_CUDA_RAM;
  259. cures = cudaEventCreateWithFlags(&req->async_channel.event.cuda_event, cudaEventDisableTiming);
  260. if (STARPU_UNLIKELY(cures != cudaSuccess)) STARPU_CUDA_REPORT_ERROR(cures);
  261. stream = starpu_cuda_get_peer_transfer_stream(src_node, dst_node);
  262. if (copy_methods->cuda_to_cuda_async)
  263. ret = copy_methods->cuda_to_cuda_async(src_interface, src_node, dst_interface, dst_node, stream);
  264. else
  265. {
  266. STARPU_ASSERT(copy_methods->any_to_any);
  267. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  268. }
  269. cures = cudaEventRecord(req->async_channel.event.cuda_event, stream);
  270. if (STARPU_UNLIKELY(cures != cudaSuccess)) STARPU_CUDA_REPORT_ERROR(cures);
  271. }
  272. break;
  273. #endif
  274. #ifdef STARPU_USE_OPENCL
  275. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_CPU_RAM):
  276. /* OpenCL -> RAM */
  277. STARPU_ASSERT(starpu_worker_get_local_memory_node() == src_node);
  278. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_opencl_copy_disabled() ||
  279. !(copy_methods->opencl_to_ram_async || copy_methods->any_to_any))
  280. {
  281. STARPU_ASSERT(copy_methods->opencl_to_ram || copy_methods->any_to_any);
  282. /* this is not associated to a request so it's synchronous */
  283. if (copy_methods->opencl_to_ram)
  284. copy_methods->opencl_to_ram(src_interface, src_node, dst_interface, dst_node);
  285. else
  286. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  287. }
  288. else
  289. {
  290. req->async_channel.type = STARPU_OPENCL_RAM;
  291. if (copy_methods->opencl_to_ram_async)
  292. ret = copy_methods->opencl_to_ram_async(src_interface, src_node, dst_interface, dst_node, &(req->async_channel.event.opencl_event));
  293. else
  294. {
  295. STARPU_ASSERT(copy_methods->any_to_any);
  296. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  297. }
  298. }
  299. break;
  300. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_OPENCL_RAM):
  301. /* STARPU_CPU_RAM -> STARPU_OPENCL_RAM */
  302. STARPU_ASSERT(starpu_worker_get_local_memory_node() == dst_node);
  303. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_opencl_copy_disabled() ||
  304. !(copy_methods->ram_to_opencl_async || copy_methods->any_to_any))
  305. {
  306. STARPU_ASSERT(copy_methods->ram_to_opencl || copy_methods->any_to_any);
  307. /* this is not associated to a request so it's synchronous */
  308. if (copy_methods->ram_to_opencl)
  309. copy_methods->ram_to_opencl(src_interface, src_node, dst_interface, dst_node);
  310. else
  311. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  312. }
  313. else
  314. {
  315. req->async_channel.type = STARPU_OPENCL_RAM;
  316. if (copy_methods->ram_to_opencl_async)
  317. ret = copy_methods->ram_to_opencl_async(src_interface, src_node, dst_interface, dst_node, &(req->async_channel.event.opencl_event));
  318. else
  319. {
  320. STARPU_ASSERT(copy_methods->any_to_any);
  321. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  322. }
  323. }
  324. break;
  325. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_OPENCL_RAM):
  326. /* STARPU_OPENCL_RAM -> STARPU_OPENCL_RAM */
  327. STARPU_ASSERT(starpu_worker_get_local_memory_node() == dst_node || starpu_worker_get_local_memory_node() == src_node);
  328. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_opencl_copy_disabled() ||
  329. !(copy_methods->opencl_to_opencl_async || copy_methods->any_to_any))
  330. {
  331. STARPU_ASSERT(copy_methods->opencl_to_opencl || copy_methods->any_to_any);
  332. /* this is not associated to a request so it's synchronous */
  333. if (copy_methods->opencl_to_opencl)
  334. copy_methods->opencl_to_opencl(src_interface, src_node, dst_interface, dst_node);
  335. else
  336. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  337. }
  338. else
  339. {
  340. req->async_channel.type = STARPU_OPENCL_RAM;
  341. if (copy_methods->opencl_to_opencl_async)
  342. ret = copy_methods->opencl_to_opencl_async(src_interface, src_node, dst_interface, dst_node, &(req->async_channel.event.opencl_event));
  343. else
  344. {
  345. STARPU_ASSERT(copy_methods->any_to_any);
  346. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  347. }
  348. }
  349. break;
  350. #endif
  351. #ifdef STARPU_USE_MIC
  352. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_MIC_RAM):
  353. /* RAM -> MIC */
  354. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_mic_copy_disabled() ||
  355. !(copy_methods->ram_to_mic_async || copy_methods->any_to_any))
  356. {
  357. /* this is not associated to a request so it's synchronous */
  358. STARPU_ASSERT(copy_methods->ram_to_mic || copy_methods->any_to_any);
  359. if (copy_methods->ram_to_mic)
  360. copy_methods->ram_to_mic(src_interface, src_node, dst_interface, dst_node);
  361. else
  362. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  363. }
  364. else
  365. {
  366. req->async_channel.type = STARPU_MIC_RAM;
  367. if (copy_methods->ram_to_mic_async)
  368. ret = copy_methods->ram_to_mic_async(src_interface, src_node, dst_interface, dst_node);
  369. else
  370. {
  371. STARPU_ASSERT(copy_methods->any_to_any);
  372. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  373. }
  374. _starpu_mic_init_event(&(req->async_channel.event.mic_event), dst_node);
  375. }
  376. break;
  377. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MIC_RAM,STARPU_CPU_RAM):
  378. /* MIC -> RAM */
  379. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_mic_copy_disabled() ||
  380. !(copy_methods->mic_to_ram_async || copy_methods->any_to_any))
  381. {
  382. /* this is not associated to a request so it's synchronous */
  383. STARPU_ASSERT(copy_methods->mic_to_ram || copy_methods->any_to_any);
  384. if (copy_methods->mic_to_ram)
  385. copy_methods->mic_to_ram(src_interface, src_node, dst_interface, dst_node);
  386. else
  387. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  388. }
  389. else
  390. {
  391. req->async_channel.type = STARPU_MIC_RAM;
  392. if (copy_methods->mic_to_ram_async)
  393. ret = copy_methods->mic_to_ram_async(src_interface, src_node, dst_interface, dst_node);
  394. else
  395. {
  396. STARPU_ASSERT(copy_methods->any_to_any);
  397. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  398. }
  399. _starpu_mic_init_event(&(req->async_channel.event.mic_event), src_node);
  400. }
  401. break;
  402. /* TODO: MIC -> MIC */
  403. #endif
  404. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  405. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_MPI_MS_RAM):
  406. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_mpi_ms_copy_disabled() ||
  407. !(copy_methods->ram_to_mpi_ms_async || copy_methods->any_to_any))
  408. {
  409. /* this is not associated to a request so it's synchronous */
  410. STARPU_ASSERT(copy_methods->ram_to_mpi_ms || copy_methods->any_to_any);
  411. if (copy_methods->ram_to_mpi_ms)
  412. copy_methods->ram_to_mpi_ms(src_interface, src_node, dst_interface, dst_node);
  413. else
  414. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  415. }
  416. else
  417. {
  418. req->async_channel.type = STARPU_MPI_MS_RAM;
  419. if(copy_methods->ram_to_mpi_ms_async)
  420. ret = copy_methods->ram_to_mpi_ms_async(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  421. else
  422. {
  423. STARPU_ASSERT(copy_methods->any_to_any);
  424. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  425. }
  426. }
  427. break;
  428. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM,STARPU_CPU_RAM):
  429. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_mpi_ms_copy_disabled() ||
  430. !(copy_methods->mpi_ms_to_ram_async || copy_methods->any_to_any))
  431. {
  432. /* this is not associated to a request so it's synchronous */
  433. STARPU_ASSERT(copy_methods->mpi_ms_to_ram || copy_methods->any_to_any);
  434. if (copy_methods->mpi_ms_to_ram)
  435. copy_methods->mpi_ms_to_ram(src_interface, src_node, dst_interface, dst_node);
  436. else
  437. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  438. }
  439. else
  440. {
  441. req->async_channel.type = STARPU_MPI_MS_RAM;
  442. if(copy_methods->mpi_ms_to_ram_async)
  443. ret = copy_methods->mpi_ms_to_ram_async(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  444. else
  445. {
  446. STARPU_ASSERT(copy_methods->any_to_any);
  447. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  448. }
  449. }
  450. break;
  451. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM,STARPU_MPI_MS_RAM):
  452. if (!req || starpu_asynchronous_copy_disabled() || starpu_asynchronous_mpi_ms_copy_disabled() ||
  453. !(copy_methods->mpi_ms_to_mpi_ms_async || copy_methods->any_to_any))
  454. {
  455. /* this is not associated to a request so it's synchronous */
  456. STARPU_ASSERT(copy_methods->mpi_ms_to_mpi_ms || copy_methods->any_to_any);
  457. if (copy_methods->mpi_ms_to_mpi_ms)
  458. copy_methods->mpi_ms_to_mpi_ms(src_interface, src_node, dst_interface, dst_node);
  459. else
  460. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  461. }
  462. else
  463. {
  464. req->async_channel.type = STARPU_MPI_MS_RAM;
  465. if(copy_methods->mpi_ms_to_mpi_ms_async)
  466. ret = copy_methods->mpi_ms_to_mpi_ms_async(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  467. else
  468. {
  469. STARPU_ASSERT(copy_methods->any_to_any);
  470. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, &req->async_channel);
  471. }
  472. }
  473. break;
  474. #endif
  475. #ifdef STARPU_USE_SCC
  476. /* SCC RAM associated to the master process is considered as
  477. * the main memory node. */
  478. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_SCC_RAM):
  479. /* master private SCC RAM -> slave private SCC RAM */
  480. if (copy_methods->scc_src_to_sink)
  481. copy_methods->scc_src_to_sink(src_interface, src_node, dst_interface, dst_node);
  482. else
  483. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  484. break;
  485. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_CPU_RAM):
  486. /* slave private SCC RAM -> master private SCC RAM */
  487. if (copy_methods->scc_sink_to_src)
  488. copy_methods->scc_sink_to_src(src_interface, src_node, dst_interface, dst_node);
  489. else
  490. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  491. break;
  492. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_SCC_RAM):
  493. /* slave private SCC RAM -> slave private SCC RAM */
  494. if (copy_methods->scc_sink_to_sink)
  495. copy_methods->scc_sink_to_sink(src_interface, src_node, dst_interface, dst_node);
  496. else
  497. copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, NULL);
  498. break;
  499. #endif
  500. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_DISK_RAM):
  501. if (req && !starpu_asynchronous_copy_disabled())
  502. {
  503. req->async_channel.type = STARPU_DISK_RAM;
  504. req->async_channel.event.disk_event.requests = NULL;
  505. req->async_channel.event.disk_event.ptr = NULL;
  506. req->async_channel.event.disk_event.handle = NULL;
  507. }
  508. if(copy_methods->any_to_any)
  509. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, req && !starpu_asynchronous_copy_disabled() ? &req->async_channel : NULL);
  510. else
  511. {
  512. void *obj = starpu_data_handle_to_pointer(handle, dst_node);
  513. void * ptr = NULL;
  514. starpu_ssize_t size = 0;
  515. handle->ops->pack_data(handle, src_node, &ptr, &size);
  516. ret = _starpu_disk_full_write(src_node, dst_node, obj, ptr, size, req && !starpu_asynchronous_copy_disabled() ? &req->async_channel : NULL);
  517. if (ret == 0)
  518. {
  519. /* write is already finished, ptr was allocated in pack_data */
  520. _starpu_free_flags_on_node(src_node, ptr, size, 0);
  521. }
  522. else if (ret == -EAGAIN)
  523. {
  524. STARPU_ASSERT(req);
  525. req->async_channel.event.disk_event.ptr = ptr;
  526. req->async_channel.event.disk_event.node = src_node;
  527. req->async_channel.event.disk_event.size = size;
  528. }
  529. STARPU_ASSERT(ret == 0 || ret == -EAGAIN);
  530. }
  531. break;
  532. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM,STARPU_CPU_RAM):
  533. if (req && !starpu_asynchronous_copy_disabled())
  534. {
  535. req->async_channel.type = STARPU_DISK_RAM;
  536. req->async_channel.event.disk_event.requests = NULL;
  537. req->async_channel.event.disk_event.ptr = NULL;
  538. req->async_channel.event.disk_event.handle = NULL;
  539. }
  540. if(copy_methods->any_to_any)
  541. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, req && !starpu_asynchronous_copy_disabled() ? &req->async_channel : NULL);
  542. else
  543. {
  544. void *obj = starpu_data_handle_to_pointer(handle, src_node);
  545. void * ptr = NULL;
  546. size_t size = 0;
  547. ret = _starpu_disk_full_read(src_node, dst_node, obj, &ptr, &size, req && !starpu_asynchronous_copy_disabled() ? &req->async_channel : NULL);
  548. if (ret == 0)
  549. {
  550. /* read is already finished, we can already unpack */
  551. handle->ops->unpack_data(handle, dst_node, ptr, size);
  552. }
  553. else if (ret == -EAGAIN)
  554. {
  555. STARPU_ASSERT(req);
  556. req->async_channel.event.disk_event.ptr = ptr;
  557. req->async_channel.event.disk_event.node = dst_node;
  558. req->async_channel.event.disk_event.size = size;
  559. req->async_channel.event.disk_event.handle = handle;
  560. }
  561. STARPU_ASSERT(ret == 0 || ret == -EAGAIN);
  562. }
  563. break;
  564. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM,STARPU_DISK_RAM):
  565. if (req && !starpu_asynchronous_copy_disabled())
  566. {
  567. req->async_channel.type = STARPU_DISK_RAM;
  568. req->async_channel.event.disk_event.requests = NULL;
  569. req->async_channel.event.disk_event.ptr = NULL;
  570. req->async_channel.event.disk_event.handle = NULL;
  571. }
  572. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, req && !starpu_asynchronous_copy_disabled() ? &req->async_channel : NULL);
  573. break;
  574. default:
  575. STARPU_ABORT();
  576. break;
  577. }
  578. return ret;
  579. #endif /* !SIMGRID */
  580. }
  581. int STARPU_ATTRIBUTE_WARN_UNUSED_RESULT _starpu_driver_copy_data_1_to_1(starpu_data_handle_t handle,
  582. struct _starpu_data_replicate *src_replicate,
  583. struct _starpu_data_replicate *dst_replicate,
  584. unsigned donotread,
  585. struct _starpu_data_request *req,
  586. unsigned may_alloc,
  587. unsigned prefetch STARPU_ATTRIBUTE_UNUSED)
  588. {
  589. if (!donotread)
  590. {
  591. STARPU_ASSERT(src_replicate->allocated);
  592. STARPU_ASSERT(src_replicate->refcnt);
  593. }
  594. unsigned src_node = src_replicate->memory_node;
  595. unsigned dst_node = dst_replicate->memory_node;
  596. /* first make sure the destination has an allocated buffer */
  597. if (!dst_replicate->allocated)
  598. {
  599. if (!may_alloc || _starpu_is_reclaiming(dst_node))
  600. /* We're not supposed to allocate there at the moment */
  601. return -ENOMEM;
  602. int ret_alloc = _starpu_allocate_memory_on_node(handle, dst_replicate, req ? req->prefetch : 0);
  603. if (ret_alloc)
  604. return -ENOMEM;
  605. }
  606. STARPU_ASSERT(dst_replicate->allocated);
  607. STARPU_ASSERT(dst_replicate->refcnt);
  608. /* if there is no need to actually read the data,
  609. * we do not perform any transfer */
  610. if (!donotread)
  611. {
  612. unsigned long STARPU_ATTRIBUTE_UNUSED com_id = 0;
  613. size_t size = _starpu_data_get_size(handle);
  614. _starpu_bus_update_profiling_info((int)src_node, (int)dst_node, size);
  615. #ifdef STARPU_USE_FXT
  616. com_id = STARPU_ATOMIC_ADDL(&communication_cnt, 1);
  617. if (req)
  618. req->com_id = com_id;
  619. #endif
  620. dst_replicate->initialized = 1;
  621. _STARPU_TRACE_START_DRIVER_COPY(src_node, dst_node, size, com_id, prefetch, handle);
  622. int ret_copy = copy_data_1_to_1_generic(handle, src_replicate, dst_replicate, req);
  623. if (!req)
  624. /* Synchronous, this is already finished */
  625. _STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, com_id, prefetch);
  626. return ret_copy;
  627. }
  628. return 0;
  629. }
  630. void starpu_interface_data_copy(unsigned src_node, unsigned dst_node, size_t size)
  631. {
  632. _STARPU_TRACE_DATA_COPY(src_node, dst_node, size);
  633. }
  634. void starpu_interface_start_driver_copy_async(unsigned src_node, unsigned dst_node, double *start)
  635. {
  636. *start = starpu_timing_now();
  637. _STARPU_TRACE_START_DRIVER_COPY_ASYNC(src_node, dst_node);
  638. }
  639. void starpu_interface_end_driver_copy_async(unsigned src_node, unsigned dst_node, double start)
  640. {
  641. double end = starpu_timing_now();
  642. double elapsed = end - start;
  643. if (elapsed > 300)
  644. {
  645. static int warned = 0;
  646. if (!warned)
  647. {
  648. char src_name[16], dst_name[16];
  649. warned = 1;
  650. starpu_memory_node_get_name(src_node, src_name, sizeof(src_name));
  651. starpu_memory_node_get_name(dst_node, dst_name, sizeof(dst_name));
  652. _STARPU_DISP("Warning: the submission of asynchronous transfer from %s to %s took a very long time (%f ms)\nFor proper asynchronous transfer overlapping, data registered to StarPU must be allocated with starpu_malloc() or pinned with starpu_memory_pin()\n", src_name, dst_name, elapsed / 1000.);
  653. }
  654. }
  655. _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
  656. }
  657. /* This can be used by interfaces to easily transfer a piece of data without
  658. * caring about the particular transfer methods. */
  659. /* This should either return 0 if the transfer is complete, or -EAGAIN if the
  660. * transfer is still pending, and will have to be waited for by
  661. * _starpu_driver_test_request_completion/_starpu_driver_wait_request_completion
  662. */
  663. 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)
  664. {
  665. struct _starpu_async_channel *async_channel = async_data;
  666. enum starpu_node_kind src_kind = starpu_node_get_kind(src_node);
  667. enum starpu_node_kind dst_kind = starpu_node_get_kind(dst_node);
  668. switch (_STARPU_MEMORY_NODE_TUPLE(src_kind,dst_kind))
  669. {
  670. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CPU_RAM):
  671. memcpy((void *) (dst + dst_offset), (void *) (src + src_offset), size);
  672. return 0;
  673. #ifdef STARPU_USE_CUDA
  674. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CPU_RAM):
  675. return starpu_cuda_copy_async_sync(
  676. (void*) (src + src_offset), src_node,
  677. (void*) (dst + dst_offset), dst_node,
  678. size,
  679. async_channel?starpu_cuda_get_out_transfer_stream(src_node):NULL,
  680. cudaMemcpyDeviceToHost);
  681. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CUDA_RAM):
  682. return starpu_cuda_copy_async_sync(
  683. (void*) (src + src_offset), src_node,
  684. (void*) (dst + dst_offset), dst_node,
  685. size,
  686. async_channel?starpu_cuda_get_in_transfer_stream(dst_node):NULL,
  687. cudaMemcpyHostToDevice);
  688. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CUDA_RAM):
  689. return starpu_cuda_copy_async_sync(
  690. (void*) (src + src_offset), src_node,
  691. (void*) (dst + dst_offset), dst_node,
  692. size,
  693. async_channel?starpu_cuda_get_peer_transfer_stream(src_node, dst_node):NULL,
  694. cudaMemcpyDeviceToDevice);
  695. #endif
  696. #ifdef STARPU_USE_OPENCL
  697. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_CPU_RAM):
  698. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_OPENCL_RAM):
  699. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_OPENCL_RAM):
  700. return starpu_opencl_copy_async_sync(
  701. src, src_offset, src_node,
  702. dst, dst_offset, dst_node,
  703. size,
  704. &async_channel->event.opencl_event);
  705. #endif
  706. #ifdef STARPU_USE_MIC
  707. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MIC_RAM,STARPU_CPU_RAM):
  708. if (async_data)
  709. return _starpu_mic_copy_mic_to_ram_async(
  710. (void*) (src + src_offset), src_node,
  711. (void*) (dst + dst_offset), dst_node,
  712. size);
  713. else
  714. return _starpu_mic_copy_mic_to_ram(
  715. (void*) (src + src_offset), src_node,
  716. (void*) (dst + dst_offset), dst_node,
  717. size);
  718. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_MIC_RAM):
  719. if (async_data)
  720. return _starpu_mic_copy_ram_to_mic_async(
  721. (void*) (src + src_offset), src_node,
  722. (void*) (dst + dst_offset), dst_node,
  723. size);
  724. else
  725. return _starpu_mic_copy_ram_to_mic(
  726. (void*) (src + src_offset), src_node,
  727. (void*) (dst + dst_offset), dst_node,
  728. size);
  729. /* TODO: MIC->MIC */
  730. #endif
  731. #ifdef STARPU_USE_SCC
  732. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_CPU_RAM):
  733. return _starpu_scc_copy_sink_to_src(
  734. (void*) (src + src_offset), src_node,
  735. (void*) (dst + dst_offset), dst_node,
  736. size);
  737. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_SCC_RAM):
  738. return _starpu_scc_copy_src_to_sink(
  739. (void*) (src + src_offset), src_node,
  740. (void*) (dst + dst_offset), dst_node,
  741. size);
  742. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_SCC_RAM):
  743. return _starpu_scc_copy_sink_to_sink(
  744. (void*) (src + src_offset), src_node,
  745. (void*) (dst + dst_offset), dst_node,
  746. size);
  747. #endif
  748. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  749. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM, STARPU_MPI_MS_RAM):
  750. if (async_data)
  751. return _starpu_mpi_copy_ram_to_mpi_async(
  752. (void*) (src + src_offset), src_node,
  753. (void*) (dst + dst_offset), dst_node,
  754. size, async_data);
  755. else
  756. return _starpu_mpi_copy_ram_to_mpi_sync(
  757. (void*) (src + src_offset), src_node,
  758. (void*) (dst + dst_offset), dst_node,
  759. size);
  760. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM, STARPU_CPU_RAM):
  761. if (async_data)
  762. return _starpu_mpi_copy_mpi_to_ram_async(
  763. (void*) (src + src_offset), src_node,
  764. (void*) (dst + dst_offset), dst_node,
  765. size, async_data);
  766. else
  767. return _starpu_mpi_copy_mpi_to_ram_sync(
  768. (void*) (src + src_offset), src_node,
  769. (void*) (dst + dst_offset), dst_node,
  770. size);
  771. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM, STARPU_MPI_MS_RAM):
  772. if (async_data)
  773. return _starpu_mpi_copy_sink_to_sink_async(
  774. (void*) (src + src_offset), src_node,
  775. (void*) (dst + dst_offset), dst_node,
  776. size, async_data);
  777. else
  778. return _starpu_mpi_copy_sink_to_sink_sync(
  779. (void*) (src + src_offset), src_node,
  780. (void*) (dst + dst_offset), dst_node,
  781. size);
  782. #endif
  783. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM, STARPU_DISK_RAM):
  784. {
  785. return _starpu_disk_copy_src_to_disk(
  786. (void*) (src + src_offset), src_node,
  787. (void*) dst, dst_offset, dst_node,
  788. size, async_channel);
  789. }
  790. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM, STARPU_CPU_RAM):
  791. return _starpu_disk_copy_disk_to_src(
  792. (void*) src, src_offset, src_node,
  793. (void*) (dst + dst_offset), dst_node,
  794. size, async_channel);
  795. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM, STARPU_DISK_RAM):
  796. return _starpu_disk_copy_disk_to_disk(
  797. (void*) src, src_offset, src_node,
  798. (void*) dst, dst_offset, dst_node,
  799. size, async_channel);
  800. default:
  801. STARPU_ABORT();
  802. return -1;
  803. }
  804. return 0;
  805. }
  806. void _starpu_driver_wait_request_completion(struct _starpu_async_channel *async_channel)
  807. {
  808. #ifdef STARPU_SIMGRID
  809. _starpu_simgrid_wait_transfer_event(&async_channel->event);
  810. #else /* !SIMGRID */
  811. enum starpu_node_kind kind = async_channel->type;
  812. #ifdef STARPU_USE_CUDA
  813. cudaEvent_t event;
  814. cudaError_t cures;
  815. #endif
  816. switch (kind)
  817. {
  818. #ifdef STARPU_USE_CUDA
  819. case STARPU_CUDA_RAM:
  820. event = (*async_channel).event.cuda_event;
  821. cures = cudaEventSynchronize(event);
  822. if (STARPU_UNLIKELY(cures))
  823. STARPU_CUDA_REPORT_ERROR(cures);
  824. cures = cudaEventDestroy(event);
  825. if (STARPU_UNLIKELY(cures))
  826. STARPU_CUDA_REPORT_ERROR(cures);
  827. break;
  828. #endif
  829. #ifdef STARPU_USE_OPENCL
  830. case STARPU_OPENCL_RAM:
  831. {
  832. cl_int err;
  833. if ((*async_channel).event.opencl_event == NULL)
  834. STARPU_ABORT();
  835. err = clWaitForEvents(1, &((*async_channel).event.opencl_event));
  836. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  837. STARPU_OPENCL_REPORT_ERROR(err);
  838. err = clReleaseEvent((*async_channel).event.opencl_event);
  839. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  840. STARPU_OPENCL_REPORT_ERROR(err);
  841. break;
  842. }
  843. #endif
  844. #ifdef STARPU_USE_MIC
  845. case STARPU_MIC_RAM:
  846. _starpu_mic_wait_request_completion(&(async_channel->event.mic_event));
  847. break;
  848. #endif
  849. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  850. case STARPU_MPI_MS_RAM:
  851. _starpu_mpi_common_wait_event(async_channel);
  852. break;
  853. #endif
  854. case STARPU_DISK_RAM:
  855. starpu_disk_wait_request(async_channel);
  856. if (async_channel->event.disk_event.ptr != NULL)
  857. {
  858. if (async_channel->event.disk_event.handle != NULL)
  859. {
  860. /* read is finished, we can already unpack */
  861. async_channel->event.disk_event.handle->ops->unpack_data(async_channel->event.disk_event.handle, async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size);
  862. }
  863. else
  864. {
  865. /* write is finished, ptr was allocated in pack_data */
  866. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  867. }
  868. }
  869. break;
  870. case STARPU_CPU_RAM:
  871. default:
  872. STARPU_ABORT();
  873. }
  874. #endif /* !SIMGRID */
  875. }
  876. unsigned _starpu_driver_test_request_completion(struct _starpu_async_channel *async_channel)
  877. {
  878. #ifdef STARPU_SIMGRID
  879. return _starpu_simgrid_test_transfer_event(&async_channel->event);
  880. #else /* !SIMGRID */
  881. enum starpu_node_kind kind = async_channel->type;
  882. unsigned success = 0;
  883. #ifdef STARPU_USE_CUDA
  884. cudaEvent_t event;
  885. #endif
  886. switch (kind)
  887. {
  888. #ifdef STARPU_USE_CUDA
  889. case STARPU_CUDA_RAM:
  890. event = (*async_channel).event.cuda_event;
  891. cudaError_t cures = cudaEventQuery(event);
  892. success = (cures == cudaSuccess);
  893. if (success)
  894. cudaEventDestroy(event);
  895. else if (cures != cudaErrorNotReady)
  896. STARPU_CUDA_REPORT_ERROR(cures);
  897. break;
  898. #endif
  899. #ifdef STARPU_USE_OPENCL
  900. case STARPU_OPENCL_RAM:
  901. {
  902. cl_int event_status;
  903. cl_event opencl_event = (*async_channel).event.opencl_event;
  904. if (opencl_event == NULL) STARPU_ABORT();
  905. cl_int err = clGetEventInfo(opencl_event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(event_status), &event_status, NULL);
  906. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  907. STARPU_OPENCL_REPORT_ERROR(err);
  908. if (event_status < 0)
  909. STARPU_OPENCL_REPORT_ERROR(event_status);
  910. if (event_status == CL_COMPLETE)
  911. {
  912. err = clReleaseEvent(opencl_event);
  913. if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);
  914. }
  915. success = (event_status == CL_COMPLETE);
  916. break;
  917. }
  918. #endif
  919. #ifdef STARPU_USE_MIC
  920. case STARPU_MIC_RAM:
  921. success = _starpu_mic_request_is_complete(&(async_channel->event.mic_event));
  922. break;
  923. #endif
  924. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  925. case STARPU_MPI_MS_RAM:
  926. success = _starpu_mpi_common_test_event(async_channel);
  927. break;
  928. #endif
  929. case STARPU_DISK_RAM:
  930. success = starpu_disk_test_request(async_channel);
  931. if (async_channel->event.disk_event.ptr != NULL && success)
  932. {
  933. if (async_channel->event.disk_event.handle != NULL)
  934. {
  935. /* read is finished, we can already unpack */
  936. async_channel->event.disk_event.handle->ops->unpack_data(async_channel->event.disk_event.handle, async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size);
  937. }
  938. else
  939. {
  940. /* write is finished, ptr was allocated in pack_data */
  941. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  942. }
  943. }
  944. break;
  945. case STARPU_CPU_RAM:
  946. default:
  947. STARPU_ABORT_MSG("Memory is not recognized (kind %d) \n", kind);
  948. }
  949. return success;
  950. #endif /* !SIMGRID */
  951. }