85 static const TypeInfo boolT = {mlir::IntegerType::getTypeID(), 1};
86 static const TypeInfo i4T = {mlir::IntegerType::getTypeID(), 4};
87 static const TypeInfo i8T = {mlir::IntegerType::getTypeID(), 8};
88 static const TypeInfo i16T = {mlir::IntegerType::getTypeID(), 16};
89 static const TypeInfo i32T = {mlir::IntegerType::getTypeID(), 32};
90 static const TypeInfo i48T = {mlir::IntegerType::getTypeID(), 48};
91 static const TypeInfo i64T = {mlir::IntegerType::getTypeID(), 64};
92 static const TypeInfo bf16T = {mlir::BFloat16Type::getTypeID(), 16};
93 static const TypeInfo fp16T = {mlir::Float16Type::getTypeID(), 16};
94 static const TypeInfo fp32T = {mlir::Float32Type::getTypeID(), 32};
95 static const TypeInfo fp8e4m3T = {mlir::Float8E4M3FNType::getTypeID(), 8};
96 static const TypeInfo fp8e5m2T = {mlir::Float8E5M2Type::getTypeID(), 8};
101 static const TypeInfo fp6e2m3T = {mlir::Float6E2M3FNType::getTypeID(), 6};
102 static const TypeInfo fp6e3m2T = {mlir::Float6E3M2FNType::getTypeID(), 6};
103 static const TypeInfo fp4e2m1T = {mlir::Float4E2M1FNType::getTypeID(), 4};
104 static const TypeInfo fp8ue8m0T = {mlir::Float8E8M0FNUType::getTypeID(), 8};
105 static const TypeInfo mxint8T = {mlir::tosa::mxint8Type::getTypeID(), 8};
108 const TypeID blockScaledID = mlir::tosa::BlockScaledType::getTypeID();
109 const TypeID fp4e2m1ID = mlir::Float4E2M1FNType::getTypeID();
110 const TypeID fp6e2m3ID = mlir::Float6E2M3FNType::getTypeID();
111 const TypeID fp6e3m2ID = mlir::Float6E3M2FNType::getTypeID();
112 const TypeID fp8e4m3ID = mlir::Float8E4M3FNType::getTypeID();
113 const TypeID fp8e5m2ID = mlir::Float8E5M2Type::getTypeID();
114 const TypeID fp8ue8m0ID = mlir::Float8E8M0FNUType::getTypeID();
115 const TypeID mxint8ID = mlir::tosa::mxint8Type::getTypeID();
117 static const TypeInfo bs32_fp8ue8m0_fp4e2m1T = {
118 blockScaledID, 4, fp4e2m1ID, fp8ue8m0ID,
119 tosa::BlockShape::BLOCK_SHAPE_32};
120 static const TypeInfo bs32_fp8ue8m0_fp6e2m3T = {
121 blockScaledID, 6, fp6e2m3ID, fp8ue8m0ID,
122 tosa::BlockShape::BLOCK_SHAPE_32};
123 static const TypeInfo bs32_fp8ue8m0_fp6e3m2T = {
124 blockScaledID, 6, fp6e3m2ID, fp8ue8m0ID,
125 tosa::BlockShape::BLOCK_SHAPE_32};
126 static const TypeInfo bs32_fp8ue8m0_fp8e4m3T = {
127 blockScaledID, 8, fp8e4m3ID, fp8ue8m0ID,
128 tosa::BlockShape::BLOCK_SHAPE_32};
129 static const TypeInfo bs32_fp8ue8m0_fp8e5m2T = {
130 blockScaledID, 8, fp8e5m2ID, fp8ue8m0ID,
131 tosa::BlockShape::BLOCK_SHAPE_32};
132 static const TypeInfo bs32_fp8ue8m0_mxint8T = {
133 blockScaledID, 8, mxint8ID, fp8ue8m0ID, tosa::BlockShape::BLOCK_SHAPE_32};
535 const auto maybeOpEntries = getOperatorMatchedEntries<T>(op);
536 if (failed(maybeOpEntries))
539 const auto opEntries = maybeOpEntries.value();
540 if (opEntries.size() == 0) {
556 const auto isVersionCompatible =
559 if (info.operandTypeInfoSet.empty())
562 info.operandTypeInfoSet.front().second};
566 for (
const auto &info : opEntries) {
570 if (isModeAllowed(info) && isVersionCompatible(info))
577 llvm::raw_string_ostream os(message);
580 const size_t numOpEntries = opEntries.size();
581 for (
const auto &[
index, info] : llvm::enumerate(opEntries)) {
582 bool mismatchedVersion =
false;
583 if (!isVersionCompatible(info)) {
584 mismatchedVersion =
true;
585 os <<
"requires specification version compatible with "
590 if (!isModeAllowed(info)) {
591 if (mismatchedVersion)
596 <<
"] profiles/extensions ";
599 if (
index != numOpEntries - 1)
602 os <<
"to be specified in the target environment";
620 const auto maybeProfEntries = getOperatorMatchedEntries<Profile>(op);
621 const auto maybeExtEntries = getOperatorMatchedEntries<Extension>(op);
622 if (failed(maybeProfEntries) && failed(maybeExtEntries))
625 const bool hasEntry =
626 (succeeded(maybeProfEntries) && !maybeProfEntries.value().empty()) ||
627 (succeeded(maybeExtEntries) && !maybeExtEntries.value().empty());
631 llvm::raw_string_ostream os(message);
632 os <<
"illegal: operation operand/result data types did not align with any "
633 "profile or extension, got (";
637 for (
const auto &typeInfo : llvm::drop_end(current))
646 const auto searchBestMatch = [&](
auto map) {
647 for (
const auto &complianceInfos : map[opName]) {
648 for (
const auto &versionedTypeInfos :
649 complianceInfos.operandTypeInfoSet) {
651 if (current.size() != typeInfos.size())
653 const int matches = llvm::count_if(
654 llvm::zip_equal(current, typeInfos), [&](
const auto zipType) {
656 std::get<1>(zipType));
658 if (matches > maxMatches) {
659 maxMatches = matches;
660 bestTypeInfo = typeInfos;
668 os <<
", did you mean (";
669 for (
const auto &typeInfo : llvm::drop_end(bestTypeInfo))
672 os <<
"Otherwise, please refer to the 'supported data types' for '"
673 << opName <<
"' in the specification.";
771 const auto stringifyScalarTypeInfo =
773 if (typeInfo.
typeID == mlir::IntegerType::getTypeID()) {
774 return {
"i" + llvm::utostr(typeInfo.
bitWidth)};
776 if (typeInfo.
typeID == mlir::Float16Type::getTypeID()) {
778 }
else if (typeInfo.
typeID == mlir::Float32Type::getTypeID()) {
780 }
else if (typeInfo.
typeID == mlir::BFloat16Type::getTypeID()) {
782 }
else if (typeInfo.
typeID == mlir::Float8E4M3FNType::getTypeID()) {
784 }
else if (typeInfo.
typeID == mlir::Float8E5M2Type::getTypeID()) {
786 }
else if (typeInfo.
typeID == mlir::Float6E2M3FNType::getTypeID()) {
788 }
else if (typeInfo.
typeID == mlir::Float6E3M2FNType::getTypeID()) {
790 }
else if (typeInfo.
typeID == mlir::Float4E2M1FNType::getTypeID()) {
792 }
else if (typeInfo.
typeID == mlir::Float8E8M0FNUType::getTypeID()) {
794 }
else if (typeInfo.
typeID == tosa::mxint8Type::getTypeID()) {
797 llvm_unreachable(
"unknown type");
800 if (typeInfo.
typeID == tosa::BlockScaledType::getTypeID()) {
804 llvm::raw_svector_ostream os(
result);
806 << tosa::BlockShapeAttr::getBlockShapeValue(typeInfo.
blockShape.value())
807 <<
"_" << stringifyScalarTypeInfo(scaleInfo) <<
"_"
808 << stringifyScalarTypeInfo(valueInfo);
812 return stringifyScalarTypeInfo(typeInfo);