Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:01

0001 /*
0002     Copyright (c) 2005-2020 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 #define __TBB_tbb_profiling_H_include_area
0021 #include "internal/_warning_suppress_enable_notice.h"
0022 
0023 namespace tbb {
0024     namespace internal {
0025 
0026         // include list of index names
0027         #define TBB_STRING_RESOURCE(index_name,str) index_name,
0028         enum string_index {
0029            #include "internal/_tbb_strings.h"
0030            NUM_STRINGS
0031         };
0032         #undef TBB_STRING_RESOURCE
0033 
0034         enum itt_relation
0035         {
0036         __itt_relation_is_unknown = 0,
0037         __itt_relation_is_dependent_on,         /**< "A is dependent on B" means that A cannot start until B completes */
0038         __itt_relation_is_sibling_of,           /**< "A is sibling of B" means that A and B were created as a group */
0039         __itt_relation_is_parent_of,            /**< "A is parent of B" means that A created B */
0040         __itt_relation_is_continuation_of,      /**< "A is continuation of B" means that A assumes the dependencies of B */
0041         __itt_relation_is_child_of,             /**< "A is child of B" means that A was created by B (inverse of is_parent_of) */
0042         __itt_relation_is_continued_by,         /**< "A is continued by B" means that B assumes the dependencies of A (inverse of is_continuation_of) */
0043         __itt_relation_is_predecessor_to        /**< "A is predecessor to B" means that B cannot start until A completes (inverse of is_dependent_on) */
0044         };
0045 
0046     }
0047 }
0048 
0049 // Check if the tools support is enabled
0050 #if (_WIN32||_WIN64||__linux__) && !__MINGW32__ && TBB_USE_THREADING_TOOLS
0051 
0052 #if _WIN32||_WIN64
0053 #include <stdlib.h>  /* mbstowcs_s */
0054 #endif
0055 #include "tbb_stddef.h"
0056 
0057 namespace tbb {
0058     namespace internal {
0059 
0060 #if _WIN32||_WIN64
0061         void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const wchar_t* name );
0062         inline size_t multibyte_to_widechar( wchar_t* wcs, const char* mbs, size_t bufsize) {
0063 #if _MSC_VER>=1400
0064             size_t len;
0065             mbstowcs_s( &len, wcs, bufsize, mbs, _TRUNCATE );
0066             return len;   // mbstowcs_s counts null terminator
0067 #else
0068             size_t len = mbstowcs( wcs, mbs, bufsize );
0069             if(wcs && len!=size_t(-1) )
0070                 wcs[len<bufsize-1? len: bufsize-1] = wchar_t('\0');
0071             return len+1; // mbstowcs does not count null terminator
0072 #endif
0073         }
0074 #else
0075         void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const char* name );
0076 #endif
0077     } // namespace internal
0078 } // namespace tbb
0079 
0080 //! Macro __TBB_DEFINE_PROFILING_SET_NAME(T) defines "set_name" methods for sync objects of type T
0081 /** Should be used in the "tbb" namespace only.
0082     Don't place semicolon after it to avoid compiler warnings. **/
0083 #if _WIN32||_WIN64
0084     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)                       \
0085         namespace profiling {                                                       \
0086             inline void set_name( sync_object_type& obj, const wchar_t* name ) {    \
0087                 tbb::internal::itt_set_sync_name_v3( &obj, name );                  \
0088             }                                                                       \
0089             inline void set_name( sync_object_type& obj, const char* name ) {       \
0090                 size_t len = tbb::internal::multibyte_to_widechar(NULL, name, 0);   \
0091                 wchar_t *wname = new wchar_t[len];                                  \
0092                 tbb::internal::multibyte_to_widechar(wname, name, len);             \
0093                 set_name( obj, wname );                                             \
0094                 delete[] wname;                                                     \
0095             }                                                                       \
0096         }
0097 #else /* !WIN */
0098     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)                       \
0099         namespace profiling {                                                       \
0100             inline void set_name( sync_object_type& obj, const char* name ) {       \
0101                 tbb::internal::itt_set_sync_name_v3( &obj, name );                  \
0102             }                                                                       \
0103         }
0104 #endif /* !WIN */
0105 
0106 #else /* no tools support */
0107 
0108 #if _WIN32||_WIN64
0109     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)               \
0110         namespace profiling {                                               \
0111             inline void set_name( sync_object_type&, const wchar_t* ) {}    \
0112             inline void set_name( sync_object_type&, const char* ) {}       \
0113         }
0114 #else /* !WIN */
0115     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)               \
0116         namespace profiling {                                               \
0117             inline void set_name( sync_object_type&, const char* ) {}       \
0118         }
0119 #endif /* !WIN */
0120 
0121 #endif /* no tools support */
0122 
0123 #include "atomic.h"
0124 
0125 // Need these to work regardless of tools support
0126 namespace tbb {
0127     namespace internal {
0128 
0129         enum notify_type {prepare=0, cancel, acquired, releasing};
0130 
0131         const uintptr_t NUM_NOTIFY_TYPES = 4; // set to # elements in enum above
0132 
0133         void __TBB_EXPORTED_FUNC call_itt_notify_v5(int t, void *ptr);
0134         void __TBB_EXPORTED_FUNC itt_store_pointer_with_release_v3(void *dst, void *src);
0135         void* __TBB_EXPORTED_FUNC itt_load_pointer_with_acquire_v3(const void *src);
0136         void* __TBB_EXPORTED_FUNC itt_load_pointer_v3( const void* src );
0137         enum itt_domain_enum { ITT_DOMAIN_FLOW=0, ITT_DOMAIN_MAIN=1, ITT_DOMAIN_ALGO=2, ITT_NUM_DOMAINS };
0138 
0139         void __TBB_EXPORTED_FUNC itt_make_task_group_v7( itt_domain_enum domain, void *group, unsigned long long group_extra,
0140                                                          void *parent, unsigned long long parent_extra, string_index name_index );
0141         void __TBB_EXPORTED_FUNC itt_metadata_str_add_v7( itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0142                                                           string_index key, const char *value );
0143         void __TBB_EXPORTED_FUNC itt_metadata_ptr_add_v11( itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0144                                                            string_index key, void* value );
0145         void __TBB_EXPORTED_FUNC itt_relation_add_v7( itt_domain_enum domain, void *addr0, unsigned long long addr0_extra,
0146                                                       itt_relation relation, void *addr1, unsigned long long addr1_extra );
0147         void __TBB_EXPORTED_FUNC itt_task_begin_v7( itt_domain_enum domain, void *task, unsigned long long task_extra,
0148                                                     void *parent, unsigned long long parent_extra, string_index name_index );
0149         void __TBB_EXPORTED_FUNC itt_task_end_v7( itt_domain_enum domain );
0150 
0151         void __TBB_EXPORTED_FUNC itt_region_begin_v9( itt_domain_enum domain, void *region, unsigned long long region_extra,
0152                                                       void *parent, unsigned long long parent_extra, string_index name_index );
0153         void __TBB_EXPORTED_FUNC itt_region_end_v9( itt_domain_enum domain, void *region, unsigned long long region_extra );
0154 
0155         // two template arguments are to workaround /Wp64 warning with tbb::atomic specialized for unsigned type
0156         template <typename T, typename U>
0157         inline void itt_store_word_with_release(tbb::atomic<T>& dst, U src) {
0158 #if TBB_USE_THREADING_TOOLS
0159             // This assertion should be replaced with static_assert
0160             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0161             itt_store_pointer_with_release_v3(&dst, (void *)uintptr_t(src));
0162 #else
0163             dst = src;
0164 #endif // TBB_USE_THREADING_TOOLS
0165         }
0166 
0167         template <typename T>
0168         inline T itt_load_word_with_acquire(const tbb::atomic<T>& src) {
0169 #if TBB_USE_THREADING_TOOLS
0170             // This assertion should be replaced with static_assert
0171             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0172 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
0173             // Workaround for overzealous compiler warnings
0174             #pragma warning (push)
0175             #pragma warning (disable: 4311)
0176 #endif
0177             T result = (T)itt_load_pointer_with_acquire_v3(&src);
0178 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
0179             #pragma warning (pop)
0180 #endif
0181             return result;
0182 #else
0183             return src;
0184 #endif // TBB_USE_THREADING_TOOLS
0185         }
0186 
0187         template <typename T>
0188         inline void itt_store_word_with_release(T& dst, T src) {
0189 #if TBB_USE_THREADING_TOOLS
0190             // This assertion should be replaced with static_assert
0191             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0192             itt_store_pointer_with_release_v3(&dst, (void *)src);
0193 #else
0194             __TBB_store_with_release(dst, src);
0195 #endif // TBB_USE_THREADING_TOOLS
0196         }
0197 
0198         template <typename T>
0199         inline T itt_load_word_with_acquire(const T& src) {
0200 #if TBB_USE_THREADING_TOOLS
0201             // This assertion should be replaced with static_assert
0202             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
0203             return (T)itt_load_pointer_with_acquire_v3(&src);
0204 #else
0205             return __TBB_load_with_acquire(src);
0206 #endif // TBB_USE_THREADING_TOOLS
0207         }
0208 
0209         template <typename T>
0210         inline void itt_hide_store_word(T& dst, T src) {
0211 #if TBB_USE_THREADING_TOOLS
0212             //TODO: This assertion should be replaced with static_assert
0213             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
0214             itt_store_pointer_with_release_v3(&dst, (void *)src);
0215 #else
0216             dst = src;
0217 #endif
0218         }
0219 
0220         //TODO: rename to itt_hide_load_word_relaxed
0221         template <typename T>
0222         inline T itt_hide_load_word(const T& src) {
0223 #if TBB_USE_THREADING_TOOLS
0224             //TODO: This assertion should be replaced with static_assert
0225             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0226             return (T)itt_load_pointer_v3(&src);
0227 #else
0228             return src;
0229 #endif
0230         }
0231 
0232 #if TBB_USE_THREADING_TOOLS
0233         inline void call_itt_notify(notify_type t, void *ptr) {
0234             call_itt_notify_v5((int)t, ptr);
0235         }
0236 
0237         inline void itt_make_task_group( itt_domain_enum domain, void *group, unsigned long long group_extra,
0238                                          void *parent, unsigned long long parent_extra, string_index name_index ) {
0239             itt_make_task_group_v7( domain, group, group_extra, parent, parent_extra, name_index );
0240         }
0241 
0242         inline void itt_metadata_str_add( itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0243                                           string_index key, const char *value ) {
0244             itt_metadata_str_add_v7( domain, addr, addr_extra, key, value );
0245         }
0246         
0247         inline void register_node_addr(itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0248             string_index key, void *value) {
0249             itt_metadata_ptr_add_v11(domain, addr, addr_extra, key, value);
0250         }
0251 
0252         inline void itt_relation_add( itt_domain_enum domain, void *addr0, unsigned long long addr0_extra,
0253                                       itt_relation relation, void *addr1, unsigned long long addr1_extra ) {
0254             itt_relation_add_v7( domain, addr0, addr0_extra, relation, addr1, addr1_extra );
0255         }
0256 
0257         inline void itt_task_begin( itt_domain_enum domain, void *task, unsigned long long task_extra,
0258                                                         void *parent, unsigned long long parent_extra, string_index name_index ) {
0259             itt_task_begin_v7( domain, task, task_extra, parent, parent_extra, name_index );
0260         }
0261 
0262         inline void itt_task_end( itt_domain_enum domain ) {
0263             itt_task_end_v7( domain );
0264         }
0265 
0266         inline void itt_region_begin( itt_domain_enum domain, void *region, unsigned long long region_extra,
0267                                       void *parent, unsigned long long parent_extra, string_index name_index ) {
0268             itt_region_begin_v9( domain, region, region_extra, parent, parent_extra, name_index );
0269         }
0270 
0271         inline void itt_region_end( itt_domain_enum domain, void *region, unsigned long long region_extra  ) {
0272             itt_region_end_v9( domain, region, region_extra );
0273         }
0274 #else
0275         inline void register_node_addr( itt_domain_enum /*domain*/, void* /*addr*/, unsigned long long /*addr_extra*/, string_index /*key*/, void* /*value*/ ) {}
0276         inline void call_itt_notify(notify_type /*t*/, void* /*ptr*/) {}
0277 
0278         inline void itt_make_task_group( itt_domain_enum /*domain*/, void* /*group*/, unsigned long long /*group_extra*/,
0279                                          void* /*parent*/, unsigned long long /*parent_extra*/, string_index /*name_index*/ ) {}
0280 
0281         inline void itt_metadata_str_add( itt_domain_enum /*domain*/, void* /*addr*/, unsigned long long /*addr_extra*/,
0282                                           string_index /*key*/, const char* /*value*/ ) {}
0283 
0284         inline void itt_relation_add( itt_domain_enum /*domain*/, void* /*addr0*/, unsigned long long /*addr0_extra*/,
0285                                       itt_relation /*relation*/, void* /*addr1*/, unsigned long long /*addr1_extra*/ ) {}
0286 
0287         inline void itt_task_begin( itt_domain_enum /*domain*/, void* /*task*/, unsigned long long /*task_extra*/,
0288                                     void* /*parent*/, unsigned long long /*parent_extra*/, string_index /*name_index*/ ) {}
0289 
0290         inline void itt_task_end( itt_domain_enum /*domain*/ ) {}
0291 
0292         inline void itt_region_begin( itt_domain_enum /*domain*/, void* /*region*/, unsigned long long /*region_extra*/,
0293                                       void* /*parent*/, unsigned long long /*parent_extra*/, string_index /*name_index*/ ) {}
0294 
0295         inline void itt_region_end( itt_domain_enum /*domain*/, void* /*region*/, unsigned long long /*region_extra*/ ) {}
0296 #endif // TBB_USE_THREADING_TOOLS
0297 
0298     } // namespace internal
0299 } // namespace tbb
0300 
0301 #if TBB_PREVIEW_FLOW_GRAPH_TRACE
0302 #include <string>
0303 
0304 namespace tbb {
0305 namespace profiling {
0306 namespace interface10 {
0307 
0308 #if TBB_USE_THREADING_TOOLS && !(TBB_USE_THREADING_TOOLS == 2)
0309 class event {
0310 /** This class supports user event traces through itt.
0311     Common use-case is tagging data flow graph tasks (data-id)
0312     and visualization by Intel Advisor Flow Graph Analyzer (FGA)  **/
0313 //  TODO: Replace implementation by itt user event api.
0314 
0315     const std::string my_name;
0316 
0317     static void emit_trace(const std::string &input) {
0318         itt_metadata_str_add( tbb::internal::ITT_DOMAIN_FLOW, NULL, tbb::internal::FLOW_NULL, tbb::internal::USER_EVENT, ( "FGA::DATAID::" + input ).c_str() );
0319     }
0320 
0321 public:
0322     event(const std::string &input)
0323               : my_name( input )
0324     { }
0325 
0326     void emit() {
0327         emit_trace(my_name);
0328     }
0329 
0330     static void emit(const std::string &description) {
0331         emit_trace(description);
0332     }
0333 
0334 };
0335 #else // TBB_USE_THREADING_TOOLS && !(TBB_USE_THREADING_TOOLS == 2)
0336 // Using empty struct if user event tracing is disabled:
0337 struct event {
0338     event(const std::string &) { }
0339 
0340     void emit() { }
0341 
0342     static void emit(const std::string &) { }
0343 };
0344 #endif // TBB_USE_THREADING_TOOLS && !(TBB_USE_THREADING_TOOLS == 2)
0345 
0346 } // interfaceX
0347 using interface10::event;
0348 } // namespace profiling
0349 } // namespace tbb
0350 #endif // TBB_PREVIEW_FLOW_GRAPH_TRACE
0351 
0352 #include "internal/_warning_suppress_disable_notice.h"
0353 #undef __TBB_tbb_profiling_H_include_area
0354 
0355 #endif /* __TBB_profiling_H */