coherency.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 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. uint32_t 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_data_state_t {
  61. struct starpu_data_requester_list_s *req_list;
  62. /* the number of requests currently in the scheduling engine
  63. * (not in the req_list anymore) */
  64. unsigned refcnt;
  65. starpu_access_mode current_mode;
  66. /* protect meta data */
  67. starpu_spinlock_t header_lock;
  68. uint32_t nnodes; /* the number of memory nodes that may use it */
  69. /* In case we user filters, the handle may describe a sub-data */
  70. struct starpu_data_state_t *root_handle; /* root of the tree */
  71. struct starpu_data_state_t *father_handle; /* father of the node, NULL if the current node is the root */
  72. unsigned sibling_index; /* indicate which child this node is from the father's perpsective (if any) */
  73. unsigned depth; /* what's the depth of the tree ? */
  74. struct starpu_data_state_t *children;
  75. unsigned nchildren;
  76. /* describe the state of the data in term of coherency */
  77. starpu_local_data_state per_node[STARPU_MAXNODES];
  78. /* describe the actual data layout */
  79. void *interface[STARPU_MAXNODES];
  80. struct starpu_data_interface_ops_t *ops;
  81. /* where is the data home ? -1 if none yet */
  82. int data_home;
  83. /* what is the default write-back mask for that data ? */
  84. uint32_t wb_mask;
  85. /* allows special optimization */
  86. uint8_t is_readonly;
  87. /* in some case, the application may explicitly tell StarPU that a
  88. * piece of data is not likely to be used soon again */
  89. unsigned is_not_important;
  90. /* Does StarPU have to enforce some implicit data-dependencies ? */
  91. unsigned sequential_consistency;
  92. /* This lock should protect any operation to enforce
  93. * sequential_consistency */
  94. pthread_mutex_t sequential_consistency_mutex;
  95. /* The last submitted task (or application data request) that declared
  96. * it would modify the piece of data ? Any task accessing the data in a
  97. * read-only mode should depend on that task implicitely if the
  98. * sequential_consistency flag is enabled. */
  99. starpu_access_mode last_submitted_mode;
  100. struct starpu_task *last_submitted_writer;
  101. struct starpu_task_list *last_submitted_readers;
  102. /* to synchronize with the latest for sync_data_with_mem* call. When
  103. * releasing a piece of data, we notify this cg, which unlocks
  104. * last_submitted_sync_task_apps */
  105. struct starpu_cg_s *last_submitted_cg_apps;
  106. struct starpu_cg_s *current_cg_apps;
  107. /* To synchronize with the last call(s) to sync_data_with_mem*,
  108. * synchronize with that (empty) task. */
  109. struct starpu_task *last_submitted_sync_task_apps;
  110. };
  111. void _starpu_display_msi_stats(void);
  112. __attribute__((warn_unused_result))
  113. int _starpu_fetch_data_on_node(struct starpu_data_state_t *state, uint32_t requesting_node, uint8_t read, uint8_t write, unsigned is_prefetch);
  114. void _starpu_release_data_on_node(struct starpu_data_state_t *state, uint32_t default_wb_mask, unsigned memory_node);
  115. void _starpu_update_data_state(struct starpu_data_state_t *state, uint32_t requesting_node, uint8_t write);
  116. uint32_t _starpu_get_data_refcnt(struct starpu_data_state_t *state, uint32_t node);
  117. void _starpu_push_task_output(struct starpu_task *task, uint32_t mask);
  118. __attribute__((warn_unused_result))
  119. int _starpu_fetch_task_input(struct starpu_task *task, uint32_t mask);
  120. unsigned _starpu_is_data_present_or_requested(struct starpu_data_state_t *state, uint32_t node);
  121. inline void _starpu_set_data_requested_flag_if_needed(struct starpu_data_state_t *state, uint32_t node);
  122. int _starpu_prefetch_task_input_on_node(struct starpu_task *task, uint32_t node);
  123. uint32_t _starpu_select_node_to_handle_request(uint32_t src_node, uint32_t dst_node);
  124. uint32_t _starpu_select_src_node(struct starpu_data_state_t *state);
  125. #endif // __COHERENCY__H__