@@ -40,6 +40,14 @@ namespace gen_pattern {
40
40
41
41
#ifdef CPU_DEBUG_CAPS
42
42
43
+ # ifdef __GNUC__
44
+ # define CURRENT_LINE_NO __builtin_LINE ()
45
+ # define CURRENT_FILE __builtin_FILE ()
46
+ # else
47
+ # define CURRENT_LINE_NO -1
48
+ # define CURRENT_FILE " "
49
+ # endif
50
+
43
51
template <typename ... Args>
44
52
static inline void _verbose_log (Args&&... args) {
45
53
std::stringstream ss;
@@ -58,6 +66,10 @@ static bool matcher_verbose_enabled() {
58
66
if (matcher_verbose_enabled()) \
59
67
_verbose_log (__VA_ARGS__)
60
68
#else
69
+
70
+ # define CURRENT_LINE_NO -1
71
+ # define CURRENT_FILE " "
72
+
61
73
static bool matcher_verbose_enabled () {
62
74
return false ;
63
75
}
@@ -181,6 +193,8 @@ class Symbol {
181
193
double literal_const_value;
182
194
std::shared_ptr<Entity> lhs;
183
195
std::shared_ptr<Entity> rhs;
196
+ const char * filename = " " ;
197
+ int line_no = -1 ;
184
198
// _,+,-,*,/
185
199
// l : literal const
186
200
// n : named symbol
@@ -220,10 +234,12 @@ class Symbol {
220
234
entity->op = ' n' ;
221
235
entity->name = name;
222
236
}
223
- Symbol (const int value) {
237
+ Symbol (const int value, int line_no = CURRENT_LINE_NO, const char * file = CURRENT_FILE ) {
224
238
entity = std::make_shared<Entity>();
225
239
entity->op = ' l' ;
226
240
entity->literal_const_value = value;
241
+ entity->line_no = line_no;
242
+ entity->filename = file;
227
243
}
228
244
Symbol (char op, const Symbol& lhs, const Symbol& rhs) {
229
245
entity = std::make_shared<Entity>();
@@ -246,8 +262,12 @@ class Symbol {
246
262
void * get_id () const {
247
263
return entity.get ();
248
264
}
249
- const char * get_name () const {
250
- return entity->name ;
265
+ std::string get_name () const {
266
+ if (entity->line_no == -1 || is_independent_var ())
267
+ return entity->name ;
268
+ auto filename = strrchr (entity->filename , ' /' ) ? strrchr (entity->filename , ' /' ) + 1 : entity->filename ;
269
+ std::string name (filename); // use filename:lineno instead
270
+ return name + " :" + std::to_string (entity->line_no );
251
271
}
252
272
bool operator <(const Symbol& rhs) const {
253
273
return get_id () < rhs.get_id ();
@@ -739,7 +759,9 @@ class GenericPattern : public ov::pass::pattern::op::Pattern {
739
759
explicit GenericPattern (const DiscreteTypeInfo& type_info,
740
760
const OutputVector& args,
741
761
const detail::AttrMap& attrs,
742
- const char * vt)
762
+ const char * vt,
763
+ const int line_no = -1 ,
764
+ const char * file = " " )
743
765
: ov::pass::pattern::op::Pattern(args),
744
766
m_type_info(type_info),
745
767
m_attrs(attrs),
@@ -758,6 +780,12 @@ class GenericPattern : public ov::pass::pattern::op::Pattern {
758
780
sep = " ," ;
759
781
}
760
782
ss << " )" ;
783
+ if (line_no != -1 ) {
784
+ // add the code line no to the log:
785
+ // O P752<opset1::Multiply>(P736,P745)@fuse_rotary_positional_embeddings.cpp:551 vs ...
786
+ auto filename = strrchr (file, ' /' ) ? strrchr (file, ' /' ) + 1 : file;
787
+ ss << " @" << filename << " :" << line_no;
788
+ }
761
789
m_signature = ss.str ();
762
790
set_friendly_name (std::string (" P" ) + std::to_string (id));
763
791
}
@@ -776,7 +804,13 @@ class GenericPattern : public ov::pass::pattern::op::Pattern {
776
804
// strictly requires pattern & graph value to come from output port with same index,
777
805
// this is absolute necessary when pattern contains split node connections.
778
806
if (pattern_value.get_index () != graph_value.get_index ()) {
779
- _VERBOSE_LOG (level, " X output index mismatch: " , pattern_value.get_index (), " !=" , graph_value.get_index ());
807
+ _VERBOSE_LOG (level,
808
+ " X output index mismatch:(" ,
809
+ m_signature,
810
+ " ): " ,
811
+ pattern_value.get_index (),
812
+ " !=" ,
813
+ graph_value.get_index ());
780
814
return false ;
781
815
}
782
816
@@ -1018,15 +1052,18 @@ template <class T>
1018
1052
std::shared_ptr<Node> makePattern (const std::vector<detail::PatternNode>& inputs,
1019
1053
detail::AttrMap attrmap = {},
1020
1054
const char * vt = nullptr ,
1021
- const char * friendly_name = nullptr ) {
1055
+ const char * friendly_name = nullptr ,
1056
+ int line_no = CURRENT_LINE_NO,
1057
+ const char * file = CURRENT_FILE) {
1022
1058
OutputVector args;
1023
1059
for (auto & in : inputs)
1024
1060
args.push_back (in.get_output ());
1025
1061
1026
1062
// pattern nodes are better for pattern matching because
1027
1063
// - it can be generic/incomplete, so normal OP node is not working properly
1028
1064
// - it has predicate to correctly decide which branch to take (in Or pattern)
1029
- auto pattern_node = std::make_shared<detail::GenericPattern>(T::get_type_info_static (), args, attrmap, vt);
1065
+ auto pattern_node =
1066
+ std::make_shared<detail::GenericPattern>(T::get_type_info_static (), args, attrmap, vt, line_no, file);
1030
1067
1031
1068
if (friendly_name)
1032
1069
pattern_node->set_friendly_name (friendly_name);
@@ -1120,7 +1157,9 @@ inline std::shared_ptr<Node> GenStridedSlice(detail::PatternNode data,
1120
1157
detail::PatternNode start,
1121
1158
detail::PatternNode stop,
1122
1159
detail::PatternNode step,
1123
- size_t axis) {
1160
+ size_t axis,
1161
+ int line_no = CURRENT_LINE_NO,
1162
+ const char * file = CURRENT_FILE) {
1124
1163
std::vector<int64_t > begin_mask (axis + 1 , 1 );
1125
1164
std::vector<int64_t > end_mask (axis + 1 , 1 );
1126
1165
std::vector<int64_t > new_axis_mask;
@@ -1135,12 +1174,27 @@ inline std::shared_ptr<Node> GenStridedSlice(detail::PatternNode data,
1135
1174
{" end_mask" , end_mask},
1136
1175
{" new_axis_mask" , new_axis_mask},
1137
1176
{" shrink_axis_mask" , shrink_axis_mask},
1138
- {" ellipsis_mask" , ellipsis_mask}});
1177
+ {" ellipsis_mask" , ellipsis_mask}},
1178
+ nullptr ,
1179
+ nullptr ,
1180
+ line_no,
1181
+ file);
1139
1182
return opt2;
1140
1183
}
1141
1184
1142
- inline std::shared_ptr<Node> GenSlice (detail::PatternNode data, Symbol start, Symbol stop, Symbol step, size_t axis) {
1143
- auto opt1 = makePattern<opset8::Slice>({data, {start}, {stop}, {step}, {static_cast <int >(axis)}});
1185
+ inline std::shared_ptr<Node> GenSlice (detail::PatternNode data,
1186
+ Symbol start,
1187
+ Symbol stop,
1188
+ Symbol step,
1189
+ size_t axis,
1190
+ int line_no = CURRENT_LINE_NO,
1191
+ const char * file = CURRENT_FILE) {
1192
+ auto opt1 = makePattern<opset8::Slice>({data, {start}, {stop}, {step}, {static_cast <int >(axis)}},
1193
+ {},
1194
+ nullptr ,
1195
+ nullptr ,
1196
+ line_no,
1197
+ file);
1144
1198
1145
1199
std::vector<Symbol> vbegin (axis + 1 , Symbol (0 ));
1146
1200
std::vector<Symbol> vend (axis + 1 , Symbol (0 ));
@@ -1168,7 +1222,11 @@ inline std::shared_ptr<Node> GenSlice(detail::PatternNode data, Symbol start, Sy
1168
1222
{" end_mask" , end_mask},
1169
1223
{" new_axis_mask" , new_axis_mask},
1170
1224
{" shrink_axis_mask" , shrink_axis_mask},
1171
- {" ellipsis_mask" , ellipsis_mask}});
1225
+ {" ellipsis_mask" , ellipsis_mask}},
1226
+ nullptr ,
1227
+ nullptr ,
1228
+ line_no,
1229
+ file);
1172
1230
return opt1 | opt2;
1173
1231
}
1174
1232
@@ -1329,7 +1387,9 @@ class PatternValidator {
1329
1387
auto id = sym.get_id ();
1330
1388
if (symbol_value_map.count (id)) {
1331
1389
if (symbol_value_map[id] != value) {
1332
- _VERBOSE_LOG (" in-consistency between multiple references of same symbol : " ,
1390
+ _VERBOSE_LOG (" in-consistency between multiple references of same symbol(" ,
1391
+ sym.get_name (),
1392
+ " ): " ,
1333
1393
symbol_value_map[id],
1334
1394
" != " ,
1335
1395
value);
@@ -1345,7 +1405,12 @@ class PatternValidator {
1345
1405
if (sym.is_literal_const ()) {
1346
1406
auto literal = sym.eval (symbol_value_map);
1347
1407
if (literal != value) {
1348
- _VERBOSE_LOG (" mismatch between literal symbol & value : " , literal, " != " , value);
1408
+ _VERBOSE_LOG (" mismatch between literal symbol & value(" ,
1409
+ sym.get_name (),
1410
+ " ): " ,
1411
+ literal,
1412
+ " != " ,
1413
+ value);
1349
1414
return false ;
1350
1415
}
1351
1416
// no need to put literal into value map to eval them.
@@ -1373,7 +1438,9 @@ class PatternValidator {
1373
1438
}
1374
1439
}
1375
1440
if (!is_match) {
1376
- _VERBOSE_LOG (" mismatch between derived & value : " ,
1441
+ _VERBOSE_LOG (" mismatch between derived & value(" ,
1442
+ sym.get_name (),
1443
+ " ): " ,
1377
1444
std::setprecision (std::numeric_limits<float >::max_digits10),
1378
1445
derived,
1379
1446
" != " ,
0 commit comments