Skip to content

Commit 9a7115e

Browse files
Improved logging for auto opaque
1 parent 5e28fe7 commit 9a7115e

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
@@ -1238,6 +1238,28 @@ std::ostream &operator<<(std::ostream &os, const FlatVariables &r) {
12381238
return os;
12391239
}
12401240

1241+
bool log_diff_variable(LogLevel level, const FlatVariables &curr,
1242+
const FlatVariables &prev, std::string &path,
1243+
uint32_t slot) {
1244+
const VarLayout &curr_l = curr.var_layout[slot];
1245+
const VarLayout &prev_l = prev.var_layout[slot];
1246+
1247+
if(curr_l.vt != prev_l.vt){
1248+
jit_log(level, "%s: The variable type changed from %u to %u.",
1249+
path.c_str(), prev_l.vt, curr_l.vt);
1250+
return false;
1251+
}
1252+
if(curr_l.size_index != prev_l.size_index){
1253+
jit_log(level,
1254+
"%s: The size equivalence class of the variable changed from "
1255+
"%u to %u.",
1256+
path.c_str(), prev_l.size_index, curr_l.size_index);
1257+
return false;
1258+
}
1259+
1260+
return true;
1261+
}
1262+
12411263
/**
12421264
* Log the difference of the layout nodes at ``index`` for the two FlatVariables.
12431265
*/
@@ -1248,6 +1270,28 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
12481270
const Layout &prev_l = prev.layout[index];
12491271
index++;
12501272

1273+
if (curr_l.flags != prev_l.flags) {
1274+
jit_log(level, "%s: The flags of this node changed from 0x%lx to 0x%lx",
1275+
path.c_str(), prev_l.flags, curr_l.flags);
1276+
return false;
1277+
}
1278+
1279+
if (curr_l.index != prev_l.index) {
1280+
jit_log(level,
1281+
"%s: The index into the array of deduplicated variables "
1282+
"changed from s%u to s%u. This can occur if two variables "
1283+
"referred to the same JIT index, but do no longer.",
1284+
path.c_str(), prev_l.index, curr_l.index);
1285+
return false;
1286+
}
1287+
1288+
if (curr_l.flags & (uint32_t) LayoutFlag::JitIndex &&
1289+
!(curr_l.flags & (uint32_t) LayoutFlag::Literal)) {
1290+
uint32_t slot = curr_l.index;
1291+
if (!log_diff_variable(level, curr, prev, path, slot))
1292+
return false;
1293+
}
1294+
12511295
if (((bool) curr_l.type != (bool) prev_l.type) ||
12521296
!(curr_l.type.equal(prev_l.type))) {
12531297
jit_log(level, "%s: The type of this node changed from %s to %s",
@@ -1347,6 +1391,13 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
13471391
prev.layout.size(), curr.layout.size());
13481392
return false;
13491393
}
1394+
if(curr.var_layout.size() != prev.var_layout.size()){
1395+
jit_log(level,
1396+
"The number of opaque variables in the input changed from %u "
1397+
"to %u.",
1398+
prev.layout.size(), curr.layout.size());
1399+
return false;
1400+
}
13501401

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

0 commit comments

Comments
 (0)