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};
575 const ProfileRange &profiles,
576 const ExtensionRange &extensions) {
579 llvm::raw_string_ostream os(message);
583 const auto gatherVersions = [&versions](
const auto &entries) {
584 for (
const auto &info : entries) {
585 if (info.operandTypeInfoSet.empty())
587 const SpecificationVersion version =
588 info.operandTypeInfoSet.front().second;
589 if (!llvm::is_contained(versions, version))
590 versions.push_back(version);
593 gatherVersions(profiles);
594 gatherVersions(extensions);
596 if (versions.empty()) {
598 const bool requiresProfile =
611 [&](SpecificationVersion version) {
612 const bool incompatible =
615 os <<
"requires specification version compatible with "
620 const bool requiresProfile =
622 if (requiresProfile) {
628 if (incompatible || requiresProfile)
635 os <<
"to be specified in the target environment";
643 const auto profiles = getOperatorMatchedEntries<Profile>(op).value_or(
645 const auto extensions = getOperatorMatchedEntries<Extension>(op).value_or(
651 const auto hasNoComplianceEntries = [](
const auto &info) {
652 return info.operandTypeInfoSet.empty();
654 const auto untypedComplianceProfiles =
655 llvm::make_filter_range(profiles, hasNoComplianceEntries);
656 const auto untypedComplianceExtensions =
657 llvm::make_filter_range(extensions, hasNoComplianceEntries);
660 const bool mandatoryConstraintsLegal =
663 if (!mandatoryConstraintsLegal)
665 untypedComplianceExtensions);
668 const auto hasComplianceEntries =
669 [&hasNoComplianceEntries](
const auto &info) {
670 return !hasNoComplianceEntries(info);
672 const auto typedComplianceProfiles =
673 llvm::make_filter_range(profiles, hasComplianceEntries);
674 const auto typedComplianceExtensions =
675 llvm::make_filter_range(extensions, hasComplianceEntries);
688 const auto hasLegalEntry = [&targetVersion,
689 &targetEnv](
const auto &candidates,
690 const auto &counterpartCandidates) {
691 return llvm::any_of(candidates, [&](
const auto &candidate) {
692 const auto version = candidate.operandTypeInfoSet.front().second;
699 if ((typedComplianceProfiles.empty() && typedComplianceExtensions.empty()) ||
700 hasLegalEntry(typedComplianceProfiles, typedComplianceExtensions) ||
701 hasLegalEntry(typedComplianceExtensions, typedComplianceProfiles))
705 typedComplianceExtensions);
709 const auto maybeProfEntries = getOperatorMatchedEntries<Profile>(op);
710 const auto maybeExtEntries = getOperatorMatchedEntries<Extension>(op);
711 if (failed(maybeProfEntries) && failed(maybeExtEntries))
714 const bool hasEntry =
715 (succeeded(maybeProfEntries) && !maybeProfEntries.value().empty()) ||
716 (succeeded(maybeExtEntries) && !maybeExtEntries.value().empty());
720 llvm::raw_string_ostream os(message);
721 os <<
"illegal: operation operand/result data types did not align with any "
722 "profile or extension, got (";
726 for (
const auto &typeInfo : llvm::drop_end(current))
735 const auto searchBestMatch = [&](
const auto &map) {
736 const auto it = map.find(opName);
739 for (
const auto &complianceInfos : it->second) {
740 for (
const auto &versionedTypeInfos :
741 complianceInfos.operandTypeInfoSet) {
743 if (current.size() != typeInfos.size())
745 const int matches = llvm::count_if(
746 llvm::zip_equal(current, typeInfos), [&](
const auto zipType) {
748 std::get<1>(zipType));
750 if (matches > maxMatches) {
751 maxMatches = matches;
752 bestTypeInfo = typeInfos;
760 os <<
", did you mean (";
761 for (
const auto &typeInfo : llvm::drop_end(bestTypeInfo))
764 os <<
"Otherwise, please refer to the 'supported data types' for '"
765 << opName <<
"' in the specification.";
835 const auto stringifyScalarTypeInfo =
837 if (typeInfo.
typeID == mlir::IntegerType::getTypeID()) {
838 return {
"i" + llvm::utostr(typeInfo.
bitWidth)};
840 if (typeInfo.
typeID == mlir::Float16Type::getTypeID()) {
842 }
else if (typeInfo.
typeID == mlir::Float32Type::getTypeID()) {
844 }
else if (typeInfo.
typeID == mlir::BFloat16Type::getTypeID()) {
846 }
else if (typeInfo.
typeID == mlir::Float8E4M3FNType::getTypeID()) {
848 }
else if (typeInfo.
typeID == mlir::Float8E5M2Type::getTypeID()) {
850 }
else if (typeInfo.
typeID == mlir::Float6E2M3FNType::getTypeID()) {
852 }
else if (typeInfo.
typeID == mlir::Float6E3M2FNType::getTypeID()) {
854 }
else if (typeInfo.
typeID == mlir::Float4E2M1FNType::getTypeID()) {
856 }
else if (typeInfo.
typeID == mlir::Float8E8M0FNUType::getTypeID()) {
858 }
else if (typeInfo.
typeID == MXI8Type::getTypeID()) {
861 llvm_unreachable(
"unknown type");
864 if (typeInfo.
typeID == tosa::BlockScaledType::getTypeID()) {
868 llvm::raw_svector_ostream os(
result);
870 << tosa::BlockShapeAttr::getBlockShapeValue(typeInfo.
blockShape.value())
871 <<
"_" << stringifyScalarTypeInfo(scaleInfo) <<
"_"
872 << stringifyScalarTypeInfo(valueInfo);
876 return stringifyScalarTypeInfo(typeInfo);