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