Skip to content

Commit aa7e77e

Browse files
authored
Better errmsg upon getScalarTypeForType failure (#3734)
Instead of `Unhandled type in getScalarTypeForType` You now get Unhandled type in getScalarTypeForType: (type name) Type properties: Is integer: yes Bit width: ... The root cause is #3720, at least for unsigned integer issues.
1 parent 6773288 commit aa7e77e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/Dialect/Torch/Utils/Utils.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,28 @@ torch_upstream::ScalarType Torch::getScalarTypeForType(Type type) {
9090
return torch_upstream::ScalarType::Float8_e5m2fnuz;
9191
if (isa<Float8E4M3FNUZType>(type))
9292
return torch_upstream::ScalarType::Float8_e4m3fnuz;
93-
llvm::report_fatal_error("unhandled type for getScalarTypeForType");
93+
std::string errorMsg = "Unhandled type in getScalarTypeForType: ";
94+
llvm::raw_string_ostream os(errorMsg);
95+
type.print(os);
96+
// os << "\nType ID: " << type.getTypeID();
97+
os << "\nType properties:";
98+
os << "\n Is integer: " << (type.isInteger() ? "yes" : "no");
99+
os << "\n Is float: "
100+
<< (type.isIntOrFloat() && !type.isInteger() ? "yes" : "no");
101+
os << "\n Is index: " << (type.isIndex() ? "yes" : "no");
102+
os << "\n Bit width: "
103+
<< (type.isIntOrFloat() ? std::to_string(type.getIntOrFloatBitWidth())
104+
: "N/A");
105+
os << "\n Is signless: " << (type.isSignlessInteger() ? "yes" : "no");
106+
os << "\n Is signed: " << (type.isSignedInteger() ? "yes" : "no");
107+
// special error message for unsigned integer
108+
if (type.isUnsignedInteger()) {
109+
os << "\n Is unsigned: yes";
110+
os << "\nUnsigned integer support is currently spotty. Please seeheck "
111+
"https://github.com/llvm/torch-mlir/issues/3720 "
112+
"for more details.";
113+
}
114+
llvm::report_fatal_error(llvm::StringRef(errorMsg));
94115
}
95116
Type Torch::getTypeForTorchType(
96117
MLIRContext *context, Type type,

0 commit comments

Comments
 (0)