simgrid.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2015 Université de Bordeaux
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <datawizard/memory_nodes.h>
  18. #include <common/config.h>
  19. #ifdef HAVE_UNISTD_H
  20. #include <unistd.h>
  21. #endif
  22. #include <core/perfmodel/perfmodel.h>
  23. #include <core/workers.h>
  24. #include <core/simgrid.h>
  25. #ifdef STARPU_SIMGRID
  26. #include <sys/resource.h>
  27. #pragma weak starpu_main
  28. extern int starpu_main(int argc, char *argv[]);
  29. #pragma weak smpi_main
  30. extern int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[]);
  31. #pragma weak _starpu_mpi_simgrid_init
  32. extern int _starpu_mpi_simgrid_init(int argc, char *argv[]);
  33. struct main_args
  34. {
  35. int argc;
  36. char **argv;
  37. };
  38. int do_starpu_main(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
  39. {
  40. struct main_args *args = (void*) argv;
  41. return starpu_main(args->argc, args->argv);
  42. }
  43. /* In case the MPI application didn't use smpicc to build the file containing
  44. * main(), try to cope by calling starpu_main */
  45. #pragma weak smpi_simulated_main_
  46. int smpi_simulated_main_(int argc, char *argv[])
  47. {
  48. if (!starpu_main)
  49. {
  50. _STARPU_ERROR("In simgrid mode, the file containing the main() function of this application needs to be compiled with starpu.h or starpu_simgrid_wrap.h included, to properly rename it into starpu_main\n");
  51. exit(EXIT_FAILURE);
  52. }
  53. return starpu_main(argc, argv);
  54. }
  55. #ifdef HAVE_MSG_ENVIRONMENT_GET_ROUTING_ROOT
  56. #ifdef HAVE_MSG_GET_AS_BY_NAME
  57. msg_as_t _starpu_simgrid_get_as_by_name(const char *name)
  58. {
  59. return MSG_get_as_by_name(name);
  60. }
  61. #else /* HAVE_MSG_GET_AS_BY_NAME */
  62. static msg_as_t __starpu_simgrid_get_as_by_name(msg_as_t root, const char *name)
  63. {
  64. xbt_dict_t dict;
  65. xbt_dict_cursor_t cursor;
  66. const char *key;
  67. msg_as_t as, ret;
  68. dict = MSG_environment_as_get_routing_sons(root);
  69. xbt_dict_foreach(dict, cursor, key, as)
  70. {
  71. if (!strcmp(MSG_environment_as_get_name(as), name))
  72. return as;
  73. ret = __starpu_simgrid_get_as_by_name(as, name);
  74. if (ret)
  75. return ret;
  76. }
  77. return NULL;
  78. }
  79. msg_as_t _starpu_simgrid_get_as_by_name(const char *name)
  80. {
  81. return __starpu_simgrid_get_as_by_name(MSG_environment_get_routing_root(), name);
  82. }
  83. #endif /* HAVE_MSG_GET_AS_BY_NAME */
  84. #endif /* HAVE_MSG_ENVIRONMENT_GET_ROUTING_ROOT */
  85. int _starpu_simgrid_get_nbhosts(const char *prefix)
  86. {
  87. int ret;
  88. xbt_dynar_t hosts;
  89. unsigned i, nb;
  90. unsigned len = strlen(prefix);
  91. #ifdef HAVE_MSG_ENVIRONMENT_GET_ROUTING_ROOT
  92. char new_prefix[32];
  93. if (_starpu_simgrid_running_smpi())
  94. {
  95. char name[32];
  96. STARPU_ASSERT(starpu_mpi_world_rank);
  97. snprintf(name, sizeof(name), STARPU_MPI_AS_PREFIX"%u", starpu_mpi_world_rank());
  98. hosts = MSG_environment_as_get_hosts(_starpu_simgrid_get_as_by_name(name));
  99. len = snprintf(new_prefix, sizeof(new_prefix), "%s-%s", name, prefix);
  100. prefix = new_prefix;
  101. len = strlen(prefix);
  102. }
  103. else
  104. #endif /* HAVE_MSG_ENVIRONMENT_GET_ROUTING_ROOT */
  105. hosts = MSG_hosts_as_dynar();
  106. nb = xbt_dynar_length(hosts);
  107. ret = 0;
  108. for (i = 0; i < nb; i++)
  109. {
  110. const char *name;
  111. name = MSG_host_get_name(xbt_dynar_get_as(hosts, i, msg_host_t));
  112. if (!strncmp(name, prefix, len))
  113. ret++;
  114. }
  115. xbt_dynar_free(&hosts);
  116. return ret;
  117. }
  118. unsigned long long _starpu_simgrid_get_memsize(const char *prefix, unsigned devid)
  119. {
  120. char name[32];
  121. msg_host_t host;
  122. const char *memsize;
  123. snprintf(name, sizeof(name), "%s%u", prefix, devid);
  124. host = _starpu_simgrid_get_host_by_name(name);
  125. if (!host)
  126. return 0;
  127. if (!MSG_host_get_properties(host))
  128. return 0;
  129. memsize = MSG_host_get_property_value(host, "memsize");
  130. if (!memsize)
  131. return 0;
  132. return atoll(memsize);
  133. }
  134. msg_host_t _starpu_simgrid_get_host_by_name(const char *name)
  135. {
  136. if (_starpu_simgrid_running_smpi())
  137. {
  138. char mpiname[32];
  139. STARPU_ASSERT(starpu_mpi_world_rank);
  140. snprintf(mpiname, sizeof(mpiname), STARPU_MPI_AS_PREFIX"%d-%s", starpu_mpi_world_rank(), name);
  141. return MSG_get_host_by_name(mpiname);
  142. }
  143. else
  144. return MSG_get_host_by_name(name);
  145. }
  146. msg_host_t _starpu_simgrid_get_host_by_worker(struct _starpu_worker *worker)
  147. {
  148. char *prefix;
  149. char name[16];
  150. msg_host_t host;
  151. switch (worker->arch)
  152. {
  153. case STARPU_CPU_WORKER:
  154. prefix = "CPU";
  155. break;
  156. case STARPU_CUDA_WORKER:
  157. prefix = "CUDA";
  158. break;
  159. case STARPU_OPENCL_WORKER:
  160. prefix = "OpenCL";
  161. break;
  162. default:
  163. STARPU_ASSERT(0);
  164. }
  165. snprintf(name, sizeof(name), "%s%d", prefix, worker->devid);
  166. host = _starpu_simgrid_get_host_by_name(name);
  167. STARPU_ASSERT_MSG(host, "Could not find host %s!", name);
  168. return host;
  169. }
  170. #ifdef STARPU_DEVEL
  171. #warning TODO: use another way to start main, when simgrid provides it, and then include the application-provided configuration for platform numbers
  172. #endif
  173. #undef main
  174. int main(int argc, char **argv)
  175. {
  176. char path[256];
  177. if (!starpu_main)
  178. {
  179. _STARPU_ERROR("In simgrid mode, the file containing the main() function of this application needs to be compiled with starpu.h or starpu_simgrid_wrap.h included, to properly rename it into starpu_main\n");
  180. exit(EXIT_FAILURE);
  181. }
  182. if (_starpu_simgrid_running_smpi())
  183. {
  184. /* Oops, we are running SMPI, let it start Simgrid, and we'll
  185. * take back hand in _starpu_simgrid_init from starpu_init() */
  186. return smpi_main(_starpu_mpi_simgrid_init, argc, argv);
  187. }
  188. MSG_init(&argc, argv);
  189. #if SIMGRID_VERSION_MAJOR < 3 || (SIMGRID_VERSION_MAJOR == 3 && SIMGRID_VERSION_MINOR < 9)
  190. /* Versions earlier than 3.9 didn't support our communication tasks */
  191. MSG_config("workstation/model", "ptask_L07");
  192. #endif
  193. /* Simgrid uses tiny stacks by default. This comes unexpected to our users. */
  194. extern xbt_cfg_t _sg_cfg_set;
  195. unsigned stack_size = 8192;
  196. struct rlimit rlim;
  197. if (getrlimit(RLIMIT_STACK, &rlim) == 0 && rlim.rlim_cur != 0 && rlim.rlim_cur != RLIM_INFINITY)
  198. stack_size = rlim.rlim_cur / 1024;
  199. xbt_cfg_set_int(_sg_cfg_set, "contexts/stack_size", stack_size);
  200. /* Load XML platform */
  201. _starpu_simgrid_get_platform_path(path, sizeof(path));
  202. MSG_create_environment(path);
  203. struct main_args *args = malloc(sizeof(*args));
  204. args->argc = argc;
  205. args->argv = argv;
  206. MSG_process_create_with_arguments("main", &do_starpu_main, calloc(MAX_TSD, sizeof(void*)), MSG_get_host_by_name("MAIN"), 0, (char**) args);
  207. MSG_main();
  208. return 0;
  209. }
  210. void _starpu_simgrid_init()
  211. {
  212. if (!starpu_main)
  213. {
  214. _STARPU_ERROR("In simgrid mode, the file containing the main() function of this application needs to be compiled with starpu.h or starpu_simgrid_wrap.h included, to properly rename it into starpu_main\n");
  215. exit(EXIT_FAILURE);
  216. }
  217. if (_starpu_simgrid_running_smpi())
  218. {
  219. MSG_process_set_data(MSG_process_self(), calloc(MAX_TSD, sizeof(void*)));
  220. }
  221. }
  222. /*
  223. * Tasks
  224. */
  225. struct task
  226. {
  227. msg_task_t task;
  228. int workerid;
  229. /* communication termination signalization */
  230. unsigned *finished;
  231. starpu_pthread_mutex_t *mutex;
  232. starpu_pthread_cond_t *cond;
  233. /* Task which waits for this task */
  234. struct task *next;
  235. };
  236. static struct task *last_task[STARPU_NMAXWORKERS];
  237. /* Actually execute the task. */
  238. static int task_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
  239. {
  240. struct task *task = (void*) argv;
  241. _STARPU_DEBUG("task %p started\n", task);
  242. MSG_task_execute(task->task);
  243. MSG_task_destroy(task->task);
  244. _STARPU_DEBUG("task %p finished\n", task);
  245. STARPU_PTHREAD_MUTEX_LOCK(task->mutex);
  246. *task->finished = 1;
  247. STARPU_PTHREAD_COND_BROADCAST(task->cond);
  248. STARPU_PTHREAD_MUTEX_UNLOCK(task->mutex);
  249. /* The worker which started this task may be sleeping out of tasks, wake it */
  250. starpu_wake_worker(task->workerid);
  251. if (last_task[task->workerid] == task)
  252. last_task[task->workerid] = NULL;
  253. if (task->next)
  254. MSG_process_create_with_arguments("task", task_execute, calloc(MAX_TSD, sizeof(void*)), MSG_host_self(), 0, (char**) task->next);
  255. /* Task is freed with process context */
  256. return 0;
  257. }
  258. /* Wait for completion of all asynchronous tasks for this worker */
  259. void _starpu_simgrid_wait_tasks(int workerid)
  260. {
  261. struct task *task = last_task[workerid];
  262. if (!task)
  263. return;
  264. unsigned *finished = task->finished;
  265. starpu_pthread_mutex_t *mutex = task->mutex;
  266. starpu_pthread_cond_t *cond = task->cond;
  267. STARPU_PTHREAD_MUTEX_LOCK(mutex);
  268. while (!*finished)
  269. STARPU_PTHREAD_COND_WAIT(cond, mutex);
  270. STARPU_PTHREAD_MUTEX_UNLOCK(mutex);
  271. }
  272. /* Task execution submitted by StarPU */
  273. void _starpu_simgrid_submit_job(int workerid, struct _starpu_job *j, struct starpu_perfmodel_arch* perf_arch, double length, unsigned *finished, starpu_pthread_mutex_t *mutex, starpu_pthread_cond_t *cond)
  274. {
  275. struct starpu_task *starpu_task = j->task;
  276. msg_task_t simgrid_task;
  277. if (j->internal)
  278. /* This is not useful to include in simulation (and probably
  279. * doesn't have a perfmodel anyway) */
  280. return;
  281. if (isnan(length))
  282. {
  283. length = starpu_task_expected_length(starpu_task, perf_arch, j->nimpl);
  284. STARPU_ASSERT_MSG(!_STARPU_IS_ZERO(length) && !isnan(length),
  285. "Codelet %s does not have a perfmodel, or is not calibrated enough, please re-run in non-simgrid mode until it is calibrated",
  286. _starpu_job_get_model_name(j));
  287. }
  288. simgrid_task = MSG_task_create(_starpu_job_get_task_name(j),
  289. length/1000000.0*MSG_get_host_speed(MSG_host_self()),
  290. 0, NULL);
  291. if (finished == NULL)
  292. {
  293. /* Synchronous execution */
  294. /* First wait for previous tasks */
  295. _starpu_simgrid_wait_tasks(workerid);
  296. MSG_task_execute(simgrid_task);
  297. MSG_task_destroy(simgrid_task);
  298. }
  299. else
  300. {
  301. /* Asynchronous execution */
  302. struct task *task = malloc(sizeof(*task));
  303. task->task = simgrid_task;
  304. task->workerid = workerid;
  305. task->finished = finished;
  306. *finished = 0;
  307. task->mutex = mutex;
  308. task->cond = cond;
  309. task->next = NULL;
  310. /* Sleep 10µs for the GPU task queueing */
  311. if (_starpu_simgrid_queue_malloc_cost())
  312. MSG_process_sleep(0.000010);
  313. if (last_task[workerid])
  314. {
  315. /* Make this task depend on the previous */
  316. last_task[workerid]->next = task;
  317. last_task[workerid] = task;
  318. }
  319. else
  320. {
  321. last_task[workerid] = task;
  322. MSG_process_create_with_arguments("task", task_execute, calloc(MAX_TSD, sizeof(void*)), MSG_host_self(), 0, (char**) task);
  323. }
  324. }
  325. }
  326. /*
  327. * Transfers
  328. */
  329. /* Note: simgrid is not parallel, so there is no need to hold locks for management of transfers. */
  330. LIST_TYPE(transfer,
  331. msg_task_t task;
  332. int src_node;
  333. int dst_node;
  334. int run_node;
  335. /* communication termination signalization */
  336. unsigned *finished;
  337. starpu_pthread_mutex_t *mutex;
  338. starpu_pthread_cond_t *cond;
  339. /* transfers which wait for this transfer */
  340. struct transfer **wake;
  341. unsigned nwake;
  342. /* Number of transfers that this transfer waits for */
  343. unsigned nwait;
  344. )
  345. struct transfer_list pending;
  346. /* Tell for two transfers whether they should be handled in sequence */
  347. static int transfers_are_sequential(struct transfer *new_transfer, struct transfer *old_transfer)
  348. {
  349. int new_is_cuda STARPU_ATTRIBUTE_UNUSED, old_is_cuda STARPU_ATTRIBUTE_UNUSED;
  350. int new_is_opencl STARPU_ATTRIBUTE_UNUSED, old_is_opencl STARPU_ATTRIBUTE_UNUSED;
  351. int new_is_gpu_gpu, old_is_gpu_gpu;
  352. new_is_cuda = starpu_node_get_kind(new_transfer->src_node) == STARPU_CUDA_RAM;
  353. new_is_cuda |= starpu_node_get_kind(new_transfer->dst_node) == STARPU_CUDA_RAM;
  354. old_is_cuda = starpu_node_get_kind(old_transfer->src_node) == STARPU_CUDA_RAM;
  355. old_is_cuda |= starpu_node_get_kind(old_transfer->dst_node) == STARPU_CUDA_RAM;
  356. new_is_opencl = starpu_node_get_kind(new_transfer->src_node) == STARPU_OPENCL_RAM;
  357. new_is_opencl |= starpu_node_get_kind(new_transfer->dst_node) == STARPU_OPENCL_RAM;
  358. old_is_opencl = starpu_node_get_kind(old_transfer->src_node) == STARPU_OPENCL_RAM;
  359. old_is_opencl |= starpu_node_get_kind(old_transfer->dst_node) == STARPU_OPENCL_RAM;
  360. new_is_gpu_gpu = new_transfer->src_node && new_transfer->dst_node;
  361. old_is_gpu_gpu = old_transfer->src_node && old_transfer->dst_node;
  362. /* We ignore cuda-opencl transfers, they can not happen */
  363. STARPU_ASSERT(!((new_is_cuda && old_is_opencl) || (old_is_cuda && new_is_opencl)));
  364. /* The following constraints have been observed with CUDA alone */
  365. /* Same source/destination, sequential */
  366. if (new_transfer->src_node == old_transfer->src_node && new_transfer->dst_node == old_transfer->dst_node)
  367. return 1;
  368. /* Crossed GPU-GPU, sequential */
  369. if (new_is_gpu_gpu
  370. && new_transfer->src_node == old_transfer->dst_node
  371. && old_transfer->src_node == new_transfer->dst_node)
  372. return 1;
  373. /* GPU-GPU transfers are sequential with any RAM->GPU transfer */
  374. if (new_is_gpu_gpu
  375. && old_transfer->dst_node == new_transfer->src_node
  376. && old_transfer->dst_node == new_transfer->dst_node)
  377. return 1;
  378. if (old_is_gpu_gpu
  379. && new_transfer->dst_node == old_transfer->src_node
  380. && new_transfer->dst_node == old_transfer->dst_node)
  381. return 1;
  382. /* StarPU's constraint on CUDA transfers is using one stream per
  383. * source/destination pair, which is already handled above */
  384. return 0;
  385. }
  386. /* Actually execute the transfer, and then start transfers waiting for this one. */
  387. static int transfer_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
  388. {
  389. struct transfer *transfer = (void*) argv;
  390. unsigned i;
  391. _STARPU_DEBUG("transfer %p started\n", transfer);
  392. MSG_task_execute(transfer->task);
  393. MSG_task_destroy(transfer->task);
  394. _STARPU_DEBUG("transfer %p finished\n", transfer);
  395. STARPU_PTHREAD_MUTEX_LOCK(transfer->mutex);
  396. *transfer->finished = 1;
  397. STARPU_PTHREAD_COND_BROADCAST(transfer->cond);
  398. STARPU_PTHREAD_MUTEX_UNLOCK(transfer->mutex);
  399. /* The workers which started this request may be sleeping out of tasks, wake it */
  400. _starpu_wake_all_blocked_workers_on_node(transfer->run_node);
  401. /* Wake transfers waiting for my termination */
  402. /* Note: due to possible preemption inside process_create, the array
  403. * may grow while doing this */
  404. for (i = 0; i < transfer->nwake; i++)
  405. {
  406. struct transfer *wake = transfer->wake[i];
  407. STARPU_ASSERT(wake->nwait > 0);
  408. wake->nwait--;
  409. if (!wake->nwait)
  410. {
  411. _STARPU_DEBUG("triggering transfer %p\n", wake);
  412. MSG_process_create_with_arguments("transfer task", transfer_execute, calloc(MAX_TSD, sizeof(void*)), _starpu_simgrid_get_host_by_name("MAIN"), 0, (char**) wake);
  413. }
  414. }
  415. free(transfer->wake);
  416. transfer_list_erase(&pending, transfer);
  417. /* transfer is freed with process context */
  418. return 0;
  419. }
  420. /* Look for sequentialization between this transfer and pending transfers, and submit this one */
  421. static void transfer_submit(struct transfer *transfer)
  422. {
  423. struct transfer *old;
  424. for (old = transfer_list_begin(&pending);
  425. old != transfer_list_end(&pending);
  426. old = transfer_list_next(old))
  427. {
  428. if (transfers_are_sequential(transfer, old))
  429. {
  430. _STARPU_DEBUG("transfer %p(%d->%d) waits for %p(%d->%d)\n",
  431. transfer, transfer->src_node, transfer->dst_node,
  432. old, old->src_node, old->dst_node);
  433. /* Make new wait for the old */
  434. transfer->nwait++;
  435. /* Make old wake the new */
  436. old->wake = realloc(old->wake, (old->nwake + 1) * sizeof(old->wake));
  437. old->wake[old->nwake] = transfer;
  438. old->nwake++;
  439. }
  440. }
  441. transfer_list_push_front(&pending, transfer);
  442. if (!transfer->nwait)
  443. {
  444. _STARPU_DEBUG("transfer %p waits for nobody, starting\n", transfer);
  445. MSG_process_create_with_arguments("transfer task", transfer_execute, calloc(MAX_TSD, sizeof(void*)), _starpu_simgrid_get_host_by_name("MAIN"), 0, (char**) transfer);
  446. }
  447. }
  448. /* Data transfer issued by StarPU */
  449. int _starpu_simgrid_transfer(size_t size, unsigned src_node, unsigned dst_node, struct _starpu_data_request *req)
  450. {
  451. msg_task_t task;
  452. msg_host_t *hosts = calloc(2, sizeof(*hosts));
  453. double *computation = calloc(2, sizeof(*computation));
  454. double *communication = calloc(4, sizeof(*communication));
  455. starpu_pthread_mutex_t mutex;
  456. starpu_pthread_cond_t cond;
  457. unsigned finished;
  458. hosts[0] = _starpu_simgrid_memory_node_get_host(src_node);
  459. hosts[1] = _starpu_simgrid_memory_node_get_host(dst_node);
  460. STARPU_ASSERT(hosts[0] != hosts[1]);
  461. communication[1] = size;
  462. task = MSG_parallel_task_create("copy", 2, hosts, computation, communication, NULL);
  463. struct transfer *transfer = transfer_new();
  464. _STARPU_DEBUG("creating transfer %p for %lu bytes\n", transfer, (unsigned long) size);
  465. transfer->task = task;
  466. transfer->src_node = src_node;
  467. transfer->dst_node = dst_node;
  468. transfer->run_node = _starpu_memory_node_get_local_key();
  469. if (req)
  470. {
  471. transfer->finished = &req->async_channel.event.finished;
  472. transfer->mutex = &req->async_channel.event.mutex;
  473. transfer->cond = &req->async_channel.event.cond;
  474. }
  475. else
  476. {
  477. transfer->finished = &finished;
  478. transfer->mutex = &mutex;
  479. transfer->cond = &cond;
  480. }
  481. *transfer->finished = 0;
  482. STARPU_PTHREAD_MUTEX_INIT(transfer->mutex, NULL);
  483. STARPU_PTHREAD_COND_INIT(transfer->cond, NULL);
  484. transfer->wake = NULL;
  485. transfer->nwake = 0;
  486. transfer->nwait = 0;
  487. if (req)
  488. _STARPU_TRACE_START_DRIVER_COPY_ASYNC(src_node, dst_node);
  489. /* Sleep 10µs for the GPU transfer queueing */
  490. if (_starpu_simgrid_queue_malloc_cost())
  491. MSG_process_sleep(0.000010);
  492. transfer_submit(transfer);
  493. /* Note: from here, transfer might be already freed */
  494. if (req)
  495. {
  496. _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
  497. _STARPU_TRACE_DATA_COPY(src_node, dst_node, size);
  498. return -EAGAIN;
  499. }
  500. else
  501. {
  502. /* this is not associated to a request so it's synchronous */
  503. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  504. while (!finished)
  505. STARPU_PTHREAD_COND_WAIT(&cond, &mutex);
  506. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  507. return 0;
  508. }
  509. }
  510. int
  511. _starpu_simgrid_thread_start(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
  512. {
  513. struct _starpu_pthread_args *_args = (void*) argv;
  514. struct _starpu_pthread_args args = *_args;
  515. /* _args is freed with process context */
  516. args.f(args.arg);
  517. return 0;
  518. }
  519. #endif