coherency.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures. *
  2. * Copyright (C) 2009-2015 Université de Bordeaux
  3. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 CNRS
  4. * Copyright (C) 2014 INRIA
  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 <datawizard/coherency.h>
  19. #include <datawizard/copy_driver.h>
  20. #include <datawizard/write_back.h>
  21. #include <datawizard/memory_nodes.h>
  22. #include <core/dependencies/data_concurrency.h>
  23. #include <core/disk.h>
  24. #include <profiling/profiling.h>
  25. #include <math.h>
  26. #include <core/task.h>
  27. #include <starpu_scheduler.h>
  28. #include <core/workers.h>
  29. #ifdef STARPU_SIMGRID
  30. #include <core/simgrid.h>
  31. #endif
  32. static int link_supports_direct_transfers(starpu_data_handle_t handle, unsigned src_node, unsigned dst_node, unsigned *handling_node);
  33. int _starpu_select_src_node(starpu_data_handle_t handle, unsigned destination)
  34. {
  35. int src_node = -1;
  36. unsigned i;
  37. unsigned nnodes = starpu_memory_nodes_get_count();
  38. /* first find a valid copy, either a STARPU_OWNER or a STARPU_SHARED */
  39. unsigned node;
  40. size_t size = _starpu_data_get_size(handle);
  41. double cost = INFINITY;
  42. unsigned src_node_mask = 0;
  43. for (node = 0; node < nnodes; node++)
  44. {
  45. if (handle->per_node[node].state != STARPU_INVALID)
  46. {
  47. /* we found a copy ! */
  48. src_node_mask |= (1<<node);
  49. }
  50. }
  51. if (src_node_mask == 0 && handle->init_cl)
  52. {
  53. /* No copy yet, but applicationg told us how to build it. */
  54. return -1;
  55. }
  56. /* we should have found at least one copy ! */
  57. STARPU_ASSERT_MSG(src_node_mask != 0, "The data for the handle %p is requested, but the handle does not have a valid value. Perhaps some initialization task is missing?", handle);
  58. /* Without knowing the size, we won't know the cost */
  59. if (!size)
  60. cost = 0;
  61. /* Check whether we have transfer cost for all nodes, if so, take the minimum */
  62. if (cost)
  63. for (i = 0; i < nnodes; i++)
  64. {
  65. if (src_node_mask & (1<<i))
  66. {
  67. double time = starpu_transfer_predict(i, destination, size);
  68. unsigned handling_node;
  69. /* Avoid indirect transfers */
  70. if (!link_supports_direct_transfers(handle, i, destination, &handling_node))
  71. continue;
  72. if (_STARPU_IS_ZERO(time))
  73. {
  74. /* No estimation, will have to revert to dumb strategy */
  75. cost = 0.0;
  76. break;
  77. }
  78. else if (time < cost)
  79. {
  80. cost = time;
  81. src_node = i;
  82. }
  83. }
  84. }
  85. if (cost && src_node != -1)
  86. /* Could estimate through cost, return that */
  87. return src_node;
  88. int i_ram = -1;
  89. int i_gpu = -1;
  90. int i_disk = -1;
  91. /* Revert to dumb strategy: take RAM unless only a GPU has it */
  92. for (i = 0; i < nnodes; i++)
  93. {
  94. if (src_node_mask & (1<<i))
  95. {
  96. int (*can_copy)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, unsigned handling_node) = handle->ops->copy_methods->can_copy;
  97. /* Avoid transfers which the interface does not want */
  98. if (can_copy)
  99. {
  100. void *src_interface = handle->per_node[i].data_interface;
  101. void *dst_interface = handle->per_node[destination].data_interface;
  102. unsigned handling_node;
  103. if (!link_supports_direct_transfers(handle, i, destination, &handling_node))
  104. {
  105. /* Avoid through RAM if the interface does not want it */
  106. void *ram_interface = handle->per_node[STARPU_MAIN_RAM].data_interface;
  107. if ((!can_copy(src_interface, i, ram_interface, STARPU_MAIN_RAM, i)
  108. && !can_copy(src_interface, i, ram_interface, STARPU_MAIN_RAM, STARPU_MAIN_RAM))
  109. || (!can_copy(ram_interface, STARPU_MAIN_RAM, dst_interface, destination, STARPU_MAIN_RAM)
  110. && !can_copy(ram_interface, STARPU_MAIN_RAM, dst_interface, destination, destination)))
  111. continue;
  112. }
  113. }
  114. /* however GPU are expensive sources, really !
  115. * Unless peer transfer is supported (and it would then have been selected above).
  116. * Other should be ok */
  117. if (starpu_node_get_kind(i) == STARPU_CUDA_RAM ||
  118. starpu_node_get_kind(i) == STARPU_OPENCL_RAM ||
  119. starpu_node_get_kind(i) == STARPU_MIC_RAM)
  120. i_gpu = i;
  121. if (starpu_node_get_kind(i) == STARPU_CPU_RAM ||
  122. starpu_node_get_kind(i) == STARPU_SCC_RAM ||
  123. starpu_node_get_kind(i) == STARPU_SCC_SHM)
  124. i_ram = i;
  125. if (starpu_node_get_kind(i) == STARPU_DISK_RAM)
  126. i_disk = i;
  127. }
  128. }
  129. /* we have to use cpu_ram in first */
  130. if (i_ram != -1)
  131. src_node = i_ram;
  132. /* no luck we have to use the disk memory */
  133. else if (i_gpu != -1)
  134. src_node = i_gpu;
  135. else
  136. src_node = i_disk;
  137. STARPU_ASSERT(src_node != -1);
  138. return src_node;
  139. }
  140. /* this may be called once the data is fetched with header and STARPU_RW-lock hold */
  141. void _starpu_update_data_state(starpu_data_handle_t handle,
  142. struct _starpu_data_replicate *requesting_replicate,
  143. enum starpu_data_access_mode mode)
  144. {
  145. /* There is nothing to do for relaxed coherency modes (scratch or
  146. * reductions) */
  147. if (!(mode & STARPU_RW))
  148. return;
  149. unsigned nnodes = starpu_memory_nodes_get_count();
  150. /* the data is present now */
  151. unsigned requesting_node = requesting_replicate->memory_node;
  152. requesting_replicate->requested &= ~(1UL << requesting_node);
  153. if (mode & STARPU_W)
  154. {
  155. /* the requesting node now has the only valid copy */
  156. unsigned node;
  157. for (node = 0; node < nnodes; node++)
  158. handle->per_node[node].state = STARPU_INVALID;
  159. requesting_replicate->state = STARPU_OWNER;
  160. if (handle->home_node != -1 && handle->per_node[handle->home_node].state == STARPU_INVALID)
  161. /* Notify that this MC is now dirty */
  162. _starpu_memchunk_dirty(requesting_replicate->mc, requesting_replicate->memory_node);
  163. }
  164. else
  165. { /* read only */
  166. if (requesting_replicate->state != STARPU_OWNER)
  167. {
  168. /* there was at least another copy of the data */
  169. unsigned node;
  170. for (node = 0; node < nnodes; node++)
  171. {
  172. struct _starpu_data_replicate *replicate = &handle->per_node[node];
  173. if (replicate->state != STARPU_INVALID)
  174. replicate->state = STARPU_SHARED;
  175. }
  176. requesting_replicate->state = STARPU_SHARED;
  177. }
  178. }
  179. }
  180. static int worker_supports_direct_access(unsigned node, unsigned handling_node)
  181. {
  182. /* only support disk <-> ram and disk <-> disk */
  183. if (starpu_node_get_kind(node) == STARPU_DISK_RAM || starpu_node_get_kind(handling_node) == STARPU_DISK_RAM)
  184. return 0;
  185. if (node == handling_node)
  186. return 1;
  187. if (!_starpu_memory_node_get_nworkers(handling_node))
  188. /* No worker to process the request from that node */
  189. return 0;
  190. int type = starpu_node_get_kind(node);
  191. switch (type)
  192. {
  193. case STARPU_CUDA_RAM:
  194. {
  195. /* GPUs not always allow direct remote access: if CUDA4
  196. * is enabled, we allow two CUDA devices to communicate. */
  197. #ifdef STARPU_SIMGRID
  198. if (starpu_node_get_kind(handling_node) == STARPU_CUDA_RAM)
  199. {
  200. char name[16];
  201. msg_host_t host;
  202. const char* cuda_memcpy_peer;
  203. snprintf(name, sizeof(name), "CUDA%d", _starpu_memory_node_get_devid(handling_node));
  204. host = _starpu_simgrid_get_host_by_name(name);
  205. cuda_memcpy_peer = MSG_host_get_property_value(host, "memcpy_peer");
  206. return cuda_memcpy_peer && atoll(cuda_memcpy_peer);
  207. }
  208. else
  209. return 0;
  210. #elif defined(HAVE_CUDA_MEMCPY_PEER)
  211. /* simgrid */
  212. enum starpu_node_kind kind = starpu_node_get_kind(handling_node);
  213. return kind == STARPU_CUDA_RAM;
  214. #else /* HAVE_CUDA_MEMCPY_PEER */
  215. /* Direct GPU-GPU transfers are not allowed in general */
  216. return 0;
  217. #endif /* HAVE_CUDA_MEMCPY_PEER */
  218. }
  219. case STARPU_OPENCL_RAM:
  220. return 0;
  221. case STARPU_MIC_RAM:
  222. /* We don't handle direct MIC-MIC transfers yet */
  223. return 0;
  224. case STARPU_SCC_RAM:
  225. return 1;
  226. default:
  227. return 1;
  228. }
  229. }
  230. static int link_supports_direct_transfers(starpu_data_handle_t handle, unsigned src_node, unsigned dst_node, unsigned *handling_node)
  231. {
  232. int (*can_copy)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, unsigned handling_node) = handle->ops->copy_methods->can_copy;
  233. void *src_interface = handle->per_node[src_node].data_interface;
  234. void *dst_interface = handle->per_node[dst_node].data_interface;
  235. /* XXX That's a hack until we fix cudaMemcpy3DPeerAsync in the block interface
  236. * Perhaps not all data interface provide a direct GPU-GPU transfer
  237. * method ! */
  238. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  239. if (src_node != dst_node && starpu_node_get_kind(src_node) == STARPU_CUDA_RAM && starpu_node_get_kind(dst_node) == STARPU_CUDA_RAM)
  240. {
  241. const struct starpu_data_copy_methods *copy_methods = handle->ops->copy_methods;
  242. if (!copy_methods->cuda_to_cuda_async && !copy_methods->any_to_any)
  243. return 0;
  244. }
  245. #endif
  246. /* Note: with CUDA, performance seems a bit better when issuing the transfer from the destination (tested without GPUDirect, but GPUDirect probably behave the same) */
  247. if (worker_supports_direct_access(src_node, dst_node) && (!can_copy || can_copy(src_interface, src_node, dst_interface, dst_node, dst_node)))
  248. {
  249. *handling_node = dst_node;
  250. return 1;
  251. }
  252. if (worker_supports_direct_access(dst_node, src_node) && (!can_copy || can_copy(src_interface, src_node, dst_interface, dst_node, src_node)))
  253. {
  254. *handling_node = src_node;
  255. return 1;
  256. }
  257. /* Link between disk and ram */
  258. if ((starpu_node_get_kind(src_node) == STARPU_DISK_RAM && starpu_node_get_kind(dst_node) == STARPU_CPU_RAM) ||
  259. (starpu_node_get_kind(src_node) == STARPU_CPU_RAM && starpu_node_get_kind(dst_node) == STARPU_DISK_RAM))
  260. {
  261. /* FIXME: not necessarily a worker :/ */
  262. *handling_node = STARPU_MAIN_RAM;
  263. return 1;
  264. }
  265. /* link between disk and disk, and they have the same kind */
  266. if (_starpu_is_same_kind_disk(src_node, dst_node))
  267. return 1;
  268. return 0;
  269. }
  270. /* Determines the path of a request : each hop is defined by (src,dst) and the
  271. * node that handles the hop. The returned value indicates the number of hops,
  272. * and the max_len is the maximum number of hops (ie. the size of the
  273. * src_nodes, dst_nodes and handling_nodes arrays. */
  274. static int determine_request_path(starpu_data_handle_t handle,
  275. unsigned src_node, unsigned dst_node,
  276. enum starpu_data_access_mode mode, int max_len,
  277. unsigned *src_nodes, unsigned *dst_nodes,
  278. unsigned *handling_nodes, unsigned write_invalidation)
  279. {
  280. if (src_node == dst_node || !(mode & STARPU_R))
  281. {
  282. if (write_invalidation)
  283. /* The invalidation request will be enough */
  284. return 0;
  285. /* The destination node should only allocate the data, no transfer is required */
  286. STARPU_ASSERT(max_len >= 1);
  287. src_nodes[0] = STARPU_MAIN_RAM; // ignored
  288. dst_nodes[0] = dst_node;
  289. handling_nodes[0] = dst_node;
  290. return 1;
  291. }
  292. unsigned handling_node;
  293. int link_is_valid = link_supports_direct_transfers(handle, src_node, dst_node, &handling_node);
  294. if (!link_is_valid)
  295. {
  296. int (*can_copy)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, unsigned handling_node) = handle->ops->copy_methods->can_copy;
  297. void *src_interface = handle->per_node[src_node].data_interface;
  298. void *dst_interface = handle->per_node[dst_node].data_interface;
  299. /* We need an intermediate hop to implement data staging
  300. * through main memory. */
  301. STARPU_ASSERT(max_len >= 2);
  302. /* GPU -> RAM */
  303. src_nodes[0] = src_node;
  304. dst_nodes[0] = STARPU_MAIN_RAM;
  305. if (starpu_node_get_kind(src_node) == STARPU_DISK_RAM)
  306. /* Disks don't have their own driver thread */
  307. handling_nodes[0] = dst_node;
  308. else if (!can_copy || can_copy(src_interface, src_node, dst_interface, dst_node, src_node))
  309. {
  310. handling_nodes[0] = src_node;
  311. }
  312. else
  313. {
  314. STARPU_ASSERT_MSG(can_copy(src_interface, src_node, dst_interface, dst_node, dst_node), "interface %d refuses all kinds of transfers from node %u to node %u\n", handle->ops->interfaceid, src_node, dst_node);
  315. handling_nodes[0] = dst_node;
  316. }
  317. /* RAM -> GPU */
  318. src_nodes[1] = STARPU_MAIN_RAM;
  319. dst_nodes[1] = dst_node;
  320. if (starpu_node_get_kind(dst_node) == STARPU_DISK_RAM)
  321. /* Disks don't have their own driver thread */
  322. handling_nodes[1] = src_node;
  323. else if (!can_copy || can_copy(src_interface, src_node, dst_interface, dst_node, dst_node))
  324. {
  325. handling_nodes[1] = dst_node;
  326. }
  327. else
  328. {
  329. STARPU_ASSERT_MSG(can_copy(src_interface, src_node, dst_interface, dst_node, src_node), "interface %d refuses all kinds of transfers from node %u to node %u\n", handle->ops->interfaceid, src_node, dst_node);
  330. handling_nodes[1] = src_node;
  331. }
  332. return 2;
  333. }
  334. else
  335. {
  336. STARPU_ASSERT(max_len >= 1);
  337. src_nodes[0] = src_node;
  338. dst_nodes[0] = dst_node;
  339. handling_nodes[0] = handling_node;
  340. #if !defined(HAVE_CUDA_MEMCPY_PEER) && !defined(STARPU_SIMGRID)
  341. STARPU_ASSERT(!(mode & STARPU_R) || starpu_node_get_kind(src_node) != STARPU_CUDA_RAM || starpu_node_get_kind(dst_node) != STARPU_CUDA_RAM);
  342. #endif
  343. return 1;
  344. }
  345. }
  346. /* handle->lock should be taken. r is returned locked. The node parameter
  347. * indicate either the source of the request, or the destination for a
  348. * write-only request. */
  349. static struct _starpu_data_request *_starpu_search_existing_data_request(struct _starpu_data_replicate *replicate, unsigned node, enum starpu_data_access_mode mode, unsigned is_prefetch)
  350. {
  351. struct _starpu_data_request *r;
  352. r = replicate->request[node];
  353. if (r)
  354. {
  355. _starpu_spin_checklocked(&r->handle->header_lock);
  356. _starpu_spin_lock(&r->lock);
  357. /* perhaps we need to "upgrade" the request */
  358. if (is_prefetch < r->prefetch)
  359. _starpu_update_prefetch_status(r, is_prefetch);
  360. if (mode & STARPU_R)
  361. {
  362. /* in case the exisiting request did not imply a memory
  363. * transfer yet, we have to take a second refcnt now
  364. * for the source, in addition to the refcnt for the
  365. * destination
  366. * (so that the source remains valid) */
  367. if (!(r->mode & STARPU_R))
  368. {
  369. replicate->refcnt++;
  370. replicate->handle->busy_count++;
  371. }
  372. r->mode = (enum starpu_data_access_mode) ((int) r->mode | (int) STARPU_R);
  373. }
  374. if (mode & STARPU_W)
  375. r->mode = (enum starpu_data_access_mode) ((int) r->mode | (int) STARPU_W);
  376. }
  377. return r;
  378. }
  379. /*
  380. * This function is called when the data is needed on the local node, this
  381. * returns a pointer to the local copy
  382. *
  383. * R STARPU_W STARPU_RW
  384. * Owner OK OK OK
  385. * Shared OK 1 1
  386. * Invalid 2 3 4
  387. *
  388. * case 1 : shared + (read)write :
  389. * no data copy but shared->Invalid/Owner
  390. * case 2 : invalid + read :
  391. * data copy + invalid->shared + owner->shared (STARPU_ASSERT(there is a valid))
  392. * case 3 : invalid + write :
  393. * no data copy + invalid->owner + (owner,shared)->invalid
  394. * case 4 : invalid + R/STARPU_W :
  395. * data copy + if (STARPU_W) (invalid->owner + owner->invalid)
  396. * else (invalid,owner->shared)
  397. */
  398. struct _starpu_data_request *_starpu_create_request_to_fetch_data(starpu_data_handle_t handle,
  399. struct _starpu_data_replicate *dst_replicate,
  400. enum starpu_data_access_mode mode, unsigned is_prefetch,
  401. unsigned async,
  402. void (*callback_func)(void *), void *callback_arg)
  403. {
  404. /* We don't care about commuting for data requests, that was handled before. */
  405. mode &= ~STARPU_COMMUTE;
  406. /* This function is called with handle's header lock taken */
  407. _starpu_spin_checklocked(&handle->header_lock);
  408. unsigned requesting_node = dst_replicate->memory_node;
  409. unsigned nwait = 0;
  410. if (mode & STARPU_W)
  411. {
  412. /* We will write to the buffer. We will have to wait for all
  413. * existing requests before the last request which will
  414. * invalidate all their results (which were possibly spurious,
  415. * e.g. too aggressive eviction).
  416. */
  417. unsigned i, j;
  418. unsigned nnodes = starpu_memory_nodes_get_count();
  419. for (i = 0; i < nnodes; i++)
  420. for (j = 0; j < nnodes; j++)
  421. if (handle->per_node[i].request[j])
  422. nwait++;
  423. /* If the request is not detached (i.e. the caller really wants
  424. * proper ownership), no new requests will appear because a
  425. * reference will be kept on the dst replicate, which will
  426. * notably prevent data reclaiming.
  427. */
  428. }
  429. if (dst_replicate->state != STARPU_INVALID && (!nwait || is_prefetch))
  430. {
  431. #ifdef STARPU_MEMORY_STATS
  432. enum _starpu_cache_state old_state = dst_replicate->state;
  433. #endif
  434. /* the data is already available and we don't have to wait for
  435. * any request, so we can stop */
  436. _starpu_update_data_state(handle, dst_replicate, mode);
  437. _starpu_msi_cache_hit(requesting_node);
  438. #ifdef STARPU_MEMORY_STATS
  439. _starpu_memory_handle_stats_cache_hit(handle, requesting_node);
  440. /* XXX Broken ? */
  441. if (old_state == STARPU_SHARED
  442. && dst_replicate->state == STARPU_OWNER)
  443. _starpu_memory_handle_stats_shared_to_owner(handle, requesting_node);
  444. #endif
  445. _starpu_memchunk_recently_used(dst_replicate->mc, requesting_node);
  446. _starpu_spin_unlock(&handle->header_lock);
  447. if (callback_func)
  448. callback_func(callback_arg);
  449. _STARPU_LOG_OUT_TAG("data available");
  450. return NULL;
  451. }
  452. _starpu_msi_cache_miss(requesting_node);
  453. /* the only remaining situation is that the local copy was invalid */
  454. STARPU_ASSERT(dst_replicate->state == STARPU_INVALID || nwait);
  455. /* find someone who already has the data */
  456. int src_node = -1;
  457. if (mode & STARPU_R)
  458. {
  459. if (dst_replicate->state == STARPU_INVALID)
  460. src_node = _starpu_select_src_node(handle, requesting_node);
  461. else
  462. src_node = requesting_node;
  463. if (src_node < 0)
  464. {
  465. /* We will create it, no need to read an existing value */
  466. mode &= ~STARPU_R;
  467. }
  468. }
  469. else
  470. {
  471. /* if the data is in write only mode (and not SCRATCH or REDUX), there is no need for a source, data will be initialized by the task itself */
  472. if (mode & STARPU_W)
  473. dst_replicate->initialized = 1;
  474. if (requesting_node == STARPU_MAIN_RAM && !nwait)
  475. {
  476. /* And this is the main RAM, really no need for a
  477. * request, just allocate */
  478. if (_starpu_allocate_memory_on_node(handle, dst_replicate, is_prefetch) == 0)
  479. {
  480. _starpu_update_data_state(handle, dst_replicate, mode);
  481. _starpu_spin_unlock(&handle->header_lock);
  482. if (callback_func)
  483. callback_func(callback_arg);
  484. _STARPU_LOG_OUT_TAG("data immediately allocated");
  485. return NULL;
  486. }
  487. }
  488. }
  489. #define MAX_REQUESTS 4
  490. /* We can safely assume that there won't be more than 2 hops in the
  491. * current implementation */
  492. unsigned src_nodes[MAX_REQUESTS], dst_nodes[MAX_REQUESTS], handling_nodes[MAX_REQUESTS];
  493. /* keep one slot for the last W request, if any */
  494. int write_invalidation = (mode & STARPU_W) && nwait && !is_prefetch;
  495. int nhops = determine_request_path(handle, src_node, requesting_node, mode, MAX_REQUESTS,
  496. src_nodes, dst_nodes, handling_nodes, write_invalidation);
  497. STARPU_ASSERT(nhops >= 0 && nhops <= MAX_REQUESTS-1);
  498. struct _starpu_data_request *requests[nhops + write_invalidation];
  499. /* Did we reuse a request for that hop ? */
  500. int reused_requests[nhops + write_invalidation];
  501. /* Construct an array with a list of requests, possibly reusing existing requests */
  502. int hop;
  503. for (hop = 0; hop < nhops; hop++)
  504. {
  505. struct _starpu_data_request *r;
  506. unsigned hop_src_node = src_nodes[hop];
  507. unsigned hop_dst_node = dst_nodes[hop];
  508. unsigned hop_handling_node = handling_nodes[hop];
  509. struct _starpu_data_replicate *hop_src_replicate;
  510. struct _starpu_data_replicate *hop_dst_replicate;
  511. /* Only the first request is independant */
  512. unsigned ndeps = (hop == 0)?0:1;
  513. hop_src_replicate = &handle->per_node[hop_src_node];
  514. hop_dst_replicate = (hop != nhops - 1)?&handle->per_node[hop_dst_node]:dst_replicate;
  515. /* Try to reuse a request if possible */
  516. r = _starpu_search_existing_data_request(hop_dst_replicate,
  517. (mode & STARPU_R)?hop_src_node:hop_dst_node,
  518. mode, is_prefetch);
  519. reused_requests[hop] = !!r;
  520. if (!r)
  521. {
  522. /* Create a new request if there was no request to reuse */
  523. r = _starpu_create_data_request(handle, hop_src_replicate,
  524. hop_dst_replicate, hop_handling_node,
  525. mode, ndeps, is_prefetch, 0);
  526. nwait++;
  527. }
  528. requests[hop] = r;
  529. }
  530. /* Chain these requests */
  531. for (hop = 0; hop < nhops; hop++)
  532. {
  533. struct _starpu_data_request *r;
  534. r = requests[hop];
  535. if (hop != nhops - 1)
  536. {
  537. if (!reused_requests[hop + 1])
  538. {
  539. r->next_req[r->next_req_count++] = requests[hop + 1];
  540. STARPU_ASSERT(r->next_req_count <= STARPU_MAXNODES);
  541. }
  542. }
  543. else if (!write_invalidation)
  544. /* The last request will perform the callback after termination */
  545. _starpu_data_request_append_callback(r, callback_func, callback_arg);
  546. if (reused_requests[hop])
  547. _starpu_spin_unlock(&r->lock);
  548. }
  549. if (write_invalidation)
  550. {
  551. /* Some requests were still pending, we have to add yet another
  552. * request, depending on them, which will invalidate their
  553. * result.
  554. */
  555. struct _starpu_data_request *r = _starpu_create_data_request(handle, dst_replicate,
  556. dst_replicate, requesting_node,
  557. STARPU_W, nwait, is_prefetch, 1);
  558. /* and perform the callback after termination */
  559. _starpu_data_request_append_callback(r, callback_func, callback_arg);
  560. /* We will write to the buffer. We will have to wait for all
  561. * existing requests before the last request which will
  562. * invalidate all their results (which were possibly spurious,
  563. * e.g. too aggressive eviction).
  564. */
  565. unsigned i, j;
  566. unsigned nnodes = starpu_memory_nodes_get_count();
  567. for (i = 0; i < nnodes; i++)
  568. for (j = 0; j < nnodes; j++)
  569. {
  570. struct _starpu_data_request *r2 = handle->per_node[i].request[j];
  571. if (r2)
  572. {
  573. _starpu_spin_lock(&r2->lock);
  574. r2->next_req[r2->next_req_count++] = r;
  575. STARPU_ASSERT(r2->next_req_count <= STARPU_MAXNODES + 1);
  576. _starpu_spin_unlock(&r2->lock);
  577. nwait--;
  578. }
  579. }
  580. STARPU_ASSERT(nwait == 0);
  581. nhops++;
  582. requests[nhops - 1] = r;
  583. /* existing requests will post this one */
  584. reused_requests[nhops - 1] = 1;
  585. }
  586. STARPU_ASSERT(nhops);
  587. if (!async)
  588. requests[nhops - 1]->refcnt++;
  589. /* we only submit the first request, the remaining will be
  590. * automatically submitted afterward */
  591. if (!reused_requests[0])
  592. _starpu_post_data_request(requests[0], handling_nodes[0]);
  593. return requests[nhops - 1];
  594. }
  595. int _starpu_fetch_data_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *dst_replicate,
  596. enum starpu_data_access_mode mode, unsigned detached, unsigned is_prefetch, unsigned async,
  597. void (*callback_func)(void *), void *callback_arg)
  598. {
  599. unsigned local_node = _starpu_memory_node_get_local_key();
  600. _STARPU_LOG_IN();
  601. int cpt = 0;
  602. while (cpt < STARPU_SPIN_MAXTRY && _starpu_spin_trylock(&handle->header_lock))
  603. {
  604. cpt++;
  605. _starpu_datawizard_progress(local_node, 1);
  606. }
  607. if (cpt == STARPU_SPIN_MAXTRY)
  608. _starpu_spin_lock(&handle->header_lock);
  609. if (!detached)
  610. {
  611. /* Take a reference which will be released by _starpu_release_data_on_node */
  612. dst_replicate->refcnt++;
  613. dst_replicate->handle->busy_count++;
  614. }
  615. struct _starpu_data_request *r;
  616. r = _starpu_create_request_to_fetch_data(handle, dst_replicate, mode,
  617. is_prefetch, async, callback_func, callback_arg);
  618. /* If no request was created, the handle was already up-to-date on the
  619. * node. In this case, _starpu_create_request_to_fetch_data has already
  620. * unlocked the header. */
  621. if (!r)
  622. return 0;
  623. _starpu_spin_unlock(&handle->header_lock);
  624. int ret = async?0:_starpu_wait_data_request_completion(r, 1);
  625. _STARPU_LOG_OUT();
  626. return ret;
  627. }
  628. static int idle_prefetch_data_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, enum starpu_data_access_mode mode)
  629. {
  630. return _starpu_fetch_data_on_node(handle, replicate, mode, 1, 2, 1, NULL, NULL);
  631. }
  632. static int prefetch_data_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, enum starpu_data_access_mode mode)
  633. {
  634. return _starpu_fetch_data_on_node(handle, replicate, mode, 1, 1, 1, NULL, NULL);
  635. }
  636. static int fetch_data(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, enum starpu_data_access_mode mode)
  637. {
  638. return _starpu_fetch_data_on_node(handle, replicate, mode, 0, 0, 0, NULL, NULL);
  639. }
  640. uint32_t _starpu_get_data_refcnt(starpu_data_handle_t handle, unsigned node)
  641. {
  642. return handle->per_node[node].refcnt;
  643. }
  644. size_t _starpu_data_get_size(starpu_data_handle_t handle)
  645. {
  646. return handle->ops->get_size(handle);
  647. }
  648. uint32_t _starpu_data_get_footprint(starpu_data_handle_t handle)
  649. {
  650. return handle->footprint;
  651. }
  652. /* in case the data was accessed on a write mode, do not forget to
  653. * make it accessible again once it is possible ! */
  654. void _starpu_release_data_on_node(starpu_data_handle_t handle, uint32_t default_wt_mask, struct _starpu_data_replicate *replicate)
  655. {
  656. uint32_t wt_mask;
  657. wt_mask = default_wt_mask | handle->wt_mask;
  658. wt_mask &= (1<<starpu_memory_nodes_get_count())-1;
  659. /* Note that it is possible that there is no valid copy of the data (if
  660. * starpu_data_invalidate was called for instance). In that case, we do
  661. * not enforce any write-through mechanism. */
  662. unsigned memory_node = replicate->memory_node;
  663. if (replicate->state != STARPU_INVALID && handle->current_mode & STARPU_W)
  664. if ((wt_mask & ~(1<<memory_node)))
  665. _starpu_write_through_data(handle, memory_node, wt_mask);
  666. unsigned local_node = _starpu_memory_node_get_local_key();
  667. int cpt = 0;
  668. while (cpt < STARPU_SPIN_MAXTRY && _starpu_spin_trylock(&handle->header_lock))
  669. {
  670. cpt++;
  671. _starpu_datawizard_progress(local_node, 1);
  672. }
  673. if (cpt == STARPU_SPIN_MAXTRY)
  674. _starpu_spin_lock(&handle->header_lock);
  675. /* Release refcnt taken by fetch_data_on_node */
  676. replicate->refcnt--;
  677. STARPU_ASSERT_MSG(replicate->refcnt >= 0, "handle %p released too many times", handle);
  678. STARPU_ASSERT_MSG(handle->busy_count > 0, "handle %p released too many times", handle);
  679. handle->busy_count--;
  680. if (!_starpu_notify_data_dependencies(handle))
  681. _starpu_spin_unlock(&handle->header_lock);
  682. }
  683. static void _starpu_set_data_requested_flag_if_needed(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate)
  684. {
  685. unsigned local_node = _starpu_memory_node_get_local_key();
  686. int cpt = 0;
  687. while (cpt < STARPU_SPIN_MAXTRY && _starpu_spin_trylock(&handle->header_lock))
  688. {
  689. cpt++;
  690. _starpu_datawizard_progress(local_node, 1);
  691. }
  692. if (cpt == STARPU_SPIN_MAXTRY)
  693. _starpu_spin_lock(&handle->header_lock);
  694. if (replicate->state == STARPU_INVALID)
  695. {
  696. unsigned dst_node = replicate->memory_node;
  697. replicate->requested |= 1UL << dst_node;
  698. }
  699. _starpu_spin_unlock(&handle->header_lock);
  700. }
  701. int starpu_prefetch_task_input_on_node(struct starpu_task *task, unsigned node)
  702. {
  703. STARPU_ASSERT(!task->prefetched);
  704. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  705. unsigned index;
  706. for (index = 0; index < nbuffers; index++)
  707. {
  708. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, index);
  709. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, index);
  710. if (mode & (STARPU_SCRATCH|STARPU_REDUX))
  711. continue;
  712. struct _starpu_data_replicate *replicate = &handle->per_node[node];
  713. prefetch_data_on_node(handle, replicate, mode);
  714. _starpu_set_data_requested_flag_if_needed(handle, replicate);
  715. }
  716. return 0;
  717. }
  718. int starpu_idle_prefetch_task_input_on_node(struct starpu_task *task, unsigned node)
  719. {
  720. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  721. unsigned index;
  722. for (index = 0; index < nbuffers; index++)
  723. {
  724. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, index);
  725. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, index);
  726. if (mode & (STARPU_SCRATCH|STARPU_REDUX))
  727. continue;
  728. struct _starpu_data_replicate *replicate = &handle->per_node[node];
  729. idle_prefetch_data_on_node(handle, replicate, mode);
  730. }
  731. return 0;
  732. }
  733. static struct _starpu_data_replicate *get_replicate(starpu_data_handle_t handle, enum starpu_data_access_mode mode, int workerid, unsigned node)
  734. {
  735. if (mode & (STARPU_SCRATCH|STARPU_REDUX))
  736. return &handle->per_worker[workerid];
  737. else
  738. /* That's a "normal" buffer (R/W) */
  739. return &handle->per_node[node];
  740. }
  741. /* Synchronously fetch data for a given task (if it's not there already) */
  742. int _starpu_fetch_task_input(struct _starpu_job *j)
  743. {
  744. _STARPU_TRACE_START_FETCH_INPUT(NULL);
  745. int profiling = starpu_profiling_status_get();
  746. struct starpu_task *task = j->task;
  747. if (profiling && task->profiling_info)
  748. _starpu_clock_gettime(&task->profiling_info->acquire_data_start_time);
  749. struct _starpu_data_descr *descrs = _STARPU_JOB_GET_ORDERED_BUFFERS(j);
  750. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  751. unsigned local_memory_node = _starpu_memory_node_get_local_key();
  752. int workerid = starpu_worker_get_id();
  753. #ifdef STARPU_USE_FXT
  754. unsigned long total_size = 0;
  755. #endif
  756. unsigned index;
  757. for (index = 0; index < nbuffers; index++)
  758. {
  759. int ret;
  760. starpu_data_handle_t handle = descrs[index].handle;
  761. enum starpu_data_access_mode mode = descrs[index].mode;
  762. int node = descrs[index].node;
  763. if (node == -1)
  764. node = local_memory_node;
  765. if (mode == STARPU_NONE ||
  766. (mode & ((1<<STARPU_MODE_SHIFT) - 1)) >= STARPU_ACCESS_MODE_MAX ||
  767. (mode >> STARPU_MODE_SHIFT) >= STARPU_SHIFTED_MODE_MAX)
  768. STARPU_ASSERT_MSG(0, "mode %d (0x%x) is bogus\n", mode, mode);
  769. struct _starpu_data_replicate *local_replicate;
  770. if (index && descrs[index-1].handle == descrs[index].handle)
  771. /* We have already took this data, skip it. This
  772. * depends on ordering putting writes before reads, see
  773. * _starpu_compar_handles */
  774. continue;
  775. local_replicate = get_replicate(handle, mode, workerid, node);
  776. ret = fetch_data(handle, local_replicate, mode);
  777. if (STARPU_UNLIKELY(ret))
  778. goto enomem;
  779. #ifdef STARPU_USE_FXT
  780. total_size += _starpu_data_get_size(handle);
  781. #endif
  782. }
  783. _STARPU_TRACE_DATA_LOAD(workerid,total_size);
  784. /* Now that we have taken the data locks in locking order, fill the codelet interfaces in function order. */
  785. for (index = 0; index < nbuffers; index++)
  786. {
  787. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, index);
  788. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, index);
  789. int node = descrs[index].node;
  790. if (node == -1)
  791. node = local_memory_node;
  792. struct _starpu_data_replicate *local_replicate;
  793. local_replicate = get_replicate(handle, mode, workerid, node);
  794. _STARPU_TASK_SET_INTERFACE(task , local_replicate->data_interface, index);
  795. /* If the replicate was not initialized yet, we have to do it now */
  796. if (!(mode & STARPU_SCRATCH) && !local_replicate->initialized)
  797. _starpu_redux_init_data_replicate(handle, local_replicate, workerid);
  798. }
  799. if (profiling && task->profiling_info)
  800. _starpu_clock_gettime(&task->profiling_info->acquire_data_end_time);
  801. _STARPU_TRACE_END_FETCH_INPUT(NULL);
  802. return 0;
  803. enomem:
  804. _STARPU_TRACE_END_FETCH_INPUT(NULL);
  805. _STARPU_DISP("something went wrong with buffer %u\n", index);
  806. /* try to unreference all the input that were successfully taken */
  807. unsigned index2;
  808. for (index2 = 0; index2 < index; index2++)
  809. {
  810. starpu_data_handle_t handle = descrs[index2].handle;
  811. enum starpu_data_access_mode mode = descrs[index2].mode;
  812. int node = descrs[index].node;
  813. if (node == -1)
  814. node = local_memory_node;
  815. struct _starpu_data_replicate *local_replicate;
  816. if (index2 && descrs[index2-1].handle == descrs[index2].handle)
  817. /* We have already released this data, skip it. This
  818. * depends on ordering putting writes before reads, see
  819. * _starpu_compar_handles */
  820. continue;
  821. local_replicate = get_replicate(handle, mode, workerid, node);
  822. _starpu_release_data_on_node(handle, 0, local_replicate);
  823. }
  824. return -1;
  825. }
  826. /* Release task data dependencies */
  827. void __starpu_push_task_output(struct _starpu_job *j)
  828. {
  829. #ifdef STARPU_OPENMP
  830. STARPU_ASSERT(!j->continuation);
  831. #endif
  832. int profiling = starpu_profiling_status_get();
  833. struct starpu_task *task = j->task;
  834. if (profiling && task->profiling_info)
  835. _starpu_clock_gettime(&task->profiling_info->release_data_start_time);
  836. struct _starpu_data_descr *descrs = _STARPU_JOB_GET_ORDERED_BUFFERS(j);
  837. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  838. int workerid = starpu_worker_get_id();
  839. unsigned local_memory_node = _starpu_memory_node_get_local_key();
  840. unsigned index;
  841. for (index = 0; index < nbuffers; index++)
  842. {
  843. starpu_data_handle_t handle = descrs[index].handle;
  844. enum starpu_data_access_mode mode = descrs[index].mode;
  845. int node = descrs[index].node;
  846. if (node == -1 && task->cl->where != STARPU_NOWHERE)
  847. node = local_memory_node;
  848. struct _starpu_data_replicate *local_replicate;
  849. if (index && descrs[index-1].handle == descrs[index].handle)
  850. /* We have already released this data, skip it. This
  851. * depends on ordering putting writes before reads, see
  852. * _starpu_compar_handles */
  853. continue;
  854. if (node != -1)
  855. local_replicate = get_replicate(handle, mode, workerid, node);
  856. /* Keep a reference for future
  857. * _starpu_release_task_enforce_sequential_consistency call */
  858. _starpu_spin_lock(&handle->header_lock);
  859. handle->busy_count++;
  860. if (node == -1)
  861. {
  862. /* NOWHERE case, just notify dependencies */
  863. if (!_starpu_notify_data_dependencies(handle))
  864. _starpu_spin_unlock(&handle->header_lock);
  865. }
  866. else
  867. {
  868. _starpu_spin_unlock(&handle->header_lock);
  869. _starpu_release_data_on_node(handle, 0, local_replicate);
  870. }
  871. }
  872. if (profiling && task->profiling_info)
  873. _starpu_clock_gettime(&task->profiling_info->release_data_end_time);
  874. }
  875. /* Version for a driver running on a worker: we show the driver state in the trace */
  876. void _starpu_push_task_output(struct _starpu_job *j)
  877. {
  878. _STARPU_TRACE_START_PUSH_OUTPUT(NULL);
  879. __starpu_push_task_output(j);
  880. _STARPU_TRACE_END_PUSH_OUTPUT(NULL);
  881. }
  882. struct fetch_nowhere_wrapper
  883. {
  884. struct _starpu_job *j;
  885. unsigned pending;
  886. };
  887. static void _starpu_fetch_nowhere_task_input_cb(void *arg);
  888. /* Asynchronously fetch data for a task which will have no content */
  889. void _starpu_fetch_nowhere_task_input(struct _starpu_job *j)
  890. {
  891. int profiling = starpu_profiling_status_get();
  892. struct starpu_task *task = j->task;
  893. if (profiling && task->profiling_info)
  894. _starpu_clock_gettime(&task->profiling_info->acquire_data_start_time);
  895. struct _starpu_data_descr *descrs = _STARPU_JOB_GET_ORDERED_BUFFERS(j);
  896. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  897. unsigned nfetchbuffers = 0;
  898. struct fetch_nowhere_wrapper *wrapper;
  899. unsigned index;
  900. for (index = 0; index < nbuffers; index++)
  901. {
  902. int node = descrs[index].node;
  903. if (node != -1)
  904. nfetchbuffers++;
  905. }
  906. if (!nfetchbuffers)
  907. {
  908. /* Nothing to fetch actually, already finished! */
  909. __starpu_push_task_output(j);
  910. _starpu_handle_job_termination(j);
  911. _STARPU_LOG_OUT_TAG("handle_job_termination");
  912. return;
  913. }
  914. wrapper = malloc(sizeof(*wrapper));
  915. wrapper->j = j;
  916. wrapper->pending = nfetchbuffers;
  917. for (index = 0; index < nbuffers; index++)
  918. {
  919. starpu_data_handle_t handle = descrs[index].handle;
  920. enum starpu_data_access_mode mode = descrs[index].mode;
  921. int node = descrs[index].node;
  922. if (node == -1)
  923. continue;
  924. if (mode == STARPU_NONE ||
  925. (mode & ((1<<STARPU_MODE_SHIFT) - 1)) >= STARPU_ACCESS_MODE_MAX ||
  926. (mode >> STARPU_MODE_SHIFT) >= STARPU_SHIFTED_MODE_MAX)
  927. STARPU_ASSERT_MSG(0, "mode %d (0x%x) is bogus\n", mode, mode);
  928. STARPU_ASSERT(mode != STARPU_SCRATCH && mode != STARPU_REDUX);
  929. struct _starpu_data_replicate *local_replicate;
  930. local_replicate = get_replicate(handle, mode, -1, node);
  931. _starpu_fetch_data_on_node(handle, local_replicate, mode, 0, 0, 1, _starpu_fetch_nowhere_task_input_cb, wrapper);
  932. }
  933. if (profiling && task->profiling_info)
  934. _starpu_clock_gettime(&task->profiling_info->acquire_data_end_time);
  935. }
  936. static void _starpu_fetch_nowhere_task_input_cb(void *arg)
  937. {
  938. /* One more transfer finished */
  939. struct fetch_nowhere_wrapper *wrapper = arg;
  940. unsigned pending = STARPU_ATOMIC_ADD(&wrapper->pending, -1);
  941. ANNOTATE_HAPPENS_BEFORE(&wrapper->pending);
  942. if (pending == 0)
  943. {
  944. ANNOTATE_HAPPENS_AFTER(&wrapper->pending);
  945. /* Finished transferring, task is over */
  946. struct _starpu_job *j = wrapper->j;
  947. free(wrapper);
  948. __starpu_push_task_output(j);
  949. _starpu_handle_job_termination(j);
  950. _STARPU_LOG_OUT_TAG("handle_job_termination");
  951. }
  952. }
  953. /* NB : this value can only be an indication of the status of a data
  954. at some point, but there is no strong garantee ! */
  955. unsigned _starpu_is_data_present_or_requested(starpu_data_handle_t handle, unsigned node)
  956. {
  957. unsigned ret = 0;
  958. // XXX : this is just a hint, so we don't take the lock ...
  959. // STARPU_PTHREAD_SPIN_LOCK(&handle->header_lock);
  960. if (handle->per_node[node].state != STARPU_INVALID)
  961. {
  962. ret = 1;
  963. }
  964. else
  965. {
  966. unsigned i;
  967. unsigned nnodes = starpu_memory_nodes_get_count();
  968. for (i = 0; i < nnodes; i++)
  969. {
  970. if ((handle->per_node[node].requested & (1UL << i)) || handle->per_node[node].request[i])
  971. ret = 1;
  972. }
  973. }
  974. // STARPU_PTHREAD_SPIN_UNLOCK(&handle->header_lock);
  975. return ret;
  976. }
  977. void _starpu_data_set_unregister_hook(starpu_data_handle_t handle, _starpu_data_handle_unregister_hook func)
  978. {
  979. handle->unregister_hook = func;
  980. }