coherency.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  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. #ifndef __COHERENCY__H__
  18. #define __COHERENCY__H__
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <common/starpu_spinlock.h>
  22. #include <common/rwlock.h>
  23. #include <common/timing.h>
  24. #include <common/fxt.h>
  25. #include <common/list.h>
  26. #include <datawizard/data_request.h>
  27. #include <datawizard/interfaces/data_interface.h>
  28. #include <datawizard/datastats.h>
  29. typedef enum {
  30. STARPU_OWNER,
  31. STARPU_SHARED,
  32. STARPU_INVALID
  33. } starpu_cache_state;
  34. /* this should contain the information relative to a given data replicate */
  35. LIST_TYPE(starpu_data_replicate,
  36. starpu_data_handle handle;
  37. /* describe the actual data layout */
  38. void *data_interface;
  39. unsigned memory_node;
  40. /* A buffer that is used for SCRATCH or reduction cannnot be used with
  41. * filters. */
  42. unsigned relaxed_coherency;
  43. /* In the case of a SCRATCH access, we need to initialize the replicate
  44. * with a neutral element before using it. */
  45. unsigned initialized;
  46. /* describes the state of the local data in term of coherency */
  47. starpu_cache_state state;
  48. int refcnt;
  49. /* is the data locally allocated ? */
  50. uint8_t allocated;
  51. /* was it automatically allocated ? */
  52. /* perhaps the allocation was perform higher in the hiearchy
  53. * for now this is just translated into !automatically_allocated
  54. * */
  55. uint8_t automatically_allocated;
  56. /* To help the scheduling policies to make some decision, we
  57. may keep a track of the tasks that are likely to request
  58. this data on the current node.
  59. It is the responsability of the scheduling _policy_ to set that
  60. flag when it assigns a task to a queue, policies which do not
  61. use this hint can simply ignore it.
  62. */
  63. uint8_t requested[STARPU_MAXNODES];
  64. struct starpu_data_request_s *request[STARPU_MAXNODES];
  65. );
  66. struct starpu_data_requester_list_s;
  67. struct starpu_jobid_list {
  68. unsigned long id;
  69. struct starpu_jobid_list *next;
  70. };
  71. /* This structure describes a simply-linked list of task */
  72. struct starpu_task_wrapper_list {
  73. struct starpu_task *task;
  74. struct starpu_task_wrapper_list *next;
  75. };
  76. struct starpu_data_state_t {
  77. struct starpu_data_requester_list_s *req_list;
  78. /* the number of requests currently in the scheduling engine
  79. * (not in the req_list anymore) */
  80. unsigned refcnt;
  81. starpu_access_mode current_mode;
  82. /* protect meta data */
  83. starpu_spinlock_t header_lock;
  84. /* In case we user filters, the handle may describe a sub-data */
  85. struct starpu_data_state_t *root_handle; /* root of the tree */
  86. struct starpu_data_state_t *father_handle; /* father of the node, NULL if the current node is the root */
  87. unsigned sibling_index; /* indicate which child this node is from the father's perpsective (if any) */
  88. unsigned depth; /* what's the depth of the tree ? */
  89. struct starpu_data_state_t *children;
  90. unsigned nchildren;
  91. /* describe the state of the data in term of coherency */
  92. struct starpu_data_replicate_s per_node[STARPU_MAXNODES];
  93. struct starpu_data_replicate_s per_worker[STARPU_NMAXWORKERS];
  94. struct starpu_data_interface_ops_t *ops;
  95. /* To avoid recomputing data size all the time, we store it directly. */
  96. size_t data_size;
  97. /* Footprint which identifies data layout */
  98. uint32_t footprint;
  99. /* where is the data home ? -1 if none yet */
  100. int home_node;
  101. /* what is the default write-through mask for that data ? */
  102. uint32_t wt_mask;
  103. /* allows special optimization */
  104. uint8_t is_readonly;
  105. /* in some case, the application may explicitly tell StarPU that a
  106. * piece of data is not likely to be used soon again */
  107. unsigned is_not_important;
  108. /* Does StarPU have to enforce some implicit data-dependencies ? */
  109. unsigned sequential_consistency;
  110. /* This lock should protect any operation to enforce
  111. * sequential_consistency */
  112. pthread_mutex_t sequential_consistency_mutex;
  113. /* The last submitted task (or application data request) that declared
  114. * it would modify the piece of data ? Any task accessing the data in a
  115. * read-only mode should depend on that task implicitely if the
  116. * sequential_consistency flag is enabled. */
  117. starpu_access_mode last_submitted_mode;
  118. struct starpu_task *last_submitted_writer;
  119. struct starpu_task_wrapper_list *last_submitted_readers;
  120. /* If FxT is enabled, we keep track of "ghost dependencies": that is to
  121. * say the dependencies that are not needed anymore, but that should
  122. * appear in the post-mortem DAG. For instance if we have the sequence
  123. * f(Aw) g(Aw), and that g is submitted after the termination of f, we
  124. * want to have f->g appear in the DAG even if StarPU does not need to
  125. * enforce this dependency anymore.*/
  126. unsigned last_submitted_ghost_writer_id_is_valid;
  127. unsigned long last_submitted_ghost_writer_id;
  128. struct starpu_jobid_list *last_submitted_ghost_readers_id;
  129. struct starpu_task_wrapper_list *post_sync_tasks;
  130. unsigned post_sync_tasks_cnt;
  131. /*
  132. * Reductions
  133. */
  134. /* During reduction we need some specific methods: redux_func performs
  135. * the reduction of an interface into another one (eg. "+="), and init_func
  136. * initializes the data interface to a default value that is stable by
  137. * reduction (eg. 0 for +=). */
  138. struct starpu_codelet_t *redux_cl;
  139. struct starpu_codelet_t *init_cl;
  140. /* Are we currently performing a reduction on that handle ? If so the
  141. * reduction_refcnt should be non null until there are pending tasks
  142. * that are performing the reduction. */
  143. unsigned reduction_refcnt;
  144. /* List of requesters that are specific to the pending reduction. This
  145. * list is used when the requests in the req_list list are frozen until
  146. * the end of the reduction. */
  147. struct starpu_data_requester_list_s *reduction_req_list;
  148. starpu_data_handle reduction_tmp_handles[STARPU_NMAXWORKERS];
  149. unsigned lazy_unregister;
  150. /* Used for MPI */
  151. int rank;
  152. int tag;
  153. };
  154. void _starpu_display_msi_stats(void);
  155. int _starpu_fetch_data_on_node(struct starpu_data_state_t *state, struct starpu_data_replicate_s *replicate,
  156. starpu_access_mode mode, unsigned is_prefetch,
  157. void (*callback_func)(void *), void *callback_arg);
  158. void _starpu_release_data_on_node(struct starpu_data_state_t *state, uint32_t default_wt_mask,
  159. struct starpu_data_replicate_s *replicate);
  160. void _starpu_update_data_state(starpu_data_handle handle,
  161. struct starpu_data_replicate_s *requesting_replicate,
  162. starpu_access_mode mode);
  163. uint32_t _starpu_get_data_refcnt(struct starpu_data_state_t *state, uint32_t node);
  164. size_t _starpu_data_get_size(starpu_data_handle handle);
  165. uint32_t _starpu_data_get_footprint(starpu_data_handle handle);
  166. void _starpu_push_task_output(struct starpu_task *task, uint32_t mask);
  167. __attribute__((warn_unused_result))
  168. int _starpu_fetch_task_input(struct starpu_task *task, uint32_t mask);
  169. unsigned _starpu_is_data_present_or_requested(struct starpu_data_state_t *state, uint32_t node);
  170. unsigned starpu_data_test_if_allocated_on_node(starpu_data_handle handle, uint32_t memory_node);
  171. uint32_t _starpu_select_src_node(struct starpu_data_state_t *state);
  172. starpu_data_request_t create_request_to_fetch_data(starpu_data_handle handle,
  173. struct starpu_data_replicate_s *dst_replicate,
  174. starpu_access_mode mode, unsigned is_prefetch,
  175. void (*callback_func)(void *), void *callback_arg);
  176. void _starpu_redux_init_data_replicate(starpu_data_handle handle, struct starpu_data_replicate_s *replicate, int workerid);
  177. void starpu_data_start_reduction_mode(starpu_data_handle handle);
  178. void starpu_data_end_reduction_mode(starpu_data_handle handle);
  179. void starpu_data_end_reduction_mode_terminate(starpu_data_handle handle);
  180. #endif // __COHERENCY__H__