data_interface.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <stdint.h>
  17. #include <stdarg.h>
  18. #include <datawizard/datawizard.h>
  19. #include <datawizard/memory_nodes.h>
  20. #include <datawizard/memstats.h>
  21. #include <datawizard/malloc.h>
  22. #include <core/dependencies/data_concurrency.h>
  23. #include <common/uthash.h>
  24. #include <common/starpu_spinlock.h>
  25. #include <core/task.h>
  26. #include <core/workers.h>
  27. #ifdef STARPU_OPENMP
  28. #include <util/openmp_runtime_support.h>
  29. #endif
  30. /* Entry in the `registered_handles' hash table. */
  31. struct handle_entry
  32. {
  33. UT_hash_handle hh;
  34. void *pointer;
  35. starpu_data_handle_t handle;
  36. };
  37. /* Hash table mapping host pointers to data handles. */
  38. static int nregistered, maxnregistered;
  39. static struct handle_entry *registered_handles;
  40. static struct _starpu_spinlock registered_handles_lock;
  41. static int _data_interface_number = STARPU_MAX_INTERFACE_ID;
  42. starpu_arbiter_t _starpu_global_arbiter;
  43. static void _starpu_data_unregister(starpu_data_handle_t handle, unsigned coherent, unsigned nowait);
  44. void _starpu_data_interface_init(void)
  45. {
  46. _starpu_spin_init(&registered_handles_lock);
  47. /* Just for testing purpose */
  48. if (starpu_get_env_number_default("STARPU_GLOBAL_ARBITER", 0) > 0)
  49. _starpu_global_arbiter = starpu_arbiter_create();
  50. }
  51. void _starpu_data_interface_shutdown()
  52. {
  53. struct handle_entry *entry=NULL, *tmp=NULL;
  54. if (registered_handles)
  55. {
  56. _STARPU_DISP("[warning] The application has not unregistered all data handles.\n");
  57. }
  58. _starpu_spin_destroy(&registered_handles_lock);
  59. HASH_ITER(hh, registered_handles, entry, tmp)
  60. {
  61. HASH_DEL(registered_handles, entry);
  62. nregistered--;
  63. free(entry);
  64. }
  65. if (starpu_get_env_number_default("STARPU_MAX_MEMORY_USE", 0))
  66. _STARPU_DISP("Memory used for %d data handles: %lu MiB\n", maxnregistered, (unsigned long) (maxnregistered * sizeof(struct _starpu_data_state)) >> 20);
  67. STARPU_ASSERT(nregistered == 0);
  68. registered_handles = NULL;
  69. }
  70. #ifdef STARPU_OPENMP
  71. void _starpu_omp_unregister_region_handles(struct starpu_omp_region *region)
  72. {
  73. _starpu_spin_lock(&region->registered_handles_lock);
  74. struct handle_entry *entry=NULL, *tmp=NULL;
  75. HASH_ITER(hh, (region->registered_handles), entry, tmp)
  76. {
  77. entry->handle->removed_from_context_hash = 1;
  78. HASH_DEL(region->registered_handles, entry);
  79. starpu_data_unregister(entry->handle);
  80. free(entry);
  81. }
  82. _starpu_spin_unlock(&region->registered_handles_lock);
  83. }
  84. void _starpu_omp_unregister_task_handles(struct starpu_omp_task *task)
  85. {
  86. struct handle_entry *entry=NULL, *tmp=NULL;
  87. HASH_ITER(hh, task->registered_handles, entry, tmp)
  88. {
  89. entry->handle->removed_from_context_hash = 1;
  90. HASH_DEL(task->registered_handles, entry);
  91. starpu_data_unregister(entry->handle);
  92. free(entry);
  93. }
  94. }
  95. #endif
  96. struct starpu_data_interface_ops *_starpu_data_interface_get_ops(unsigned interface_id)
  97. {
  98. switch (interface_id)
  99. {
  100. case STARPU_MATRIX_INTERFACE_ID:
  101. return &starpu_interface_matrix_ops;
  102. case STARPU_BLOCK_INTERFACE_ID:
  103. return &starpu_interface_block_ops;
  104. case STARPU_VECTOR_INTERFACE_ID:
  105. return &starpu_interface_vector_ops;
  106. case STARPU_CSR_INTERFACE_ID:
  107. return &starpu_interface_csr_ops;
  108. case STARPU_BCSR_INTERFACE_ID:
  109. return &starpu_interface_bcsr_ops;
  110. case STARPU_VARIABLE_INTERFACE_ID:
  111. return &starpu_interface_variable_ops;
  112. case STARPU_VOID_INTERFACE_ID:
  113. return &starpu_interface_void_ops;
  114. case STARPU_MULTIFORMAT_INTERFACE_ID:
  115. return &starpu_interface_multiformat_ops;
  116. default:
  117. STARPU_ABORT();
  118. return NULL;
  119. }
  120. }
  121. /* Register the mapping from PTR to HANDLE. If PTR is already mapped to
  122. * some handle, the new mapping shadows the previous one. */
  123. void _starpu_data_register_ram_pointer(starpu_data_handle_t handle, void *ptr)
  124. {
  125. struct handle_entry *entry;
  126. _STARPU_MALLOC(entry, sizeof(*entry));
  127. entry->pointer = ptr;
  128. entry->handle = handle;
  129. #ifdef STARPU_OPENMP
  130. struct starpu_omp_task *task = _starpu_omp_get_task();
  131. if (task)
  132. {
  133. if (task->flags & STARPU_OMP_TASK_FLAGS_IMPLICIT)
  134. {
  135. struct starpu_omp_region *parallel_region = task->owner_region;
  136. _starpu_spin_lock(&parallel_region->registered_handles_lock);
  137. HASH_ADD_PTR(parallel_region->registered_handles, pointer, entry);
  138. _starpu_spin_unlock(&parallel_region->registered_handles_lock);
  139. }
  140. else
  141. {
  142. HASH_ADD_PTR(task->registered_handles, pointer, entry);
  143. }
  144. }
  145. else
  146. #endif
  147. {
  148. struct handle_entry *old_entry;
  149. _starpu_spin_lock(&registered_handles_lock);
  150. HASH_FIND_PTR(registered_handles, &ptr, old_entry);
  151. if (old_entry)
  152. {
  153. /* Already registered this pointer, avoid undefined
  154. * behavior of duplicate in hash table */
  155. _starpu_spin_unlock(&registered_handles_lock);
  156. free(entry);
  157. }
  158. else
  159. {
  160. nregistered++;
  161. if (nregistered > maxnregistered)
  162. maxnregistered = nregistered;
  163. HASH_ADD_PTR(registered_handles, pointer, entry);
  164. _starpu_spin_unlock(&registered_handles_lock);
  165. }
  166. }
  167. }
  168. starpu_data_handle_t starpu_data_lookup(const void *ptr)
  169. {
  170. starpu_data_handle_t result;
  171. #ifdef STARPU_OPENMP
  172. struct starpu_omp_task *task = _starpu_omp_get_task();
  173. if (task)
  174. {
  175. if (task->flags & STARPU_OMP_TASK_FLAGS_IMPLICIT)
  176. {
  177. struct starpu_omp_region *parallel_region = task->owner_region;
  178. _starpu_spin_lock(&parallel_region->registered_handles_lock);
  179. {
  180. struct handle_entry *entry;
  181. HASH_FIND_PTR(parallel_region->registered_handles, &ptr, entry);
  182. if(STARPU_UNLIKELY(entry == NULL))
  183. result = NULL;
  184. else
  185. result = entry->handle;
  186. }
  187. _starpu_spin_unlock(&parallel_region->registered_handles_lock);
  188. }
  189. else
  190. {
  191. struct handle_entry *entry;
  192. HASH_FIND_PTR(task->registered_handles, &ptr, entry);
  193. if(STARPU_UNLIKELY(entry == NULL))
  194. result = NULL;
  195. else
  196. result = entry->handle;
  197. }
  198. }
  199. else
  200. #endif
  201. {
  202. _starpu_spin_lock(&registered_handles_lock);
  203. {
  204. struct handle_entry *entry;
  205. HASH_FIND_PTR(registered_handles, &ptr, entry);
  206. if(STARPU_UNLIKELY(entry == NULL))
  207. result = NULL;
  208. else
  209. result = entry->handle;
  210. }
  211. _starpu_spin_unlock(&registered_handles_lock);
  212. }
  213. return result;
  214. }
  215. /*
  216. * Start monitoring a piece of data
  217. */
  218. static void _starpu_register_new_data(starpu_data_handle_t handle,
  219. int home_node, uint32_t wt_mask)
  220. {
  221. void *ptr;
  222. STARPU_ASSERT(handle);
  223. /* first take care to properly lock the data */
  224. _starpu_spin_lock(&handle->header_lock);
  225. handle->root_handle = handle;
  226. //handle->father_handle = NULL;
  227. //handle->nsiblings = 0;
  228. //handle->siblings = NULL;
  229. //handle->sibling_index = 0; /* could be anything for the root */
  230. handle->depth = 1; /* the tree is just a node yet */
  231. handle->active = 1;
  232. /* Store some values directly in the handle not to recompute them all
  233. * the time. */
  234. handle->footprint = _starpu_compute_data_footprint(handle);
  235. handle->home_node = home_node;
  236. handle->wt_mask = wt_mask;
  237. //handle->aliases = 0;
  238. //handle->readonly_dup = NULL;
  239. //handle->readonly_dup_of = NULL;
  240. //handle->is_not_important = 0;
  241. handle->sequential_consistency =
  242. starpu_data_get_default_sequential_consistency_flag();
  243. handle->initialized = home_node != -1;
  244. //handle->readonly = 0;
  245. handle->ooc = 1;
  246. /* By default, there are no methods available to perform a reduction */
  247. //handle->redux_cl = NULL;
  248. //handle->init_cl = NULL;
  249. /* that new data is invalid from all nodes perpective except for the
  250. * home node */
  251. unsigned node;
  252. for (node = 0; node < STARPU_MAXNODES; node++)
  253. {
  254. struct _starpu_data_replicate *replicate;
  255. replicate = &handle->per_node[node];
  256. replicate->memory_node = node;
  257. //replicate->relaxed_coherency = 0;
  258. //replicate->refcnt = 0;
  259. if ((int) node == home_node)
  260. {
  261. /* this is the home node with the only valid copy */
  262. replicate->state = STARPU_OWNER;
  263. replicate->allocated = 1;
  264. //replicate->automatically_allocated = 0;
  265. replicate->initialized = 1;
  266. }
  267. else
  268. {
  269. /* the value is not available here yet */
  270. replicate->state = STARPU_INVALID;
  271. //replicate->allocated = 0;
  272. //replicate->initialized = 0;
  273. }
  274. }
  275. /* now the data is available ! */
  276. _starpu_spin_unlock(&handle->header_lock);
  277. for (node = 0; node < STARPU_MAXNODES; node++)
  278. {
  279. if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
  280. continue;
  281. ptr = starpu_data_handle_to_pointer(handle, node);
  282. if (ptr != NULL)
  283. _starpu_data_register_ram_pointer(handle, ptr);
  284. }
  285. }
  286. void
  287. _starpu_data_initialize_per_worker(starpu_data_handle_t handle)
  288. {
  289. unsigned worker;
  290. unsigned nworkers = starpu_worker_get_count();
  291. _starpu_spin_checklocked(&handle->header_lock);
  292. _STARPU_CALLOC(handle->per_worker, nworkers, sizeof(*handle->per_worker));
  293. size_t interfacesize = handle->ops->interface_size;
  294. for (worker = 0; worker < nworkers; worker++)
  295. {
  296. struct _starpu_data_replicate *replicate;
  297. unsigned node;
  298. replicate = &handle->per_worker[worker];
  299. replicate->allocated = 0;
  300. replicate->automatically_allocated = 0;
  301. replicate->state = STARPU_INVALID;
  302. replicate->refcnt = 0;
  303. replicate->handle = handle;
  304. replicate->requested = 0;
  305. for (node = 0; node < STARPU_MAXNODES; node++)
  306. {
  307. replicate->request[node] = NULL;
  308. }
  309. /* Assuming being used for SCRATCH for now, patched when entering REDUX mode */
  310. replicate->relaxed_coherency = 1;
  311. replicate->initialized = 0;
  312. replicate->memory_node = starpu_worker_get_memory_node(worker);
  313. _STARPU_CALLOC(replicate->data_interface, 1, interfacesize);
  314. /* duplicate the content of the interface on node 0 */
  315. memcpy(replicate->data_interface, handle->per_node[STARPU_MAIN_RAM].data_interface, interfacesize);
  316. }
  317. }
  318. void starpu_data_ptr_register(starpu_data_handle_t handle, unsigned node)
  319. {
  320. struct _starpu_data_replicate *replicate = &handle->per_node[node];
  321. _starpu_spin_lock(&handle->header_lock);
  322. STARPU_ASSERT_MSG(replicate->allocated == 0, "starpu_data_ptr_register must be called right after starpu_data_register");
  323. replicate->allocated = 1;
  324. replicate->automatically_allocated = 0;
  325. _starpu_spin_unlock(&handle->header_lock);
  326. }
  327. int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_interface_ops *interface_ops, unsigned int mf_node)
  328. {
  329. unsigned node;
  330. /* Tell helgrind that our access to busy_count in
  331. * starpu_data_unregister is actually safe */
  332. STARPU_HG_DISABLE_CHECKING(handle->busy_count);
  333. handle->magic = 42;
  334. /* When not specified, the fields are initialized in _starpu_register_new_data and _starpu_data_partition */
  335. _starpu_data_requester_prio_list_init0(&handle->req_list);
  336. //handle->refcnt = 0;
  337. //handle->unlocking_reqs = 0;
  338. //handle->current_mode = STARPU_NONE;
  339. _starpu_spin_init(&handle->header_lock);
  340. //handle->busy_count = 0;
  341. //handle->busy_waiting = 0;
  342. STARPU_PTHREAD_MUTEX_INIT0(&handle->busy_mutex, NULL);
  343. STARPU_PTHREAD_COND_INIT0(&handle->busy_cond, NULL);
  344. //handle->root_handle
  345. //handle->father_handle
  346. //handle->active_children = NULL;
  347. //handle->active_readonly_children = NULL;
  348. //handle->nactive_readonly_children = 0;
  349. //handle->nsiblings
  350. //handle->siblings
  351. //handle->sibling_index
  352. //handle->depth
  353. /* there is no hierarchy yet */
  354. //handle->children = NULL;
  355. //handle->nchildren = 0;
  356. //handle->nplans = 0;
  357. //handle->switch_cl = NULL;
  358. //handle->switch_cl_nparts = 0;
  359. //handle->partitioned = 0;
  360. //handle->part_readonly = 0;
  361. //handle->active
  362. //handle->active_ro = 0;
  363. //handle->per_node below
  364. handle->ops = interface_ops;
  365. size_t interfacesize = interface_ops->interface_size;
  366. for (node = 0; node < STARPU_MAXNODES; node++)
  367. {
  368. _starpu_memory_stats_init_per_node(handle, node);
  369. struct _starpu_data_replicate *replicate;
  370. replicate = &handle->per_node[node];
  371. /* relaxed_coherency = 0 */
  372. replicate->handle = handle;
  373. _STARPU_CALLOC(replicate->data_interface, 1, interfacesize);
  374. if (handle->ops->init) handle->ops->init(replicate->data_interface);
  375. }
  376. //handle->per_worker = NULL;
  377. //handle->ops above
  378. //handle->footprint
  379. //handle->home_node
  380. //handle->wt_mask
  381. //handle->aliases = 0;
  382. //handle->is_not_important
  383. //handle->sequential_consistency
  384. //handle->initialized
  385. //handle->readonly
  386. //handle->ooc
  387. //handle->lazy_unregister = 0;
  388. //handle->partition_automatic_disabled = 0;
  389. //handle->removed_from_context_hash = 0;
  390. STARPU_PTHREAD_MUTEX_INIT0(&handle->sequential_consistency_mutex, NULL);
  391. handle->last_submitted_mode = STARPU_R;
  392. //handle->last_sync_task = NULL;
  393. //handle->last_submitted_accessors.task = NULL;
  394. handle->last_submitted_accessors.next = &handle->last_submitted_accessors;
  395. handle->last_submitted_accessors.prev = &handle->last_submitted_accessors;
  396. #ifdef STARPU_USE_FXT
  397. //handle->last_submitted_ghost_sync_id_is_valid = 0;
  398. //handle->last_submitted_ghost_sync_id = 0;
  399. //handle->last_submitted_ghost_accessors_id = NULL;
  400. #endif
  401. //handle->post_sync_tasks = NULL;
  402. /* Tell helgrind that the race in _starpu_unlock_post_sync_tasks is fine */
  403. STARPU_HG_DISABLE_CHECKING(handle->post_sync_tasks_cnt);
  404. //handle->post_sync_tasks_cnt = 0;
  405. //handle->redux_cl
  406. //handle->init_cl
  407. //handle->reduction_refcnt = 0;
  408. _starpu_data_requester_prio_list_init0(&handle->reduction_req_list);
  409. //handle->reduction_tmp_handles = NULL;
  410. //handle->write_invalidation_req = NULL;
  411. //handle->mpi_data = NULL; /* invalid until set */
  412. _starpu_memory_stats_init(handle);
  413. handle->mf_node = mf_node;
  414. //handle->unregister_hook = NULL;
  415. if (_starpu_global_arbiter)
  416. /* Just for testing purpose */
  417. starpu_data_assign_arbiter(handle, _starpu_global_arbiter);
  418. else
  419. {
  420. //handle->arbiter = NULL;
  421. }
  422. _starpu_data_requester_prio_list_init0(&handle->arbitered_req_list);
  423. handle->last_locality = -1;
  424. //handle->dimensions = 0;
  425. //handle->coordinates = {};
  426. //handle->user_data = NULL;
  427. return 0;
  428. }
  429. static
  430. starpu_data_handle_t _starpu_data_handle_allocate(struct starpu_data_interface_ops *interface_ops, unsigned int mf_node)
  431. {
  432. starpu_data_handle_t handle;
  433. _STARPU_CALLOC(handle, 1, sizeof(struct _starpu_data_state));
  434. _starpu_data_handle_init(handle, interface_ops, mf_node);
  435. return handle;
  436. }
  437. void starpu_data_register(starpu_data_handle_t *handleptr, int home_node,
  438. void *data_interface,
  439. struct starpu_data_interface_ops *ops)
  440. {
  441. starpu_data_handle_t handle = _starpu_data_handle_allocate(ops, home_node);
  442. STARPU_ASSERT(handleptr);
  443. *handleptr = handle;
  444. /* fill the interface fields with the appropriate method */
  445. STARPU_ASSERT(ops->register_data_handle);
  446. ops->register_data_handle(handle, home_node, data_interface);
  447. _starpu_register_new_data(handle, home_node, 0);
  448. _STARPU_TRACE_HANDLE_DATA_REGISTER(handle);
  449. }
  450. void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc)
  451. {
  452. void *local_interface = starpu_data_get_interface_on_node(handlesrc, STARPU_MAIN_RAM);
  453. starpu_data_register(handledst, -1, local_interface, handlesrc->ops);
  454. }
  455. void *starpu_data_handle_to_pointer(starpu_data_handle_t handle, unsigned node)
  456. {
  457. /* Check whether the operation is supported and the node has actually
  458. * been allocated. */
  459. if (!starpu_data_test_if_allocated_on_node(handle, node))
  460. return NULL;
  461. if (handle->ops->to_pointer)
  462. {
  463. return handle->ops->to_pointer(starpu_data_get_interface_on_node(handle, node), node);
  464. }
  465. /* Deprecated */
  466. if (handle->ops->handle_to_pointer)
  467. {
  468. return handle->ops->handle_to_pointer(handle, node);
  469. }
  470. return NULL;
  471. }
  472. int starpu_data_pointer_is_inside(starpu_data_handle_t handle, unsigned node, void *ptr)
  473. {
  474. /* Check whether the operation is supported and the node has actually
  475. * been allocated. */
  476. if (!starpu_data_test_if_allocated_on_node(handle, node))
  477. return 0;
  478. if (handle->ops->pointer_is_inside)
  479. {
  480. return handle->ops->pointer_is_inside(starpu_data_get_interface_on_node(handle, node), node, ptr);
  481. }
  482. /* Don't know :/ */
  483. return -1;
  484. }
  485. void *starpu_data_get_local_ptr(starpu_data_handle_t handle)
  486. {
  487. return starpu_data_handle_to_pointer(handle, starpu_worker_get_local_memory_node());
  488. }
  489. struct starpu_data_interface_ops* starpu_data_get_interface_ops(starpu_data_handle_t handle)
  490. {
  491. return handle->ops;
  492. }
  493. /*
  494. * Stop monitoring a piece of data
  495. */
  496. void _starpu_data_unregister_ram_pointer(starpu_data_handle_t handle, unsigned node)
  497. {
  498. if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
  499. return;
  500. #ifdef STARPU_OPENMP
  501. if (handle->removed_from_context_hash)
  502. return;
  503. #endif
  504. const void *ram_ptr = starpu_data_handle_to_pointer(handle, node);
  505. if (ram_ptr != NULL)
  506. {
  507. /* Remove the PTR -> HANDLE mapping. If a mapping from PTR
  508. * to another handle existed before (e.g., when using
  509. * filters), it becomes visible again. */
  510. struct handle_entry *entry;
  511. #ifdef STARPU_OPENMP
  512. struct starpu_omp_task *task = _starpu_omp_get_task();
  513. if (task)
  514. {
  515. if (task->flags & STARPU_OMP_TASK_FLAGS_IMPLICIT)
  516. {
  517. struct starpu_omp_region *parallel_region = task->owner_region;
  518. _starpu_spin_lock(&parallel_region->registered_handles_lock);
  519. HASH_FIND_PTR(parallel_region->registered_handles, &ram_ptr, entry);
  520. STARPU_ASSERT(entry != NULL);
  521. HASH_DEL(registered_handles, entry);
  522. _starpu_spin_unlock(&parallel_region->registered_handles_lock);
  523. }
  524. else
  525. {
  526. HASH_FIND_PTR(task->registered_handles, &ram_ptr, entry);
  527. STARPU_ASSERT(entry != NULL);
  528. HASH_DEL(task->registered_handles, entry);
  529. }
  530. }
  531. else
  532. #endif
  533. {
  534. _starpu_spin_lock(&registered_handles_lock);
  535. HASH_FIND_PTR(registered_handles, &ram_ptr, entry);
  536. if (entry)
  537. {
  538. if (entry->handle == handle)
  539. {
  540. nregistered--;
  541. HASH_DEL(registered_handles, entry);
  542. }
  543. else
  544. /* don't free it, it's not ours */
  545. entry = NULL;
  546. }
  547. _starpu_spin_unlock(&registered_handles_lock);
  548. }
  549. free(entry);
  550. }
  551. }
  552. void _starpu_data_free_interfaces(starpu_data_handle_t handle)
  553. {
  554. unsigned node;
  555. unsigned nworkers = starpu_worker_get_count();
  556. for (node = 0; node < STARPU_MAXNODES; node++)
  557. free(handle->per_node[node].data_interface);
  558. if (handle->per_worker)
  559. {
  560. unsigned worker;
  561. for (worker = 0; worker < nworkers; worker++)
  562. free(handle->per_worker[worker].data_interface);
  563. free(handle->per_worker);
  564. }
  565. }
  566. struct _starpu_unregister_callback_arg
  567. {
  568. unsigned memory_node;
  569. starpu_data_handle_t handle;
  570. unsigned terminated;
  571. starpu_pthread_mutex_t mutex;
  572. starpu_pthread_cond_t cond;
  573. };
  574. /* Check whether we should tell starpu_data_unregister that the data handle is
  575. * not busy any more.
  576. * The header is supposed to be locked.
  577. * This may free the handle, if it was lazily unregistered (1 is returned in
  578. * that case). The handle pointer thus becomes invalid for the caller.
  579. *
  580. * Note: we inline some of the tests in the _starpu_data_check_not_busy macro.
  581. */
  582. int __starpu_data_check_not_busy(starpu_data_handle_t handle)
  583. {
  584. if (STARPU_LIKELY(handle->busy_count))
  585. return 0;
  586. /* Not busy any more, perhaps have to unregister etc. */
  587. if (STARPU_UNLIKELY(handle->busy_waiting))
  588. {
  589. STARPU_PTHREAD_MUTEX_LOCK(&handle->busy_mutex);
  590. STARPU_PTHREAD_COND_BROADCAST(&handle->busy_cond);
  591. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->busy_mutex);
  592. }
  593. /* The handle has been destroyed in between (eg. this was a temporary
  594. * handle created for a reduction.) */
  595. if (STARPU_UNLIKELY(handle->lazy_unregister))
  596. {
  597. handle->lazy_unregister = 0;
  598. _starpu_spin_unlock(&handle->header_lock);
  599. _starpu_data_unregister(handle, 0, 1);
  600. /* Warning: in case we unregister the handle, we must be sure
  601. * that the caller will not try to unlock the header after
  602. * !*/
  603. return 1;
  604. }
  605. return 0;
  606. }
  607. static
  608. void _starpu_check_if_valid_and_fetch_data_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, const char *origin)
  609. {
  610. unsigned node;
  611. unsigned nnodes = starpu_memory_nodes_get_count();
  612. int valid = 0;
  613. for (node = 0; node < nnodes; node++)
  614. {
  615. if (handle->per_node[node].state != STARPU_INVALID)
  616. {
  617. /* we found a copy ! */
  618. valid = 1;
  619. }
  620. }
  621. if (valid)
  622. {
  623. int ret = _starpu_fetch_data_on_node(handle, handle->home_node, replicate, STARPU_R, 0, STARPU_FETCH, 0, NULL, NULL, 0, origin);
  624. STARPU_ASSERT(!ret);
  625. _starpu_release_data_on_node(handle, 0, STARPU_NONE, replicate);
  626. }
  627. else
  628. {
  629. _starpu_spin_lock(&handle->header_lock);
  630. if (!_starpu_notify_data_dependencies(handle, STARPU_NONE))
  631. _starpu_spin_unlock(&handle->header_lock);
  632. }
  633. }
  634. static void _starpu_data_unregister_fetch_data_callback(void *_arg)
  635. {
  636. struct _starpu_unregister_callback_arg *arg = (struct _starpu_unregister_callback_arg *) _arg;
  637. starpu_data_handle_t handle = arg->handle;
  638. STARPU_ASSERT(handle);
  639. struct _starpu_data_replicate *replicate = &handle->per_node[arg->memory_node];
  640. _starpu_check_if_valid_and_fetch_data_on_node(handle, replicate, "_starpu_data_unregister_fetch_data_callback");
  641. /* unlock the caller */
  642. STARPU_PTHREAD_MUTEX_LOCK(&arg->mutex);
  643. arg->terminated = 1;
  644. STARPU_PTHREAD_COND_SIGNAL(&arg->cond);
  645. STARPU_PTHREAD_MUTEX_UNLOCK(&arg->mutex);
  646. }
  647. void _starpu_data_set_unregister_hook(starpu_data_handle_t handle, _starpu_data_handle_unregister_hook func)
  648. {
  649. STARPU_ASSERT(handle->unregister_hook == NULL);
  650. handle->unregister_hook = func;
  651. }
  652. /*
  653. * We are about to unregister this R/O data. There might be still other aliases,
  654. * in which case this returns 0. If not, users are not supposed to see it
  655. * any more, so detach it from their sight and return 1 to let unregistration happen.
  656. */
  657. static int _starpu_ro_data_detach(starpu_data_handle_t handle)
  658. {
  659. _starpu_spin_lock(&handle->header_lock);
  660. if (handle->aliases)
  661. {
  662. handle->aliases--;
  663. _starpu_spin_unlock(&handle->header_lock);
  664. return 0;
  665. }
  666. if (handle->readonly_dup)
  667. {
  668. STARPU_ASSERT(handle->readonly_dup->readonly_dup_of == handle);
  669. handle->readonly_dup->readonly_dup_of = NULL;
  670. handle->readonly_dup = NULL;
  671. }
  672. if (handle->readonly_dup_of)
  673. {
  674. STARPU_ASSERT(handle->readonly_dup_of->readonly_dup == handle);
  675. handle->readonly_dup_of->readonly_dup = NULL;
  676. handle->readonly_dup_of = NULL;
  677. }
  678. /* So that unregistration can use write dependencies to wait for
  679. * anything to finish */
  680. handle->readonly = 0;
  681. _starpu_spin_unlock(&handle->header_lock);
  682. return 1;
  683. }
  684. /* Unregister the data handle, perhaps we don't need to update the home_node
  685. * (in that case coherent is set to 0)
  686. * nowait is for internal use when we already know for sure that we won't have to wait.
  687. */
  688. static void _starpu_data_unregister(starpu_data_handle_t handle, unsigned coherent, unsigned nowait)
  689. {
  690. STARPU_ASSERT(handle);
  691. STARPU_ASSERT_MSG(handle->nchildren == 0, "data %p needs to be unpartitioned before unregistration", handle);
  692. STARPU_ASSERT_MSG(handle->nplans == 0, "data %p needs its partition plans to be cleaned before unregistration", handle);
  693. STARPU_ASSERT_MSG(handle->partitioned == 0, "data %p needs its partitioned plans to be unpartitioned before unregistration", handle);
  694. /* TODO: also check that it has the latest coherency */
  695. STARPU_ASSERT(!(nowait && handle->busy_count != 0));
  696. if (!_starpu_ro_data_detach(handle))
  697. return;
  698. int sequential_consistency = handle->sequential_consistency;
  699. if (sequential_consistency && !nowait)
  700. {
  701. /* We will acquire it in write mode to catch all dependencies,
  702. * but possibly it's not actually initialized. Fake it to avoid
  703. getting caught doing it */
  704. handle->initialized = 1;
  705. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_data_unregister must not be called from a task or callback, perhaps you can use starpu_data_unregister_submit instead");
  706. /* If sequential consistency is enabled, wait until data is available */
  707. _starpu_data_wait_until_available(handle, handle->readonly?STARPU_R:STARPU_RW, "starpu_data_unregister");
  708. }
  709. if (coherent && !nowait)
  710. {
  711. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_data_unregister must not be called from a task or callback, perhaps you can use starpu_data_unregister_submit instead");
  712. /* Fetch data in the home of the data to ensure we have a valid copy
  713. * where we registered it */
  714. int home_node = handle->home_node;
  715. if (home_node >= 0)
  716. {
  717. struct _starpu_unregister_callback_arg arg = { 0 };
  718. arg.handle = handle;
  719. arg.memory_node = (unsigned)home_node;
  720. arg.terminated = 0;
  721. STARPU_PTHREAD_MUTEX_INIT0(&arg.mutex, NULL);
  722. STARPU_PTHREAD_COND_INIT0(&arg.cond, NULL);
  723. if (!_starpu_attempt_to_submit_data_request_from_apps(handle, STARPU_R,
  724. _starpu_data_unregister_fetch_data_callback, &arg))
  725. {
  726. /* no one has locked this data yet, so we proceed immediately */
  727. struct _starpu_data_replicate *home_replicate = &handle->per_node[home_node];
  728. _starpu_check_if_valid_and_fetch_data_on_node(handle, home_replicate, "_starpu_data_unregister");
  729. }
  730. else
  731. {
  732. STARPU_PTHREAD_MUTEX_LOCK(&arg.mutex);
  733. while (!arg.terminated)
  734. STARPU_PTHREAD_COND_WAIT(&arg.cond, &arg.mutex);
  735. STARPU_PTHREAD_MUTEX_UNLOCK(&arg.mutex);
  736. }
  737. STARPU_PTHREAD_MUTEX_DESTROY(&arg.mutex);
  738. STARPU_PTHREAD_COND_DESTROY(&arg.cond);
  739. }
  740. /* If this handle uses a multiformat interface, we may have to convert
  741. * this piece of data back into the CPU format.
  742. * XXX : This is quite hacky, could we submit a task instead ?
  743. */
  744. if (_starpu_data_is_multiformat_handle(handle) && (starpu_node_get_kind(handle->mf_node) != STARPU_CPU_RAM))
  745. {
  746. _STARPU_DEBUG("Conversion needed\n");
  747. void *buffers[1];
  748. struct starpu_multiformat_interface *format_interface;
  749. home_node = handle->home_node;
  750. if (home_node < 0 || (starpu_node_get_kind(home_node) != STARPU_CPU_RAM))
  751. home_node = STARPU_MAIN_RAM;
  752. format_interface = (struct starpu_multiformat_interface *) starpu_data_get_interface_on_node(handle, home_node);
  753. struct starpu_codelet *cl = NULL;
  754. enum starpu_node_kind node_kind = starpu_node_get_kind(handle->mf_node);
  755. switch (node_kind)
  756. {
  757. #ifdef STARPU_USE_CUDA
  758. case STARPU_CUDA_RAM:
  759. {
  760. struct starpu_multiformat_data_interface_ops *mf_ops;
  761. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  762. cl = mf_ops->cuda_to_cpu_cl;
  763. break;
  764. }
  765. #endif
  766. #ifdef STARPU_USE_OPENCL
  767. case STARPU_OPENCL_RAM:
  768. {
  769. struct starpu_multiformat_data_interface_ops *mf_ops;
  770. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  771. cl = mf_ops->opencl_to_cpu_cl;
  772. break;
  773. }
  774. #endif
  775. #ifdef STARPU_USE_MIC
  776. case STARPU_MIC_RAM:
  777. {
  778. struct starpu_multiformat_data_interface_ops *mf_ops;
  779. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  780. cl = mf_ops->mic_to_cpu_cl;
  781. break;
  782. }
  783. #endif
  784. case STARPU_CPU_RAM: /* Impossible ! */
  785. default:
  786. STARPU_ABORT();
  787. }
  788. buffers[0] = format_interface;
  789. _starpu_cl_func_t func = _starpu_task_get_cpu_nth_implementation(cl, 0);
  790. STARPU_ASSERT(func);
  791. func(buffers, NULL);
  792. }
  793. }
  794. /* Prevent any further unregistration */
  795. handle->magic = 0;
  796. _starpu_spin_lock(&handle->header_lock);
  797. if (!coherent)
  798. {
  799. /* Should we postpone the unregister operation ? */
  800. if ((handle->busy_count > 0) && handle->lazy_unregister)
  801. {
  802. _starpu_spin_unlock(&handle->header_lock);
  803. return;
  804. }
  805. }
  806. /* Tell holders of references that we're starting waiting */
  807. handle->busy_waiting = 1;
  808. _starpu_spin_unlock(&handle->header_lock);
  809. retry_busy:
  810. /* Wait for all requests to finish (notably WT requests) */
  811. STARPU_PTHREAD_MUTEX_LOCK(&handle->busy_mutex);
  812. while (1)
  813. {
  814. /* Here helgrind would shout that this an unprotected access,
  815. * but this is actually fine: all threads who do busy_count--
  816. * are supposed to call _starpu_data_check_not_busy, which will
  817. * wake us up through the busy_mutex/busy_cond. */
  818. if (!handle->busy_count)
  819. break;
  820. /* This is woken by _starpu_data_check_not_busy, always called
  821. * after decrementing busy_count */
  822. STARPU_PTHREAD_COND_WAIT(&handle->busy_cond, &handle->busy_mutex);
  823. }
  824. STARPU_PTHREAD_MUTEX_UNLOCK(&handle->busy_mutex);
  825. /* Unregister MPI things after having waiting for MPI reqs etc. to settle down */
  826. if (handle->unregister_hook)
  827. {
  828. handle->unregister_hook(handle);
  829. handle->unregister_hook = NULL;
  830. }
  831. /* Wait for finished requests to release the handle */
  832. _starpu_spin_lock(&handle->header_lock);
  833. if (handle->busy_count)
  834. {
  835. /* Bad luck: some request went in in between, wait again... */
  836. _starpu_spin_unlock(&handle->header_lock);
  837. goto retry_busy;
  838. }
  839. size_t size = _starpu_data_get_alloc_size(handle);
  840. /* Destroy the data now */
  841. unsigned node;
  842. for (node = 0; node < STARPU_MAXNODES; node++)
  843. {
  844. struct _starpu_data_replicate *local = &handle->per_node[node];
  845. if (local->allocated)
  846. {
  847. _starpu_data_unregister_ram_pointer(handle, node);
  848. /* free the data copy in a lazy fashion */
  849. if (local->automatically_allocated)
  850. _starpu_request_mem_chunk_removal(handle, local, node, size);
  851. }
  852. }
  853. if (handle->per_worker)
  854. {
  855. unsigned worker;
  856. unsigned nworkers = starpu_worker_get_count();
  857. for (worker = 0; worker < nworkers; worker++)
  858. {
  859. struct _starpu_data_replicate *local = &handle->per_worker[worker];
  860. /* free the data copy in a lazy fashion */
  861. if (local->allocated && local->automatically_allocated)
  862. _starpu_request_mem_chunk_removal(handle, local, starpu_worker_get_memory_node(worker), size);
  863. }
  864. }
  865. _starpu_data_free_interfaces(handle);
  866. _starpu_memory_stats_free(handle);
  867. _starpu_spin_unlock(&handle->header_lock);
  868. _starpu_spin_destroy(&handle->header_lock);
  869. _starpu_data_clear_implicit(handle);
  870. free(handle->active_readonly_children);
  871. STARPU_PTHREAD_MUTEX_DESTROY(&handle->busy_mutex);
  872. STARPU_PTHREAD_COND_DESTROY(&handle->busy_cond);
  873. STARPU_PTHREAD_MUTEX_DESTROY(&handle->sequential_consistency_mutex);
  874. STARPU_HG_ENABLE_CHECKING(handle->post_sync_tasks_cnt);
  875. STARPU_HG_ENABLE_CHECKING(handle->busy_count);
  876. if (handle->switch_cl)
  877. {
  878. free(handle->switch_cl->dyn_nodes);
  879. free(handle->switch_cl);
  880. }
  881. _STARPU_TRACE_HANDLE_DATA_UNREGISTER(handle);
  882. free(handle);
  883. }
  884. void starpu_data_unregister(starpu_data_handle_t handle)
  885. {
  886. STARPU_ASSERT_MSG(handle->magic == 42, "data %p is invalid (was it already registered?)", handle);
  887. STARPU_ASSERT_MSG(!handle->lazy_unregister, "data %p can not be unregistered twice", handle);
  888. _starpu_data_unregister(handle, 1, 0);
  889. }
  890. void starpu_data_unregister_no_coherency(starpu_data_handle_t handle)
  891. {
  892. STARPU_ASSERT_MSG(handle->magic == 42, "data %p is invalid (was it already registered?)", handle);
  893. _starpu_data_unregister(handle, 0, 0);
  894. }
  895. static void _starpu_data_unregister_submit_cb(void *arg)
  896. {
  897. starpu_data_handle_t handle = arg;
  898. _starpu_spin_lock(&handle->header_lock);
  899. handle->lazy_unregister = 1;
  900. /* The handle should be busy since we are working on it.
  901. * when we releases the handle below, it will be destroyed by
  902. * _starpu_data_check_not_busy */
  903. STARPU_ASSERT(handle->busy_count);
  904. _starpu_spin_unlock(&handle->header_lock);
  905. starpu_data_release_on_node(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL);
  906. }
  907. void starpu_data_unregister_submit(starpu_data_handle_t handle)
  908. {
  909. STARPU_ASSERT_MSG(handle->magic == 42, "data %p is invalid (was it already registered?)", handle);
  910. STARPU_ASSERT_MSG(!handle->lazy_unregister, "data %p can not be unregistered twice", handle);
  911. if (!_starpu_ro_data_detach(handle))
  912. return;
  913. /* Wait for all task dependencies on this handle before putting it for free */
  914. starpu_data_acquire_on_node_cb(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL, handle->initialized?STARPU_RW:STARPU_W, _starpu_data_unregister_submit_cb, handle);
  915. }
  916. static void _starpu_data_invalidate(void *data)
  917. {
  918. starpu_data_handle_t handle = data;
  919. size_t size = _starpu_data_get_alloc_size(handle);
  920. _starpu_spin_lock(&handle->header_lock);
  921. //_STARPU_DEBUG("Really invalidating data %p\n", data);
  922. #ifdef STARPU_DEBUG
  923. {
  924. /* There shouldn't be any pending request since we acquired the data in W mode */
  925. unsigned i, j, nnodes = starpu_memory_nodes_get_count();
  926. for (i = 0; i < nnodes; i++)
  927. for (j = 0; j < nnodes; j++)
  928. STARPU_ASSERT_MSG(!handle->per_node[i].request[j], "request for handle %p pending from %u to %u while invalidating data!", handle, j, i);
  929. }
  930. #endif
  931. unsigned node;
  932. for (node = 0; node < STARPU_MAXNODES; node++)
  933. {
  934. struct _starpu_data_replicate *local = &handle->per_node[node];
  935. if (local->mc && local->allocated && local->automatically_allocated)
  936. {
  937. _starpu_data_unregister_ram_pointer(handle, node);
  938. /* free the data copy in a lazy fashion */
  939. _starpu_request_mem_chunk_removal(handle, local, node, size);
  940. }
  941. if (local->state != STARPU_INVALID)
  942. _STARPU_TRACE_DATA_STATE_INVALID(handle, node);
  943. local->state = STARPU_INVALID;
  944. }
  945. if (handle->per_worker)
  946. {
  947. unsigned worker;
  948. unsigned nworkers = starpu_worker_get_count();
  949. for (worker = 0; worker < nworkers; worker++)
  950. {
  951. struct _starpu_data_replicate *local = &handle->per_worker[worker];
  952. if (local->mc && local->allocated && local->automatically_allocated)
  953. /* free the data copy in a lazy fashion */
  954. _starpu_request_mem_chunk_removal(handle, local, starpu_worker_get_memory_node(worker), size);
  955. local->state = STARPU_INVALID;
  956. }
  957. }
  958. _starpu_spin_unlock(&handle->header_lock);
  959. starpu_data_release_on_node(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL);
  960. }
  961. void starpu_data_invalidate(starpu_data_handle_t handle)
  962. {
  963. STARPU_ASSERT(handle);
  964. starpu_data_acquire_on_node(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL, STARPU_W);
  965. _starpu_data_invalidate(handle);
  966. handle->initialized = 0;
  967. }
  968. void starpu_data_invalidate_submit(starpu_data_handle_t handle)
  969. {
  970. STARPU_ASSERT(handle);
  971. starpu_data_acquire_on_node_cb(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL, STARPU_W, _starpu_data_invalidate, handle);
  972. handle->initialized = 0;
  973. }
  974. enum starpu_data_interface_id starpu_data_get_interface_id(starpu_data_handle_t handle)
  975. {
  976. return handle->ops->interfaceid;
  977. }
  978. void *starpu_data_get_interface_on_node(starpu_data_handle_t handle, unsigned memory_node)
  979. {
  980. return handle->per_node[memory_node].data_interface;
  981. }
  982. int starpu_data_interface_get_next_id(void)
  983. {
  984. _data_interface_number += 1;
  985. return _data_interface_number-1;
  986. }
  987. int starpu_data_pack(starpu_data_handle_t handle, void **ptr, starpu_ssize_t *count)
  988. {
  989. STARPU_ASSERT_MSG(handle->ops->pack_data, "The datatype interface %s (%d) does not have a pack operation", handle->ops->name, handle->ops->interfaceid);
  990. return handle->ops->pack_data(handle, starpu_worker_get_local_memory_node(), ptr, count);
  991. }
  992. int starpu_data_unpack(starpu_data_handle_t handle, void *ptr, size_t count)
  993. {
  994. STARPU_ASSERT_MSG(handle->ops->unpack_data, "The datatype interface %s (%d) does not have an unpack operation", handle->ops->name, handle->ops->interfaceid);
  995. int ret;
  996. ret = handle->ops->unpack_data(handle, starpu_worker_get_local_memory_node(), ptr, count);
  997. return ret;
  998. }
  999. size_t starpu_data_get_size(starpu_data_handle_t handle)
  1000. {
  1001. return handle->ops->get_size(handle);
  1002. }
  1003. size_t starpu_data_get_alloc_size(starpu_data_handle_t handle)
  1004. {
  1005. if (handle->ops->get_alloc_size)
  1006. return handle->ops->get_alloc_size(handle);
  1007. else
  1008. return handle->ops->get_size(handle);
  1009. }
  1010. void starpu_data_set_name(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, const char *name STARPU_ATTRIBUTE_UNUSED)
  1011. {
  1012. _STARPU_TRACE_DATA_NAME(handle, name);
  1013. }
  1014. int starpu_data_get_home_node(starpu_data_handle_t handle)
  1015. {
  1016. return handle->home_node;
  1017. }
  1018. void starpu_data_set_coordinates_array(starpu_data_handle_t handle, unsigned dimensions, int dims[])
  1019. {
  1020. unsigned i;
  1021. unsigned max_dimensions = sizeof(handle->coordinates)/sizeof(handle->coordinates[0]);
  1022. if (dimensions > max_dimensions)
  1023. dimensions = max_dimensions;
  1024. handle->dimensions = dimensions;
  1025. for (i = 0; i < dimensions; i++)
  1026. handle->coordinates[i] = dims[i];
  1027. _STARPU_TRACE_DATA_COORDINATES(handle, dimensions, dims);
  1028. }
  1029. void starpu_data_set_coordinates(starpu_data_handle_t handle, unsigned dimensions, ...)
  1030. {
  1031. int dims[dimensions];
  1032. unsigned i;
  1033. va_list varg_list;
  1034. va_start(varg_list, dimensions);
  1035. for (i = 0; i < dimensions; i++)
  1036. dims[i] = va_arg(varg_list, int);
  1037. va_end(varg_list);
  1038. starpu_data_set_coordinates_array(handle, dimensions, dims);
  1039. }
  1040. unsigned starpu_data_get_coordinates_array(starpu_data_handle_t handle, unsigned dimensions, int dims[])
  1041. {
  1042. unsigned i;
  1043. if (dimensions > handle->dimensions)
  1044. dimensions = handle->dimensions;
  1045. for (i = 0; i < dimensions; i++)
  1046. dims[i] = handle->coordinates[i];
  1047. return dimensions;
  1048. }