simgrid.c 18 KB

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