copy_driver.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2017 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2013, 2016, 2017 CNRS
  5. * Copyright (C) 2016-2017 INRIA
  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_memory_node_get_local_key() == 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_memory_node_get_local_key() == 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_memory_node_get_local_key() == 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_memory_node_get_local_key() == 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_memory_node_get_local_key() == dst_node || _starpu_memory_node_get_local_key() == 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. /* ptr is allocated in full_read */
  553. _starpu_free_flags_on_node(dst_node, ptr, size, 0);
  554. }
  555. else if (ret == -EAGAIN)
  556. {
  557. STARPU_ASSERT(req);
  558. req->async_channel.event.disk_event.ptr = ptr;
  559. req->async_channel.event.disk_event.node = dst_node;
  560. req->async_channel.event.disk_event.size = size;
  561. req->async_channel.event.disk_event.handle = handle;
  562. }
  563. STARPU_ASSERT(ret == 0 || ret == -EAGAIN);
  564. }
  565. break;
  566. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM,STARPU_DISK_RAM):
  567. if (req && !starpu_asynchronous_copy_disabled())
  568. {
  569. req->async_channel.type = STARPU_DISK_RAM;
  570. req->async_channel.event.disk_event.requests = NULL;
  571. req->async_channel.event.disk_event.ptr = NULL;
  572. req->async_channel.event.disk_event.handle = NULL;
  573. }
  574. ret = copy_methods->any_to_any(src_interface, src_node, dst_interface, dst_node, req && !starpu_asynchronous_copy_disabled() ? &req->async_channel : NULL);
  575. break;
  576. default:
  577. STARPU_ABORT();
  578. break;
  579. }
  580. return ret;
  581. #endif /* !SIMGRID */
  582. }
  583. int STARPU_ATTRIBUTE_WARN_UNUSED_RESULT _starpu_driver_copy_data_1_to_1(starpu_data_handle_t handle,
  584. struct _starpu_data_replicate *src_replicate,
  585. struct _starpu_data_replicate *dst_replicate,
  586. unsigned donotread,
  587. struct _starpu_data_request *req,
  588. unsigned may_alloc,
  589. unsigned prefetch STARPU_ATTRIBUTE_UNUSED)
  590. {
  591. if (!donotread)
  592. {
  593. STARPU_ASSERT(src_replicate->allocated);
  594. STARPU_ASSERT(src_replicate->refcnt);
  595. }
  596. unsigned src_node = src_replicate->memory_node;
  597. unsigned dst_node = dst_replicate->memory_node;
  598. /* first make sure the destination has an allocated buffer */
  599. if (!dst_replicate->allocated)
  600. {
  601. if (!may_alloc || _starpu_is_reclaiming(dst_node))
  602. /* We're not supposed to allocate there at the moment */
  603. return -ENOMEM;
  604. int ret_alloc = _starpu_allocate_memory_on_node(handle, dst_replicate, req ? req->prefetch : 0);
  605. if (ret_alloc)
  606. return -ENOMEM;
  607. }
  608. STARPU_ASSERT(dst_replicate->allocated);
  609. STARPU_ASSERT(dst_replicate->refcnt);
  610. /* if there is no need to actually read the data,
  611. * we do not perform any transfer */
  612. if (!donotread)
  613. {
  614. unsigned long STARPU_ATTRIBUTE_UNUSED com_id = 0;
  615. size_t size = _starpu_data_get_size(handle);
  616. _starpu_bus_update_profiling_info((int)src_node, (int)dst_node, size);
  617. #ifdef STARPU_USE_FXT
  618. com_id = STARPU_ATOMIC_ADDL(&communication_cnt, 1);
  619. if (req)
  620. req->com_id = com_id;
  621. #endif
  622. dst_replicate->initialized = 1;
  623. _STARPU_TRACE_START_DRIVER_COPY(src_node, dst_node, size, com_id, prefetch, handle);
  624. int ret_copy = copy_data_1_to_1_generic(handle, src_replicate, dst_replicate, req);
  625. if (!req)
  626. /* Synchronous, this is already finished */
  627. _STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, com_id, prefetch);
  628. return ret_copy;
  629. }
  630. return 0;
  631. }
  632. /* This can be used by interfaces to easily transfer a piece of data without
  633. * caring about the particular transfer methods. */
  634. /* This should either return 0 if the transfer is complete, or -EAGAIN if the
  635. * transfer is still pending, and will have to be waited for by
  636. * _starpu_driver_test_request_completion/_starpu_driver_wait_request_completion
  637. */
  638. 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)
  639. {
  640. struct _starpu_async_channel *async_channel = async_data;
  641. enum starpu_node_kind src_kind = starpu_node_get_kind(src_node);
  642. enum starpu_node_kind dst_kind = starpu_node_get_kind(dst_node);
  643. switch (_STARPU_MEMORY_NODE_TUPLE(src_kind,dst_kind))
  644. {
  645. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CPU_RAM):
  646. memcpy((void *) (dst + dst_offset), (void *) (src + src_offset), size);
  647. return 0;
  648. #ifdef STARPU_USE_CUDA
  649. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CPU_RAM):
  650. return starpu_cuda_copy_async_sync(
  651. (void*) (src + src_offset), src_node,
  652. (void*) (dst + dst_offset), dst_node,
  653. size,
  654. async_channel?starpu_cuda_get_out_transfer_stream(src_node):NULL,
  655. cudaMemcpyDeviceToHost);
  656. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CUDA_RAM):
  657. return starpu_cuda_copy_async_sync(
  658. (void*) (src + src_offset), src_node,
  659. (void*) (dst + dst_offset), dst_node,
  660. size,
  661. async_channel?starpu_cuda_get_in_transfer_stream(dst_node):NULL,
  662. cudaMemcpyHostToDevice);
  663. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CUDA_RAM):
  664. return starpu_cuda_copy_async_sync(
  665. (void*) (src + src_offset), src_node,
  666. (void*) (dst + dst_offset), dst_node,
  667. size,
  668. async_channel?starpu_cuda_get_peer_transfer_stream(src_node, dst_node):NULL,
  669. cudaMemcpyDeviceToDevice);
  670. #endif
  671. #ifdef STARPU_USE_OPENCL
  672. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_CPU_RAM):
  673. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_OPENCL_RAM):
  674. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_OPENCL_RAM):
  675. return starpu_opencl_copy_async_sync(
  676. src, src_offset, src_node,
  677. dst, dst_offset, dst_node,
  678. size,
  679. &async_channel->event.opencl_event);
  680. #endif
  681. #ifdef STARPU_USE_MIC
  682. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MIC_RAM,STARPU_CPU_RAM):
  683. if (async_data)
  684. return _starpu_mic_copy_mic_to_ram_async(
  685. (void*) (src + src_offset), src_node,
  686. (void*) (dst + dst_offset), dst_node,
  687. size);
  688. else
  689. return _starpu_mic_copy_mic_to_ram(
  690. (void*) (src + src_offset), src_node,
  691. (void*) (dst + dst_offset), dst_node,
  692. size);
  693. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_MIC_RAM):
  694. if (async_data)
  695. return _starpu_mic_copy_ram_to_mic_async(
  696. (void*) (src + src_offset), src_node,
  697. (void*) (dst + dst_offset), dst_node,
  698. size);
  699. else
  700. return _starpu_mic_copy_ram_to_mic(
  701. (void*) (src + src_offset), src_node,
  702. (void*) (dst + dst_offset), dst_node,
  703. size);
  704. /* TODO: MIC->MIC */
  705. #endif
  706. #ifdef STARPU_USE_SCC
  707. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_CPU_RAM):
  708. return _starpu_scc_copy_sink_to_src(
  709. (void*) (src + src_offset), src_node,
  710. (void*) (dst + dst_offset), dst_node,
  711. size);
  712. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_SCC_RAM):
  713. return _starpu_scc_copy_src_to_sink(
  714. (void*) (src + src_offset), src_node,
  715. (void*) (dst + dst_offset), dst_node,
  716. size);
  717. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_SCC_RAM):
  718. return _starpu_scc_copy_sink_to_sink(
  719. (void*) (src + src_offset), src_node,
  720. (void*) (dst + dst_offset), dst_node,
  721. size);
  722. #endif
  723. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  724. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM, STARPU_MPI_MS_RAM):
  725. if (async_data)
  726. return _starpu_mpi_copy_ram_to_mpi_async(
  727. (void*) (src + src_offset), src_node,
  728. (void*) (dst + dst_offset), dst_node,
  729. size, async_data);
  730. else
  731. return _starpu_mpi_copy_ram_to_mpi_sync(
  732. (void*) (src + src_offset), src_node,
  733. (void*) (dst + dst_offset), dst_node,
  734. size);
  735. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM, STARPU_CPU_RAM):
  736. if (async_data)
  737. return _starpu_mpi_copy_mpi_to_ram_async(
  738. (void*) (src + src_offset), src_node,
  739. (void*) (dst + dst_offset), dst_node,
  740. size, async_data);
  741. else
  742. return _starpu_mpi_copy_mpi_to_ram_sync(
  743. (void*) (src + src_offset), src_node,
  744. (void*) (dst + dst_offset), dst_node,
  745. size);
  746. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM, STARPU_MPI_MS_RAM):
  747. if (async_data)
  748. return _starpu_mpi_copy_sink_to_sink_async(
  749. (void*) (src + src_offset), src_node,
  750. (void*) (dst + dst_offset), dst_node,
  751. size, async_data);
  752. else
  753. return _starpu_mpi_copy_sink_to_sink_sync(
  754. (void*) (src + src_offset), src_node,
  755. (void*) (dst + dst_offset), dst_node,
  756. size);
  757. #endif
  758. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM, STARPU_DISK_RAM):
  759. {
  760. return _starpu_disk_copy_src_to_disk(
  761. (void*) (src + src_offset), src_node,
  762. (void*) dst, dst_offset, dst_node,
  763. size, async_channel);
  764. }
  765. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM, STARPU_CPU_RAM):
  766. return _starpu_disk_copy_disk_to_src(
  767. (void*) src, src_offset, src_node,
  768. (void*) (dst + dst_offset), dst_node,
  769. size, async_channel);
  770. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM, STARPU_DISK_RAM):
  771. return _starpu_disk_copy_disk_to_disk(
  772. (void*) src, src_offset, src_node,
  773. (void*) dst, dst_offset, dst_node,
  774. size, async_channel);
  775. default:
  776. STARPU_ABORT();
  777. return -1;
  778. }
  779. return 0;
  780. }
  781. void _starpu_driver_wait_request_completion(struct _starpu_async_channel *async_channel)
  782. {
  783. #ifdef STARPU_SIMGRID
  784. _starpu_simgrid_wait_transfer_event(&async_channel->event);
  785. #else /* !SIMGRID */
  786. enum starpu_node_kind kind = async_channel->type;
  787. #ifdef STARPU_USE_CUDA
  788. cudaEvent_t event;
  789. cudaError_t cures;
  790. #endif
  791. switch (kind)
  792. {
  793. #ifdef STARPU_USE_CUDA
  794. case STARPU_CUDA_RAM:
  795. event = (*async_channel).event.cuda_event;
  796. cures = cudaEventSynchronize(event);
  797. if (STARPU_UNLIKELY(cures))
  798. STARPU_CUDA_REPORT_ERROR(cures);
  799. cures = cudaEventDestroy(event);
  800. if (STARPU_UNLIKELY(cures))
  801. STARPU_CUDA_REPORT_ERROR(cures);
  802. break;
  803. #endif
  804. #ifdef STARPU_USE_OPENCL
  805. case STARPU_OPENCL_RAM:
  806. {
  807. cl_int err;
  808. if ((*async_channel).event.opencl_event == NULL)
  809. STARPU_ABORT();
  810. err = clWaitForEvents(1, &((*async_channel).event.opencl_event));
  811. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  812. STARPU_OPENCL_REPORT_ERROR(err);
  813. err = clReleaseEvent((*async_channel).event.opencl_event);
  814. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  815. STARPU_OPENCL_REPORT_ERROR(err);
  816. break;
  817. }
  818. #endif
  819. #ifdef STARPU_USE_MIC
  820. case STARPU_MIC_RAM:
  821. _starpu_mic_wait_request_completion(&(async_channel->event.mic_event));
  822. break;
  823. #endif
  824. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  825. case STARPU_MPI_MS_RAM:
  826. _starpu_mpi_common_wait_event(async_channel);
  827. break;
  828. #endif
  829. case STARPU_DISK_RAM:
  830. starpu_disk_wait_request(async_channel);
  831. if (async_channel->event.disk_event.ptr != NULL)
  832. {
  833. if (async_channel->event.disk_event.handle != NULL)
  834. {
  835. /* read is finished, we can already unpack */
  836. 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);
  837. /* ptr is allocated in full_read */
  838. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  839. }
  840. else
  841. {
  842. /* write is finished, ptr was allocated in pack_data */
  843. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  844. }
  845. }
  846. break;
  847. case STARPU_CPU_RAM:
  848. default:
  849. STARPU_ABORT();
  850. }
  851. #endif /* !SIMGRID */
  852. }
  853. unsigned _starpu_driver_test_request_completion(struct _starpu_async_channel *async_channel)
  854. {
  855. #ifdef STARPU_SIMGRID
  856. return _starpu_simgrid_test_transfer_event(&async_channel->event);
  857. #else /* !SIMGRID */
  858. enum starpu_node_kind kind = async_channel->type;
  859. unsigned success = 0;
  860. #ifdef STARPU_USE_CUDA
  861. cudaEvent_t event;
  862. #endif
  863. switch (kind)
  864. {
  865. #ifdef STARPU_USE_CUDA
  866. case STARPU_CUDA_RAM:
  867. event = (*async_channel).event.cuda_event;
  868. cudaError_t cures = cudaEventQuery(event);
  869. success = (cures == cudaSuccess);
  870. if (success)
  871. cudaEventDestroy(event);
  872. else if (cures != cudaErrorNotReady)
  873. STARPU_CUDA_REPORT_ERROR(cures);
  874. break;
  875. #endif
  876. #ifdef STARPU_USE_OPENCL
  877. case STARPU_OPENCL_RAM:
  878. {
  879. cl_int event_status;
  880. cl_event opencl_event = (*async_channel).event.opencl_event;
  881. if (opencl_event == NULL) STARPU_ABORT();
  882. cl_int err = clGetEventInfo(opencl_event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(event_status), &event_status, NULL);
  883. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  884. STARPU_OPENCL_REPORT_ERROR(err);
  885. if (event_status < 0)
  886. STARPU_OPENCL_REPORT_ERROR(event_status);
  887. if (event_status == CL_COMPLETE)
  888. {
  889. err = clReleaseEvent(opencl_event);
  890. if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);
  891. }
  892. success = (event_status == CL_COMPLETE);
  893. break;
  894. }
  895. #endif
  896. #ifdef STARPU_USE_MIC
  897. case STARPU_MIC_RAM:
  898. success = _starpu_mic_request_is_complete(&(async_channel->event.mic_event));
  899. break;
  900. #endif
  901. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  902. case STARPU_MPI_MS_RAM:
  903. success = _starpu_mpi_common_test_event(async_channel);
  904. break;
  905. #endif
  906. case STARPU_DISK_RAM:
  907. success = starpu_disk_test_request(async_channel);
  908. if (async_channel->event.disk_event.ptr != NULL && success)
  909. {
  910. if (async_channel->event.disk_event.handle != NULL)
  911. {
  912. /* read is finished, we can already unpack */
  913. 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);
  914. /* ptr is allocated in full_read */
  915. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  916. }
  917. else
  918. {
  919. /* write is finished, ptr was allocated in pack_data */
  920. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  921. }
  922. }
  923. break;
  924. case STARPU_CPU_RAM:
  925. default:
  926. STARPU_ABORT_MSG("Memory is not recognized (kind %d) \n", kind);
  927. }
  928. return success;
  929. #endif /* !SIMGRID */
  930. }