copy_driver.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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-2018 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_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. void starpu_interface_start_driver_copy_async(unsigned src_node, unsigned dst_node, double *start)
  633. {
  634. *start = starpu_timing_now();
  635. _STARPU_TRACE_START_DRIVER_COPY_ASYNC(src_node, dst_node);
  636. }
  637. void starpu_interface_end_driver_copy_async(unsigned src_node, unsigned dst_node, double start)
  638. {
  639. double end = starpu_timing_now();
  640. double elapsed = end - start;
  641. if (elapsed > 300)
  642. {
  643. static int warned = 0;
  644. if (!warned)
  645. {
  646. char src_name[16], dst_name[16];
  647. warned = 1;
  648. starpu_memory_node_get_name(src_node, src_name, sizeof(src_name));
  649. starpu_memory_node_get_name(dst_node, dst_name, sizeof(dst_name));
  650. _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.);
  651. }
  652. }
  653. _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
  654. }
  655. /* This can be used by interfaces to easily transfer a piece of data without
  656. * caring about the particular transfer methods. */
  657. /* This should either return 0 if the transfer is complete, or -EAGAIN if the
  658. * transfer is still pending, and will have to be waited for by
  659. * _starpu_driver_test_request_completion/_starpu_driver_wait_request_completion
  660. */
  661. 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)
  662. {
  663. struct _starpu_async_channel *async_channel = async_data;
  664. enum starpu_node_kind src_kind = starpu_node_get_kind(src_node);
  665. enum starpu_node_kind dst_kind = starpu_node_get_kind(dst_node);
  666. switch (_STARPU_MEMORY_NODE_TUPLE(src_kind,dst_kind))
  667. {
  668. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CPU_RAM):
  669. memcpy((void *) (dst + dst_offset), (void *) (src + src_offset), size);
  670. return 0;
  671. #ifdef STARPU_USE_CUDA
  672. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CPU_RAM):
  673. return starpu_cuda_copy_async_sync(
  674. (void*) (src + src_offset), src_node,
  675. (void*) (dst + dst_offset), dst_node,
  676. size,
  677. async_channel?starpu_cuda_get_out_transfer_stream(src_node):NULL,
  678. cudaMemcpyDeviceToHost);
  679. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_CUDA_RAM):
  680. return starpu_cuda_copy_async_sync(
  681. (void*) (src + src_offset), src_node,
  682. (void*) (dst + dst_offset), dst_node,
  683. size,
  684. async_channel?starpu_cuda_get_in_transfer_stream(dst_node):NULL,
  685. cudaMemcpyHostToDevice);
  686. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CUDA_RAM,STARPU_CUDA_RAM):
  687. return starpu_cuda_copy_async_sync(
  688. (void*) (src + src_offset), src_node,
  689. (void*) (dst + dst_offset), dst_node,
  690. size,
  691. async_channel?starpu_cuda_get_peer_transfer_stream(src_node, dst_node):NULL,
  692. cudaMemcpyDeviceToDevice);
  693. #endif
  694. #ifdef STARPU_USE_OPENCL
  695. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_CPU_RAM):
  696. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_OPENCL_RAM):
  697. case _STARPU_MEMORY_NODE_TUPLE(STARPU_OPENCL_RAM,STARPU_OPENCL_RAM):
  698. return starpu_opencl_copy_async_sync(
  699. src, src_offset, src_node,
  700. dst, dst_offset, dst_node,
  701. size,
  702. &async_channel->event.opencl_event);
  703. #endif
  704. #ifdef STARPU_USE_MIC
  705. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MIC_RAM,STARPU_CPU_RAM):
  706. if (async_data)
  707. return _starpu_mic_copy_mic_to_ram_async(
  708. (void*) (src + src_offset), src_node,
  709. (void*) (dst + dst_offset), dst_node,
  710. size);
  711. else
  712. return _starpu_mic_copy_mic_to_ram(
  713. (void*) (src + src_offset), src_node,
  714. (void*) (dst + dst_offset), dst_node,
  715. size);
  716. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_MIC_RAM):
  717. if (async_data)
  718. return _starpu_mic_copy_ram_to_mic_async(
  719. (void*) (src + src_offset), src_node,
  720. (void*) (dst + dst_offset), dst_node,
  721. size);
  722. else
  723. return _starpu_mic_copy_ram_to_mic(
  724. (void*) (src + src_offset), src_node,
  725. (void*) (dst + dst_offset), dst_node,
  726. size);
  727. /* TODO: MIC->MIC */
  728. #endif
  729. #ifdef STARPU_USE_SCC
  730. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_CPU_RAM):
  731. return _starpu_scc_copy_sink_to_src(
  732. (void*) (src + src_offset), src_node,
  733. (void*) (dst + dst_offset), dst_node,
  734. size);
  735. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM,STARPU_SCC_RAM):
  736. return _starpu_scc_copy_src_to_sink(
  737. (void*) (src + src_offset), src_node,
  738. (void*) (dst + dst_offset), dst_node,
  739. size);
  740. case _STARPU_MEMORY_NODE_TUPLE(STARPU_SCC_RAM,STARPU_SCC_RAM):
  741. return _starpu_scc_copy_sink_to_sink(
  742. (void*) (src + src_offset), src_node,
  743. (void*) (dst + dst_offset), dst_node,
  744. size);
  745. #endif
  746. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  747. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM, STARPU_MPI_MS_RAM):
  748. if (async_data)
  749. return _starpu_mpi_copy_ram_to_mpi_async(
  750. (void*) (src + src_offset), src_node,
  751. (void*) (dst + dst_offset), dst_node,
  752. size, async_data);
  753. else
  754. return _starpu_mpi_copy_ram_to_mpi_sync(
  755. (void*) (src + src_offset), src_node,
  756. (void*) (dst + dst_offset), dst_node,
  757. size);
  758. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM, STARPU_CPU_RAM):
  759. if (async_data)
  760. return _starpu_mpi_copy_mpi_to_ram_async(
  761. (void*) (src + src_offset), src_node,
  762. (void*) (dst + dst_offset), dst_node,
  763. size, async_data);
  764. else
  765. return _starpu_mpi_copy_mpi_to_ram_sync(
  766. (void*) (src + src_offset), src_node,
  767. (void*) (dst + dst_offset), dst_node,
  768. size);
  769. case _STARPU_MEMORY_NODE_TUPLE(STARPU_MPI_MS_RAM, STARPU_MPI_MS_RAM):
  770. if (async_data)
  771. return _starpu_mpi_copy_sink_to_sink_async(
  772. (void*) (src + src_offset), src_node,
  773. (void*) (dst + dst_offset), dst_node,
  774. size, async_data);
  775. else
  776. return _starpu_mpi_copy_sink_to_sink_sync(
  777. (void*) (src + src_offset), src_node,
  778. (void*) (dst + dst_offset), dst_node,
  779. size);
  780. #endif
  781. case _STARPU_MEMORY_NODE_TUPLE(STARPU_CPU_RAM, STARPU_DISK_RAM):
  782. {
  783. return _starpu_disk_copy_src_to_disk(
  784. (void*) (src + src_offset), src_node,
  785. (void*) dst, dst_offset, dst_node,
  786. size, async_channel);
  787. }
  788. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM, STARPU_CPU_RAM):
  789. return _starpu_disk_copy_disk_to_src(
  790. (void*) src, src_offset, src_node,
  791. (void*) (dst + dst_offset), dst_node,
  792. size, async_channel);
  793. case _STARPU_MEMORY_NODE_TUPLE(STARPU_DISK_RAM, STARPU_DISK_RAM):
  794. return _starpu_disk_copy_disk_to_disk(
  795. (void*) src, src_offset, src_node,
  796. (void*) dst, dst_offset, dst_node,
  797. size, async_channel);
  798. default:
  799. STARPU_ABORT();
  800. return -1;
  801. }
  802. return 0;
  803. }
  804. void _starpu_driver_wait_request_completion(struct _starpu_async_channel *async_channel)
  805. {
  806. #ifdef STARPU_SIMGRID
  807. _starpu_simgrid_wait_transfer_event(&async_channel->event);
  808. #else /* !SIMGRID */
  809. enum starpu_node_kind kind = async_channel->type;
  810. #ifdef STARPU_USE_CUDA
  811. cudaEvent_t event;
  812. cudaError_t cures;
  813. #endif
  814. switch (kind)
  815. {
  816. #ifdef STARPU_USE_CUDA
  817. case STARPU_CUDA_RAM:
  818. event = (*async_channel).event.cuda_event;
  819. cures = cudaEventSynchronize(event);
  820. if (STARPU_UNLIKELY(cures))
  821. STARPU_CUDA_REPORT_ERROR(cures);
  822. cures = cudaEventDestroy(event);
  823. if (STARPU_UNLIKELY(cures))
  824. STARPU_CUDA_REPORT_ERROR(cures);
  825. break;
  826. #endif
  827. #ifdef STARPU_USE_OPENCL
  828. case STARPU_OPENCL_RAM:
  829. {
  830. cl_int err;
  831. if ((*async_channel).event.opencl_event == NULL)
  832. STARPU_ABORT();
  833. err = clWaitForEvents(1, &((*async_channel).event.opencl_event));
  834. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  835. STARPU_OPENCL_REPORT_ERROR(err);
  836. err = clReleaseEvent((*async_channel).event.opencl_event);
  837. if (STARPU_UNLIKELY(err != CL_SUCCESS))
  838. STARPU_OPENCL_REPORT_ERROR(err);
  839. break;
  840. }
  841. #endif
  842. #ifdef STARPU_USE_MIC
  843. case STARPU_MIC_RAM:
  844. _starpu_mic_wait_request_completion(&(async_channel->event.mic_event));
  845. break;
  846. #endif
  847. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  848. case STARPU_MPI_MS_RAM:
  849. _starpu_mpi_common_wait_event(async_channel);
  850. break;
  851. #endif
  852. case STARPU_DISK_RAM:
  853. starpu_disk_wait_request(async_channel);
  854. if (async_channel->event.disk_event.ptr != NULL)
  855. {
  856. if (async_channel->event.disk_event.handle != NULL)
  857. {
  858. /* read is finished, we can already unpack */
  859. 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);
  860. /* ptr is allocated in full_read */
  861. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  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. /* ptr is allocated in full_read */
  938. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  939. }
  940. else
  941. {
  942. /* write is finished, ptr was allocated in pack_data */
  943. _starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
  944. }
  945. }
  946. break;
  947. case STARPU_CPU_RAM:
  948. default:
  949. STARPU_ABORT_MSG("Memory is not recognized (kind %d) \n", kind);
  950. }
  951. return success;
  952. #endif /* !SIMGRID */
  953. }