coherency.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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. #ifndef __COHERENCY__H__
  17. #define __COHERENCY__H__
  18. #include <starpu.h>
  19. #include <common/config.h>
  20. #include <common/starpu_spinlock.h>
  21. #include <common/rwlock.h>
  22. #include <common/timing.h>
  23. #include <common/fxt.h>
  24. #include <common/list.h>
  25. #include <datawizard/data_request.h>
  26. #include <datawizard/interfaces/data_interface.h>
  27. #include <datawizard/datastats.h>
  28. typedef enum {
  29. STARPU_OWNER,
  30. STARPU_SHARED,
  31. STARPU_INVALID
  32. } starpu_cache_state;
  33. /* this should contain the information relative to a given node */
  34. typedef struct starpu_local_data_state_t {
  35. /* describes the state of the local data in term of coherency */
  36. starpu_cache_state state;
  37. int refcnt;
  38. /* is the data locally allocated ? */
  39. uint8_t allocated;
  40. /* was it automatically allocated ? */
  41. /* perhaps the allocation was perform higher in the hiearchy
  42. * for now this is just translated into !automatically_allocated
  43. * */
  44. uint8_t automatically_allocated;
  45. /* To help the scheduling policies to make some decision, we
  46. may keep a track of the tasks that are likely to request
  47. this data on the current node.
  48. It is the responsability of the scheduling _policy_ to set that
  49. flag when it assigns a task to a queue, policies which do not
  50. use this hint can simply ignore it.
  51. */
  52. uint8_t requested;
  53. struct starpu_data_request_s *request;
  54. } starpu_local_data_state;
  55. struct starpu_data_requester_list_s;
  56. struct starpu_task_list {
  57. struct starpu_task *task;
  58. struct starpu_task_list *next;
  59. };
  60. struct starpu_jobid_list {
  61. unsigned long id;
  62. struct starpu_jobid_list *next;
  63. };
  64. struct starpu_data_state_t {
  65. struct starpu_data_requester_list_s *req_list;
  66. /* the number of requests currently in the scheduling engine
  67. * (not in the req_list anymore) */
  68. unsigned refcnt;
  69. starpu_access_mode current_mode;
  70. /* protect meta data */
  71. starpu_spinlock_t header_lock;
  72. /* In case we user filters, the handle may describe a sub-data */
  73. struct starpu_data_state_t *root_handle; /* root of the tree */
  74. struct starpu_data_state_t *father_handle; /* father of the node, NULL if the current node is the root */
  75. unsigned sibling_index; /* indicate which child this node is from the father's perpsective (if any) */
  76. unsigned depth; /* what's the depth of the tree ? */
  77. struct starpu_data_state_t *children;
  78. unsigned nchildren;
  79. /* describe the state of the data in term of coherency */
  80. starpu_local_data_state per_node[STARPU_MAXNODES];
  81. /* describe the actual data layout */
  82. void *interface[STARPU_MAXNODES];
  83. struct starpu_data_interface_ops_t *ops;
  84. /* To avoid recomputing data size all the time, we store it directly. */
  85. size_t data_size;
  86. /* Footprint which identifies data layout */
  87. uint32_t footprint;
  88. /* where is the data home ? -1 if none yet */
  89. int home_node;
  90. /* what is the default write-back mask for that data ? */
  91. uint32_t wb_mask;
  92. /* allows special optimization */
  93. uint8_t is_readonly;
  94. /* in some case, the application may explicitly tell StarPU that a
  95. * piece of data is not likely to be used soon again */
  96. unsigned is_not_important;
  97. /* Does StarPU have to enforce some implicit data-dependencies ? */
  98. unsigned sequential_consistency;
  99. /* This lock should protect any operation to enforce
  100. * sequential_consistency */
  101. pthread_mutex_t sequential_consistency_mutex;
  102. /* The last submitted task (or application data request) that declared
  103. * it would modify the piece of data ? Any task accessing the data in a
  104. * read-only mode should depend on that task implicitely if the
  105. * sequential_consistency flag is enabled. */
  106. starpu_access_mode last_submitted_mode;
  107. struct starpu_task *last_submitted_writer;
  108. struct starpu_task_list *last_submitted_readers;
  109. #ifdef STARPU_USE_FXT
  110. /* If FxT is enabled, we keep track of "ghost dependencies": that is to
  111. * say the dependencies that are not needed anymore, but that should
  112. * appear in the post-mortem DAG. For instance if we have the sequence
  113. * f(Aw) g(Aw), and that g is submitted after the termination of f, we
  114. * want to have f->g appear in the DAG even if StarPU does not need to
  115. * enforce this dependency anymore.*/
  116. unsigned last_submitted_ghost_writer_id_is_valid;
  117. unsigned long last_submitted_ghost_writer_id;
  118. struct starpu_jobid_list *last_submitted_ghost_readers_id;
  119. #endif
  120. struct starpu_task_list *post_sync_tasks;
  121. unsigned post_sync_tasks_cnt;
  122. };
  123. void _starpu_display_msi_stats(void);
  124. int _starpu_fetch_data_on_node(struct starpu_data_state_t *state, uint32_t requesting_node,
  125. starpu_access_mode mode, unsigned is_prefetch,
  126. void (*callback_func)(void *), void *callback_arg);
  127. void _starpu_release_data_on_node(struct starpu_data_state_t *state, uint32_t default_wb_mask, unsigned memory_node);
  128. void _starpu_update_data_state(struct starpu_data_state_t *state, uint32_t requesting_node, starpu_access_mode mode);
  129. uint32_t _starpu_get_data_refcnt(struct starpu_data_state_t *state, uint32_t node);
  130. size_t _starpu_data_get_size(starpu_data_handle handle);
  131. uint32_t _starpu_data_get_footprint(starpu_data_handle handle);
  132. void _starpu_push_task_output(struct starpu_task *task, uint32_t mask);
  133. __attribute__((warn_unused_result))
  134. int _starpu_fetch_task_input(struct starpu_task *task, uint32_t mask);
  135. unsigned _starpu_is_data_present_or_requested(struct starpu_data_state_t *state, uint32_t node);
  136. void _starpu_set_data_requested_flag_if_needed(struct starpu_data_state_t *state, uint32_t node);
  137. int _starpu_prefetch_task_input_on_node(struct starpu_task *task, uint32_t node);
  138. uint32_t _starpu_select_node_to_handle_request(uint32_t src_node, uint32_t dst_node);
  139. uint32_t _starpu_select_src_node(struct starpu_data_state_t *state);
  140. #endif // __COHERENCY__H__