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