Skip to content

Missing UInt support fo getScalarTypeForType #3720

Open
@renxida

Description

@renxida

torch_upstream::ScalarType Torch::getScalarTypeForType(Type type) {
if (isa<Float32Type>(type))
return torch_upstream::ScalarType::Float;
if (isa<Float64Type>(type))
return torch_upstream::ScalarType::Double;
if (type.isSignedInteger(64))
return torch_upstream::ScalarType::Long;
if (type.isSignedInteger(32))
return torch_upstream::ScalarType::Int;
if (type.isSignedInteger(16))
return torch_upstream::ScalarType::Short;
if (type.isSignlessInteger(1))
return torch_upstream::ScalarType::Bool;
if (type.isBF16())
return torch_upstream::ScalarType::BFloat16;
if (type.isF16())
return torch_upstream::ScalarType::Half;
if (type.isUnsignedInteger(8))
return torch_upstream::ScalarType::Byte;
if (type.isSignedInteger(8))
return torch_upstream::ScalarType::Char;
if (isa<QUInt8Type>(type))
return torch_upstream::ScalarType::QUInt8;
if (isa<QInt8Type>(type))
return torch_upstream::ScalarType::QInt8;
if (isa<QInt16Type>(type))
return torch_upstream::ScalarType::QInt16;
if (isa<QInt32Type>(type))
return torch_upstream::ScalarType::QInt32;
if (isa<ComplexType>(type)) {
mlir::Type complexElemType = cast<ComplexType>(type).getElementType();
if (complexElemType.isF16())
return torch_upstream::ScalarType::ComplexHalf;
if (complexElemType.isF32())
return torch_upstream::ScalarType::ComplexFloat;
if (complexElemType.isF64())
return torch_upstream::ScalarType::ComplexDouble;
}
if (isa<Float8E5M2Type>(type))
return torch_upstream::ScalarType::Float8_e5m2;
if (isa<Float8E4M3FNType>(type))
return torch_upstream::ScalarType::Float8_e4m3fn;
if (isa<Float8E5M2FNUZType>(type))
return torch_upstream::ScalarType::Float8_e5m2fnuz;
if (isa<Float8E4M3FNUZType>(type))
return torch_upstream::ScalarType::Float8_e4m3fnuz;
llvm::report_fatal_error("unhandled type for getScalarTypeForType");
}
Type Torch::getTypeForTorchType(
MLIRContext *context, Type type,
mlir::IntegerType::SignednessSemantics signedness) {
if (isa<Torch::IntType>(type))
return IntegerType::get(context, 64, signedness);
if (isa<Torch::FloatType>(type))

As seen here, we don't have support for getScalarTypeForType. Also, the error message not very informative: it just says unhandled type for getScalarTypeForType without specifying what the unsupported type is.

Implementing this also requires modifying this ScalarType enum in TorchUpstream.h:

#define AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(_) \
_(uint8_t, Byte) /* 0 */ \
_(int8_t, Char) /* 1 */ \
_(int16_t, Short) /* 2 */ \
_(int, Int) /* 3 */ \
_(int64_t, Long) /* 4 */ \
_(at::Half, Half) /* 5 */ \
_(float, Float) /* 6 */ \
_(double, Double) /* 7 */ \
_(c10::complex<c10::Half>, ComplexHalf) /* 8 */ \
_(c10::complex<float>, ComplexFloat) /* 9 */ \

which is not up to date compared to the ScalarType.h in the pytorch/pytorch repo:
https://github.com/pytorch/pytorch/blob/main/c10/core/ScalarType.h#L84-L93

Related issue where this prevents supporting certain onnx dtypes: #3255

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions