Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * kmp_taskdeps.cpp |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3 | */ |
| 4 | |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 5 | //===----------------------------------------------------------------------===// |
| 6 | // |
| 7 | // The LLVM Compiler Infrastructure |
| 8 | // |
| 9 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 10 | // Source Licenses. See LICENSE.txt for details. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 14 | //#define KMP_SUPPORT_GRAPH_OUTPUT 1 |
| 15 | |
| 16 | #include "kmp.h" |
| 17 | #include "kmp_io.h" |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 18 | #include "kmp_wait_release.h" |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 19 | #if OMPT_SUPPORT |
| 20 | #include "ompt-specific.h" |
| 21 | #endif |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 22 | |
| 23 | #if OMP_40_ENABLED |
| 24 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 25 | // TODO: Improve memory allocation? keep a list of pre-allocated structures? |
| 26 | // allocate in blocks? re-use list finished list entries? |
| 27 | // TODO: don't use atomic ref counters for stack-allocated nodes. |
| 28 | // TODO: find an alternate to atomic refs for heap-allocated nodes? |
| 29 | // TODO: Finish graph output support |
| 30 | // TODO: kmp_lock_t seems a tad to big (and heavy weight) for this. Check other |
| 31 | // runtime locks |
| 32 | // TODO: Any ITT support needed? |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 33 | |
| 34 | #ifdef KMP_SUPPORT_GRAPH_OUTPUT |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 35 | static std::atomic<kmp_int32> kmp_node_id_seed = ATOMIC_VAR_INIT(0); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 38 | static void __kmp_init_node(kmp_depnode_t *node) { |
| 39 | node->dn.task = NULL; // set to null initially, it will point to the right |
| 40 | // task once dependences have been processed |
| 41 | node->dn.successors = NULL; |
| 42 | __kmp_init_lock(&node->dn.lock); |
Jonathan Peyton | 61d44f1 | 2018-07-09 18:09:25 +0000 | [diff] [blame] | 43 | KMP_ATOMIC_ST_RLX(&node->dn.nrefs, |
| 44 | 1); // init creates the first reference to the node |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 45 | #ifdef KMP_SUPPORT_GRAPH_OUTPUT |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 46 | node->dn.id = KMP_ATOMIC_INC(&kmp_node_id_seed); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 47 | #endif |
| 48 | } |
| 49 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 50 | static inline kmp_depnode_t *__kmp_node_ref(kmp_depnode_t *node) { |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 51 | KMP_ATOMIC_INC(&node->dn.nrefs); |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 52 | return node; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 55 | static inline void __kmp_node_deref(kmp_info_t *thread, kmp_depnode_t *node) { |
| 56 | if (!node) |
| 57 | return; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 58 | |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 59 | kmp_int32 n = KMP_ATOMIC_DEC(&node->dn.nrefs) - 1; |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 60 | if (n == 0) { |
| 61 | KMP_ASSERT(node->dn.nrefs == 0); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 62 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 63 | __kmp_fast_free(thread, node); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 64 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 65 | __kmp_thread_free(thread, node); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 66 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 67 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 70 | #define KMP_ACQUIRE_DEPNODE(gtid, n) __kmp_acquire_lock(&(n)->dn.lock, (gtid)) |
| 71 | #define KMP_RELEASE_DEPNODE(gtid, n) __kmp_release_lock(&(n)->dn.lock, (gtid)) |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 72 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 73 | static void __kmp_depnode_list_free(kmp_info_t *thread, kmp_depnode_list *list); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 74 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 75 | enum { KMP_DEPHASH_OTHER_SIZE = 97, KMP_DEPHASH_MASTER_SIZE = 997 }; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 76 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 77 | static inline kmp_int32 __kmp_dephash_hash(kmp_intptr_t addr, size_t hsize) { |
| 78 | // TODO alternate to try: set = (((Addr64)(addrUsefulBits * 9.618)) % |
| 79 | // m_num_sets ); |
| 80 | return ((addr >> 6) ^ (addr >> 2)) % hsize; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 83 | static kmp_dephash_t *__kmp_dephash_create(kmp_info_t *thread, |
| 84 | kmp_taskdata_t *current_task) { |
| 85 | kmp_dephash_t *h; |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 86 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 87 | size_t h_size; |
Jonathan Peyton | 7d45451 | 2016-01-28 23:10:44 +0000 | [diff] [blame] | 88 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 89 | if (current_task->td_flags.tasktype == TASK_IMPLICIT) |
| 90 | h_size = KMP_DEPHASH_MASTER_SIZE; |
| 91 | else |
| 92 | h_size = KMP_DEPHASH_OTHER_SIZE; |
Jonathan Peyton | 7d45451 | 2016-01-28 23:10:44 +0000 | [diff] [blame] | 93 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 94 | kmp_int32 size = |
| 95 | h_size * sizeof(kmp_dephash_entry_t *) + sizeof(kmp_dephash_t); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 96 | |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 97 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 98 | h = (kmp_dephash_t *)__kmp_fast_allocate(thread, size); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 99 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 100 | h = (kmp_dephash_t *)__kmp_thread_malloc(thread, size); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 101 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 102 | h->size = h_size; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 103 | |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 104 | #ifdef KMP_DEBUG |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 105 | h->nelements = 0; |
| 106 | h->nconflicts = 0; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 107 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 108 | h->buckets = (kmp_dephash_entry **)(h + 1); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 109 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 110 | for (size_t i = 0; i < h_size; i++) |
| 111 | h->buckets[i] = 0; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 112 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 113 | return h; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 116 | void __kmp_dephash_free_entries(kmp_info_t *thread, kmp_dephash_t *h) { |
| 117 | for (size_t i = 0; i < h->size; i++) { |
| 118 | if (h->buckets[i]) { |
| 119 | kmp_dephash_entry_t *next; |
| 120 | for (kmp_dephash_entry_t *entry = h->buckets[i]; entry; entry = next) { |
| 121 | next = entry->next_in_bucket; |
| 122 | __kmp_depnode_list_free(thread, entry->last_ins); |
| 123 | __kmp_node_deref(thread, entry->last_out); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 124 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 125 | __kmp_fast_free(thread, entry); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 126 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 127 | __kmp_thread_free(thread, entry); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 128 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 129 | } |
| 130 | h->buckets[i] = 0; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 131 | } |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 132 | } |
Andrey Churbanov | df0d75e | 2016-10-27 11:43:07 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 135 | void __kmp_dephash_free(kmp_info_t *thread, kmp_dephash_t *h) { |
| 136 | __kmp_dephash_free_entries(thread, h); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 137 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 138 | __kmp_fast_free(thread, h); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 139 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 140 | __kmp_thread_free(thread, h); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 141 | #endif |
| 142 | } |
| 143 | |
| 144 | static kmp_dephash_entry * |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 145 | __kmp_dephash_find(kmp_info_t *thread, kmp_dephash_t *h, kmp_intptr_t addr) { |
| 146 | kmp_int32 bucket = __kmp_dephash_hash(addr, h->size); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 147 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 148 | kmp_dephash_entry_t *entry; |
| 149 | for (entry = h->buckets[bucket]; entry; entry = entry->next_in_bucket) |
| 150 | if (entry->addr == addr) |
| 151 | break; |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 152 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 153 | if (entry == NULL) { |
| 154 | // create entry. This is only done by one thread so no locking required |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 155 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 156 | entry = (kmp_dephash_entry_t *)__kmp_fast_allocate( |
| 157 | thread, sizeof(kmp_dephash_entry_t)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 158 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 159 | entry = (kmp_dephash_entry_t *)__kmp_thread_malloc( |
| 160 | thread, sizeof(kmp_dephash_entry_t)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 161 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 162 | entry->addr = addr; |
| 163 | entry->last_out = NULL; |
| 164 | entry->last_ins = NULL; |
| 165 | entry->next_in_bucket = h->buckets[bucket]; |
| 166 | h->buckets[bucket] = entry; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 167 | #ifdef KMP_DEBUG |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 168 | h->nelements++; |
| 169 | if (entry->next_in_bucket) |
| 170 | h->nconflicts++; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 171 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 172 | } |
| 173 | return entry; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 176 | static kmp_depnode_list_t *__kmp_add_node(kmp_info_t *thread, |
| 177 | kmp_depnode_list_t *list, |
| 178 | kmp_depnode_t *node) { |
| 179 | kmp_depnode_list_t *new_head; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 180 | |
| 181 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 182 | new_head = (kmp_depnode_list_t *)__kmp_fast_allocate( |
| 183 | thread, sizeof(kmp_depnode_list_t)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 184 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 185 | new_head = (kmp_depnode_list_t *)__kmp_thread_malloc( |
| 186 | thread, sizeof(kmp_depnode_list_t)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 187 | #endif |
| 188 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 189 | new_head->node = __kmp_node_ref(node); |
| 190 | new_head->next = list; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 191 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 192 | return new_head; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 195 | static void __kmp_depnode_list_free(kmp_info_t *thread, |
| 196 | kmp_depnode_list *list) { |
| 197 | kmp_depnode_list *next; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 198 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 199 | for (; list; list = next) { |
| 200 | next = list->next; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 201 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 202 | __kmp_node_deref(thread, list->node); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 203 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 204 | __kmp_fast_free(thread, list); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 205 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 206 | __kmp_thread_free(thread, list); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 207 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 208 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 211 | static inline void __kmp_track_dependence(kmp_depnode_t *source, |
| 212 | kmp_depnode_t *sink, |
| 213 | kmp_task_t *sink_task) { |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 214 | #ifdef KMP_SUPPORT_GRAPH_OUTPUT |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 215 | kmp_taskdata_t *task_source = KMP_TASK_TO_TASKDATA(source->dn.task); |
| 216 | // do not use sink->dn.task as that is only filled after the dependencies |
| 217 | // are already processed! |
| 218 | kmp_taskdata_t *task_sink = KMP_TASK_TO_TASKDATA(sink_task); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 219 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 220 | __kmp_printf("%d(%s) -> %d(%s)\n", source->dn.id, |
| 221 | task_source->td_ident->psource, sink->dn.id, |
| 222 | task_sink->td_ident->psource); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 223 | #endif |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 224 | #if OMPT_SUPPORT && OMPT_OPTIONAL |
| 225 | /* OMPT tracks dependences between task (a=source, b=sink) in which |
| 226 | task a blocks the execution of b through the ompt_new_dependence_callback |
| 227 | */ |
| 228 | if (ompt_enabled.ompt_callback_task_dependence) { |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 229 | kmp_taskdata_t *task_source = KMP_TASK_TO_TASKDATA(source->dn.task); |
| 230 | kmp_taskdata_t *task_sink = KMP_TASK_TO_TASKDATA(sink_task); |
Jonas Hahnfeld | 39b6862 | 2016-01-28 10:39:52 +0000 | [diff] [blame] | 231 | |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 232 | ompt_callbacks.ompt_callback(ompt_callback_task_dependence)( |
| 233 | &(task_source->ompt_task_info.task_data), |
| 234 | &(task_sink->ompt_task_info.task_data)); |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 235 | } |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 236 | #endif /* OMPT_SUPPORT && OMPT_OPTIONAL */ |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 239 | template <bool filter> |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 240 | static inline kmp_int32 |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 241 | __kmp_process_deps(kmp_int32 gtid, kmp_depnode_t *node, kmp_dephash_t *hash, |
| 242 | bool dep_barrier, kmp_int32 ndeps, |
| 243 | kmp_depend_info_t *dep_list, kmp_task_t *task) { |
| 244 | KA_TRACE(30, ("__kmp_process_deps<%d>: T#%d processing %d dependencies : " |
| 245 | "dep_barrier = %d\n", |
| 246 | filter, gtid, ndeps, dep_barrier)); |
Jonathan Peyton | 6111849 | 2016-05-20 19:03:38 +0000 | [diff] [blame] | 247 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 248 | kmp_info_t *thread = __kmp_threads[gtid]; |
| 249 | kmp_int32 npredecessors = 0; |
| 250 | for (kmp_int32 i = 0; i < ndeps; i++) { |
| 251 | const kmp_depend_info_t *dep = &dep_list[i]; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 252 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 253 | KMP_DEBUG_ASSERT(dep->flags.in); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 254 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 255 | if (filter && dep->base_addr == 0) |
| 256 | continue; // skip filtered entries |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 257 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 258 | kmp_dephash_entry_t *info = |
| 259 | __kmp_dephash_find(thread, hash, dep->base_addr); |
| 260 | kmp_depnode_t *last_out = info->last_out; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 261 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 262 | if (dep->flags.out && info->last_ins) { |
| 263 | for (kmp_depnode_list_t *p = info->last_ins; p; p = p->next) { |
| 264 | kmp_depnode_t *indep = p->node; |
| 265 | if (indep->dn.task) { |
| 266 | KMP_ACQUIRE_DEPNODE(gtid, indep); |
| 267 | if (indep->dn.task) { |
| 268 | __kmp_track_dependence(indep, node, task); |
| 269 | indep->dn.successors = |
| 270 | __kmp_add_node(thread, indep->dn.successors, node); |
| 271 | KA_TRACE(40, ("__kmp_process_deps<%d>: T#%d adding dependence from " |
| 272 | "%p to %p\n", |
| 273 | filter, gtid, KMP_TASK_TO_TASKDATA(indep->dn.task), |
| 274 | KMP_TASK_TO_TASKDATA(task))); |
| 275 | npredecessors++; |
| 276 | } |
| 277 | KMP_RELEASE_DEPNODE(gtid, indep); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 278 | } |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 279 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 280 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 281 | __kmp_depnode_list_free(thread, info->last_ins); |
| 282 | info->last_ins = NULL; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 283 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 284 | } else if (last_out && last_out->dn.task) { |
| 285 | KMP_ACQUIRE_DEPNODE(gtid, last_out); |
| 286 | if (last_out->dn.task) { |
| 287 | __kmp_track_dependence(last_out, node, task); |
| 288 | last_out->dn.successors = |
| 289 | __kmp_add_node(thread, last_out->dn.successors, node); |
| 290 | KA_TRACE( |
| 291 | 40, |
| 292 | ("__kmp_process_deps<%d>: T#%d adding dependence from %p to %p\n", |
| 293 | filter, gtid, KMP_TASK_TO_TASKDATA(last_out->dn.task), |
| 294 | KMP_TASK_TO_TASKDATA(task))); |
| 295 | |
| 296 | npredecessors++; |
| 297 | } |
| 298 | KMP_RELEASE_DEPNODE(gtid, last_out); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 299 | } |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 300 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 301 | if (dep_barrier) { |
| 302 | // if this is a sync point in the serial sequence, then the previous |
| 303 | // outputs are guaranteed to be completed after |
| 304 | // the execution of this task so the previous output nodes can be cleared. |
| 305 | __kmp_node_deref(thread, last_out); |
| 306 | info->last_out = NULL; |
| 307 | } else { |
| 308 | if (dep->flags.out) { |
| 309 | __kmp_node_deref(thread, last_out); |
| 310 | info->last_out = __kmp_node_ref(node); |
| 311 | } else |
| 312 | info->last_ins = __kmp_add_node(thread, info->last_ins, node); |
| 313 | } |
| 314 | } |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 315 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 316 | KA_TRACE(30, ("__kmp_process_deps<%d>: T#%d found %d predecessors\n", filter, |
| 317 | gtid, npredecessors)); |
| 318 | |
| 319 | return npredecessors; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | #define NO_DEP_BARRIER (false) |
| 323 | #define DEP_BARRIER (true) |
| 324 | |
| 325 | // returns true if the task has any outstanding dependence |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 326 | static bool __kmp_check_deps(kmp_int32 gtid, kmp_depnode_t *node, |
| 327 | kmp_task_t *task, kmp_dephash_t *hash, |
| 328 | bool dep_barrier, kmp_int32 ndeps, |
| 329 | kmp_depend_info_t *dep_list, |
| 330 | kmp_int32 ndeps_noalias, |
| 331 | kmp_depend_info_t *noalias_dep_list) { |
| 332 | int i; |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 333 | |
Jonathan Peyton | d2eb3c7 | 2015-08-26 20:02:21 +0000 | [diff] [blame] | 334 | #if KMP_DEBUG |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 335 | kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task); |
Jonathan Peyton | d2eb3c7 | 2015-08-26 20:02:21 +0000 | [diff] [blame] | 336 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 337 | KA_TRACE(20, ("__kmp_check_deps: T#%d checking dependencies for task %p : %d " |
| 338 | "possibly aliased dependencies, %d non-aliased depedencies : " |
| 339 | "dep_barrier=%d .\n", |
| 340 | gtid, taskdata, ndeps, ndeps_noalias, dep_barrier)); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 341 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 342 | // Filter deps in dep_list |
| 343 | // TODO: Different algorithm for large dep_list ( > 10 ? ) |
| 344 | for (i = 0; i < ndeps; i++) { |
| 345 | if (dep_list[i].base_addr != 0) |
| 346 | for (int j = i + 1; j < ndeps; j++) |
| 347 | if (dep_list[i].base_addr == dep_list[j].base_addr) { |
| 348 | dep_list[i].flags.in |= dep_list[j].flags.in; |
| 349 | dep_list[i].flags.out |= dep_list[j].flags.out; |
| 350 | dep_list[j].base_addr = 0; // Mark j element as void |
| 351 | } |
| 352 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 353 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 354 | // doesn't need to be atomic as no other thread is going to be accessing this |
| 355 | // node just yet. |
| 356 | // npredecessors is set -1 to ensure that none of the releasing tasks queues |
| 357 | // this task before we have finished processing all the dependencies |
| 358 | node->dn.npredecessors = -1; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 359 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 360 | // used to pack all npredecessors additions into a single atomic operation at |
| 361 | // the end |
| 362 | int npredecessors; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 363 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 364 | npredecessors = __kmp_process_deps<true>(gtid, node, hash, dep_barrier, ndeps, |
| 365 | dep_list, task); |
| 366 | npredecessors += __kmp_process_deps<false>( |
| 367 | gtid, node, hash, dep_barrier, ndeps_noalias, noalias_dep_list, task); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 368 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 369 | node->dn.task = task; |
| 370 | KMP_MB(); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 371 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 372 | // Account for our initial fake value |
| 373 | npredecessors++; |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 374 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 375 | // Update predecessors and obtain current value to check if there are still |
| 376 | // any outstandig dependences (some tasks may have finished while we processed |
| 377 | // the dependences) |
Andrey Churbanov | c47afcd | 2017-07-03 11:24:08 +0000 | [diff] [blame] | 378 | npredecessors = |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 379 | node->dn.npredecessors.fetch_add(npredecessors) + npredecessors; |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 380 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 381 | KA_TRACE(20, ("__kmp_check_deps: T#%d found %d predecessors for task %p \n", |
| 382 | gtid, npredecessors, taskdata)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 383 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 384 | // beyond this point the task could be queued (and executed) by a releasing |
| 385 | // task... |
| 386 | return npredecessors > 0 ? true : false; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 389 | void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) { |
| 390 | kmp_info_t *thread = __kmp_threads[gtid]; |
| 391 | kmp_depnode_t *node = task->td_depnode; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 392 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 393 | if (task->td_dephash) { |
| 394 | KA_TRACE( |
| 395 | 40, ("__kmp_release_deps: T#%d freeing dependencies hash of task %p.\n", |
| 396 | gtid, task)); |
| 397 | __kmp_dephash_free(thread, task->td_dephash); |
| 398 | task->td_dephash = NULL; |
| 399 | } |
| 400 | |
| 401 | if (!node) |
| 402 | return; |
| 403 | |
| 404 | KA_TRACE(20, ("__kmp_release_deps: T#%d notifying successors of task %p.\n", |
| 405 | gtid, task)); |
| 406 | |
| 407 | KMP_ACQUIRE_DEPNODE(gtid, node); |
| 408 | node->dn.task = |
| 409 | NULL; // mark this task as finished, so no new dependencies are generated |
| 410 | KMP_RELEASE_DEPNODE(gtid, node); |
| 411 | |
| 412 | kmp_depnode_list_t *next; |
| 413 | for (kmp_depnode_list_t *p = node->dn.successors; p; p = next) { |
| 414 | kmp_depnode_t *successor = p->node; |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 415 | kmp_int32 npredecessors = KMP_ATOMIC_DEC(&successor->dn.npredecessors) - 1; |
| 416 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 417 | // successor task can be NULL for wait_depends or because deps are still |
| 418 | // being processed |
| 419 | if (npredecessors == 0) { |
| 420 | KMP_MB(); |
| 421 | if (successor->dn.task) { |
| 422 | KA_TRACE(20, ("__kmp_release_deps: T#%d successor %p of %p scheduled " |
| 423 | "for execution.\n", |
| 424 | gtid, successor->dn.task, task)); |
| 425 | __kmp_omp_task(gtid, successor->dn.task, false); |
| 426 | } |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 427 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 428 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 429 | next = p->next; |
| 430 | __kmp_node_deref(thread, p->node); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 431 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 432 | __kmp_fast_free(thread, p); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 433 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 434 | __kmp_thread_free(thread, p); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 435 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 436 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 437 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 438 | __kmp_node_deref(thread, node); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 439 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 440 | KA_TRACE( |
| 441 | 20, |
| 442 | ("__kmp_release_deps: T#%d all successors of %p notified of completion\n", |
| 443 | gtid, task)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /*! |
| 447 | @ingroup TASKING |
| 448 | @param loc_ref location of the original task directive |
| 449 | @param gtid Global Thread ID of encountering thread |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 450 | @param new_task task thunk allocated by __kmp_omp_task_alloc() for the ''new |
| 451 | task'' |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 452 | @param ndeps Number of depend items with possible aliasing |
| 453 | @param dep_list List of depend items with possible aliasing |
| 454 | @param ndeps_noalias Number of depend items with no aliasing |
| 455 | @param noalias_dep_list List of depend items with no aliasing |
| 456 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 457 | @return Returns either TASK_CURRENT_NOT_QUEUED if the current task was not |
| 458 | suspendend and queued, or TASK_CURRENT_QUEUED if it was suspended and queued |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 459 | |
| 460 | Schedule a non-thread-switchable task with dependences for execution |
| 461 | */ |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 462 | kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid, |
| 463 | kmp_task_t *new_task, kmp_int32 ndeps, |
| 464 | kmp_depend_info_t *dep_list, |
| 465 | kmp_int32 ndeps_noalias, |
| 466 | kmp_depend_info_t *noalias_dep_list) { |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 467 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 468 | kmp_taskdata_t *new_taskdata = KMP_TASK_TO_TASKDATA(new_task); |
| 469 | KA_TRACE(10, ("__kmpc_omp_task_with_deps(enter): T#%d loc=%p task=%p\n", gtid, |
| 470 | loc_ref, new_taskdata)); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 471 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 472 | kmp_info_t *thread = __kmp_threads[gtid]; |
| 473 | kmp_taskdata_t *current_task = thread->th.th_current_task; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 474 | |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 475 | #if OMPT_SUPPORT |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 476 | if (ompt_enabled.enabled) { |
Joachim Protze | 265fb58 | 2017-12-24 07:30:23 +0000 | [diff] [blame] | 477 | OMPT_STORE_RETURN_ADDRESS(gtid); |
| 478 | if (!current_task->ompt_task_info.frame.enter_frame) |
Joachim Protze | b0e4f87 | 2018-02-17 09:54:10 +0000 | [diff] [blame] | 479 | current_task->ompt_task_info.frame.enter_frame = |
| 480 | OMPT_GET_FRAME_ADDRESS(1); |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 481 | if (ompt_enabled.ompt_callback_task_create) { |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 482 | ompt_data_t task_data = ompt_data_none; |
| 483 | ompt_callbacks.ompt_callback(ompt_callback_task_create)( |
Joachim Protze | 265fb58 | 2017-12-24 07:30:23 +0000 | [diff] [blame] | 484 | current_task ? &(current_task->ompt_task_info.task_data) : &task_data, |
| 485 | current_task ? &(current_task->ompt_task_info.frame) : NULL, |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 486 | &(new_taskdata->ompt_task_info.task_data), |
| 487 | ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 1, |
| 488 | OMPT_LOAD_RETURN_ADDRESS(gtid)); |
| 489 | } |
| 490 | |
Joachim Protze | c255ca7 | 2017-11-05 14:11:10 +0000 | [diff] [blame] | 491 | new_taskdata->ompt_task_info.frame.enter_frame = OMPT_GET_FRAME_ADDRESS(0); |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | #if OMPT_OPTIONAL |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 495 | /* OMPT grab all dependences if requested by the tool */ |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 496 | if (ndeps + ndeps_noalias > 0 && |
| 497 | ompt_enabled.ompt_callback_task_dependences) { |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 498 | kmp_int32 i; |
Jonas Hahnfeld | 39b6862 | 2016-01-28 10:39:52 +0000 | [diff] [blame] | 499 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 500 | new_taskdata->ompt_task_info.ndeps = ndeps + ndeps_noalias; |
| 501 | new_taskdata->ompt_task_info.deps = |
| 502 | (ompt_task_dependence_t *)KMP_OMPT_DEPS_ALLOC( |
| 503 | thread, (ndeps + ndeps_noalias) * sizeof(ompt_task_dependence_t)); |
Jonas Hahnfeld | 39b6862 | 2016-01-28 10:39:52 +0000 | [diff] [blame] | 504 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 505 | KMP_ASSERT(new_taskdata->ompt_task_info.deps != NULL); |
Jonas Hahnfeld | 39b6862 | 2016-01-28 10:39:52 +0000 | [diff] [blame] | 506 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 507 | for (i = 0; i < ndeps; i++) { |
| 508 | new_taskdata->ompt_task_info.deps[i].variable_addr = |
| 509 | (void *)dep_list[i].base_addr; |
| 510 | if (dep_list[i].flags.in && dep_list[i].flags.out) |
| 511 | new_taskdata->ompt_task_info.deps[i].dependence_flags = |
| 512 | ompt_task_dependence_type_inout; |
| 513 | else if (dep_list[i].flags.out) |
| 514 | new_taskdata->ompt_task_info.deps[i].dependence_flags = |
| 515 | ompt_task_dependence_type_out; |
| 516 | else if (dep_list[i].flags.in) |
| 517 | new_taskdata->ompt_task_info.deps[i].dependence_flags = |
| 518 | ompt_task_dependence_type_in; |
Jonas Hahnfeld | 39b6862 | 2016-01-28 10:39:52 +0000 | [diff] [blame] | 519 | } |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 520 | for (i = 0; i < ndeps_noalias; i++) { |
| 521 | new_taskdata->ompt_task_info.deps[ndeps + i].variable_addr = |
| 522 | (void *)noalias_dep_list[i].base_addr; |
| 523 | if (noalias_dep_list[i].flags.in && noalias_dep_list[i].flags.out) |
| 524 | new_taskdata->ompt_task_info.deps[ndeps + i].dependence_flags = |
| 525 | ompt_task_dependence_type_inout; |
| 526 | else if (noalias_dep_list[i].flags.out) |
| 527 | new_taskdata->ompt_task_info.deps[ndeps + i].dependence_flags = |
| 528 | ompt_task_dependence_type_out; |
| 529 | else if (noalias_dep_list[i].flags.in) |
| 530 | new_taskdata->ompt_task_info.deps[ndeps + i].dependence_flags = |
| 531 | ompt_task_dependence_type_in; |
| 532 | } |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 533 | ompt_callbacks.ompt_callback(ompt_callback_task_dependences)( |
| 534 | &(new_taskdata->ompt_task_info.task_data), |
| 535 | new_taskdata->ompt_task_info.deps, new_taskdata->ompt_task_info.ndeps); |
| 536 | /* We can now free the allocated memory for the dependencies */ |
| 537 | /* For OMPD we might want to delay the free until task_end */ |
| 538 | KMP_OMPT_DEPS_FREE(thread, new_taskdata->ompt_task_info.deps); |
| 539 | new_taskdata->ompt_task_info.deps = NULL; |
| 540 | new_taskdata->ompt_task_info.ndeps = 0; |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 541 | } |
Joachim Protze | 82e94a5 | 2017-11-01 10:08:30 +0000 | [diff] [blame] | 542 | #endif /* OMPT_OPTIONAL */ |
| 543 | #endif /* OMPT_SUPPORT */ |
Jonas Hahnfeld | 39b6862 | 2016-01-28 10:39:52 +0000 | [diff] [blame] | 544 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 545 | bool serial = current_task->td_flags.team_serial || |
| 546 | current_task->td_flags.tasking_ser || |
| 547 | current_task->td_flags.final; |
Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 548 | #if OMP_45_ENABLED |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 549 | kmp_task_team_t *task_team = thread->th.th_task_team; |
| 550 | serial = serial && !(task_team && task_team->tt.tt_found_proxy_tasks); |
Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 551 | #endif |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 552 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 553 | if (!serial && (ndeps > 0 || ndeps_noalias > 0)) { |
| 554 | /* if no dependencies have been tracked yet, create the dependence hash */ |
| 555 | if (current_task->td_dephash == NULL) |
| 556 | current_task->td_dephash = __kmp_dephash_create(thread, current_task); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 557 | |
| 558 | #if USE_FAST_MEMORY |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 559 | kmp_depnode_t *node = |
| 560 | (kmp_depnode_t *)__kmp_fast_allocate(thread, sizeof(kmp_depnode_t)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 561 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 562 | kmp_depnode_t *node = |
| 563 | (kmp_depnode_t *)__kmp_thread_malloc(thread, sizeof(kmp_depnode_t)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 564 | #endif |
| 565 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 566 | __kmp_init_node(node); |
| 567 | new_taskdata->td_depnode = node; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 568 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 569 | if (__kmp_check_deps(gtid, node, new_task, current_task->td_dephash, |
| 570 | NO_DEP_BARRIER, ndeps, dep_list, ndeps_noalias, |
| 571 | noalias_dep_list)) { |
| 572 | KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d task had blocking " |
| 573 | "dependencies: " |
| 574 | "loc=%p task=%p, return: TASK_CURRENT_NOT_QUEUED\n", |
| 575 | gtid, loc_ref, new_taskdata)); |
Joachim Protze | 265fb58 | 2017-12-24 07:30:23 +0000 | [diff] [blame] | 576 | #if OMPT_SUPPORT |
| 577 | if (ompt_enabled.enabled) { |
| 578 | current_task->ompt_task_info.frame.enter_frame = NULL; |
| 579 | } |
| 580 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 581 | return TASK_CURRENT_NOT_QUEUED; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 582 | } |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 583 | } else { |
| 584 | KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d ignored dependencies " |
| 585 | "for task (serialized)" |
| 586 | "loc=%p task=%p\n", |
| 587 | gtid, loc_ref, new_taskdata)); |
| 588 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 589 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 590 | KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d task had no blocking " |
| 591 | "dependencies : " |
| 592 | "loc=%p task=%p, transferring to __kmpc_omp_task\n", |
| 593 | gtid, loc_ref, new_taskdata)); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 594 | |
Joachim Protze | 265fb58 | 2017-12-24 07:30:23 +0000 | [diff] [blame] | 595 | kmp_int32 ret = __kmp_omp_task(gtid, new_task, true); |
| 596 | #if OMPT_SUPPORT |
| 597 | if (ompt_enabled.enabled) { |
| 598 | current_task->ompt_task_info.frame.enter_frame = NULL; |
| 599 | } |
| 600 | #endif |
| 601 | return ret; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /*! |
| 605 | @ingroup TASKING |
| 606 | @param loc_ref location of the original task directive |
| 607 | @param gtid Global Thread ID of encountering thread |
| 608 | @param ndeps Number of depend items with possible aliasing |
| 609 | @param dep_list List of depend items with possible aliasing |
| 610 | @param ndeps_noalias Number of depend items with no aliasing |
| 611 | @param noalias_dep_list List of depend items with no aliasing |
| 612 | |
| 613 | Blocks the current task until all specifies dependencies have been fulfilled. |
| 614 | */ |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 615 | void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps, |
| 616 | kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias, |
| 617 | kmp_depend_info_t *noalias_dep_list) { |
| 618 | KA_TRACE(10, ("__kmpc_omp_wait_deps(enter): T#%d loc=%p\n", gtid, loc_ref)); |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 619 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 620 | if (ndeps == 0 && ndeps_noalias == 0) { |
| 621 | KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no dependencies to " |
| 622 | "wait upon : loc=%p\n", |
| 623 | gtid, loc_ref)); |
| 624 | return; |
| 625 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 626 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 627 | kmp_info_t *thread = __kmp_threads[gtid]; |
| 628 | kmp_taskdata_t *current_task = thread->th.th_current_task; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 629 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 630 | // We can return immediately as: |
| 631 | // - dependences are not computed in serial teams (except with proxy tasks) |
| 632 | // - if the dephash is not yet created it means we have nothing to wait for |
| 633 | bool ignore = current_task->td_flags.team_serial || |
| 634 | current_task->td_flags.tasking_ser || |
| 635 | current_task->td_flags.final; |
Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 636 | #if OMP_45_ENABLED |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 637 | ignore = ignore && thread->th.th_task_team != NULL && |
| 638 | thread->th.th_task_team->tt.tt_found_proxy_tasks == FALSE; |
Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 639 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 640 | ignore = ignore || current_task->td_dephash == NULL; |
Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 641 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 642 | if (ignore) { |
| 643 | KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no blocking " |
| 644 | "dependencies : loc=%p\n", |
| 645 | gtid, loc_ref)); |
| 646 | return; |
| 647 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 648 | |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 649 | kmp_depnode_t node = {0}; |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 650 | __kmp_init_node(&node); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 651 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 652 | if (!__kmp_check_deps(gtid, &node, NULL, current_task->td_dephash, |
| 653 | DEP_BARRIER, ndeps, dep_list, ndeps_noalias, |
| 654 | noalias_dep_list)) { |
| 655 | KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no blocking " |
| 656 | "dependencies : loc=%p\n", |
| 657 | gtid, loc_ref)); |
| 658 | return; |
| 659 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 660 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 661 | int thread_finished = FALSE; |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 662 | kmp_flag_32 flag((std::atomic<kmp_uint32> *)&node.dn.npredecessors, 0U); |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 663 | while (node.dn.npredecessors > 0) { |
Jonathan Peyton | 37e2ef5 | 2018-07-09 17:36:22 +0000 | [diff] [blame] | 664 | flag.execute_tasks(thread, gtid, FALSE, |
| 665 | &thread_finished USE_ITT_BUILD_ARG(NULL), |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 666 | __kmp_task_stealing_constraint); |
| 667 | } |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 668 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 669 | KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d finished waiting : loc=%p\n", |
| 670 | gtid, loc_ref)); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | #endif /* OMP_40_ENABLED */ |