#if USE_ITT_BUILD /* * kmp_itt.inl -- Inline functions of ITT Notify. */ //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // Inline function definitions. This file should be included into kmp_itt.h file // for production build (to let compiler inline functions) or into kmp_itt.c // file for debug build (to reduce the number of files to recompile and save // build time). #include "kmp.h" #include "kmp_str.h" #if KMP_ITT_DEBUG extern kmp_bootstrap_lock_t __kmp_itt_debug_lock; #define KMP_ITT_DEBUG_LOCK … #define KMP_ITT_DEBUG_PRINT … #else #define KMP_ITT_DEBUG_LOCK() … #define KMP_ITT_DEBUG_PRINT(...) … #endif // KMP_ITT_DEBUG // Ensure that the functions are static if they're supposed to be being inlined. // Otherwise they cannot be used in more than one file, since there will be // multiple definitions. #if KMP_DEBUG #define LINKAGE #else #define LINKAGE … #endif // ZCA interface used by Intel(R) Inspector. Intel(R) Parallel Amplifier uses // this API to support user-defined synchronization primitives, but does not use // ZCA; it would be safe to turn this off until wider support becomes available. #if USE_ITT_ZCA #ifdef __INTEL_COMPILER #if __INTEL_COMPILER >= 1200 #undef __itt_sync_acquired #undef __itt_sync_releasing #define __itt_sync_acquired … #define __itt_sync_releasing … #endif #endif #endif static kmp_bootstrap_lock_t metadata_lock = …; #if USE_ITT_NOTIFY LINKAGE size_t __kmp_itthash_hash(kmp_intptr_t addr, size_t hsize) { … } LINKAGE kmp_itthash_entry *__kmp_itthash_find(kmp_info_t *thread, kmp_itthash_t *h, ident_t *loc, int team_size) { … } #endif /* Parallel region reporting. * __kmp_itt_region_forking should be called by primary thread of a team. Exact moment of call does not matter, but it should be completed before any thread of this team calls __kmp_itt_region_starting. * __kmp_itt_region_starting should be called by each thread of a team just before entering parallel region body. * __kmp_itt_region_finished should be called by each thread of a team right after returning from parallel region body. * __kmp_itt_region_joined should be called by primary thread of a team, after all threads called __kmp_itt_region_finished. Note: Thread waiting at join barrier (after __kmp_itt_region_finished) can execute some more user code -- such a thread can execute tasks. Note: The overhead of logging region_starting and region_finished in each thread is too large, so these calls are not used. */ LINKAGE void __kmp_itt_region_forking(int gtid, int team_size, int barriers) { … } // __kmp_itt_region_forking // ----------------------------------------------------------------------------- LINKAGE void __kmp_itt_frame_submit(int gtid, __itt_timestamp begin, __itt_timestamp end, int imbalance, ident_t *loc, int team_size, int region) { … } // __kmp_itt_frame_submit // ----------------------------------------------------------------------------- LINKAGE void __kmp_itt_metadata_imbalance(int gtid, kmp_uint64 begin, kmp_uint64 end, kmp_uint64 imbalance, kmp_uint64 reduction) { … } // __kmp_itt_metadata_imbalance // ----------------------------------------------------------------------------- LINKAGE void __kmp_itt_metadata_loop(ident_t *loc, kmp_uint64 sched_type, kmp_uint64 iterations, kmp_uint64 chunk) { … } // __kmp_itt_metadata_loop // ----------------------------------------------------------------------------- LINKAGE void __kmp_itt_metadata_single(ident_t *loc) { … } // __kmp_itt_metadata_single // ----------------------------------------------------------------------------- LINKAGE void __kmp_itt_region_starting(int gtid) { … } // __kmp_itt_region_starting // ----------------------------------------------------------------------------- LINKAGE void __kmp_itt_region_finished(int gtid) { … } // __kmp_itt_region_finished // ---------------------------------------------------------------------------- LINKAGE void __kmp_itt_region_joined(int gtid) { … } // __kmp_itt_region_joined /* Barriers reporting. A barrier consists of two phases: 1. Gather -- primary thread waits for all worker threads to arrive; each worker thread registers arrival and goes further. 2. Release -- each worker thread waits until primary thread lets it go; primary thread lets worker threads go. Function should be called by each thread: * __kmp_itt_barrier_starting() -- before arriving to the gather phase. * __kmp_itt_barrier_middle() -- between gather and release phases. * __kmp_itt_barrier_finished() -- after release phase. Note: Call __kmp_itt_barrier_object() before call to __kmp_itt_barrier_starting() and save result in local variable. __kmp_itt_barrier_object(), being called too late (e. g. after gather phase) would return itt sync object for the next barrier! ITT need an address (void *) to be specified as a sync object. OpenMP RTL does not have barrier object or barrier data structure. Barrier is just a counter in team and thread structures. We could use an address of team structure as a barrier sync object, but ITT wants different objects for different barriers (even whithin the same team). So let us use team address as barrier sync object for the first barrier, then increase it by one for the next barrier, and so on (but wrap it not to use addresses outside of team structure). */ void *__kmp_itt_barrier_object(int gtid, int bt, int set_name, int delta // 0 (current barrier) is default // value; specify -1 to get previous // barrier. ) { … } // __kmp_itt_barrier_object // ----------------------------------------------------------------------------- void __kmp_itt_barrier_starting(int gtid, void *object) { … } // __kmp_itt_barrier_starting // ----------------------------------------------------------------------------- void __kmp_itt_barrier_middle(int gtid, void *object) { … } // __kmp_itt_barrier_middle // ----------------------------------------------------------------------------- void __kmp_itt_barrier_finished(int gtid, void *object) { … } // __kmp_itt_barrier_finished /* Taskwait reporting. ITT need an address (void *) to be specified as a sync object. OpenMP RTL does not have taskwait structure, so we need to construct something. */ void *__kmp_itt_taskwait_object(int gtid) { … } // __kmp_itt_taskwait_object void __kmp_itt_taskwait_starting(int gtid, void *object) { … } // __kmp_itt_taskwait_starting void __kmp_itt_taskwait_finished(int gtid, void *object) { … } // __kmp_itt_taskwait_finished /* Task reporting. Only those tasks are reported which are executed by a thread spinning at barrier (or taskwait). Synch object passed to the function must be barrier of taskwait the threads waiting at. */ void __kmp_itt_task_starting( void *object // ITT sync object: barrier or taskwait. ) { … } // __kmp_itt_task_starting // ----------------------------------------------------------------------------- void __kmp_itt_task_finished( void *object // ITT sync object: barrier or taskwait. ) { … } // __kmp_itt_task_finished /* Lock reporting. * __kmp_itt_lock_creating( lock ) should be called *before* the first lock operation (set/unset). It is not a real event shown to the user but just setting a name for synchronization object. `lock' is an address of sync object, the same address should be used in all subsequent calls. * __kmp_itt_lock_acquiring() should be called before setting the lock. * __kmp_itt_lock_acquired() should be called after setting the lock. * __kmp_itt_lock_realeasing() should be called before unsetting the lock. * __kmp_itt_lock_cancelled() should be called after thread cancelled waiting for the lock. * __kmp_itt_lock_destroyed( lock ) should be called after the last lock operation. After __kmp_itt_lock_destroyed() all the references to the same address will be considered as another sync object, not related with the original one. */ #if KMP_USE_DYNAMIC_LOCK // Takes location information directly __kmp_inline void ___kmp_itt_lock_init(kmp_user_lock_p lock, char const *type, const ident_t *loc) { … } #else // KMP_USE_DYNAMIC_LOCK // Internal guts -- common code for locks and critical sections, do not call // directly. __kmp_inline void ___kmp_itt_lock_init(kmp_user_lock_p lock, char const *type) { #if USE_ITT_NOTIFY if (__itt_sync_create_ptr) { ident_t const *loc = NULL; if (__kmp_get_user_lock_location_ != NULL) loc = __kmp_get_user_lock_location_((lock)); char const *src = (loc == NULL ? NULL : loc->psource); KMP_ITT_DEBUG_LOCK(); __itt_sync_create(lock, type, src, 0); KMP_ITT_DEBUG_PRINT("[lck ini] scre( %p, \"%s\", \"%s\", 0 )\n", lock, type, src); } #endif } // ___kmp_itt_lock_init #endif // KMP_USE_DYNAMIC_LOCK // Internal guts -- common code for locks and critical sections, do not call // directly. __kmp_inline void ___kmp_itt_lock_fini(kmp_user_lock_p lock, char const *type) { … } // ___kmp_itt_lock_fini // ----------------------------------------------------------------------------- #if KMP_USE_DYNAMIC_LOCK void __kmp_itt_lock_creating(kmp_user_lock_p lock, const ident_t *loc) { … } #else void __kmp_itt_lock_creating(kmp_user_lock_p lock) { ___kmp_itt_lock_init(lock, "OMP Lock"); } // __kmp_itt_lock_creating #endif void __kmp_itt_lock_acquiring(kmp_user_lock_p lock) { … } // __kmp_itt_lock_acquiring void __kmp_itt_lock_acquired(kmp_user_lock_p lock) { … } // __kmp_itt_lock_acquired void __kmp_itt_lock_releasing(kmp_user_lock_p lock) { … } // __kmp_itt_lock_releasing void __kmp_itt_lock_cancelled(kmp_user_lock_p lock) { … } // __kmp_itt_lock_cancelled void __kmp_itt_lock_destroyed(kmp_user_lock_p lock) { … } // __kmp_itt_lock_destroyed /* Critical reporting. Critical sections are treated exactly as locks (but have different object type). */ #if KMP_USE_DYNAMIC_LOCK void __kmp_itt_critical_creating(kmp_user_lock_p lock, const ident_t *loc) { … } #else void __kmp_itt_critical_creating(kmp_user_lock_p lock) { ___kmp_itt_lock_init(lock, "OMP Critical"); } // __kmp_itt_critical_creating #endif void __kmp_itt_critical_acquiring(kmp_user_lock_p lock) { … } // __kmp_itt_critical_acquiring void __kmp_itt_critical_acquired(kmp_user_lock_p lock) { … } // __kmp_itt_critical_acquired void __kmp_itt_critical_releasing(kmp_user_lock_p lock) { … } // __kmp_itt_critical_releasing void __kmp_itt_critical_destroyed(kmp_user_lock_p lock) { … } // __kmp_itt_critical_destroyed /* Single reporting. */ void __kmp_itt_single_start(int gtid) { … } // __kmp_itt_single_start void __kmp_itt_single_end(int gtid) { … } // __kmp_itt_single_end /* Ordered reporting. * __kmp_itt_ordered_init is called by each thread *before* first using sync object. ITT team would like it to be called once, but it requires extra synchronization. * __kmp_itt_ordered_prep is called when thread is going to enter ordered section (before synchronization). * __kmp_itt_ordered_start is called just before entering user code (after synchronization). * __kmp_itt_ordered_end is called after returning from user code. Sync object is th->th.th_dispatch->th_dispatch_sh_current. Events are not generated in case of serialized team. */ void __kmp_itt_ordered_init(int gtid) { … } // __kmp_itt_ordered_init void __kmp_itt_ordered_prep(int gtid) { … } // __kmp_itt_ordered_prep void __kmp_itt_ordered_start(int gtid) { … } // __kmp_itt_ordered_start void __kmp_itt_ordered_end(int gtid) { … } // __kmp_itt_ordered_end /* Threads reporting. */ void __kmp_itt_thread_ignore() { … } // __kmp_itt_thread_ignore void __kmp_itt_thread_name(int gtid) { … } // __kmp_itt_thread_name /* System object reporting. ITT catches operations with system sync objects (like Windows* OS on IA-32 architecture API critical sections and events). We only need to specify name ("OMP Scheduler") for the object to let ITT know it is an object used by OpenMP RTL for internal purposes. */ void __kmp_itt_system_object_created(void *object, char const *name) { … } // __kmp_itt_system_object_created /* Stack stitching api. Primary thread calls "create" and put the stitching id into team structure. Workers read the stitching id and call "enter" / "leave" api. Primary thread calls "destroy" at the end of the parallel region. */ __itt_caller __kmp_itt_stack_caller_create() { … } void __kmp_itt_stack_caller_destroy(__itt_caller id) { … } void __kmp_itt_stack_callee_enter(__itt_caller id) { … } void __kmp_itt_stack_callee_leave(__itt_caller id) { … } #endif /* USE_ITT_BUILD */