user_interactions.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2015, 2016 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <common/config.h>
  18. #include <common/utils.h>
  19. #include <core/task.h>
  20. #include <datawizard/coherency.h>
  21. #include <datawizard/copy_driver.h>
  22. #include <datawizard/write_back.h>
  23. #include <core/dependencies/data_concurrency.h>
  24. #include <core/sched_policy.h>
  25. /* Explicitly ask StarPU to allocate room for a piece of data on the specified
  26. * memory node. */
  27. int starpu_data_request_allocation(starpu_data_handle_t handle, unsigned node)
  28. {
  29. struct _starpu_data_request *r;
  30. STARPU_ASSERT(handle);
  31. _starpu_spin_lock(&handle->header_lock);
  32. r = _starpu_create_data_request(handle, NULL, &handle->per_node[node], node, STARPU_NONE, 0, 1, 0, 0, "starpu_data_request_allocation");
  33. /* we do not increase the refcnt associated to the request since we are
  34. * not waiting for its termination */
  35. _starpu_post_data_request(r, node);
  36. _starpu_spin_unlock(&handle->header_lock);
  37. return 0;
  38. }
  39. struct user_interaction_wrapper
  40. {
  41. starpu_data_handle_t handle;
  42. enum starpu_data_access_mode mode;
  43. int node;
  44. starpu_pthread_cond_t cond;
  45. starpu_pthread_mutex_t lock;
  46. unsigned finished;
  47. unsigned async;
  48. unsigned prefetch;
  49. int prio;
  50. void (*callback)(void *);
  51. void (*callback_fetch_data)(void *); // called after fetch_data
  52. void *callback_arg;
  53. struct starpu_task *pre_sync_task;
  54. struct starpu_task *post_sync_task;
  55. };
  56. /*
  57. * Non Blocking data request from application
  58. */
  59. /* put the current value of the data into RAM */
  60. static void _starpu_data_acquire_fetch_data_callback(void *arg)
  61. {
  62. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  63. starpu_data_handle_t handle = wrapper->handle;
  64. /* At that moment, the caller holds a reference to the piece of data.
  65. * We enqueue the "post" sync task in the list associated to the handle
  66. * so that it is submitted by the starpu_data_release
  67. * function. */
  68. if (wrapper->post_sync_task)
  69. _starpu_add_post_sync_tasks(wrapper->post_sync_task, handle);
  70. wrapper->callback(wrapper->callback_arg);
  71. free(wrapper);
  72. }
  73. static void _starpu_data_acquire_continuation_non_blocking(void *arg)
  74. {
  75. int ret;
  76. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  77. starpu_data_handle_t handle = wrapper->handle;
  78. STARPU_ASSERT(handle);
  79. struct _starpu_data_replicate *replicate =
  80. wrapper->node >= 0 ? &handle->per_node[wrapper->node] : NULL;
  81. ret = _starpu_fetch_data_on_node(handle, wrapper->node, replicate, wrapper->mode, 0, 0, 1,
  82. _starpu_data_acquire_fetch_data_callback, wrapper, 0, "_starpu_data_acquire_continuation_non_blocking");
  83. STARPU_ASSERT(!ret);
  84. }
  85. static void starpu_data_acquire_cb_pre_sync_callback(void *arg)
  86. {
  87. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  88. /* we try to get the data, if we do not succeed immediately, we set a
  89. * callback function that will be executed automatically when the data is
  90. * available again, otherwise we fetch the data directly */
  91. if (!_starpu_attempt_to_submit_data_request_from_apps(wrapper->handle, wrapper->mode,
  92. _starpu_data_acquire_continuation_non_blocking, wrapper))
  93. {
  94. /* no one has locked this data yet, so we proceed immediately */
  95. _starpu_data_acquire_continuation_non_blocking(wrapper);
  96. }
  97. }
  98. /* The data must be released by calling starpu_data_release later on */
  99. int starpu_data_acquire_on_node_cb_sequential_consistency(starpu_data_handle_t handle, int node,
  100. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg,
  101. int sequential_consistency)
  102. {
  103. STARPU_ASSERT(handle);
  104. STARPU_ASSERT_MSG(handle->nchildren == 0, "Acquiring a partitioned data (%p) is not possible", handle);
  105. _STARPU_LOG_IN();
  106. struct user_interaction_wrapper *wrapper;
  107. _STARPU_MALLOC(wrapper, sizeof(struct user_interaction_wrapper));
  108. wrapper->handle = handle;
  109. wrapper->node = node;
  110. wrapper->mode = mode;
  111. wrapper->callback = callback;
  112. wrapper->callback_arg = arg;
  113. STARPU_PTHREAD_COND_INIT(&wrapper->cond, NULL);
  114. STARPU_PTHREAD_MUTEX_INIT(&wrapper->lock, NULL);
  115. wrapper->finished = 0;
  116. wrapper->pre_sync_task = NULL;
  117. wrapper->post_sync_task = NULL;
  118. STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  119. int handle_sequential_consistency = handle->sequential_consistency;
  120. if (handle_sequential_consistency && sequential_consistency)
  121. {
  122. struct starpu_task *new_task;
  123. wrapper->pre_sync_task = starpu_task_create();
  124. wrapper->pre_sync_task->name = "_starpu_data_acquire_cb_pre";
  125. wrapper->pre_sync_task->detach = 1;
  126. wrapper->pre_sync_task->callback_func = starpu_data_acquire_cb_pre_sync_callback;
  127. wrapper->pre_sync_task->callback_arg = wrapper;
  128. wrapper->post_sync_task = starpu_task_create();
  129. wrapper->post_sync_task->name = "_starpu_data_acquire_cb_post";
  130. wrapper->post_sync_task->detach = 1;
  131. new_task = _starpu_detect_implicit_data_deps_with_handle(wrapper->pre_sync_task, wrapper->post_sync_task, &_starpu_get_job_associated_to_task(wrapper->post_sync_task)->implicit_dep_slot, handle, mode);
  132. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  133. if (new_task)
  134. {
  135. int ret = _starpu_task_submit_internally(new_task);
  136. STARPU_ASSERT(!ret);
  137. }
  138. /* TODO detect if this is superflous */
  139. int ret = _starpu_task_submit_internally(wrapper->pre_sync_task);
  140. STARPU_ASSERT(!ret);
  141. }
  142. else
  143. {
  144. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  145. starpu_data_acquire_cb_pre_sync_callback(wrapper);
  146. }
  147. _STARPU_LOG_OUT();
  148. return 0;
  149. }
  150. int starpu_data_acquire_on_node_cb(starpu_data_handle_t handle, int node,
  151. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  152. {
  153. return starpu_data_acquire_on_node_cb_sequential_consistency(handle, node, mode, callback, arg, 1);
  154. }
  155. int starpu_data_acquire_cb(starpu_data_handle_t handle,
  156. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  157. {
  158. return starpu_data_acquire_on_node_cb(handle, STARPU_MAIN_RAM, mode, callback, arg);
  159. }
  160. int starpu_data_acquire_cb_sequential_consistency(starpu_data_handle_t handle,
  161. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg, int sequential_consistency)
  162. {
  163. return starpu_data_acquire_on_node_cb_sequential_consistency(handle, STARPU_MAIN_RAM, mode, callback, arg, sequential_consistency);
  164. }
  165. /*
  166. * Block data request from application
  167. */
  168. static inline void _starpu_data_acquire_continuation(void *arg)
  169. {
  170. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  171. starpu_data_handle_t handle = wrapper->handle;
  172. STARPU_ASSERT(handle);
  173. struct _starpu_data_replicate *replicate =
  174. wrapper->node >= 0 ? &handle->per_node[wrapper->node] : NULL;
  175. int ret;
  176. ret = _starpu_fetch_data_on_node(handle, wrapper->node, replicate, wrapper->mode, 0, 0, 0, NULL, NULL, 0, "_starpu_data_acquire_continuation");
  177. STARPU_ASSERT(!ret);
  178. /* continuation of starpu_data_acquire */
  179. STARPU_PTHREAD_MUTEX_LOCK(&wrapper->lock);
  180. wrapper->finished = 1;
  181. STARPU_PTHREAD_COND_SIGNAL(&wrapper->cond);
  182. STARPU_PTHREAD_MUTEX_UNLOCK(&wrapper->lock);
  183. }
  184. /* The data must be released by calling starpu_data_release later on */
  185. int starpu_data_acquire_on_node(starpu_data_handle_t handle, int node, enum starpu_data_access_mode mode)
  186. {
  187. STARPU_ASSERT(handle);
  188. STARPU_ASSERT_MSG(handle->nchildren == 0, "Acquiring a partitioned data is not possible");
  189. _STARPU_LOG_IN();
  190. /* unless asynchronous, it is forbidden to call this function from a callback or a codelet */
  191. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "Acquiring a data synchronously is not possible from a codelet or from a task callback, use starpu_data_acquire_cb instead.");
  192. if (_starpu_data_is_multiformat_handle(handle) &&
  193. _starpu_handle_needs_conversion_task(handle, 0))
  194. {
  195. struct starpu_task *task = _starpu_create_conversion_task(handle, 0);
  196. int ret;
  197. _starpu_spin_lock(&handle->header_lock);
  198. handle->refcnt--;
  199. handle->busy_count--;
  200. handle->mf_node = 0;
  201. _starpu_spin_unlock(&handle->header_lock);
  202. task->synchronous = 1;
  203. ret = _starpu_task_submit_internally(task);
  204. STARPU_ASSERT(!ret);
  205. }
  206. struct user_interaction_wrapper wrapper =
  207. {
  208. .handle = handle,
  209. .mode = mode,
  210. .node = node,
  211. .finished = 0
  212. };
  213. STARPU_PTHREAD_COND_INIT(&wrapper.cond, NULL);
  214. STARPU_PTHREAD_MUTEX_INIT(&wrapper.lock, NULL);
  215. // _STARPU_DEBUG("TAKE sequential_consistency_mutex starpu_data_acquire\n");
  216. STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  217. int sequential_consistency = handle->sequential_consistency;
  218. if (sequential_consistency)
  219. {
  220. struct starpu_task *new_task;
  221. wrapper.pre_sync_task = starpu_task_create();
  222. wrapper.pre_sync_task->name = "_starpu_data_acquire_pre";
  223. wrapper.pre_sync_task->detach = 0;
  224. wrapper.post_sync_task = starpu_task_create();
  225. wrapper.post_sync_task->name = "_starpu_data_acquire_post";
  226. wrapper.post_sync_task->detach = 1;
  227. new_task = _starpu_detect_implicit_data_deps_with_handle(wrapper.pre_sync_task, wrapper.post_sync_task, &_starpu_get_job_associated_to_task(wrapper.post_sync_task)->implicit_dep_slot, handle, mode);
  228. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  229. if (new_task)
  230. {
  231. int ret = _starpu_task_submit_internally(new_task);
  232. STARPU_ASSERT(!ret);
  233. }
  234. /* TODO detect if this is superflous */
  235. wrapper.pre_sync_task->synchronous = 1;
  236. int ret = _starpu_task_submit_internally(wrapper.pre_sync_task);
  237. STARPU_ASSERT(!ret);
  238. }
  239. else
  240. {
  241. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  242. }
  243. /* we try to get the data, if we do not succeed immediately, we set a
  244. * callback function that will be executed automatically when the data is
  245. * available again, otherwise we fetch the data directly */
  246. if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode, _starpu_data_acquire_continuation, &wrapper))
  247. {
  248. struct _starpu_data_replicate *replicate =
  249. node >= 0 ? &handle->per_node[node] : NULL;
  250. /* no one has locked this data yet, so we proceed immediately */
  251. int ret = _starpu_fetch_data_on_node(handle, node, replicate, mode, 0, 0, 0, NULL, NULL, 0, "starpu_data_acquire_on_node");
  252. STARPU_ASSERT(!ret);
  253. }
  254. else
  255. {
  256. STARPU_PTHREAD_MUTEX_LOCK(&wrapper.lock);
  257. while (!wrapper.finished)
  258. STARPU_PTHREAD_COND_WAIT(&wrapper.cond, &wrapper.lock);
  259. STARPU_PTHREAD_MUTEX_UNLOCK(&wrapper.lock);
  260. }
  261. STARPU_PTHREAD_COND_DESTROY(&wrapper.cond);
  262. STARPU_PTHREAD_MUTEX_DESTROY(&wrapper.lock);
  263. /* At that moment, the caller holds a reference to the piece of data.
  264. * We enqueue the "post" sync task in the list associated to the handle
  265. * so that it is submitted by the starpu_data_release
  266. * function. */
  267. if (sequential_consistency)
  268. _starpu_add_post_sync_tasks(wrapper.post_sync_task, handle);
  269. _STARPU_LOG_OUT();
  270. return 0;
  271. }
  272. int starpu_data_acquire(starpu_data_handle_t handle, enum starpu_data_access_mode mode)
  273. {
  274. return starpu_data_acquire_on_node(handle, STARPU_MAIN_RAM, mode);
  275. }
  276. /* This function must be called after starpu_data_acquire so that the
  277. * application release the data */
  278. void starpu_data_release_on_node(starpu_data_handle_t handle, int node)
  279. {
  280. STARPU_ASSERT(handle);
  281. /* In case there are some implicit dependencies, unlock the "post sync" tasks */
  282. _starpu_unlock_post_sync_tasks(handle);
  283. /* The application can now release the rw-lock */
  284. if (node >= 0)
  285. _starpu_release_data_on_node(handle, 0, &handle->per_node[node]);
  286. else
  287. {
  288. _starpu_spin_lock(&handle->header_lock);
  289. if (node == STARPU_ACQUIRE_NO_NODE_LOCK_ALL)
  290. {
  291. int i;
  292. for (i = 0; i < STARPU_MAXNODES; i++)
  293. handle->per_node[i].refcnt--;
  294. }
  295. handle->busy_count--;
  296. if (!_starpu_notify_data_dependencies(handle))
  297. _starpu_spin_unlock(&handle->header_lock);
  298. }
  299. }
  300. void starpu_data_release(starpu_data_handle_t handle)
  301. {
  302. starpu_data_release_on_node(handle, STARPU_MAIN_RAM);
  303. }
  304. static void _prefetch_data_on_node(void *arg)
  305. {
  306. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  307. starpu_data_handle_t handle = wrapper->handle;
  308. int ret;
  309. struct _starpu_data_replicate *replicate = &handle->per_node[wrapper->node];
  310. ret = _starpu_fetch_data_on_node(handle, wrapper->node, replicate, STARPU_R, wrapper->async, wrapper->prefetch, wrapper->async, NULL, NULL, wrapper->prio, "_prefetch_data_on_node");
  311. STARPU_ASSERT(!ret);
  312. if (wrapper->async)
  313. free(wrapper);
  314. else
  315. {
  316. STARPU_PTHREAD_MUTEX_LOCK(&wrapper->lock);
  317. wrapper->finished = 1;
  318. STARPU_PTHREAD_COND_SIGNAL(&wrapper->cond);
  319. STARPU_PTHREAD_MUTEX_UNLOCK(&wrapper->lock);
  320. }
  321. _starpu_spin_lock(&handle->header_lock);
  322. if (!_starpu_notify_data_dependencies(handle))
  323. _starpu_spin_unlock(&handle->header_lock);
  324. }
  325. static
  326. int _starpu_prefetch_data_on_node_with_mode(starpu_data_handle_t handle, unsigned node, unsigned async, enum starpu_data_access_mode mode, unsigned prefetch, int prio)
  327. {
  328. STARPU_ASSERT(handle);
  329. /* it is forbidden to call this function from a callback or a codelet */
  330. STARPU_ASSERT_MSG(async || _starpu_worker_may_perform_blocking_calls(), "Synchronous prefetch is not possible from a task or a callback");
  331. struct user_interaction_wrapper *wrapper;
  332. _STARPU_MALLOC(wrapper, sizeof(*wrapper));
  333. wrapper->handle = handle;
  334. wrapper->node = node;
  335. wrapper->async = async;
  336. wrapper->prefetch = prefetch;
  337. wrapper->prio = prio;
  338. STARPU_PTHREAD_COND_INIT(&wrapper->cond, NULL);
  339. STARPU_PTHREAD_MUTEX_INIT(&wrapper->lock, NULL);
  340. wrapper->finished = 0;
  341. if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode, _prefetch_data_on_node, wrapper))
  342. {
  343. /* we can immediately proceed */
  344. struct _starpu_data_replicate *replicate = &handle->per_node[node];
  345. STARPU_PTHREAD_COND_DESTROY(&wrapper->cond);
  346. STARPU_PTHREAD_MUTEX_DESTROY(&wrapper->lock);
  347. free(wrapper);
  348. _starpu_fetch_data_on_node(handle, node, replicate, mode, async, prefetch, async, NULL, NULL, prio, "_starpu_prefetch_data_on_node_with_mode");
  349. /* remove the "lock"/reference */
  350. _starpu_spin_lock(&handle->header_lock);
  351. if (!async)
  352. {
  353. /* Release our refcnt, like _starpu_release_data_on_node would do */
  354. replicate->refcnt--;
  355. STARPU_ASSERT(replicate->refcnt >= 0);
  356. STARPU_ASSERT(handle->busy_count > 0);
  357. handle->busy_count--;
  358. }
  359. /* In case there was a temporary handle (eg. used for reduction), this
  360. * handle may have requested to be destroyed when the data is released
  361. * */
  362. if (!_starpu_notify_data_dependencies(handle))
  363. _starpu_spin_unlock(&handle->header_lock);
  364. }
  365. else if (!async)
  366. {
  367. STARPU_PTHREAD_MUTEX_LOCK(&wrapper->lock);
  368. while (!wrapper->finished)
  369. STARPU_PTHREAD_COND_WAIT(&wrapper->cond, &wrapper->lock);
  370. STARPU_PTHREAD_MUTEX_UNLOCK(&wrapper->lock);
  371. STARPU_PTHREAD_COND_DESTROY(&wrapper->cond);
  372. STARPU_PTHREAD_MUTEX_DESTROY(&wrapper->lock);
  373. free(wrapper);
  374. }
  375. return 0;
  376. }
  377. int starpu_data_fetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  378. {
  379. return _starpu_prefetch_data_on_node_with_mode(handle, node, async, STARPU_R, 0, 0);
  380. }
  381. int starpu_data_prefetch_on_node_prio(starpu_data_handle_t handle, unsigned node, unsigned async, int prio)
  382. {
  383. return _starpu_prefetch_data_on_node_with_mode(handle, node, async, STARPU_R, 1, prio);
  384. }
  385. int starpu_data_prefetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  386. {
  387. return starpu_data_prefetch_on_node_prio(handle, node, async, 0);
  388. }
  389. int starpu_data_idle_prefetch_on_node_prio(starpu_data_handle_t handle, unsigned node, unsigned async, int prio)
  390. {
  391. return _starpu_prefetch_data_on_node_with_mode(handle, node, async, STARPU_R, 2, prio);
  392. }
  393. int starpu_data_idle_prefetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  394. {
  395. return starpu_data_idle_prefetch_on_node_prio(handle, node, async, 0);
  396. }
  397. static void _starpu_data_wont_use(void *data)
  398. {
  399. unsigned node;
  400. starpu_data_handle_t handle = data;
  401. _starpu_spin_lock(&handle->header_lock);
  402. for (node = 0; node < STARPU_MAXNODES; node++)
  403. {
  404. struct _starpu_data_replicate *local = &handle->per_node[node];
  405. if (local->allocated && local->automatically_allocated)
  406. _starpu_memchunk_wont_use(local->mc, node);
  407. }
  408. if (handle->per_worker)
  409. {
  410. unsigned nworkers = starpu_worker_get_count();
  411. unsigned worker;
  412. for (worker = 0; worker < nworkers; worker++)
  413. {
  414. struct _starpu_data_replicate *local = &handle->per_worker[worker];
  415. if (local->allocated && local->automatically_allocated)
  416. _starpu_memchunk_wont_use(local->mc, starpu_worker_get_memory_node(worker));
  417. }
  418. }
  419. _starpu_spin_unlock(&handle->header_lock);
  420. starpu_data_release_on_node(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL);
  421. if (handle->home_node != -1)
  422. starpu_data_idle_prefetch_on_node(handle, handle->home_node, 1);
  423. }
  424. void starpu_data_wont_use(starpu_data_handle_t handle)
  425. {
  426. starpu_data_acquire_on_node_cb(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL, STARPU_R, _starpu_data_wont_use, handle);
  427. }
  428. /*
  429. * It is possible to specify that a piece of data can be discarded without
  430. * impacting the application.
  431. */
  432. int _starpu_has_not_important_data;
  433. void starpu_data_advise_as_important(starpu_data_handle_t handle, unsigned is_important)
  434. {
  435. if (!is_important)
  436. _starpu_has_not_important_data = 1;
  437. _starpu_spin_lock(&handle->header_lock);
  438. /* first take all the children lock (in order !) */
  439. unsigned child;
  440. for (child = 0; child < handle->nchildren; child++)
  441. {
  442. /* make sure the intermediate children is advised as well */
  443. starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
  444. if (child_handle->nchildren > 0)
  445. starpu_data_advise_as_important(child_handle, is_important);
  446. }
  447. handle->is_not_important = !is_important;
  448. /* now the parent may be used again so we release the lock */
  449. _starpu_spin_unlock(&handle->header_lock);
  450. }
  451. void starpu_data_set_sequential_consistency_flag(starpu_data_handle_t handle, unsigned flag)
  452. {
  453. _starpu_spin_lock(&handle->header_lock);
  454. unsigned child;
  455. for (child = 0; child < handle->nchildren; child++)
  456. {
  457. /* make sure that the flags are applied to the children as well */
  458. starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
  459. if (child_handle->nchildren > 0)
  460. starpu_data_set_sequential_consistency_flag(child_handle, flag);
  461. }
  462. STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  463. handle->sequential_consistency = flag;
  464. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  465. _starpu_spin_unlock(&handle->header_lock);
  466. }
  467. unsigned starpu_data_get_sequential_consistency_flag(starpu_data_handle_t handle)
  468. {
  469. return handle->sequential_consistency;
  470. }
  471. /* By default, sequential consistency is enabled */
  472. static unsigned default_sequential_consistency_flag = 1;
  473. unsigned starpu_data_get_default_sequential_consistency_flag(void)
  474. {
  475. return default_sequential_consistency_flag;
  476. }
  477. void starpu_data_set_default_sequential_consistency_flag(unsigned flag)
  478. {
  479. default_sequential_consistency_flag = flag;
  480. }
  481. /* Query the status of the handle on the specified memory node. */
  482. void starpu_data_query_status(starpu_data_handle_t handle, int memory_node, int *is_allocated, int *is_valid, int *is_requested)
  483. {
  484. // XXX : this is just a hint, so we don't take the lock ...
  485. // _starpu_spin_lock(&handle->header_lock);
  486. if (is_allocated)
  487. *is_allocated = handle->per_node[memory_node].allocated;
  488. if (is_valid)
  489. *is_valid = (handle->per_node[memory_node].state != STARPU_INVALID);
  490. if (is_requested)
  491. {
  492. int requested = 0;
  493. unsigned node;
  494. for (node = 0; node < STARPU_MAXNODES; node++)
  495. {
  496. if (handle->per_node[memory_node].requested & (1UL << node))
  497. {
  498. requested = 1;
  499. break;
  500. }
  501. }
  502. *is_requested = requested;
  503. }
  504. // _starpu_spin_unlock(&handle->header_lock);
  505. }