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:
63 llvm_unreachable(
"Unknown TOSA extension");
68 case Extension::int16:
70 case Extension::doubleround:
71 case Extension::inexactround:
72 return {Profile::pro_int};
74 case Extension::fp8e4m3:
75 case Extension::fp8e5m2:
78 case Extension::mxfp_conv:
79 return {Profile::pro_fp};
80 case Extension::variable:
81 case Extension::controlflow:
82 case Extension::dynamic:
83 case Extension::int64:
84 case Extension::shape:
85 return {Profile::pro_fp, Profile::pro_int};
89 llvm_unreachable(
"bad Extension type");
98 llvm_unreachable(
"Unknown TOSA level");
107 return TargetEnv(targetAttr.getSpecificationVersion(), targetAttr.getLevel(),
108 targetAttr.getProfiles(), targetAttr.getExtensions());
115 const auto isCompatibleWithTargetVersion =
116 [&](
const auto &targetEnum,
Location targetAttrLoc,
117 StringRef enumName) -> LogicalResult {
121 return emitError(targetAttrLoc, enumName)
122 <<
" '" << stringifyEnum(targetEnum)
123 <<
"' is not compatible with the target version "
125 <<
", minimum required version is "
130 const auto isExtensionCooperativeWithProfile =
131 [&](Extension ext) -> LogicalResult {
135 if (!llvm::any_of(cooperativeProfiles,
136 [&targetProfiles](
const auto &profile) {
137 return llvm::is_contained(targetProfiles, profile);
140 <<
"use of extension '" << stringifyEnum(ext)
141 <<
"' requires any of profiles: [" << cooperativeProfiles
142 <<
"] to be enabled in the target";
147 for (
const auto &profile : targetAttr.getProfiles())
149 isCompatibleWithTargetVersion(profile, targetAttrLoc,
"profile")))
151 for (
const auto &extension : targetAttr.getExtensions()) {
152 if (failed(isCompatibleWithTargetVersion(extension, targetAttrLoc,
155 if (failed(isExtensionCooperativeWithProfile(extension)))
158 if (failed(isCompatibleWithTargetVersion(targetAttr.getLevel(), targetAttrLoc,
171 if (
auto attr = op->
getAttrOfType<TargetEnvAttr>(TargetEnvAttr::name))
181 return TargetEnvAttr::get(context, SpecificationVersion::V_1_0, Level::eightK,
182 {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.