1 /* 2 Copyright (c) 2005-2022 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef _TBB_ITT_NOTIFY 18 #define _TBB_ITT_NOTIFY 19 20 #include "oneapi/tbb/detail/_config.h" 21 22 #if __TBB_USE_ITT_NOTIFY 23 24 #if _WIN32||_WIN64 25 #ifndef UNICODE 26 #define UNICODE 27 #endif 28 #endif /* WIN */ 29 30 #ifndef INTEL_ITTNOTIFY_API_PRIVATE 31 #define INTEL_ITTNOTIFY_API_PRIVATE 32 #endif 33 34 #include "tools_api/ittnotify.h" 35 #include "tools_api/legacy/ittnotify.h" 36 extern "C" void __itt_fini_ittlib(void); 37 extern "C" void __itt_release_resources(void); 38 39 #if _WIN32||_WIN64 40 #undef _T 41 #endif /* WIN */ 42 43 #endif /* __TBB_USE_ITT_NOTIFY */ 44 45 #if !ITT_CALLER_NULL 46 #define ITT_CALLER_NULL ((__itt_caller)0) 47 #endif 48 49 namespace tbb { 50 namespace detail { 51 namespace r1 { 52 53 //! Unicode support 54 #if (_WIN32||_WIN64) 55 //! Unicode character type. Always wchar_t on Windows. 56 /** We do not use typedefs from Windows TCHAR family to keep consistence of TBB coding style. **/ 57 using tchar = wchar_t; 58 //! Standard Windows macro to markup the string literals. 59 #define _T(string_literal) L ## string_literal 60 #else /* !WIN */ 61 using tchar = char; 62 //! Standard Windows style macro to markup the string literals. 63 #define _T(string_literal) string_literal 64 #endif /* !WIN */ 65 66 //! Display names of internal synchronization types 67 extern const tchar 68 *SyncType_Scheduler; 69 //! Display names of internal synchronization components/scenarios 70 extern const tchar 71 *SyncObj_ContextsList 72 ; 73 74 #if __TBB_USE_ITT_NOTIFY 75 // const_cast<void*>() is necessary to cast off volatility 76 #define ITT_NOTIFY(name,obj) __itt_##name(const_cast<void*>(static_cast<volatile void*>(obj))) 77 #define ITT_THREAD_SET_NAME(name) __itt_thread_set_name(name) 78 #define ITT_FINI_ITTLIB() __itt_fini_ittlib() 79 #define ITT_RELEASE_RESOURCES() __itt_release_resources() 80 #define ITT_SYNC_CREATE(obj, type, name) __itt_sync_create((void*)(obj), type, name, 2) 81 #define ITT_STACK_CREATE(obj) obj = __itt_stack_caller_create() 82 #define ITT_STACK_DESTROY(obj) (obj!=nullptr) ? __itt_stack_caller_destroy(static_cast<__itt_caller>(obj)) : ((void)0) 83 #define ITT_CALLEE_ENTER(cond, t, obj) if(cond) {\ 84 __itt_stack_callee_enter(static_cast<__itt_caller>(obj));\ 85 __itt_sync_acquired(t);\ 86 } 87 #define ITT_CALLEE_LEAVE(cond, obj) (cond) ? __itt_stack_callee_leave(static_cast<__itt_caller>(obj)) : ((void)0) 88 89 #define ITT_TASK_GROUP(obj,name,parent) r1::itt_make_task_group(d1::ITT_DOMAIN_MAIN,(void*)(obj),ALGORITHM,(void*)(parent),(parent!=nullptr) ? ALGORITHM : FLOW_NULL,name) 90 #define ITT_TASK_BEGIN(obj,name,id) r1::itt_task_begin(d1::ITT_DOMAIN_MAIN,(void*)(id),ALGORITHM,(void*)(obj),ALGORITHM,name) 91 #define ITT_TASK_END r1::itt_task_end(d1::ITT_DOMAIN_MAIN) 92 93 94 #else /* !__TBB_USE_ITT_NOTIFY */ 95 96 #define ITT_NOTIFY(name,obj) ((void)0) 97 #define ITT_THREAD_SET_NAME(name) ((void)0) 98 #define ITT_FINI_ITTLIB() ((void)0) 99 #define ITT_RELEASE_RESOURCES() ((void)0) 100 #define ITT_SYNC_CREATE(obj, type, name) ((void)0) 101 #define ITT_STACK_CREATE(obj) ((void)0) 102 #define ITT_STACK_DESTROY(obj) ((void)0) 103 #define ITT_CALLEE_ENTER(cond, t, obj) ((void)0) 104 #define ITT_CALLEE_LEAVE(cond, obj) ((void)0) 105 #define ITT_TASK_GROUP(type,name,parent) ((void)0) 106 #define ITT_TASK_BEGIN(type,name,id) ((void)0) 107 #define ITT_TASK_END ((void)0) 108 109 #endif /* !__TBB_USE_ITT_NOTIFY */ 110 111 int __TBB_load_ittnotify(); 112 113 } // namespace r1 114 } // namespace detail 115 } // namespace tbb 116 117 #endif /* _TBB_ITT_NOTIFY */ 118