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::MXI8Type::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::MXI8Type::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};
536 const auto maybeOpEntries = getOperatorMatchedEntries<T>(op);
537 if (failed(maybeOpEntries))
540 const auto &opEntries = maybeOpEntries.value();
541 if (opEntries.size() == 0) {
557 const auto isVersionCompatible =
560 if (info.operandTypeInfoSet.empty())
563 info.operandTypeInfoSet.front().second};
567 for (
const auto &info : opEntries) {
571 if (isModeAllowed(info) && isVersionCompatible(info))
578 llvm::raw_string_ostream os(message);
581 const size_t numOpEntries = opEntries.size();
582 for (
const auto &[
index, info] : llvm::enumerate(opEntries)) {
583 bool mismatchedVersion =
false;
584 if (!isVersionCompatible(info)) {
585 mismatchedVersion =
true;
586 os <<
"requires specification version compatible with "
591 if (!isModeAllowed(info)) {
592 if (mismatchedVersion)
597 <<
"] profiles/extensions ";
600 if (
index != numOpEntries - 1)
603 os <<
"to be specified in the target environment";
621 const auto maybeProfEntries = getOperatorMatchedEntries<Profile>(op);
622 const auto maybeExtEntries = getOperatorMatchedEntries<Extension>(op);
623 if (failed(maybeProfEntries) && failed(maybeExtEntries))
626 const bool hasEntry =
627 (succeeded(maybeProfEntries) && !maybeProfEntries.value().empty()) ||
628 (succeeded(maybeExtEntries) && !maybeExtEntries.value().empty());
632 llvm::raw_string_ostream os(message);
633 os <<
"illegal: operation operand/result data types did not align with any "
634 "profile or extension, got (";
638 for (
const auto &typeInfo : llvm::drop_end(current))
647 const auto searchBestMatch = [&](
const auto &map) {
648 const auto it = map.find(opName);
651 for (
const auto &complianceInfos : it->second) {
652 for (
const auto &versionedTypeInfos :
653 complianceInfos.operandTypeInfoSet) {
655 if (current.size() != typeInfos.size())
657 const int matches = llvm::count_if(
658 llvm::zip_equal(current, typeInfos), [&](
const auto zipType) {
660 std::get<1>(zipType));
662 if (matches > maxMatches) {
663 maxMatches = matches;
664 bestTypeInfo = typeInfos;
672 os <<
", did you mean (";
673 for (
const auto &typeInfo : llvm::drop_end(bestTypeInfo))
676 os <<
"Otherwise, please refer to the 'supported data types' for '"
677 << opName <<
"' in the specification.";
773 const auto stringifyScalarTypeInfo =
775 if (typeInfo.
typeID == mlir::IntegerType::getTypeID()) {
776 return {
"i" + llvm::utostr(typeInfo.
bitWidth)};
778 if (typeInfo.
typeID == mlir::Float16Type::getTypeID()) {
780 }
else if (typeInfo.
typeID == mlir::Float32Type::getTypeID()) {
782 }
else if (typeInfo.
typeID == mlir::BFloat16Type::getTypeID()) {
784 }
else if (typeInfo.
typeID == mlir::Float8E4M3FNType::getTypeID()) {
786 }
else if (typeInfo.
typeID == mlir::Float8E5M2Type::getTypeID()) {
788 }
else if (typeInfo.
typeID == mlir::Float6E2M3FNType::getTypeID()) {
790 }
else if (typeInfo.
typeID == mlir::Float6E3M2FNType::getTypeID()) {
792 }
else if (typeInfo.
typeID == mlir::Float4E2M1FNType::getTypeID()) {
794 }
else if (typeInfo.
typeID == mlir::Float8E8M0FNUType::getTypeID()) {
796 }
else if (typeInfo.
typeID == MXI8Type::getTypeID()) {
799 llvm_unreachable(
"unknown type");
802 if (typeInfo.
typeID == tosa::BlockScaledType::getTypeID()) {
806 llvm::raw_svector_ostream os(
result);
808 << tosa::BlockShapeAttr::getBlockShapeValue(typeInfo.
blockShape.value())
809 <<
"_" << stringifyScalarTypeInfo(scaleInfo) <<
"_"
810 << stringifyScalarTypeInfo(valueInfo);
814 return stringifyScalarTypeInfo(typeInfo);