10#include "llvm/Support/FormatVariadic.h"
22 llvm_unreachable(
"Unknown TOSA level");
27 version.
isDraft() ?
".draft" :
"");
32 case Profile::pro_int:
38 llvm_unreachable(
"Unknown TOSA profile");
43 case Extension::int16:
46 case Extension::fp8e4m3:
47 case Extension::fp8e5m2:
49 case Extension::variable:
50 case Extension::controlflow:
51 case Extension::doubleround:
52 case Extension::inexactround:
53 case Extension::dynamic:
56 case Extension::int64:
57 case Extension::mxfp_conv:
58 case Extension::shape:
59 case Extension::mx_common:
60 case Extension::mx_fp4e2m1:
61 case Extension::mx_fp6e2m3:
62 case Extension::mx_fp6e3m2:
63 case Extension::mx_fp8e4m3:
64 case Extension::mx_fp8e5m2:
65 case Extension::mx_int8:
70 llvm_unreachable(
"Unknown TOSA extension");
75 case Extension::int16:
77 case Extension::doubleround:
78 case Extension::inexactround:
79 return {Profile::pro_int};
81 case Extension::fp8e4m3:
82 case Extension::fp8e5m2:
85 case Extension::mxfp_conv:
86 case Extension::mx_common:
87 case Extension::mx_fp4e2m1:
88 case Extension::mx_fp6e2m3:
89 case Extension::mx_fp6e3m2:
90 case Extension::mx_fp8e4m3:
91 case Extension::mx_fp8e5m2:
92 case Extension::mx_int8:
93 return {Profile::pro_fp};
94 case Extension::variable:
95 case Extension::controlflow:
96 case Extension::dynamic:
97 case Extension::int64:
98 case Extension::shape:
99 return {Profile::pro_fp, Profile::pro_int};
100 case Extension::none:
103 llvm_unreachable(
"bad Extension type");
112 llvm_unreachable(
"Unknown TOSA level");
121 return TargetEnv(targetAttr.getSpecificationVersion(), targetAttr.getLevel(),
122 targetAttr.getProfiles(), targetAttr.getExtensions());
129 const auto isCompatibleWithTargetVersion =
130 [&](
const auto &targetEnum,
Location targetAttrLoc,
131 StringRef enumName) -> LogicalResult {
135 return emitError(targetAttrLoc, enumName)
136 <<
" '" << stringifyEnum(targetEnum)
137 <<
"' is not compatible with the target version "
139 <<
", minimum required version is "
144 const auto isExtensionCooperativeWithProfile =
145 [&](Extension ext) -> LogicalResult {
149 if (!llvm::any_of(cooperativeProfiles,
150 [&targetProfiles](
const auto &profile) {
151 return llvm::is_contained(targetProfiles, profile);
154 <<
"use of extension '" << stringifyEnum(ext)
155 <<
"' requires any of profiles: [" << cooperativeProfiles
156 <<
"] to be enabled in the target";
161 for (
const auto &profile : targetAttr.getProfiles())
163 isCompatibleWithTargetVersion(profile, targetAttrLoc,
"profile")))
165 for (
const auto &extension : targetAttr.getExtensions()) {
166 if (failed(isCompatibleWithTargetVersion(extension, targetAttrLoc,
169 if (failed(isExtensionCooperativeWithProfile(extension)))
172 if (failed(isCompatibleWithTargetVersion(targetAttr.getLevel(), targetAttrLoc,
185 if (
auto attr = op->
getAttrOfType<TargetEnvAttr>(TargetEnvAttr::name))
195 return TargetEnvAttr::get(context, SpecificationVersion::V_1_0, Level::eightK,
196 {Profile::pro_int, Profile::pro_fp}, {});
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
AttrClass getAttrOfType(StringAttr name)
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
MLIRContext * getContext()
Return the context this operation is associated with.
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
static FailureOr< TargetEnv > createTargetEnvFromAttr(TargetEnvAttr targetAttr, Location targetEnvAttrLoc)
static LogicalResult verifyTargetInformation(TargetEnvAttr targetAttr, Location targetAttrLoc)
A thin wrapper around the SpecificationVersion enum to represent and provide utilities around the TOS...
bool isBackwardsCompatibleWith(TosaSpecificationVersion baseVersion) const
uint32_t getMinor() const
uint32_t getMajor() const
llvm::SmallString< 4 > stringifyVersion(TosaSpecificationVersion version)
TosaLevel getTosaLevelFromEnum(const Level level)
static constexpr TosaLevel TOSA_LEVEL_EIGHTK
static constexpr TosaLevel TOSA_LEVEL_NONE
SmallVector< Profile, 2 > getCooperativeProfiles(Extension ext)
TargetEnvAttr getDefaultTargetEnv(MLIRContext *context)
TosaSpecificationVersion getMinVersion(const Profile &profile)
TargetEnvAttr lookupTargetEnv(Operation *op)
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.