From 5394db1c58593550bbf4f7b08671a52c0191ff52 Mon Sep 17 00:00:00 2001 From: Xida Ren Date: Wed, 25 Sep 2024 16:17:04 +0000 Subject: [PATCH 1/3] Better error message upon getScalarTypeForType failure --- lib/Dialect/Torch/Utils/Utils.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Dialect/Torch/Utils/Utils.cpp b/lib/Dialect/Torch/Utils/Utils.cpp index eb8b37502efc..d7b11a505f84 100644 --- a/lib/Dialect/Torch/Utils/Utils.cpp +++ b/lib/Dialect/Torch/Utils/Utils.cpp @@ -90,7 +90,19 @@ 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"); + llvm::report_fatal_error(llvm::StringRef(errorMsg)); } Type Torch::getTypeForTorchType( MLIRContext *context, Type type, From f45ef2f4fb4fd80435fd2b1aa322124d7bf8575a Mon Sep 17 00:00:00 2001 From: Xida Ren Date: Wed, 25 Sep 2024 16:19:26 +0000 Subject: [PATCH 2/3] add a little bit more to the errmsg --- lib/Dialect/Torch/Utils/Utils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Dialect/Torch/Utils/Utils.cpp b/lib/Dialect/Torch/Utils/Utils.cpp index d7b11a505f84..c87481e8e997 100644 --- a/lib/Dialect/Torch/Utils/Utils.cpp +++ b/lib/Dialect/Torch/Utils/Utils.cpp @@ -102,6 +102,8 @@ torch_upstream::ScalarType Torch::getScalarTypeForType(Type type) { 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"); llvm::report_fatal_error(llvm::StringRef(errorMsg)); } Type Torch::getTypeForTorchType( From a2a557805b9ed0f8323c8d98035b30441eba9d91 Mon Sep 17 00:00:00 2001 From: Xida Ren Date: Wed, 25 Sep 2024 16:23:08 +0000 Subject: [PATCH 3/3] add message for unsigned integers --- lib/Dialect/Torch/Utils/Utils.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Dialect/Torch/Utils/Utils.cpp b/lib/Dialect/Torch/Utils/Utils.cpp index c87481e8e997..38f32eefbf4c 100644 --- a/lib/Dialect/Torch/Utils/Utils.cpp +++ b/lib/Dialect/Torch/Utils/Utils.cpp @@ -104,6 +104,13 @@ torch_upstream::ScalarType Torch::getScalarTypeForType(Type type) { : "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(