simgrid.c 18 KB

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