Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/oneapi/tbb/profiling.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     Copyright (c) 2005-2023 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 #ifndef __TBB_profiling_H
0018 #define __TBB_profiling_H
0019 
0020 #include "detail/_config.h"
0021 #include <cstdint>
0022 
0023 #include <string>
0024 
0025 namespace tbb {
0026 namespace detail {
0027 inline namespace d0 {
0028     // include list of index names
0029     #define TBB_STRING_RESOURCE(index_name,str) index_name,
0030     enum string_resource_index : std::uintptr_t {
0031         #include "detail/_string_resource.h"
0032         NUM_STRINGS
0033     };
0034     #undef TBB_STRING_RESOURCE
0035 
0036     enum itt_relation
0037     {
0038     __itt_relation_is_unknown = 0,
0039     __itt_relation_is_dependent_on,         /**< "A is dependent on B" means that A cannot start until B completes */
0040     __itt_relation_is_sibling_of,           /**< "A is sibling of B" means that A and B were created as a group */
0041     __itt_relation_is_parent_of,            /**< "A is parent of B" means that A created B */
0042     __itt_relation_is_continuation_of,      /**< "A is continuation of B" means that A assumes the dependencies of B */
0043     __itt_relation_is_child_of,             /**< "A is child of B" means that A was created by B (inverse of is_parent_of) */
0044     __itt_relation_is_continued_by,         /**< "A is continued by B" means that B assumes the dependencies of A (inverse of is_continuation_of) */
0045     __itt_relation_is_predecessor_to        /**< "A is predecessor to B" means that B cannot start until A completes (inverse of is_dependent_on) */
0046     };
0047 
0048 //! Unicode support
0049 #if (_WIN32||_WIN64)
0050     //! Unicode character type. Always wchar_t on Windows.
0051     using tchar = wchar_t;
0052 #else /* !WIN */
0053     using tchar = char;
0054 #endif /* !WIN */
0055 
0056 } // namespace d0
0057 } // namespace detail
0058 } // namespace tbb
0059 
0060 #include <atomic>
0061 #if _WIN32||_WIN64
0062 #include <stdlib.h>  /* mbstowcs_s */
0063 #endif
0064 // Need these to work regardless of tools support
0065 namespace tbb {
0066 namespace detail {
0067 namespace d1 {
0068     enum notify_type {prepare=0, cancel, acquired, releasing, destroy};
0069     enum itt_domain_enum { ITT_DOMAIN_FLOW=0, ITT_DOMAIN_MAIN=1, ITT_DOMAIN_ALGO=2, ITT_NUM_DOMAINS };
0070 } // namespace d1
0071 
0072 namespace r1 {
0073     TBB_EXPORT void __TBB_EXPORTED_FUNC call_itt_notify(int t, void* ptr);
0074     TBB_EXPORT void __TBB_EXPORTED_FUNC create_itt_sync(void* ptr, const tchar* objtype, const tchar* objname);
0075     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_make_task_group(d1::itt_domain_enum domain, void* group, unsigned long long group_extra,
0076         void* parent, unsigned long long parent_extra, string_resource_index name_index);
0077     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_task_begin(d1::itt_domain_enum domain, void* task, unsigned long long task_extra,
0078         void* parent, unsigned long long parent_extra, string_resource_index name_index);
0079     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_task_end(d1::itt_domain_enum domain);
0080     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_set_sync_name(void* obj, const tchar* name);
0081     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_metadata_str_add(d1::itt_domain_enum domain, void* addr, unsigned long long addr_extra,
0082         string_resource_index key, const char* value);
0083     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_metadata_ptr_add(d1::itt_domain_enum domain, void* addr, unsigned long long addr_extra,
0084         string_resource_index key, void* value);
0085     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_relation_add(d1::itt_domain_enum domain, void* addr0, unsigned long long addr0_extra,
0086         itt_relation relation, void* addr1, unsigned long long addr1_extra);
0087     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_region_begin(d1::itt_domain_enum domain, void* region, unsigned long long region_extra,
0088         void* parent, unsigned long long parent_extra, string_resource_index /* name_index */);
0089     TBB_EXPORT void __TBB_EXPORTED_FUNC itt_region_end(d1::itt_domain_enum domain, void* region, unsigned long long region_extra);
0090 } // namespace r1
0091 
0092 namespace d1 {
0093 #if TBB_USE_PROFILING_TOOLS && (_WIN32||_WIN64)
0094     inline std::size_t multibyte_to_widechar(wchar_t* wcs, const char* mbs, std::size_t bufsize) {
0095         std::size_t len;
0096         mbstowcs_s(&len, wcs, bufsize, mbs, _TRUNCATE);
0097         return len;   // mbstowcs_s counts null terminator
0098     }
0099 #endif
0100 
0101 #if TBB_USE_PROFILING_TOOLS
0102     inline void create_itt_sync(void *ptr, const char *objtype, const char *objname) {
0103 #if (_WIN32||_WIN64)
0104         std::size_t len_type = multibyte_to_widechar(nullptr, objtype, 0);
0105         wchar_t *type = new wchar_t[len_type];
0106         multibyte_to_widechar(type, objtype, len_type);
0107         std::size_t len_name = multibyte_to_widechar(nullptr, objname, 0);
0108         wchar_t *name = new wchar_t[len_name];
0109         multibyte_to_widechar(name, objname, len_name);
0110 #else // WIN
0111         const char *type = objtype;
0112         const char *name = objname;
0113 #endif
0114         r1::create_itt_sync(ptr, type, name);
0115 
0116 #if (_WIN32||_WIN64)
0117         delete[] type;
0118         delete[] name;
0119 #endif // WIN
0120     }
0121 
0122 // Distinguish notifications on task for reducing overheads
0123 #if TBB_USE_PROFILING_TOOLS == 2
0124     inline void call_itt_task_notify(d1::notify_type t, void *ptr) {
0125         r1::call_itt_notify(static_cast<int>(t), ptr);
0126     }
0127 #else
0128     inline void call_itt_task_notify(d1::notify_type, void *) {}
0129 #endif // TBB_USE_PROFILING_TOOLS
0130 
0131     inline void call_itt_notify(d1::notify_type t, void *ptr) {
0132         r1::call_itt_notify(static_cast<int>(t), ptr);
0133     }
0134 
0135 #if (_WIN32||_WIN64) && !__MINGW32__
0136     inline void itt_set_sync_name(void* obj, const wchar_t* name) {
0137         r1::itt_set_sync_name(obj, name);
0138     }
0139     inline void itt_set_sync_name(void* obj, const char* name) {
0140         std::size_t len_name = multibyte_to_widechar(nullptr, name, 0);
0141         wchar_t *obj_name = new wchar_t[len_name];
0142         multibyte_to_widechar(obj_name, name, len_name);
0143         r1::itt_set_sync_name(obj, obj_name);
0144         delete[] obj_name;
0145     }
0146 #else
0147     inline void itt_set_sync_name( void* obj, const char* name) {
0148         r1::itt_set_sync_name(obj, name);
0149     }
0150 #endif //WIN
0151 
0152     inline void itt_make_task_group(itt_domain_enum domain, void* group, unsigned long long group_extra,
0153         void* parent, unsigned long long parent_extra, string_resource_index name_index) {
0154         r1::itt_make_task_group(domain, group, group_extra, parent, parent_extra, name_index);
0155     }
0156 
0157     inline void itt_metadata_str_add( itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0158                                         string_resource_index key, const char *value ) {
0159         r1::itt_metadata_str_add( domain, addr, addr_extra, key, value );
0160     }
0161 
0162     inline void register_node_addr(itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0163         string_resource_index key, void *value) {
0164         r1::itt_metadata_ptr_add(domain, addr, addr_extra, key, value);
0165     }
0166 
0167     inline void itt_relation_add( itt_domain_enum domain, void *addr0, unsigned long long addr0_extra,
0168                                     itt_relation relation, void *addr1, unsigned long long addr1_extra ) {
0169         r1::itt_relation_add( domain, addr0, addr0_extra, relation, addr1, addr1_extra );
0170     }
0171 
0172     inline void itt_task_begin( itt_domain_enum domain, void *task, unsigned long long task_extra,
0173                                                     void *parent, unsigned long long parent_extra, string_resource_index name_index ) {
0174         r1::itt_task_begin( domain, task, task_extra, parent, parent_extra, name_index );
0175     }
0176 
0177     inline void itt_task_end( itt_domain_enum domain ) {
0178         r1::itt_task_end( domain );
0179     }
0180 
0181     inline void itt_region_begin( itt_domain_enum domain, void *region, unsigned long long region_extra,
0182                                     void *parent, unsigned long long parent_extra, string_resource_index name_index ) {
0183         r1::itt_region_begin( domain, region, region_extra, parent, parent_extra, name_index );
0184     }
0185 
0186     inline void itt_region_end( itt_domain_enum domain, void *region, unsigned long long region_extra  ) {
0187         r1::itt_region_end( domain, region, region_extra );
0188     }
0189 #else
0190     inline void create_itt_sync(void* /*ptr*/, const char* /*objtype*/, const char* /*objname*/) {}
0191 
0192     inline void call_itt_notify(notify_type /*t*/, void* /*ptr*/) {}
0193 
0194     inline void call_itt_task_notify(notify_type /*t*/, void* /*ptr*/) {}
0195 #endif // TBB_USE_PROFILING_TOOLS
0196 
0197 #if TBB_USE_PROFILING_TOOLS && !(TBB_USE_PROFILING_TOOLS == 2)
0198 class event {
0199 /** This class supports user event traces through itt.
0200     Common use-case is tagging data flow graph tasks (data-id)
0201     and visualization by Intel Advisor Flow Graph Analyzer (FGA)  **/
0202 //  TODO: Replace implementation by itt user event api.
0203 
0204     const std::string my_name;
0205 
0206     static void emit_trace(const std::string &input) {
0207         itt_metadata_str_add( ITT_DOMAIN_FLOW, nullptr, FLOW_NULL, USER_EVENT, ( "FGA::DATAID::" + input ).c_str() );
0208     }
0209 
0210 public:
0211     event(const std::string &input)
0212               : my_name( input )
0213     { }
0214 
0215     void emit() {
0216         emit_trace(my_name);
0217     }
0218 
0219     static void emit(const std::string &description) {
0220         emit_trace(description);
0221     }
0222 
0223 };
0224 #else // TBB_USE_PROFILING_TOOLS && !(TBB_USE_PROFILING_TOOLS == 2)
0225 // Using empty struct if user event tracing is disabled:
0226 struct event {
0227     event(const std::string &) { }
0228 
0229     void emit() { }
0230 
0231     static void emit(const std::string &) { }
0232 };
0233 #endif // TBB_USE_PROFILING_TOOLS && !(TBB_USE_PROFILING_TOOLS == 2)
0234 } // namespace d1
0235 } // namespace detail
0236 
0237 namespace profiling {
0238     using detail::d1::event;
0239 }
0240 } // namespace tbb
0241 
0242 
0243 #endif /* __TBB_profiling_H */