From aa7e77ee64160bfc4acf9281efd11b284facf411 Mon Sep 17 00:00:00 2001 From: "Xida Ren (Cedar)" Date: Wed, 25 Sep 2024 12:32:26 -0400 Subject: [PATCH] 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 https://github.com/llvm/torch-mlir/issues/3720, at least for unsigned integer issues. --- lib/Dialect/Torch/Utils/Utils.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Dialect/Torch/Utils/Utils.cpp b/lib/Dialect/Torch/Utils/Utils.cpp index 988df760d..3d842f44a 100644 --- a/lib/Dialect/Torch/Utils/Utils.cpp +++ b/lib/Dialect/Torch/Utils/Utils.cpp @@ -90,7 +90,28 @@ torch_upstream::ScalarType Torch::getScalarTypeForType(Type type) { return torch_upstream::ScalarType::Float8_e5m2fnuz; if (isa(type)) return torch_upstream::ScalarType::Float8_e4m3fnuz; - llvm::report_fatal_error("unhandled type for getScalarTypeForType"); + std::string errorMsg = "Unhandled type in getScalarTypeForType: "; + llvm::raw_string_ostream os(errorMsg); + type.print(os); + // os << "\nType ID: " << type.getTypeID(); + os << "\nType properties:"; + os << "\n Is integer: " << (type.isInteger() ? "yes" : "no"); + os << "\n Is float: " + << (type.isIntOrFloat() && !type.isInteger() ? "yes" : "no"); + os << "\n Is index: " << (type.isIndex() ? "yes" : "no"); + os << "\n Bit width: " + << (type.isIntOrFloat() ? std::to_string(type.getIntOrFloatBitWidth()) + : "N/A"); + os << "\n Is signless: " << (type.isSignlessInteger() ? "yes" : "no"); + os << "\n Is signed: " << (type.isSignedInteger() ? "yes" : "no"); + // special error message for unsigned integer + if (type.isUnsignedInteger()) { + os << "\n Is unsigned: yes"; + os << "\nUnsigned integer support is currently spotty. Please seeheck " + "https://github.com/llvm/torch-mlir/issues/3720 " + "for more details."; + } + llvm::report_fatal_error(llvm::StringRef(errorMsg)); } Type Torch::getTypeForTorchType( MLIRContext *context, Type type,