Skip to content

Commit 6bf85ea

Browse files
Improved logging for auto opaque
1 parent 7b42ffa commit 6bf85ea

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/python/freeze.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,28 @@ std::ostream &operator<<(std::ostream &os, const FlatVariables &r) {
12601260
return os;
12611261
}
12621262

1263+
bool log_diff_variable(LogLevel level, const FlatVariables &curr,
1264+
const FlatVariables &prev, std::string &path,
1265+
uint32_t slot) {
1266+
const VarLayout &curr_l = curr.var_layout[slot];
1267+
const VarLayout &prev_l = prev.var_layout[slot];
1268+
1269+
if(curr_l.vt != prev_l.vt){
1270+
jit_log(level, "%s: The variable type changed from %u to %u.",
1271+
path.c_str(), prev_l.vt, curr_l.vt);
1272+
return false;
1273+
}
1274+
if(curr_l.size_index != prev_l.size_index){
1275+
jit_log(level,
1276+
"%s: The size equivalence class of the variable changed from "
1277+
"%u to %u.",
1278+
path.c_str(), prev_l.size_index, curr_l.size_index);
1279+
return false;
1280+
}
1281+
1282+
return true;
1283+
}
1284+
12631285
/**
12641286
* Log the difference of the layout nodes at ``index`` for the two FlatVariables.
12651287
*/
@@ -1270,6 +1292,28 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
12701292
const Layout &prev_l = prev.layout[index];
12711293
index++;
12721294

1295+
if (curr_l.flags != prev_l.flags) {
1296+
jit_log(level, "%s: The flags of this node changed from 0x%lx to 0x%lx",
1297+
path.c_str(), prev_l.flags, curr_l.flags);
1298+
return false;
1299+
}
1300+
1301+
if (curr_l.index != prev_l.index) {
1302+
jit_log(level,
1303+
"%s: The index into the array of deduplicated variables "
1304+
"changed from s%u to s%u. This can occur if two variables "
1305+
"referred to the same JIT index, but do no longer.",
1306+
path.c_str(), prev_l.index, curr_l.index);
1307+
return false;
1308+
}
1309+
1310+
if (curr_l.flags & (uint32_t) LayoutFlag::JitIndex &&
1311+
!(curr_l.flags & (uint32_t) LayoutFlag::Literal)) {
1312+
uint32_t slot = curr_l.index;
1313+
if (!log_diff_variable(level, curr, prev, path, slot))
1314+
return false;
1315+
}
1316+
12731317
if (((bool) curr_l.type != (bool) prev_l.type) ||
12741318
!(curr_l.type.equal(prev_l.type))) {
12751319
jit_log(level, "%s: The type of this node changed from %s to %s",
@@ -1369,6 +1413,13 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
13691413
prev.layout.size(), curr.layout.size());
13701414
return false;
13711415
}
1416+
if(curr.var_layout.size() != prev.var_layout.size()){
1417+
jit_log(level,
1418+
"The number of opaque variables in the input changed from %u "
1419+
"to %u.",
1420+
prev.layout.size(), curr.layout.size());
1421+
return false;
1422+
}
13721423

13731424
uint32_t index = 0;
13741425
std::string path;
@@ -1689,6 +1740,16 @@ nb::object FrozenFunction::operator()(nb::args args, nb::kwargs kwargs) {
16891740
// If new variables have been discovered that should be made
16901741
// opaque, we repeat traversal of the input to make them opaque.
16911742
// This reduces the number of variants that are saved by one.
1743+
jit_log(LogLevel::Warn,
1744+
"While traversing the frozen function input, new "
1745+
"literal variables have been discovered which changed "
1746+
"from one call to another. These will be made opaque, "
1747+
"and the input will be traversed again. This will "
1748+
"incur some overhead. To prevent this, make those "
1749+
"variables opaque in beforehand. Below, a list of "
1750+
"variables that changed will be shown.");
1751+
if (prev_key)
1752+
log_diff(LogLevel::Warn, *in_variables, *prev_key);
16921753
in_variables->release();
16931754
in_variables = std::make_shared<FlatVariables>(
16941755
FlatVariables(in_heuristics));

0 commit comments

Comments
 (0)