coherency.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011 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. enum _starpu_cache_state
  30. {
  31. STARPU_OWNER,
  32. STARPU_SHARED,
  33. STARPU_INVALID
  34. };
  35. /* this should contain the information relative to a given data replicate */
  36. LIST_TYPE(_starpu_data_replicate,
  37. starpu_data_handle_t handle;
  38. /* describe the actual data layout */
  39. void *data_interface;
  40. unsigned memory_node;
  41. /* A buffer that is used for SCRATCH or reduction cannnot be used with
  42. * filters. */
  43. unsigned relaxed_coherency;
  44. /* In the case of a SCRATCH access, we need to initialize the replicate
  45. * with a neutral element before using it. */
  46. unsigned initialized;
  47. /* describes the state of the local data in term of coherency */
  48. enum _starpu_cache_state state;
  49. int refcnt;
  50. /* is the data locally allocated ? */
  51. uint8_t allocated;
  52. /* was it automatically allocated ? */
  53. /* perhaps the allocation was perform higher in the hiearchy
  54. * for now this is just translated into !automatically_allocated
  55. * */
  56. uint8_t automatically_allocated;
  57. /* Pointer to memchunk for LRU strategy */
  58. struct _starpu_mem_chunk * mc;
  59. /* To help the scheduling policies to make some decision, we
  60. may keep a track of the tasks that are likely to request
  61. this data on the current node.
  62. It is the responsability of the scheduling _policy_ to set that
  63. flag when it assigns a task to a queue, policies which do not
  64. use this hint can simply ignore it.
  65. */
  66. uint8_t requested[STARPU_MAXNODES];
  67. struct _starpu_data_request *request[STARPU_MAXNODES];
  68. )
  69. struct _starpu_data_requester_list;
  70. struct _starpu_jobid_list
  71. {
  72. unsigned long id;
  73. struct _starpu_jobid_list *next;
  74. };
  75. /* This structure describes a simply-linked list of task */
  76. struct _starpu_task_wrapper_list
  77. {
  78. struct starpu_task *task;
  79. struct _starpu_task_wrapper_list *next;
  80. };
  81. struct _starpu_data_state
  82. {
  83. struct _starpu_data_requester_list *req_list;
  84. /* the number of requests currently in the scheduling engine (not in
  85. * the req_list anymore), i.e. the number of holders of the
  86. * current_mode rwlock */
  87. unsigned refcnt;
  88. enum starpu_access_mode current_mode;
  89. /* protect meta data */
  90. struct _starpu_spinlock header_lock;
  91. /* Condition to make application wait for all transfers before freeing handle */
  92. /* busy_count is the number of handle->refcnt, handle->per_node[*]->refcnt, and number of starpu_data_requesters */
  93. /* Core code which releases busy_count has to call
  94. * _starpu_data_check_not_busy to let starpu_data_unregister proceed */
  95. unsigned busy_count;
  96. /* Is starpu_data_unregister waiting for busy_count? */
  97. unsigned busy_waiting;
  98. pthread_mutex_t busy_mutex;
  99. pthread_cond_t busy_cond;
  100. /* In case we user filters, the handle may describe a sub-data */
  101. struct _starpu_data_state *root_handle; /* root of the tree */
  102. struct _starpu_data_state *father_handle; /* father of the node, NULL if the current node is the root */
  103. unsigned sibling_index; /* indicate which child this node is from the father's perpsective (if any) */
  104. unsigned depth; /* what's the depth of the tree ? */
  105. struct _starpu_data_state *children;
  106. unsigned nchildren;
  107. /* describe the state of the data in term of coherency */
  108. struct _starpu_data_replicate per_node[STARPU_MAXNODES];
  109. struct _starpu_data_replicate per_worker[STARPU_NMAXWORKERS];
  110. struct starpu_data_interface_ops *ops;
  111. /* To avoid recomputing data size all the time, we store it directly. */
  112. size_t data_size;
  113. /* Footprint which identifies data layout */
  114. uint32_t footprint;
  115. /* where is the data home ? -1 if none yet */
  116. int home_node;
  117. /* what is the default write-through mask for that data ? */
  118. uint32_t wt_mask;
  119. /* allows special optimization */
  120. uint8_t is_readonly;
  121. /* in some case, the application may explicitly tell StarPU that a
  122. * piece of data is not likely to be used soon again */
  123. unsigned is_not_important;
  124. /* Does StarPU have to enforce some implicit data-dependencies ? */
  125. unsigned sequential_consistency;
  126. /* This lock should protect any operation to enforce
  127. * sequential_consistency */
  128. pthread_mutex_t sequential_consistency_mutex;
  129. /* The last submitted task (or application data request) that declared
  130. * it would modify the piece of data ? Any task accessing the data in a
  131. * read-only mode should depend on that task implicitely if the
  132. * sequential_consistency flag is enabled. */
  133. enum starpu_access_mode last_submitted_mode;
  134. struct starpu_task *last_submitted_writer;
  135. struct _starpu_task_wrapper_list *last_submitted_readers;
  136. /* If FxT is enabled, we keep track of "ghost dependencies": that is to
  137. * say the dependencies that are not needed anymore, but that should
  138. * appear in the post-mortem DAG. For instance if we have the sequence
  139. * f(Aw) g(Aw), and that g is submitted after the termination of f, we
  140. * want to have f->g appear in the DAG even if StarPU does not need to
  141. * enforce this dependency anymore.*/
  142. unsigned last_submitted_ghost_writer_id_is_valid;
  143. unsigned long last_submitted_ghost_writer_id;
  144. struct _starpu_jobid_list *last_submitted_ghost_readers_id;
  145. struct _starpu_task_wrapper_list *post_sync_tasks;
  146. unsigned post_sync_tasks_cnt;
  147. /*
  148. * Reductions
  149. */
  150. /* During reduction we need some specific methods: redux_func performs
  151. * the reduction of an interface into another one (eg. "+="), and init_func
  152. * initializes the data interface to a default value that is stable by
  153. * reduction (eg. 0 for +=). */
  154. struct starpu_codelet *redux_cl;
  155. struct starpu_codelet *init_cl;
  156. /* Are we currently performing a reduction on that handle ? If so the
  157. * reduction_refcnt should be non null until there are pending tasks
  158. * that are performing the reduction. */
  159. unsigned reduction_refcnt;
  160. /* List of requesters that are specific to the pending reduction. This
  161. * list is used when the requests in the req_list list are frozen until
  162. * the end of the reduction. */
  163. struct _starpu_data_requester_list *reduction_req_list;
  164. starpu_data_handle_t reduction_tmp_handles[STARPU_NMAXWORKERS];
  165. unsigned lazy_unregister;
  166. /* Used for MPI */
  167. int rank;
  168. int tag;
  169. #ifdef STARPU_MEMORY_STATUS
  170. /* Handle access stats per node */
  171. unsigned stats_direct_access[STARPU_MAXNODES];
  172. unsigned stats_loaded_shared[STARPU_MAXNODES];
  173. unsigned stats_loaded_owner[STARPU_MAXNODES];
  174. unsigned stats_shared_to_owner[STARPU_MAXNODES];
  175. unsigned stats_invalidated[STARPU_MAXNODES];
  176. #endif
  177. unsigned int mf_node; //XXX
  178. };
  179. void _starpu_display_msi_stats(void);
  180. /* This does not take a reference on the handle, the caller has to do it,
  181. * e.g. through _starpu_attempt_to_submit_data_request_from_apps() */
  182. int _starpu_fetch_data_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate,
  183. enum starpu_access_mode mode, unsigned is_prefetch,
  184. void (*callback_func)(void *), void *callback_arg);
  185. /* This releases a reference on the handle */
  186. void _starpu_release_data_on_node(struct _starpu_data_state *state, uint32_t default_wt_mask,
  187. struct _starpu_data_replicate *replicate);
  188. void _starpu_update_data_state(starpu_data_handle_t handle,
  189. struct _starpu_data_replicate *requesting_replicate,
  190. enum starpu_access_mode mode);
  191. uint32_t _starpu_get_data_refcnt(struct _starpu_data_state *state, uint32_t node);
  192. size_t _starpu_data_get_size(starpu_data_handle_t handle);
  193. uint32_t _starpu_data_get_footprint(starpu_data_handle_t handle);
  194. void _starpu_push_task_output(struct _starpu_job *j, uint32_t mask);
  195. __attribute__((warn_unused_result))
  196. int _starpu_fetch_task_input(struct _starpu_job *j, uint32_t mask);
  197. unsigned _starpu_is_data_present_or_requested(struct _starpu_data_state *state, uint32_t node);
  198. unsigned starpu_data_test_if_allocated_on_node(starpu_data_handle_t handle, uint32_t memory_node);
  199. uint32_t _starpu_select_src_node(struct _starpu_data_state *state, unsigned destination);
  200. struct _starpu_data_request *_starpu_create_request_to_fetch_data(starpu_data_handle_t handle,
  201. struct _starpu_data_replicate *dst_replicate,
  202. enum starpu_access_mode mode, unsigned is_prefetch,
  203. void (*callback_func)(void *), void *callback_arg);
  204. void _starpu_redux_init_data_replicate(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, int workerid);
  205. void _starpu_data_start_reduction_mode(starpu_data_handle_t handle);
  206. void _starpu_data_end_reduction_mode(starpu_data_handle_t handle);
  207. void _starpu_data_end_reduction_mode_terminate(starpu_data_handle_t handle);
  208. #endif // __COHERENCY__H__