1 /* 2 * kmp_taskdeps.cpp 3 */ 4 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 14 //#define KMP_SUPPORT_GRAPH_OUTPUT 1 15 16 #include "kmp.h" 17 #include "kmp_io.h" 18 #include "kmp_wait_release.h" 19 #if OMPT_SUPPORT 20 #include "ompt-specific.h" 21 #endif 22 23 #if OMP_40_ENABLED 24 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? 33 34 #ifdef KMP_SUPPORT_GRAPH_OUTPUT 35 static std::atomic<kmp_int32> kmp_node_id_seed = ATOMIC_VAR_INIT(0); 36 #endif 37 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 KMP_ATOMIC_ST_RLX(&node->dn.nrefs, 44 1); // init creates the first reference to the node 45 #ifdef KMP_SUPPORT_GRAPH_OUTPUT 46 node->dn.id = KMP_ATOMIC_INC(&kmp_node_id_seed); 47 #endif 48 } 49 50 static inline kmp_depnode_t *__kmp_node_ref(kmp_depnode_t *node) { 51 KMP_ATOMIC_INC(&node->dn.nrefs); 52 return node; 53 } 54 55 static inline void __kmp_node_deref(kmp_info_t *thread, kmp_depnode_t *node) { 56 if (!node) 57 return; 58 59 kmp_int32 n = KMP_ATOMIC_DEC(&node->dn.nrefs) - 1; 60 if (n == 0) { 61 KMP_ASSERT(node->dn.nrefs == 0); 62 #if USE_FAST_MEMORY 63 __kmp_fast_free(thread, node); 64 #else 65 __kmp_thread_free(thread, node); 66 #endif 67 } 68 } 69 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)) 72 73 static void __kmp_depnode_list_free(kmp_info_t *thread, kmp_depnode_list *list); 74 75 enum { KMP_DEPHASH_OTHER_SIZE = 97, KMP_DEPHASH_MASTER_SIZE = 997 }; 76 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; 81 } 82 83 static kmp_dephash_t *__kmp_dephash_create(kmp_info_t *thread, 84 kmp_taskdata_t *current_task) { 85 kmp_dephash_t *h; 86 87 size_t h_size; 88 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; 93 94 kmp_int32 size = 95 h_size * sizeof(kmp_dephash_entry_t *) + sizeof(kmp_dephash_t); 96 97 #if USE_FAST_MEMORY 98 h = (kmp_dephash_t *)__kmp_fast_allocate(thread, size); 99 #else 100 h = (kmp_dephash_t *)__kmp_thread_malloc(thread, size); 101 #endif 102 h->size = h_size; 103 104 #ifdef KMP_DEBUG 105 h->nelements = 0; 106 h->nconflicts = 0; 107 #endif 108 h->buckets = (kmp_dephash_entry **)(h + 1); 109 110 for (size_t i = 0; i < h_size; i++) 111 h->buckets[i] = 0; 112 113 return h; 114 } 115 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); 124 #if USE_FAST_MEMORY 125 __kmp_fast_free(thread, entry); 126 #else 127 __kmp_thread_free(thread, entry); 128 #endif 129 } 130 h->buckets[i] = 0; 131 } 132 } 133 } 134 135 void __kmp_dephash_free(kmp_info_t *thread, kmp_dephash_t *h) { 136 __kmp_dephash_free_entries(thread, h); 137 #if USE_FAST_MEMORY 138 __kmp_fast_free(thread, h); 139 #else 140 __kmp_thread_free(thread, h); 141 #endif 142 } 143 144 static kmp_dephash_entry * 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); 147 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; 152 153 if (entry == NULL) { 154 // create entry. This is only done by one thread so no locking required 155 #if USE_FAST_MEMORY 156 entry = (kmp_dephash_entry_t *)__kmp_fast_allocate( 157 thread, sizeof(kmp_dephash_entry_t)); 158 #else 159 entry = (kmp_dephash_entry_t *)__kmp_thread_malloc( 160 thread, sizeof(kmp_dephash_entry_t)); 161 #endif 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; 167 #ifdef KMP_DEBUG 168 h->nelements++; 169 if (entry->next_in_bucket) 170 h->nconflicts++; 171 #endif 172 } 173 return entry; 174 } 175 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; 180 181 #if USE_FAST_MEMORY 182 new_head = (kmp_depnode_list_t *)__kmp_fast_allocate( 183 thread, sizeof(kmp_depnode_list_t)); 184 #else 185 new_head = (kmp_depnode_list_t *)__kmp_thread_malloc( 186 thread, sizeof(kmp_depnode_list_t)); 187 #endif 188 189 new_head->node = __kmp_node_ref(node); 190 new_head->next = list; 191 192 return new_head; 193 } 194 195 static void __kmp_depnode_list_free(kmp_info_t *thread, 196 kmp_depnode_list *list) { 197 kmp_depnode_list *next; 198 199 for (; list; list = next) { 200 next = list->next; 201 202 __kmp_node_deref(thread, list->node); 203 #if USE_FAST_MEMORY 204 __kmp_fast_free(thread, list); 205 #else 206 __kmp_thread_free(thread, list); 207 #endif 208 } 209 } 210 211 static inline void __kmp_track_dependence(kmp_depnode_t *source, 212 kmp_depnode_t *sink, 213 kmp_task_t *sink_task) { 214 #ifdef KMP_SUPPORT_GRAPH_OUTPUT 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); 219 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); 223 #endif 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) { 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); 231 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)); 235 } 236 #endif /* OMPT_SUPPORT && OMPT_OPTIONAL */ 237 } 238 239 template <bool filter> 240 static inline kmp_int32 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)); 247 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]; 252 253 KMP_DEBUG_ASSERT(dep->flags.in); 254 255 if (filter && dep->base_addr == 0) 256 continue; // skip filtered entries 257 258 kmp_dephash_entry_t *info = 259 __kmp_dephash_find(thread, hash, dep->base_addr); 260 kmp_depnode_t *last_out = info->last_out; 261 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); 278 } 279 } 280 281 __kmp_depnode_list_free(thread, info->last_ins); 282 info->last_ins = NULL; 283 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); 299 } 300 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 } 315 316 KA_TRACE(30, ("__kmp_process_deps<%d>: T#%d found %d predecessors\n", filter, 317 gtid, npredecessors)); 318 319 return npredecessors; 320 } 321 322 #define NO_DEP_BARRIER (false) 323 #define DEP_BARRIER (true) 324 325 // returns true if the task has any outstanding dependence 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; 333 334 #if KMP_DEBUG 335 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task); 336 #endif 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)); 341 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 } 353 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; 359 360 // used to pack all npredecessors additions into a single atomic operation at 361 // the end 362 int npredecessors; 363 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); 368 369 node->dn.task = task; 370 KMP_MB(); 371 372 // Account for our initial fake value 373 npredecessors++; 374 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) 378 npredecessors = 379 node->dn.npredecessors.fetch_add(npredecessors) + npredecessors; 380 381 KA_TRACE(20, ("__kmp_check_deps: T#%d found %d predecessors for task %p \n", 382 gtid, npredecessors, taskdata)); 383 384 // beyond this point the task could be queued (and executed) by a releasing 385 // task... 386 return npredecessors > 0 ? true : false; 387 } 388 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; 392 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; 415 kmp_int32 npredecessors = KMP_ATOMIC_DEC(&successor->dn.npredecessors) - 1; 416 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 } 427 } 428 429 next = p->next; 430 __kmp_node_deref(thread, p->node); 431 #if USE_FAST_MEMORY 432 __kmp_fast_free(thread, p); 433 #else 434 __kmp_thread_free(thread, p); 435 #endif 436 } 437 438 __kmp_node_deref(thread, node); 439 440 KA_TRACE( 441 20, 442 ("__kmp_release_deps: T#%d all successors of %p notified of completion\n", 443 gtid, task)); 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 450 @param new_task task thunk allocated by __kmp_omp_task_alloc() for the ''new 451 task'' 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 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 459 460 Schedule a non-thread-switchable task with dependences for execution 461 */ 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) { 467 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)); 471 472 kmp_info_t *thread = __kmp_threads[gtid]; 473 kmp_taskdata_t *current_task = thread->th.th_current_task; 474 475 #if OMPT_SUPPORT 476 if (ompt_enabled.enabled) { 477 OMPT_STORE_RETURN_ADDRESS(gtid); 478 if (!current_task->ompt_task_info.frame.enter_frame) 479 current_task->ompt_task_info.frame.enter_frame = 480 OMPT_GET_FRAME_ADDRESS(1); 481 if (ompt_enabled.ompt_callback_task_create) { 482 ompt_data_t task_data = ompt_data_none; 483 ompt_callbacks.ompt_callback(ompt_callback_task_create)( 484 current_task ? &(current_task->ompt_task_info.task_data) : &task_data, 485 current_task ? &(current_task->ompt_task_info.frame) : NULL, 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 491 new_taskdata->ompt_task_info.frame.enter_frame = OMPT_GET_FRAME_ADDRESS(0); 492 } 493 494 #if OMPT_OPTIONAL 495 /* OMPT grab all dependences if requested by the tool */ 496 if (ndeps + ndeps_noalias > 0 && 497 ompt_enabled.ompt_callback_task_dependences) { 498 kmp_int32 i; 499 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)); 504 505 KMP_ASSERT(new_taskdata->ompt_task_info.deps != NULL); 506 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_type = 512 ompt_task_dependence_type_inout; 513 else if (dep_list[i].flags.out) 514 new_taskdata->ompt_task_info.deps[i].dependence_type = 515 ompt_task_dependence_type_out; 516 else if (dep_list[i].flags.in) 517 new_taskdata->ompt_task_info.deps[i].dependence_type = 518 ompt_task_dependence_type_in; 519 } 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_type = 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_type = 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_type = 531 ompt_task_dependence_type_in; 532 } 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; 541 } 542 #endif /* OMPT_OPTIONAL */ 543 #endif /* OMPT_SUPPORT */ 544 545 bool serial = current_task->td_flags.team_serial || 546 current_task->td_flags.tasking_ser || 547 current_task->td_flags.final; 548 #if OMP_45_ENABLED 549 kmp_task_team_t *task_team = thread->th.th_task_team; 550 serial = serial && !(task_team && task_team->tt.tt_found_proxy_tasks); 551 #endif 552 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); 557 558 #if USE_FAST_MEMORY 559 kmp_depnode_t *node = 560 (kmp_depnode_t *)__kmp_fast_allocate(thread, sizeof(kmp_depnode_t)); 561 #else 562 kmp_depnode_t *node = 563 (kmp_depnode_t *)__kmp_thread_malloc(thread, sizeof(kmp_depnode_t)); 564 #endif 565 566 __kmp_init_node(node); 567 new_taskdata->td_depnode = node; 568 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)); 576 #if OMPT_SUPPORT 577 if (ompt_enabled.enabled) { 578 current_task->ompt_task_info.frame.enter_frame = NULL; 579 } 580 #endif 581 return TASK_CURRENT_NOT_QUEUED; 582 } 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 } 589 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)); 594 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; 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 */ 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)); 619 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 } 626 627 kmp_info_t *thread = __kmp_threads[gtid]; 628 kmp_taskdata_t *current_task = thread->th.th_current_task; 629 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; 636 #if OMP_45_ENABLED 637 ignore = ignore && thread->th.th_task_team != NULL && 638 thread->th.th_task_team->tt.tt_found_proxy_tasks == FALSE; 639 #endif 640 ignore = ignore || current_task->td_dephash == NULL; 641 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 } 648 649 kmp_depnode_t node = {0}; 650 __kmp_init_node(&node); 651 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 } 660 661 int thread_finished = FALSE; 662 kmp_flag_32 flag((std::atomic<kmp_uint32> *)&node.dn.npredecessors, 0U); 663 while (node.dn.npredecessors > 0) { 664 flag.execute_tasks(thread, gtid, FALSE, 665 &thread_finished USE_ITT_BUILD_ARG(NULL), 666 __kmp_task_stealing_constraint); 667 } 668 669 KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d finished waiting : loc=%p\n", 670 gtid, loc_ref)); 671 } 672 673 #endif /* OMP_40_ENABLED */ 674