user_interactions.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2015 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2015 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);
  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. void (*callback)(void *);
  50. void (*callback_fetch_data)(void *); // called after fetch_data
  51. void *callback_arg;
  52. struct starpu_task *pre_sync_task;
  53. struct starpu_task *post_sync_task;
  54. };
  55. /*
  56. * Non Blocking data request from application
  57. */
  58. /* put the current value of the data into RAM */
  59. static void _starpu_data_acquire_fetch_data_callback(void *arg)
  60. {
  61. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  62. starpu_data_handle_t handle = wrapper->handle;
  63. /* At that moment, the caller holds a reference to the piece of data.
  64. * We enqueue the "post" sync task in the list associated to the handle
  65. * so that it is submitted by the starpu_data_release
  66. * function. */
  67. if (wrapper->post_sync_task)
  68. _starpu_add_post_sync_tasks(wrapper->post_sync_task, handle);
  69. wrapper->callback(wrapper->callback_arg);
  70. free(wrapper);
  71. }
  72. static void _starpu_data_acquire_continuation_non_blocking(void *arg)
  73. {
  74. int ret;
  75. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  76. starpu_data_handle_t handle = wrapper->handle;
  77. STARPU_ASSERT(handle);
  78. if (wrapper->node >= 0)
  79. {
  80. struct _starpu_data_replicate *replicate = &handle->per_node[wrapper->node];
  81. ret = _starpu_fetch_data_on_node(handle, replicate, wrapper->mode, 0, 0, 1,
  82. _starpu_data_acquire_fetch_data_callback, wrapper);
  83. STARPU_ASSERT(!ret);
  84. }
  85. else
  86. _starpu_data_acquire_fetch_data_callback(wrapper);
  87. }
  88. static void starpu_data_acquire_cb_pre_sync_callback(void *arg)
  89. {
  90. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  91. /* we try to get the data, if we do not succeed immediately, we set a
  92. * callback function that will be executed automatically when the data is
  93. * available again, otherwise we fetch the data directly */
  94. if (!_starpu_attempt_to_submit_data_request_from_apps(wrapper->handle, wrapper->mode,
  95. _starpu_data_acquire_continuation_non_blocking, wrapper))
  96. {
  97. /* no one has locked this data yet, so we proceed immediately */
  98. _starpu_data_acquire_continuation_non_blocking(wrapper);
  99. }
  100. }
  101. /* The data must be released by calling starpu_data_release later on */
  102. int starpu_data_acquire_on_node_cb_sequential_consistency(starpu_data_handle_t handle, int node,
  103. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg,
  104. int sequential_consistency)
  105. {
  106. STARPU_ASSERT(handle);
  107. STARPU_ASSERT_MSG(handle->nchildren == 0, "Acquiring a partitioned data (%p) is not possible", handle);
  108. _STARPU_LOG_IN();
  109. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) malloc(sizeof(struct user_interaction_wrapper));
  110. STARPU_ASSERT(wrapper);
  111. wrapper->handle = handle;
  112. wrapper->node = node;
  113. wrapper->mode = mode;
  114. wrapper->callback = callback;
  115. wrapper->callback_arg = arg;
  116. STARPU_PTHREAD_COND_INIT(&wrapper->cond, NULL);
  117. STARPU_PTHREAD_MUTEX_INIT(&wrapper->lock, NULL);
  118. wrapper->finished = 0;
  119. wrapper->pre_sync_task = NULL;
  120. wrapper->post_sync_task = NULL;
  121. STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  122. int handle_sequential_consistency = handle->sequential_consistency;
  123. if (handle_sequential_consistency && sequential_consistency)
  124. {
  125. struct starpu_task *new_task;
  126. wrapper->pre_sync_task = starpu_task_create();
  127. wrapper->pre_sync_task->name = "_starpu_data_acquire_cb_pre";
  128. wrapper->pre_sync_task->detach = 1;
  129. wrapper->pre_sync_task->callback_func = starpu_data_acquire_cb_pre_sync_callback;
  130. wrapper->pre_sync_task->callback_arg = wrapper;
  131. wrapper->post_sync_task = starpu_task_create();
  132. wrapper->post_sync_task->name = "_starpu_data_acquire_cb_post";
  133. wrapper->post_sync_task->detach = 1;
  134. 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);
  135. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  136. if (new_task)
  137. {
  138. int ret = _starpu_task_submit_internally(new_task);
  139. STARPU_ASSERT(!ret);
  140. }
  141. /* TODO detect if this is superflous */
  142. int ret = _starpu_task_submit_internally(wrapper->pre_sync_task);
  143. STARPU_ASSERT(!ret);
  144. }
  145. else
  146. {
  147. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  148. starpu_data_acquire_cb_pre_sync_callback(wrapper);
  149. }
  150. _STARPU_LOG_OUT();
  151. return 0;
  152. }
  153. int starpu_data_acquire_on_node_cb(starpu_data_handle_t handle, int node,
  154. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  155. {
  156. return starpu_data_acquire_on_node_cb_sequential_consistency(handle, node, mode, callback, arg, 1);
  157. }
  158. int starpu_data_acquire_cb(starpu_data_handle_t handle,
  159. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  160. {
  161. return starpu_data_acquire_on_node_cb(handle, STARPU_MAIN_RAM, mode, callback, arg);
  162. }
  163. int starpu_data_acquire_cb_sequential_consistency(starpu_data_handle_t handle,
  164. enum starpu_data_access_mode mode, void (*callback)(void *), void *arg, int sequential_consistency)
  165. {
  166. return starpu_data_acquire_on_node_cb_sequential_consistency(handle, STARPU_MAIN_RAM, mode, callback, arg, sequential_consistency);
  167. }
  168. /*
  169. * Block data request from application
  170. */
  171. static inline void _starpu_data_acquire_continuation(void *arg)
  172. {
  173. struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) arg;
  174. starpu_data_handle_t handle = wrapper->handle;
  175. STARPU_ASSERT(handle);
  176. if (wrapper->node >= 0)
  177. {
  178. int ret;
  179. struct _starpu_data_replicate *replicate = &handle->per_node[wrapper->node];
  180. ret = _starpu_fetch_data_on_node(handle, replicate, wrapper->mode, 0, 0, 0, NULL, NULL);
  181. STARPU_ASSERT(!ret);
  182. }
  183. /* continuation of starpu_data_acquire */
  184. STARPU_PTHREAD_MUTEX_LOCK(&wrapper->lock);
  185. wrapper->finished = 1;
  186. STARPU_PTHREAD_COND_SIGNAL(&wrapper->cond);
  187. STARPU_PTHREAD_MUTEX_UNLOCK(&wrapper->lock);
  188. }
  189. /* The data must be released by calling starpu_data_release later on */
  190. int starpu_data_acquire_on_node(starpu_data_handle_t handle, int node, enum starpu_data_access_mode mode)
  191. {
  192. STARPU_ASSERT(handle);
  193. STARPU_ASSERT_MSG(handle->nchildren == 0, "Acquiring a partitioned data is not possible");
  194. _STARPU_LOG_IN();
  195. /* unless asynchronous, it is forbidden to call this function from a callback or a codelet */
  196. 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.");
  197. if (_starpu_data_is_multiformat_handle(handle) &&
  198. _starpu_handle_needs_conversion_task(handle, 0))
  199. {
  200. struct starpu_task *task = _starpu_create_conversion_task(handle, 0);
  201. int ret;
  202. _starpu_spin_lock(&handle->header_lock);
  203. handle->refcnt--;
  204. handle->busy_count--;
  205. handle->mf_node = 0;
  206. _starpu_spin_unlock(&handle->header_lock);
  207. task->synchronous = 1;
  208. ret = _starpu_task_submit_internally(task);
  209. STARPU_ASSERT(!ret);
  210. }
  211. struct user_interaction_wrapper wrapper =
  212. {
  213. .handle = handle,
  214. .mode = mode,
  215. .node = node,
  216. .finished = 0
  217. };
  218. STARPU_PTHREAD_COND_INIT(&wrapper.cond, NULL);
  219. STARPU_PTHREAD_MUTEX_INIT(&wrapper.lock, NULL);
  220. // _STARPU_DEBUG("TAKE sequential_consistency_mutex starpu_data_acquire\n");
  221. STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  222. int sequential_consistency = handle->sequential_consistency;
  223. if (sequential_consistency)
  224. {
  225. struct starpu_task *new_task;
  226. wrapper.pre_sync_task = starpu_task_create();
  227. wrapper.pre_sync_task->name = "_starpu_data_acquire_pre";
  228. wrapper.pre_sync_task->detach = 0;
  229. wrapper.post_sync_task = starpu_task_create();
  230. wrapper.post_sync_task->name = "_starpu_data_acquire_post";
  231. wrapper.post_sync_task->detach = 1;
  232. 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);
  233. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  234. if (new_task)
  235. {
  236. int ret = _starpu_task_submit_internally(new_task);
  237. STARPU_ASSERT(!ret);
  238. }
  239. /* TODO detect if this is superflous */
  240. wrapper.pre_sync_task->synchronous = 1;
  241. int ret = _starpu_task_submit_internally(wrapper.pre_sync_task);
  242. STARPU_ASSERT(!ret);
  243. }
  244. else
  245. {
  246. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  247. }
  248. /* we try to get the data, if we do not succeed immediately, we set a
  249. * callback function that will be executed automatically when the data is
  250. * available again, otherwise we fetch the data directly */
  251. if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode, _starpu_data_acquire_continuation, &wrapper))
  252. {
  253. if (node >= 0)
  254. {
  255. /* no one has locked this data yet, so we proceed immediately */
  256. struct _starpu_data_replicate *replicate = &handle->per_node[node];
  257. int ret = _starpu_fetch_data_on_node(handle, replicate, mode, 0, 0, 0, NULL, NULL);
  258. STARPU_ASSERT(!ret);
  259. }
  260. }
  261. else
  262. {
  263. STARPU_PTHREAD_MUTEX_LOCK(&wrapper.lock);
  264. while (!wrapper.finished)
  265. STARPU_PTHREAD_COND_WAIT(&wrapper.cond, &wrapper.lock);
  266. STARPU_PTHREAD_MUTEX_UNLOCK(&wrapper.lock);
  267. }
  268. STARPU_PTHREAD_COND_DESTROY(&wrapper.cond);
  269. STARPU_PTHREAD_MUTEX_DESTROY(&wrapper.lock);
  270. /* At that moment, the caller holds a reference to the piece of data.
  271. * We enqueue the "post" sync task in the list associated to the handle
  272. * so that it is submitted by the starpu_data_release
  273. * function. */
  274. if (sequential_consistency)
  275. _starpu_add_post_sync_tasks(wrapper.post_sync_task, handle);
  276. _STARPU_LOG_OUT();
  277. return 0;
  278. }
  279. int starpu_data_acquire(starpu_data_handle_t handle, enum starpu_data_access_mode mode)
  280. {
  281. return starpu_data_acquire_on_node(handle, STARPU_MAIN_RAM, mode);
  282. }
  283. /* This function must be called after starpu_data_acquire so that the
  284. * application release the data */
  285. void starpu_data_release_on_node(starpu_data_handle_t handle, int node)
  286. {
  287. STARPU_ASSERT(handle);
  288. /* In case there are some implicit dependencies, unlock the "post sync" tasks */
  289. _starpu_unlock_post_sync_tasks(handle);
  290. /* The application can now release the rw-lock */
  291. if (node >= 0)
  292. _starpu_release_data_on_node(handle, 0, &handle->per_node[node]);
  293. else
  294. {
  295. _starpu_spin_lock(&handle->header_lock);
  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, replicate, STARPU_R, wrapper->async, wrapper->prefetch, wrapper->async, NULL, NULL);
  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)
  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 = (struct user_interaction_wrapper *) malloc(sizeof(*wrapper));
  332. wrapper->handle = handle;
  333. wrapper->node = node;
  334. wrapper->async = async;
  335. wrapper->prefetch = prefetch;
  336. STARPU_PTHREAD_COND_INIT(&wrapper->cond, NULL);
  337. STARPU_PTHREAD_MUTEX_INIT(&wrapper->lock, NULL);
  338. wrapper->finished = 0;
  339. if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode, _prefetch_data_on_node, wrapper))
  340. {
  341. /* we can immediately proceed */
  342. struct _starpu_data_replicate *replicate = &handle->per_node[node];
  343. STARPU_PTHREAD_COND_DESTROY(&wrapper->cond);
  344. STARPU_PTHREAD_MUTEX_DESTROY(&wrapper->lock);
  345. free(wrapper);
  346. _starpu_fetch_data_on_node(handle, replicate, mode, async, prefetch, async, NULL, NULL);
  347. /* remove the "lock"/reference */
  348. _starpu_spin_lock(&handle->header_lock);
  349. if (!async)
  350. {
  351. /* Release our refcnt, like _starpu_release_data_on_node would do */
  352. replicate->refcnt--;
  353. STARPU_ASSERT(replicate->refcnt >= 0);
  354. STARPU_ASSERT(handle->busy_count > 0);
  355. handle->busy_count--;
  356. }
  357. /* In case there was a temporary handle (eg. used for reduction), this
  358. * handle may have requested to be destroyed when the data is released
  359. * */
  360. if (!_starpu_notify_data_dependencies(handle))
  361. _starpu_spin_unlock(&handle->header_lock);
  362. }
  363. else if (!async)
  364. {
  365. STARPU_PTHREAD_MUTEX_LOCK(&wrapper->lock);
  366. while (!wrapper->finished)
  367. STARPU_PTHREAD_COND_WAIT(&wrapper->cond, &wrapper->lock);
  368. STARPU_PTHREAD_MUTEX_UNLOCK(&wrapper->lock);
  369. STARPU_PTHREAD_COND_DESTROY(&wrapper->cond);
  370. STARPU_PTHREAD_MUTEX_DESTROY(&wrapper->lock);
  371. free(wrapper);
  372. }
  373. return 0;
  374. }
  375. int starpu_data_fetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  376. {
  377. return _starpu_prefetch_data_on_node_with_mode(handle, node, async, STARPU_R, 0);
  378. }
  379. int starpu_data_prefetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  380. {
  381. return _starpu_prefetch_data_on_node_with_mode(handle, node, async, STARPU_R, 1);
  382. }
  383. int starpu_data_idle_prefetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  384. {
  385. return _starpu_prefetch_data_on_node_with_mode(handle, node, async, STARPU_R, 2);
  386. }
  387. static void _starpu_data_wont_use(void *data)
  388. {
  389. unsigned node, worker, nworkers = starpu_worker_get_count();
  390. starpu_data_handle_t handle = data;
  391. _starpu_spin_lock(&handle->header_lock);
  392. for (node = 0; node < STARPU_MAXNODES; node++)
  393. {
  394. struct _starpu_data_replicate *local = &handle->per_node[node];
  395. if (local->allocated && local->automatically_allocated)
  396. _starpu_memchunk_wont_use(local->mc, node);
  397. }
  398. for (worker = 0; worker < nworkers; worker++)
  399. {
  400. struct _starpu_data_replicate *local = &handle->per_worker[node];
  401. if (local->allocated && local->automatically_allocated)
  402. _starpu_memchunk_wont_use(local->mc, node);
  403. }
  404. _starpu_spin_unlock(&handle->header_lock);
  405. starpu_data_release_on_node(handle, -1);
  406. if (handle->home_node != -1)
  407. starpu_data_idle_prefetch_on_node(handle, handle->home_node, 1);
  408. }
  409. void starpu_data_wont_use(starpu_data_handle_t handle)
  410. {
  411. starpu_data_acquire_on_node_cb(handle, -1, STARPU_R, _starpu_data_wont_use, handle);
  412. }
  413. /*
  414. * It is possible to specify that a piece of data can be discarded without
  415. * impacting the application.
  416. */
  417. int _starpu_has_not_important_data;
  418. void starpu_data_advise_as_important(starpu_data_handle_t handle, unsigned is_important)
  419. {
  420. if (!is_important)
  421. _starpu_has_not_important_data = 1;
  422. _starpu_spin_lock(&handle->header_lock);
  423. /* first take all the children lock (in order !) */
  424. unsigned child;
  425. for (child = 0; child < handle->nchildren; child++)
  426. {
  427. /* make sure the intermediate children is advised as well */
  428. starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
  429. if (child_handle->nchildren > 0)
  430. starpu_data_advise_as_important(child_handle, is_important);
  431. }
  432. handle->is_not_important = !is_important;
  433. /* now the parent may be used again so we release the lock */
  434. _starpu_spin_unlock(&handle->header_lock);
  435. }
  436. void starpu_data_set_sequential_consistency_flag(starpu_data_handle_t handle, unsigned flag)
  437. {
  438. _starpu_spin_lock(&handle->header_lock);
  439. unsigned child;
  440. for (child = 0; child < handle->nchildren; child++)
  441. {
  442. /* make sure that the flags are applied to the children as well */
  443. starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
  444. if (child_handle->nchildren > 0)
  445. starpu_data_set_sequential_consistency_flag(child_handle, flag);
  446. }
  447. STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  448. handle->sequential_consistency = flag;
  449. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  450. _starpu_spin_unlock(&handle->header_lock);
  451. }
  452. unsigned starpu_data_get_sequential_consistency_flag(starpu_data_handle_t handle)
  453. {
  454. return handle->sequential_consistency;
  455. }
  456. /* By default, sequential consistency is enabled */
  457. static unsigned default_sequential_consistency_flag = 1;
  458. unsigned starpu_data_get_default_sequential_consistency_flag(void)
  459. {
  460. return default_sequential_consistency_flag;
  461. }
  462. void starpu_data_set_default_sequential_consistency_flag(unsigned flag)
  463. {
  464. default_sequential_consistency_flag = flag;
  465. }
  466. /* Query the status of the handle on the specified memory node. */
  467. void starpu_data_query_status(starpu_data_handle_t handle, int memory_node, int *is_allocated, int *is_valid, int *is_requested)
  468. {
  469. // XXX : this is just a hint, so we don't take the lock ...
  470. // _starpu_spin_lock(&handle->header_lock);
  471. if (is_allocated)
  472. *is_allocated = handle->per_node[memory_node].allocated;
  473. if (is_valid)
  474. *is_valid = (handle->per_node[memory_node].state != STARPU_INVALID);
  475. if (is_requested)
  476. {
  477. int requested = 0;
  478. unsigned node;
  479. for (node = 0; node < STARPU_MAXNODES; node++)
  480. {
  481. if (handle->per_node[memory_node].requested & (1UL << node))
  482. {
  483. requested = 1;
  484. break;
  485. }
  486. }
  487. *is_requested = requested;
  488. }
  489. // _starpu_spin_unlock(&handle->header_lock);
  490. }