Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-30 08:46:18

0001 /*
0002     Copyright (c) 2005-2022 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 _FGT_GRAPH_TRACE_IMPL_H
0018 #define _FGT_GRAPH_TRACE_IMPL_H
0019 
0020 #include "../profiling.h"
0021 #if (_MSC_VER >= 1900)
0022     #include <intrin.h>
0023 #endif
0024 
0025 namespace tbb {
0026 namespace detail {
0027 namespace d1 {
0028 
0029 template< typename T > class sender;
0030 template< typename T > class receiver;
0031 
0032 #if TBB_USE_PROFILING_TOOLS
0033     #if __TBB_FLOW_TRACE_CODEPTR
0034         #if (_MSC_VER >= 1900)
0035             #define CODEPTR() (_ReturnAddress())
0036         #elif __TBB_GCC_VERSION >= 40800
0037             #define CODEPTR() ( __builtin_return_address(0))
0038         #else
0039             #define CODEPTR() nullptr
0040         #endif
0041     #else
0042         #define CODEPTR() nullptr
0043     #endif /* __TBB_FLOW_TRACE_CODEPTR */
0044 
0045 static inline void fgt_alias_port(void *node, void *p, bool visible) {
0046     if(visible)
0047         itt_relation_add( ITT_DOMAIN_FLOW, node, FLOW_NODE, __itt_relation_is_parent_of, p, FLOW_NODE );
0048     else
0049         itt_relation_add( ITT_DOMAIN_FLOW, p, FLOW_NODE, __itt_relation_is_child_of, node, FLOW_NODE );
0050 }
0051 
0052 static inline void fgt_composite ( void* codeptr, void *node, void *graph ) {
0053     itt_make_task_group( ITT_DOMAIN_FLOW, node, FLOW_NODE, graph, FLOW_GRAPH, FLOW_COMPOSITE_NODE );
0054     suppress_unused_warning( codeptr );
0055 #if __TBB_FLOW_TRACE_CODEPTR
0056     if (codeptr != nullptr) {
0057         register_node_addr(ITT_DOMAIN_FLOW, node, FLOW_NODE, CODE_ADDRESS, &codeptr);
0058     }
0059 #endif
0060 }
0061 
0062 static inline void fgt_internal_alias_input_port( void *node, void *p, string_resource_index name_index ) {
0063     itt_make_task_group( ITT_DOMAIN_FLOW, p, FLOW_INPUT_PORT, node, FLOW_NODE, name_index );
0064     itt_relation_add( ITT_DOMAIN_FLOW, node, FLOW_NODE, __itt_relation_is_parent_of, p, FLOW_INPUT_PORT );
0065 }
0066 
0067 static inline void fgt_internal_alias_output_port( void *node, void *p, string_resource_index name_index ) {
0068     itt_make_task_group( ITT_DOMAIN_FLOW, p, FLOW_OUTPUT_PORT, node, FLOW_NODE, name_index );
0069     itt_relation_add( ITT_DOMAIN_FLOW, node, FLOW_NODE, __itt_relation_is_parent_of, p, FLOW_OUTPUT_PORT );
0070 }
0071 
0072 template<typename InputType>
0073 void alias_input_port(void *node, receiver<InputType>* port, string_resource_index name_index) {
0074     // TODO: Make fgt_internal_alias_input_port a function template?
0075     fgt_internal_alias_input_port( node, port, name_index);
0076 }
0077 
0078 template < typename PortsTuple, int N >
0079 struct fgt_internal_input_alias_helper {
0080     static void alias_port( void *node, PortsTuple &ports ) {
0081         alias_input_port( node, &(std::get<N-1>(ports)), static_cast<string_resource_index>(FLOW_INPUT_PORT_0 + N - 1) );
0082         fgt_internal_input_alias_helper<PortsTuple, N-1>::alias_port( node, ports );
0083     }
0084 };
0085 
0086 template < typename PortsTuple >
0087 struct fgt_internal_input_alias_helper<PortsTuple, 0> {
0088     static void alias_port( void * /* node */, PortsTuple & /* ports */ ) { }
0089 };
0090 
0091 template<typename OutputType>
0092 void alias_output_port(void *node, sender<OutputType>* port, string_resource_index name_index) {
0093     // TODO: Make fgt_internal_alias_output_port a function template?
0094     fgt_internal_alias_output_port( node, static_cast<void *>(port), name_index);
0095 }
0096 
0097 template < typename PortsTuple, int N >
0098 struct fgt_internal_output_alias_helper {
0099     static void alias_port( void *node, PortsTuple &ports ) {
0100         alias_output_port( node, &(std::get<N-1>(ports)), static_cast<string_resource_index>(FLOW_OUTPUT_PORT_0 + N - 1) );
0101         fgt_internal_output_alias_helper<PortsTuple, N-1>::alias_port( node, ports );
0102     }
0103 };
0104 
0105 template < typename PortsTuple >
0106 struct fgt_internal_output_alias_helper<PortsTuple, 0> {
0107     static void alias_port( void * /*node*/, PortsTuple &/*ports*/ ) {
0108     }
0109 };
0110 
0111 static inline void fgt_internal_create_input_port( void *node, void *p, string_resource_index name_index ) {
0112     itt_make_task_group( ITT_DOMAIN_FLOW, p, FLOW_INPUT_PORT, node, FLOW_NODE, name_index );
0113 }
0114 
0115 static inline void fgt_internal_create_output_port( void* codeptr, void *node, void *p, string_resource_index name_index ) {
0116     itt_make_task_group(ITT_DOMAIN_FLOW, p, FLOW_OUTPUT_PORT, node, FLOW_NODE, name_index);
0117     suppress_unused_warning( codeptr );
0118 #if __TBB_FLOW_TRACE_CODEPTR
0119     if (codeptr != nullptr) {
0120         register_node_addr(ITT_DOMAIN_FLOW, node, FLOW_NODE, CODE_ADDRESS, &codeptr);
0121     }
0122 #endif
0123 }
0124 
0125 template<typename InputType>
0126 void register_input_port(void *node, receiver<InputType>* port, string_resource_index name_index) {
0127     // TODO: Make fgt_internal_create_input_port a function template?
0128     fgt_internal_create_input_port(node, static_cast<void*>(port), name_index);
0129 }
0130 
0131 template < typename PortsTuple, int N >
0132 struct fgt_internal_input_helper {
0133     static void register_port( void *node, PortsTuple &ports ) {
0134         register_input_port( node, &(std::get<N-1>(ports)), static_cast<string_resource_index>(FLOW_INPUT_PORT_0 + N - 1) );
0135         fgt_internal_input_helper<PortsTuple, N-1>::register_port( node, ports );
0136     }
0137 };
0138 
0139 template < typename PortsTuple >
0140 struct fgt_internal_input_helper<PortsTuple, 1> {
0141     static void register_port( void *node, PortsTuple &ports ) {
0142         register_input_port( node, &(std::get<0>(ports)), FLOW_INPUT_PORT_0 );
0143     }
0144 };
0145 
0146 template<typename OutputType>
0147 void register_output_port(void* codeptr, void *node, sender<OutputType>* port, string_resource_index name_index) {
0148     // TODO: Make fgt_internal_create_output_port a function template?
0149     fgt_internal_create_output_port( codeptr, node, static_cast<void *>(port), name_index);
0150 }
0151 
0152 template < typename PortsTuple, int N >
0153 struct fgt_internal_output_helper {
0154     static void register_port( void* codeptr, void *node, PortsTuple &ports ) {
0155         register_output_port( codeptr, node, &(std::get<N-1>(ports)), static_cast<string_resource_index>(FLOW_OUTPUT_PORT_0 + N - 1) );
0156         fgt_internal_output_helper<PortsTuple, N-1>::register_port( codeptr, node, ports );
0157     }
0158 };
0159 
0160 template < typename PortsTuple >
0161 struct fgt_internal_output_helper<PortsTuple,1> {
0162     static void register_port( void* codeptr, void *node, PortsTuple &ports ) {
0163         register_output_port( codeptr, node, &(std::get<0>(ports)), FLOW_OUTPUT_PORT_0 );
0164     }
0165 };
0166 
0167 template< typename NodeType >
0168 void fgt_multioutput_node_desc( const NodeType *node, const char *desc ) {
0169     void *addr =  (void *)( static_cast< receiver< typename NodeType::input_type > * >(const_cast< NodeType *>(node)) );
0170     itt_metadata_str_add( ITT_DOMAIN_FLOW, addr, FLOW_NODE, FLOW_OBJECT_NAME, desc );
0171 }
0172 
0173 template< typename NodeType >
0174 void fgt_multiinput_multioutput_node_desc( const NodeType *node, const char *desc ) {
0175     void *addr =  const_cast<NodeType *>(node);
0176     itt_metadata_str_add( ITT_DOMAIN_FLOW, addr, FLOW_NODE, FLOW_OBJECT_NAME, desc );
0177 }
0178 
0179 template< typename NodeType >
0180 static inline void fgt_node_desc( const NodeType *node, const char *desc ) {
0181     void *addr =  (void *)( static_cast< sender< typename NodeType::output_type > * >(const_cast< NodeType *>(node)) );
0182     itt_metadata_str_add( ITT_DOMAIN_FLOW, addr, FLOW_NODE, FLOW_OBJECT_NAME, desc );
0183 }
0184 
0185 static inline void fgt_graph_desc( const void *g, const char *desc ) {
0186     void *addr = const_cast< void *>(g);
0187     itt_metadata_str_add( ITT_DOMAIN_FLOW, addr, FLOW_GRAPH, FLOW_OBJECT_NAME, desc );
0188 }
0189 
0190 static inline void fgt_body( void *node, void *body ) {
0191     itt_relation_add( ITT_DOMAIN_FLOW, body, FLOW_BODY, __itt_relation_is_child_of, node, FLOW_NODE );
0192 }
0193 
0194 template< int N, typename PortsTuple >
0195 static inline void fgt_multioutput_node(void* codeptr, string_resource_index t, void *g, void *input_port, PortsTuple &ports ) {
0196     itt_make_task_group( ITT_DOMAIN_FLOW, input_port, FLOW_NODE, g, FLOW_GRAPH, t );
0197     fgt_internal_create_input_port( input_port, input_port, FLOW_INPUT_PORT_0 );
0198     fgt_internal_output_helper<PortsTuple, N>::register_port(codeptr, input_port, ports );
0199 }
0200 
0201 template< int N, typename PortsTuple >
0202 static inline void fgt_multioutput_node_with_body( void* codeptr, string_resource_index t, void *g, void *input_port, PortsTuple &ports, void *body ) {
0203     itt_make_task_group( ITT_DOMAIN_FLOW, input_port, FLOW_NODE, g, FLOW_GRAPH, t );
0204     fgt_internal_create_input_port( input_port, input_port, FLOW_INPUT_PORT_0 );
0205     fgt_internal_output_helper<PortsTuple, N>::register_port( codeptr, input_port, ports );
0206     fgt_body( input_port, body );
0207 }
0208 
0209 template< int N, typename PortsTuple >
0210 static inline void fgt_multiinput_node( void* codeptr, string_resource_index t, void *g, PortsTuple &ports, void *output_port) {
0211     itt_make_task_group( ITT_DOMAIN_FLOW, output_port, FLOW_NODE, g, FLOW_GRAPH, t );
0212     fgt_internal_create_output_port( codeptr, output_port, output_port, FLOW_OUTPUT_PORT_0 );
0213     fgt_internal_input_helper<PortsTuple, N>::register_port( output_port, ports );
0214 }
0215 
0216 static inline void fgt_multiinput_multioutput_node( void* codeptr, string_resource_index t, void *n, void *g ) {
0217     itt_make_task_group( ITT_DOMAIN_FLOW, n, FLOW_NODE, g, FLOW_GRAPH, t );
0218     suppress_unused_warning( codeptr );
0219 #if __TBB_FLOW_TRACE_CODEPTR
0220     if (codeptr != nullptr) {
0221         register_node_addr(ITT_DOMAIN_FLOW, n, FLOW_NODE, CODE_ADDRESS, &codeptr);
0222     }
0223 #endif
0224 }
0225 
0226 static inline void fgt_node( void* codeptr, string_resource_index t, void *g, void *output_port ) {
0227     itt_make_task_group( ITT_DOMAIN_FLOW, output_port, FLOW_NODE, g, FLOW_GRAPH, t );
0228     fgt_internal_create_output_port( codeptr, output_port, output_port, FLOW_OUTPUT_PORT_0 );
0229 }
0230 
0231 static void fgt_node_with_body( void* codeptr, string_resource_index t, void *g, void *output_port, void *body ) {
0232     itt_make_task_group( ITT_DOMAIN_FLOW, output_port, FLOW_NODE, g, FLOW_GRAPH, t );
0233     fgt_internal_create_output_port(codeptr, output_port, output_port, FLOW_OUTPUT_PORT_0 );
0234     fgt_body( output_port, body );
0235 }
0236 
0237 static inline void fgt_node( void* codeptr, string_resource_index t, void *g, void *input_port, void *output_port ) {
0238     fgt_node( codeptr, t, g, output_port );
0239     fgt_internal_create_input_port( output_port, input_port, FLOW_INPUT_PORT_0 );
0240 }
0241 
0242 static inline void  fgt_node_with_body( void* codeptr, string_resource_index t, void *g, void *input_port, void *output_port, void *body ) {
0243     fgt_node_with_body( codeptr, t, g, output_port, body );
0244     fgt_internal_create_input_port( output_port, input_port, FLOW_INPUT_PORT_0 );
0245 }
0246 
0247 
0248 static inline void  fgt_node( void* codeptr, string_resource_index t, void *g, void *input_port, void *decrement_port, void *output_port ) {
0249     fgt_node( codeptr, t, g, input_port, output_port );
0250     fgt_internal_create_input_port( output_port, decrement_port, FLOW_INPUT_PORT_1 );
0251 }
0252 
0253 static inline void fgt_make_edge( void *output_port, void *input_port ) {
0254     itt_relation_add( ITT_DOMAIN_FLOW, output_port, FLOW_OUTPUT_PORT, __itt_relation_is_predecessor_to, input_port, FLOW_INPUT_PORT);
0255 }
0256 
0257 static inline void fgt_remove_edge( void *output_port, void *input_port ) {
0258     itt_relation_add( ITT_DOMAIN_FLOW, output_port, FLOW_OUTPUT_PORT, __itt_relation_is_sibling_of, input_port, FLOW_INPUT_PORT);
0259 }
0260 
0261 static inline void fgt_graph( void *g ) {
0262     itt_make_task_group( ITT_DOMAIN_FLOW, g, FLOW_GRAPH, nullptr, FLOW_NULL, FLOW_GRAPH );
0263 }
0264 
0265 static inline void fgt_begin_body( void *body ) {
0266     itt_task_begin( ITT_DOMAIN_FLOW, body, FLOW_BODY, nullptr, FLOW_NULL, FLOW_BODY );
0267 }
0268 
0269 static inline void fgt_end_body( void * ) {
0270     itt_task_end( ITT_DOMAIN_FLOW );
0271 }
0272 
0273 static inline void fgt_async_try_put_begin( void *node, void *port ) {
0274     itt_task_begin( ITT_DOMAIN_FLOW, port, FLOW_OUTPUT_PORT, node, FLOW_NODE, FLOW_OUTPUT_PORT );
0275 }
0276 
0277 static inline void fgt_async_try_put_end( void *, void * ) {
0278     itt_task_end( ITT_DOMAIN_FLOW );
0279 }
0280 
0281 static inline void fgt_async_reserve( void *node, void *graph ) {
0282     itt_region_begin( ITT_DOMAIN_FLOW, node, FLOW_NODE, graph, FLOW_GRAPH, FLOW_NULL );
0283 }
0284 
0285 static inline void fgt_async_commit( void *node, void * /*graph*/) {
0286     itt_region_end( ITT_DOMAIN_FLOW, node, FLOW_NODE );
0287 }
0288 
0289 static inline void fgt_reserve_wait( void *graph ) {
0290     itt_region_begin( ITT_DOMAIN_FLOW, graph, FLOW_GRAPH, nullptr, FLOW_NULL, FLOW_NULL );
0291 }
0292 
0293 static inline void fgt_release_wait( void *graph ) {
0294     itt_region_end( ITT_DOMAIN_FLOW, graph, FLOW_GRAPH );
0295 }
0296 
0297 #else // TBB_USE_PROFILING_TOOLS
0298 
0299 #define CODEPTR() nullptr
0300 
0301 static inline void fgt_alias_port(void * /*node*/, void * /*p*/, bool /*visible*/ ) { }
0302 
0303 static inline void fgt_composite ( void* /*codeptr*/, void * /*node*/, void * /*graph*/ ) { }
0304 
0305 static inline void fgt_graph( void * /*g*/ ) { }
0306 
0307 template< typename NodeType >
0308 static inline void fgt_multioutput_node_desc( const NodeType * /*node*/, const char * /*desc*/ ) { }
0309 
0310 template< typename NodeType >
0311 static inline void fgt_node_desc( const NodeType * /*node*/, const char * /*desc*/ ) { }
0312 
0313 static inline void fgt_graph_desc( const void * /*g*/, const char * /*desc*/ ) { }
0314 
0315 template< int N, typename PortsTuple >
0316 static inline void fgt_multioutput_node( void* /*codeptr*/, string_resource_index /*t*/, void * /*g*/, void * /*input_port*/, PortsTuple & /*ports*/ ) { }
0317 
0318 template< int N, typename PortsTuple >
0319 static inline void fgt_multioutput_node_with_body( void* /*codeptr*/, string_resource_index /*t*/, void * /*g*/, void * /*input_port*/, PortsTuple & /*ports*/, void * /*body*/ ) { }
0320 
0321 template< int N, typename PortsTuple >
0322 static inline void fgt_multiinput_node( void* /*codeptr*/, string_resource_index /*t*/, void * /*g*/, PortsTuple & /*ports*/, void * /*output_port*/ ) { }
0323 
0324 static inline void fgt_multiinput_multioutput_node( void* /*codeptr*/, string_resource_index /*t*/, void * /*node*/, void * /*graph*/ ) { }
0325 
0326 static inline void fgt_node( void* /*codeptr*/, string_resource_index /*t*/, void * /*g*/, void * /*input_port*/, void * /*output_port*/ ) { }
0327 static inline void  fgt_node( void* /*codeptr*/, string_resource_index /*t*/, void * /*g*/, void * /*input_port*/, void * /*decrement_port*/, void * /*output_port*/ ) { }
0328 
0329 static inline void fgt_node_with_body( void* /*codeptr*/, string_resource_index /*t*/, void * /*g*/, void * /*output_port*/, void * /*body*/ ) { }
0330 static inline void fgt_node_with_body( void* /*codeptr*/, string_resource_index /*t*/, void * /*g*/, void * /*input_port*/, void * /*output_port*/, void * /*body*/ ) { }
0331 
0332 static inline void fgt_make_edge( void * /*output_port*/, void * /*input_port*/ ) { }
0333 static inline void fgt_remove_edge( void * /*output_port*/, void * /*input_port*/ ) { }
0334 
0335 static inline void fgt_begin_body( void * /*body*/ ) { }
0336 static inline void fgt_end_body( void *  /*body*/) { }
0337 
0338 static inline void fgt_async_try_put_begin( void * /*node*/, void * /*port*/ ) { }
0339 static inline void fgt_async_try_put_end( void * /*node*/ , void * /*port*/ ) { }
0340 static inline void fgt_async_reserve( void * /*node*/, void * /*graph*/ ) { }
0341 static inline void fgt_async_commit( void * /*node*/, void * /*graph*/ ) { }
0342 static inline void fgt_reserve_wait( void * /*graph*/ ) { }
0343 static inline void fgt_release_wait( void * /*graph*/ ) { }
0344 
0345 template< typename NodeType >
0346 void fgt_multiinput_multioutput_node_desc( const NodeType * /*node*/, const char * /*desc*/ ) { }
0347 
0348 template < typename PortsTuple, int N >
0349 struct fgt_internal_input_alias_helper {
0350     static void alias_port( void * /*node*/, PortsTuple & /*ports*/ ) { }
0351 };
0352 
0353 template < typename PortsTuple, int N >
0354 struct fgt_internal_output_alias_helper {
0355     static void alias_port( void * /*node*/, PortsTuple & /*ports*/ ) { }
0356 };
0357 
0358 #endif // TBB_USE_PROFILING_TOOLS
0359 
0360 } // d1
0361 } // namespace detail
0362 } // namespace tbb
0363 
0364 #endif // _FGT_GRAPH_TRACE_IMPL_H