BRE12
_flow_graph_trace_impl.h
1 /*
2  Copyright 2005-2016 Intel Corporation. All Rights Reserved.
3 
4  This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5  you can redistribute it and/or modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation. Threading Building Blocks is
7  distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9  See the GNU General Public License for more details. You should have received a copy of
10  the GNU General Public License along with Threading Building Blocks; if not, write to the
11  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12 
13  As a special exception, you may use this file as part of a free software library without
14  restriction. Specifically, if other files instantiate templates or use macros or inline
15  functions from this file, or you compile this file and link it with other files to produce
16  an executable, this file does not by itself cause the resulting executable to be covered
17  by the GNU General Public License. This exception does not however invalidate any other
18  reasons why the executable file might be covered by the GNU General Public License.
19 */
20 
21 #ifndef _FGT_GRAPH_TRACE_IMPL_H
22 #define _FGT_GRAPH_TRACE_IMPL_H
23 
24 #include "../tbb_profiling.h"
25 
26 namespace tbb {
27  namespace internal {
28 
29 #if TBB_PREVIEW_FLOW_GRAPH_TRACE
30 
31 static inline void fgt_internal_create_input_port( void *node, void *p, string_index name_index ) {
32  itt_make_task_group( ITT_DOMAIN_FLOW, p, FLOW_INPUT_PORT, node, FLOW_NODE, name_index );
33 }
34 
35 static inline void fgt_internal_create_output_port( void *node, void *p, string_index name_index ) {
36  itt_make_task_group( ITT_DOMAIN_FLOW, p, FLOW_OUTPUT_PORT, node, FLOW_NODE, name_index );
37 }
38 
39 template<typename InputType>
40 void register_input_port(void *node, tbb::flow::receiver<InputType>* port, string_index name_index) {
41  //TODO: Make fgt_internal_create_input_port a function template?
42  fgt_internal_create_input_port( node, port, name_index);
43 }
44 
45 template < typename PortsTuple, int N >
46 struct fgt_internal_input_helper {
47  static void register_port( void *node, PortsTuple &ports ) {
48  register_input_port( node, &(tbb::flow::get<N-1>(ports)), static_cast<tbb::internal::string_index>(FLOW_INPUT_PORT_0 + N - 1) );
49  fgt_internal_input_helper<PortsTuple, N-1>::register_port( node, ports );
50  }
51 };
52 
53 template < typename PortsTuple >
54 struct fgt_internal_input_helper<PortsTuple, 1> {
55  static void register_port( void *node, PortsTuple &ports ) {
56  register_input_port( node, &(tbb::flow::get<0>(ports)), FLOW_INPUT_PORT_0 );
57  }
58 };
59 
60 template<typename OutputType>
61 void register_output_port(void *node, tbb::flow::sender<OutputType>* port, string_index name_index) {
62  //TODO: Make fgt_internal_create_output_port a function template?
63  fgt_internal_create_output_port( node, static_cast<void *>(port), name_index);
64 }
65 
66 template < typename PortsTuple, int N >
67 struct fgt_internal_output_helper {
68  static void register_port( void *node, PortsTuple &ports ) {
69  register_output_port( node, &(tbb::flow::get<N-1>(ports)), static_cast<tbb::internal::string_index>(FLOW_OUTPUT_PORT_0 + N - 1) );
70  fgt_internal_output_helper<PortsTuple, N-1>::register_port( node, ports );
71  }
72 };
73 
74 template < typename PortsTuple >
75 struct fgt_internal_output_helper<PortsTuple,1> {
76  static void register_port( void *node, PortsTuple &ports ) {
77  register_output_port( node, &(tbb::flow::get<0>(ports)), FLOW_OUTPUT_PORT_0 );
78  }
79 };
80 
81 template< typename NodeType >
82 void fgt_multioutput_node_desc( const NodeType *node, const char *desc ) {
83  void *addr = (void *)( static_cast< tbb::flow::receiver< typename NodeType::input_type > * >(const_cast< NodeType *>(node)) );
84  itt_metadata_str_add( ITT_DOMAIN_FLOW, addr, FLOW_NODE, FLOW_OBJECT_NAME, desc );
85 }
86 
87 template< typename NodeType >
88 void fgt_multiinput_multioutput_node_desc( const NodeType *node, const char *desc ) {
89  void *addr = const_cast<NodeType *>(node);
90  itt_metadata_str_add( ITT_DOMAIN_FLOW, addr, FLOW_NODE, FLOW_OBJECT_NAME, desc );
91 }
92 
93 template< typename NodeType >
94 static inline void fgt_node_desc( const NodeType *node, const char *desc ) {
95  void *addr = (void *)( static_cast< tbb::flow::sender< typename NodeType::output_type > * >(const_cast< NodeType *>(node)) );
96  itt_metadata_str_add( ITT_DOMAIN_FLOW, addr, FLOW_NODE, FLOW_OBJECT_NAME, desc );
97 }
98 
99 static inline void fgt_graph_desc( void *g, const char *desc ) {
100  itt_metadata_str_add( ITT_DOMAIN_FLOW, g, FLOW_GRAPH, FLOW_OBJECT_NAME, desc );
101 }
102 
103 static inline void fgt_body( void *node, void *body ) {
104  itt_relation_add( ITT_DOMAIN_FLOW, body, FLOW_BODY, __itt_relation_is_child_of, node, FLOW_NODE );
105 }
106 
107 template< int N, typename PortsTuple >
108 static inline void fgt_multioutput_node( string_index t, void *g, void *input_port, PortsTuple &ports ) {
109  itt_make_task_group( ITT_DOMAIN_FLOW, input_port, FLOW_NODE, g, FLOW_GRAPH, t );
110  fgt_internal_create_input_port( input_port, input_port, FLOW_INPUT_PORT_0 );
111  fgt_internal_output_helper<PortsTuple, N>::register_port( input_port, ports );
112 }
113 
114 template< int N, typename PortsTuple >
115 static inline void fgt_multioutput_node_with_body( string_index t, void *g, void *input_port, PortsTuple &ports, void *body ) {
116  itt_make_task_group( ITT_DOMAIN_FLOW, input_port, FLOW_NODE, g, FLOW_GRAPH, t );
117  fgt_internal_create_input_port( input_port, input_port, FLOW_INPUT_PORT_0 );
118  fgt_internal_output_helper<PortsTuple, N>::register_port( input_port, ports );
119  fgt_body( input_port, body );
120 }
121 
122 template< int N, typename PortsTuple >
123 static inline void fgt_multiinput_node( string_index t, void *g, PortsTuple &ports, void *output_port) {
124  itt_make_task_group( ITT_DOMAIN_FLOW, output_port, FLOW_NODE, g, FLOW_GRAPH, t );
125  fgt_internal_create_output_port( output_port, output_port, FLOW_OUTPUT_PORT_0 );
126  fgt_internal_input_helper<PortsTuple, N>::register_port( output_port, ports );
127 }
128 
129 static inline void fgt_node( string_index t, void *g, void *output_port ) {
130  itt_make_task_group( ITT_DOMAIN_FLOW, output_port, FLOW_NODE, g, FLOW_GRAPH, t );
131  fgt_internal_create_output_port( output_port, output_port, FLOW_OUTPUT_PORT_0 );
132 }
133 
134 static inline void fgt_node_with_body( string_index t, void *g, void *output_port, void *body ) {
135  itt_make_task_group( ITT_DOMAIN_FLOW, output_port, FLOW_NODE, g, FLOW_GRAPH, t );
136  fgt_internal_create_output_port( output_port, output_port, FLOW_OUTPUT_PORT_0 );
137  fgt_body( output_port, body );
138 }
139 
140 
141 static inline void fgt_node( string_index t, void *g, void *input_port, void *output_port ) {
142  fgt_node( t, g, output_port );
143  fgt_internal_create_input_port( output_port, input_port, FLOW_INPUT_PORT_0 );
144 }
145 
146 static inline void fgt_node_with_body( string_index t, void *g, void *input_port, void *output_port, void *body ) {
147  fgt_node_with_body( t, g, output_port, body );
148  fgt_internal_create_input_port( output_port, input_port, FLOW_INPUT_PORT_0 );
149 }
150 
151 
152 static inline void fgt_node( string_index t, void *g, void *input_port, void *decrement_port, void *output_port ) {
153  fgt_node( t, g, input_port, output_port );
154  fgt_internal_create_input_port( output_port, decrement_port, FLOW_INPUT_PORT_1 );
155 }
156 
157 static inline void fgt_make_edge( void *output_port, void *input_port ) {
158  itt_relation_add( ITT_DOMAIN_FLOW, output_port, FLOW_OUTPUT_PORT, __itt_relation_is_predecessor_to, input_port, FLOW_INPUT_PORT);
159 }
160 
161 static inline void fgt_remove_edge( void *output_port, void *input_port ) {
162  itt_relation_add( ITT_DOMAIN_FLOW, output_port, FLOW_OUTPUT_PORT, __itt_relation_is_sibling_of, input_port, FLOW_INPUT_PORT);
163 }
164 
165 static inline void fgt_graph( void *g ) {
166  itt_make_task_group( ITT_DOMAIN_FLOW, g, FLOW_GRAPH, NULL, FLOW_NULL, FLOW_GRAPH );
167 }
168 
169 static inline void fgt_begin_body( void *body ) {
170  itt_task_begin( ITT_DOMAIN_FLOW, body, FLOW_BODY, NULL, FLOW_NULL, FLOW_BODY );
171 }
172 
173 static inline void fgt_end_body( void * ) {
174  itt_task_end( ITT_DOMAIN_FLOW );
175 }
176 
177 static inline void fgt_async_try_put_begin( void *node, void *port ) {
178  itt_task_begin( ITT_DOMAIN_FLOW, port, FLOW_OUTPUT_PORT, node, FLOW_NODE, FLOW_OUTPUT_PORT );
179 }
180 
181 static inline void fgt_async_try_put_end( void *, void * ) {
182  itt_task_end( ITT_DOMAIN_FLOW );
183 }
184 
185 static inline void fgt_async_reserve( void *node, void *graph ) {
186  itt_region_begin( ITT_DOMAIN_FLOW, node, FLOW_NODE, graph, FLOW_GRAPH, FLOW_NULL );
187 }
188 
189 static inline void fgt_async_commit( void *node, void *graph ) {
190  itt_region_end( ITT_DOMAIN_FLOW, node, FLOW_NODE );
191 }
192 
193 #else // TBB_PREVIEW_FLOW_GRAPH_TRACE
194 
195 static inline void fgt_graph( void * /*g*/ ) { }
196 
197 template< typename NodeType >
198 static inline void fgt_multioutput_node_desc( const NodeType * /*node*/, const char * /*desc*/ ) { }
199 
200 template< typename NodeType >
201 static inline void fgt_node_desc( const NodeType * /*node*/, const char * /*desc*/ ) { }
202 
203 static inline void fgt_graph_desc( void * /*g*/, const char * /*desc*/ ) { }
204 
205 static inline void fgt_body( void * /*node*/, void * /*body*/ ) { }
206 
207 template< int N, typename PortsTuple >
208 static inline void fgt_multioutput_node( string_index /*t*/, void * /*g*/, void * /*input_port*/, PortsTuple & /*ports*/ ) { }
209 
210 template< int N, typename PortsTuple >
211 static inline void fgt_multioutput_node_with_body( string_index /*t*/, void * /*g*/, void * /*input_port*/, PortsTuple & /*ports*/, void * /*body*/ ) { }
212 
213 template< int N, typename PortsTuple >
214 static inline void fgt_multiinput_node( string_index /*t*/, void * /*g*/, PortsTuple & /*ports*/, void * /*output_port*/ ) { }
215 
216 static inline void fgt_node( string_index /*t*/, void * /*g*/, void * /*output_port*/ ) { }
217 static inline void fgt_node( string_index /*t*/, void * /*g*/, void * /*input_port*/, void * /*output_port*/ ) { }
218 static inline void fgt_node( string_index /*t*/, void * /*g*/, void * /*input_port*/, void * /*decrement_port*/, void * /*output_port*/ ) { }
219 
220 static inline void fgt_node_with_body( string_index /*t*/, void * /*g*/, void * /*output_port*/, void * /*body*/ ) { }
221 static inline void fgt_node_with_body( string_index /*t*/, void * /*g*/, void * /*input_port*/, void * /*output_port*/, void * /*body*/ ) { }
222 
223 static inline void fgt_make_edge( void * /*output_port*/, void * /*input_port*/ ) { }
224 static inline void fgt_remove_edge( void * /*output_port*/, void * /*input_port*/ ) { }
225 
226 static inline void fgt_begin_body( void * /*body*/ ) { }
227 static inline void fgt_end_body( void * /*body*/) { }
228 static inline void fgt_async_try_put_begin( void * /*node*/, void * /*port*/ ) { }
229 static inline void fgt_async_try_put_end( void * /*node*/ , void * /*port*/ ) { }
230 static inline void fgt_async_reserve( void * /*node*/, void * /*graph*/ ) { }
231 static inline void fgt_async_commit( void * /*node*/, void * /*graph*/ ) { }
232 
233 #endif // TBB_PREVIEW_FLOW_GRAPH_TRACE
234 
235  } // namespace internal
236 } // namespace tbb
237 
238 #endif
Pure virtual template class that defines a receiver of messages of type T.
Definition: flow_graph.h:103
Definition: _flow_graph_async_msg_impl.h:32
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
Pure virtual template class that defines a sender of messages of type T.
Definition: flow_graph.h:102