30#include "llvm/ADT/STLExtras.h"
31#include "llvm/ADT/StringExtras.h"
32#include "llvm/ADT/TypeSwitch.h"
33#include "llvm/Support/FormatVariadic.h"
37#define GEN_PASS_DEF_TOSAVALIDATION
38#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
49 for (
const auto index : operandIndices) {
52 return op->
emitOpError(
"expected compile time resolvable constant, but "
53 "got variable value for operand #")
60static LogicalResult checkConstantOperandMul(
Operation *op,
62 if (!env.
allows(Extension::dynamic) && isa<tosa::MulOp>(op)) {
64 return checkConstantOperands(op, {2});
69static LogicalResult checkConstantOperandTable(
Operation *op,
71 if (!env.
allows(Extension::dynamic) && isa<tosa::TableOp>(op)) {
73 return checkConstantOperands(op, {1});
78static LogicalResult checkConstantOperandPad(
Operation *op,
80 if (
auto padOp = dyn_cast<tosa::PadOp>(op)) {
82 if (!env.
allows(Extension::dynamic) && padOp.getPadConst())
85 return checkConstantOperands(op, {2});
90static LogicalResult checkConstantOperandRescale(
Operation *op,
92 if (!env.
allows(Extension::dynamic) && isa<tosa::RescaleOp>(op)) {
94 return checkConstantOperands(op, {1, 2, 3, 4});
100static LogicalResult checkConstantOperandConvOps(
Operation *op,
102 if (!env.
allows(Extension::dynamic) && isa<T>(op)) {
104 return checkConstantOperands(op, {3, 4});
109static LogicalResult checkConstantOperandMatMul(
Operation *op,
111 if (!env.
allows(Extension::dynamic) &&
112 isa<tosa::MatMulOp, tosa::MatMulTOp>(op)) {
114 return checkConstantOperands(op, {2, 3});
121 if (!env.
allows(Extension::dynamic) &&
122 isa<tosa::RowGatherBlockScaledOp>(op)) {
123 auto rowGatherOp = cast<tosa::RowGatherBlockScaledOp>(op);
124 const unsigned rowCountIndex = rowGatherOp.getValues().size() + 1;
125 return checkConstantOperands(op, {rowCountIndex});
130static LogicalResult checkConstantOperandRowGather(
Operation *op,
132 if (!env.
allows(Extension::dynamic) && isa<tosa::RowGatherOp>(op)) {
134 return checkConstantOperands(op, {2});
139static LogicalResult checkConstantOperandAvgPool2d(
Operation *op,
141 if (!env.
allows(Extension::dynamic) && isa<tosa::AvgPool2dOp>(op)) {
143 return checkConstantOperands(op, {1, 2});
150 if (!env.
allows(Extension::dynamic) && isa<tosa::AvgPool2dAdaptiveOp>(op)) {
154 return checkConstantOperands(op, {1, 2});
159static LogicalResult checkConstantOperandNegate(
Operation *op,
161 if (!env.
allows(Extension::dynamic) && isa<tosa::NegateOp>(op)) {
163 return checkConstantOperands(op, {1, 2});
168static LogicalResult checkConstantOperandSilceShape(
Operation *op,
170 if (!env.
allows(Extension::dynamic) && isa<tosa::SliceShapeOp>(op)) {
172 return checkConstantOperands(op, {1, 2});
179static LogicalResult checkSpecificationVersionConstraint(
Operation *op,
181 auto matmul = dyn_cast<tosa::MatMulOp>(op);
187 auto aType = dyn_cast<RankedTensorType>(matmul.getA().getType());
188 auto bType = dyn_cast<RankedTensorType>(matmul.getB().getType());
189 auto outputType = dyn_cast<RankedTensorType>(matmul.getOutput().getType());
190 auto getBatchDimOrDynamic = [](RankedTensorType type) {
191 return type ? type.getDimSize(0) : ShapedType::kDynamic;
193 if ((!aType || aType.getRank() == 3) && (!bType || bType.getRank() == 3) &&
194 (!outputType || outputType.getRank() == 3) &&
196 getBatchDimOrDynamic(bType),
197 getBatchDimOrDynamic(outputType)})))
201 "MATMUL ranks other than 3 or batch broadcasting require TOSA "
202 "specification version 1.1.draft");
211 explicit TosaValidation() { populateConstantOperandChecks(); }
213 explicit TosaValidation(
const TosaValidationOptions &
options)
215 this->strictOpSpecAlignment =
options.strictOpSpecAlignment;
216 this->allowInvalidOpDatatypeCombinations =
217 options.allowInvalidOpDatatypeCombinations;
218 this->validateFunctionSignature =
options.validateFunctionSignature;
220 void runOnOperation() final;
222 LogicalResult applyConstantOperandCheck(Operation *op) {
223 for (
auto &checker : constCheckers) {
224 if (
failed(checker(op, targetEnv)))
230 LogicalResult applyFunctionSignatureCheck(func::FuncOp op);
231 LogicalResult applyLevelCheck(Operation *op);
232 LogicalResult applyAttributeCheck(Operation *op);
235 LogicalResult applyVariableCheck(Operation *op);
238 LogicalResult applyErrorIfCheck(Operation *op);
241 void populateConstantOperandChecks() {
242 constCheckers.emplace_back(checkConstantOperandMul);
243 constCheckers.emplace_back(checkConstantOperandTable);
244 constCheckers.emplace_back(checkConstantOperandPad);
245 constCheckers.emplace_back(checkConstantOperandRescale);
246 constCheckers.emplace_back(checkConstantOperandConvOps<tosa::Conv2DOp>);
247 constCheckers.emplace_back(checkConstantOperandConvOps<tosa::Conv3DOp>);
248 constCheckers.emplace_back(
249 checkConstantOperandConvOps<tosa::DepthwiseConv2DOp>);
250 constCheckers.emplace_back(
251 checkConstantOperandConvOps<tosa::TransposeConv2DOp>);
252 constCheckers.emplace_back(checkConstantOperandMatMul);
253 constCheckers.emplace_back(checkConstantOperandRowGather);
254 constCheckers.emplace_back(checkConstantOperandRowGatherBlockScaled);
255 constCheckers.emplace_back(checkConstantOperandAvgPool2d);
256 constCheckers.emplace_back(checkConstantOperandAvgPool2dAdaptive);
257 constCheckers.emplace_back(checkConstantOperandNegate);
258 constCheckers.emplace_back(checkConstantOperandSilceShape);
261 LogicalResult levelCheck(Operation *op,
const int32_t calculatedValue,
262 const int32_t maxLevel,
const StringRef inputName,
263 const StringRef levelName) {
264 if (calculatedValue > maxLevel)
266 <<
"failed level check: " << inputName <<
" <= " << levelName
267 <<
" (" << maxLevel <<
"), got " << calculatedValue;
271 LogicalResult levelCheckKernel(Operation *op, int32_t v,
272 const StringRef inputName) {
273 return levelCheck(op, v, targetEnv.getLevel().MAX_KERNEL, inputName,
277 LogicalResult levelCheckStride(Operation *op, int32_t v,
278 const StringRef inputName) {
279 return levelCheck(op, v, targetEnv.getLevel().MAX_STRIDE, inputName,
283 LogicalResult levelCheckScale(Operation *op, int32_t v,
284 const StringRef inputName) {
285 return levelCheck(op, v, targetEnv.getLevel().MAX_SCALE, inputName,
289 LogicalResult levelCheckListSize(Operation *op, int32_t v,
290 const StringRef inputName) {
291 const std::string inputDesc =
292 llvm::formatv(
"length(tensor_list_shape({0}))", inputName);
293 return levelCheck(op, v, targetEnv.getLevel().MAX_TENSOR_LIST_SIZE,
294 inputDesc,
"MAX_TENSOR_LIST_SIZE");
298 LogicalResult levelCheckRank(Operation *op,
const Type typeToCheck,
299 const StringRef operandOrResult,
300 int32_t highest_rank) {
301 if (ShapedType type = dyn_cast<ShapedType>(typeToCheck)) {
303 return op->
emitOpError() <<
"failed level check: unranked tensor";
304 if (type.getRank() > highest_rank)
305 return op->
emitOpError() <<
"failed level check: " << operandOrResult
306 <<
" rank(shape) <= MAX_RANK";
312 LogicalResult levelCheckRank(Operation *op,
const Value &v,
313 const StringRef operandOrResult,
314 int32_t highest_rank) {
315 return levelCheckRank(op, v.
getType(), operandOrResult, highest_rank);
319 LogicalResult levelCheckSize(Operation *op,
const Type &typeToCheck,
320 const StringRef operandOrResult);
323 LogicalResult levelCheckSize(Operation *op,
const Value &v,
324 const StringRef operandOrResult) {
325 return levelCheckSize(op, v.
getType(), operandOrResult);
329 LogicalResult levelCheckShapeLength(Operation *op,
const Type typeToCheck,
330 const StringRef operandOrResult) {
331 if (tosa::shapeType shapeType = dyn_cast<tosa::shapeType>(typeToCheck)) {
332 if (shapeType.getRank() > targetEnv.getLevel().MAX_SHAPE_LEN)
334 <<
"failed shape type level check: " << typeToCheck
335 <<
" exceeds MAX_SHAPE_LEN";
341 template <
typename T>
342 LogicalResult levelCheckSizes(T tosaOp) {
343 auto op = tosaOp.getOperation();
345 if (
failed(levelCheckSize(op, v,
"operand")))
350 if (
failed(levelCheckSize(op, v,
"result")))
357 template <
typename T>
358 LogicalResult levelCheckRanks(T tosaOp) {
359 auto op = tosaOp.getOperation();
360 const TosaLevel tosaLevel = targetEnv.getLevel();
374 template <
typename T>
375 LogicalResult levelCheckShapeLengths(T tosaOp) {
376 for (
const auto &v : tosaOp->getOperands()) {
377 if (
failed(levelCheckShapeLength(tosaOp, v.getType(),
"operand")))
380 for (
const auto &v : tosaOp->getResults()) {
381 if (
failed(levelCheckShapeLength(tosaOp, v.getType(),
"result")))
389 LogicalResult levelCheckRanksAndSizes(Operation *op);
392 template <
typename T>
393 LogicalResult levelCheckPool(Operation *op) {
394 if (
auto poolOp = dyn_cast<T>(op)) {
395 for (
auto k : poolOp.getKernel()) {
396 if (
failed(levelCheckKernel(op, k,
"kernel"))) {
400 for (
auto s : poolOp.getStride()) {
401 if (
failed(levelCheckStride(op, s,
"stride"))) {
405 for (
auto p : poolOp.getPad()) {
406 if (
failed(levelCheckKernel(op, p,
"pad"))) {
414 template <
typename T>
415 static constexpr bool IsSupportedAdaptivePoolOp =
416 std::is_same_v<T, tosa::AvgPool2dAdaptiveOp> ||
417 std::is_same_v<T, tosa::MaxPool2dAdaptiveOp>;
419 template <
typename T,
typename std::enable_if<IsSupportedAdaptivePoolOp<T>,
421 LogicalResult levelCheckAdaptivePool(Operation *op) {
422 auto poolOp = dyn_cast<T>(op);
426 SmallVector<int64_t> kernelValues;
429 for (
const auto k : kernelValues)
430 if (
failed(levelCheckKernel(op, k,
"kernel")))
434 SmallVector<int64_t> strideValues;
437 for (
const auto s : strideValues)
438 if (
failed(levelCheckStride(op, s,
"stride")))
442 SmallVector<int64_t> padValues;
444 for (
const auto p : padValues)
445 if (
failed(levelCheckKernel(op, p,
"pad")))
453 template <
typename T>
454 LogicalResult levelCheckConv(Operation *op) {
455 if (
auto convOp = dyn_cast<T>(op)) {
457 for (
auto k : convOp.getDilation()) {
458 if (
failed(levelCheckKernel(op, k,
"dilation"))) {
462 for (
auto p : convOp.getPad()) {
463 if (
failed(levelCheckKernel(op, p,
"pad"))) {
467 for (
auto s : convOp.getStride()) {
468 if (
failed(levelCheckStride(op, s,
"stride"))) {
472 auto dilation = convOp.getDilation();
473 if (ShapedType weightType =
475 auto shape = weightType.getShape();
476 if (isa<tosa::Conv2DOp>(op)) {
477 assert(shape.size() == 4);
478 assert(dilation.size() == 2);
479 if (
failed(levelCheckKernel(op, dilation[0] * shape[1],
480 "dilation_y * KH")) ||
481 failed(levelCheckKernel(op, dilation[1] * shape[2],
484 }
else if (isa<tosa::Conv3DOp>(op)) {
485 assert(shape.size() == 5);
486 assert(dilation.size() == 3);
487 if (
failed(levelCheckKernel(op, dilation[0] * shape[1],
488 "dilation_d * KD")) ||
489 failed(levelCheckKernel(op, dilation[1] * shape[2],
490 "dilation_y * KH")) ||
491 failed(levelCheckKernel(op, dilation[2] * shape[3],
494 }
else if (isa<tosa::DepthwiseConv2DOp>(op)) {
495 assert(shape.size() == 4);
496 assert(dilation.size() == 2);
497 if (
failed(levelCheckKernel(op, dilation[0] * shape[0],
498 "dilation_y * KH")) ||
499 failed(levelCheckKernel(op, dilation[1] * shape[1],
508 LogicalResult levelCheckConv2DBlockScaled(Operation *op) {
509 auto convOp = dyn_cast<Conv2DBlockScaledOp>(op);
513 SmallVector<int64_t> padValues;
515 for (
const auto p : padValues)
516 if (
failed(levelCheckKernel(op, p,
"pad <= MAX_KERNEL")))
520 SmallVector<int64_t> strideValues;
523 for (
const auto s : strideValues)
524 if (
failed(levelCheckKernel(op, s,
"stride <= MAX_KERNEL")))
528 SmallVector<int64_t> dilationValues;
531 int64_t KH = ShapedType::kDynamic;
532 int64_t KW = ShapedType::kDynamic;
533 const ShapeAdaptor weightDataShape(convOp.getWeightData().getType());
534 KH = weightDataShape.getDimSize(1);
535 KW = weightDataShape.getDimSize(2);
536 const ShapeAdaptor weightScaleShape(convOp.getWeightScale().getType());
537 KH = ShapedType::isDynamic(KH) ? weightScaleShape.getDimSize(1) : KH;
538 KW = ShapedType::isDynamic(KW) ? weightScaleShape.getDimSize(2) : KW;
540 if (!ShapedType::isDynamic(KH) &&
541 failed(levelCheckKernel(op, dilationValues[0] * KH,
542 "dilation_y * KH <= MAX_KERNEL)")))
545 if (!ShapedType::isDynamic(KW) &&
546 failed(levelCheckKernel(op, dilationValues[1] * KW,
547 "dilation_x * KW <= MAX_KERNEL)")))
555 template <
typename T>
556 LogicalResult levelCheckFFT(Operation *op) {
559 if (ShapedType type = dyn_cast<ShapedType>(v.getType())) {
560 auto shape = type.getShape();
561 assert(shape.size() == 3);
562 if (
failed(levelCheckKernel(op, shape[1],
"H")) ||
563 failed(levelCheckKernel(op, shape[2],
"W"))) {
573 LogicalResult levelCheckTransposeConv2d(Operation *op) {
574 if (
auto transpose = dyn_cast<tosa::TransposeConv2DOp>(op)) {
575 if (ShapedType filterType =
576 dyn_cast<ShapedType>(transpose.getWeight().getType())) {
577 auto shape = filterType.getShape();
578 assert(shape.size() == 4);
580 if (
failed(levelCheckKernel(op, shape[1],
"KH")) ||
581 failed(levelCheckKernel(op, shape[2],
"KW"))) {
585 for (
auto p : transpose.getOutPad()) {
586 if (
failed(levelCheckKernel(op, p,
"pad"))) {
590 for (
auto s : transpose.getStride()) {
591 if (
failed(levelCheckStride(op, s,
"stride"))) {
600 LogicalResult levelCheckResize(Operation *op) {
601 if (
auto resize = dyn_cast<tosa::ResizeOp>(op)) {
602 SmallVector<int64_t> scale;
607 const int64_t scaleYN = scale[0];
608 const int64_t scaleYD = scale[1];
609 const int64_t scaleXN = scale[2];
610 const int64_t scaleXD = scale[3];
616 if (llvm::any_of(scale, [](int64_t s) {
return s <= 0; }))
620 levelCheckScale(op, scaleYN / scaleYD,
"scale_y_n/scale_y_d")) ||
622 levelCheckScale(op, scaleXN / scaleXD,
"scale_x_n/scale_x_d"))) {
633 static void getMaxNestedDepth(Operation *op, int32_t &depth) {
634 if (isa<mlir::func::FuncOp>(op) || isa<ModuleOp>(op))
642 getMaxNestedDepth(op, depth);
645 LogicalResult levelCheckMaxNesting(Operation *op) {
646 int32_t maxNestedDepth = 0;
647 getMaxNestedDepth(op, maxNestedDepth);
649 const int32_t maxNestingLevel = targetEnv.getLevel().MAX_NESTING;
650 if (maxNestedDepth >= maxNestingLevel)
652 <<
"failed level check: tosa_nesting_depth < MAX_NESTING" <<
" ("
653 << maxNestingLevel <<
"), got " << maxNestedDepth;
657 LogicalResult levelCheckListSize(Operation *op) {
658 if (
auto concat = dyn_cast<tosa::ConcatOp>(op)) {
659 return levelCheckListSize(op,
concat.getInput1().size(),
"input1");
661 if (
auto custom = dyn_cast<tosa::CustomOp>(op)) {
662 if (
failed(levelCheckListSize(op, custom.getInputList().size(),
664 failed(levelCheckListSize(op, custom.getOutputList().size(),
669 if (
auto condIf = dyn_cast<tosa::IfOp>(op)) {
671 levelCheckListSize(op, condIf.getInputList().size(),
"inputs")) ||
672 failed(levelCheckListSize(op, condIf.getOutputList().size(),
677 if (
auto w = dyn_cast<tosa::WhileOp>(op)) {
678 if (
failed(levelCheckListSize(op, w.getInputList().size(),
"inputs")) ||
679 failed(levelCheckListSize(op, w.getOutputList().size(),
"outputs"))) {
683 if (
auto concat_shape = dyn_cast<tosa::ConcatShapeOp>(op))
684 return levelCheckListSize(op, concat_shape.getInput().size(),
"input");
688 LogicalResult attributeCheckRescale(Operation *op) {
689 if (
auto rescale = dyn_cast<tosa::RescaleOp>(op)) {
690 if (rescale.getRoundingMode() == RoundingMode::DOUBLE_ROUND &&
691 !targetEnv.allows(Extension::doubleround)) {
693 <<
"failed attribute check: rounding_mode = DOUBLE_ROUND "
694 <<
"requires extension [doubleround]";
697 if (rescale.getRoundingMode() == RoundingMode::INEXACT_ROUND &&
698 !targetEnv.allows(Extension::inexactround)) {
700 <<
"failed attribute check: rounding_mode = INEXACT_ROUND "
701 <<
"requires extension [inexactround]";
708 LogicalResult attributeCheckCast(Operation *op) {
709 if (
auto cast = dyn_cast<tosa::CastOp>(op)) {
710 const TosaSpecificationVersion targetVersion = targetEnv.getSpecVersion();
711 const TosaSpecificationVersion minRequiredVersion(1, 1,
true);
712 if (cast.getInputUnsigned() &&
715 <<
"failed attribute check: CAST attribute input_unsigned "
716 <<
"requires version 1.1.draft"
722 LogicalResult CheckVariable(Operation *op);
723 LogicalResult CheckVariableReadOrWrite(Operation *op);
724 LogicalResult validateValidElementType(Operation *op, Type type,
725 bool allowUnsigned =
false);
726 LogicalResult validateOperationElementTypes(TosaOp op,
727 bool allowUnsigned =
false);
728 LogicalResult validateOperationElementTypes(func::FuncOp op,
729 bool allowUnsigned =
false);
732 std::function<LogicalResult(Operation *,
const tosa::TargetEnv &)>>
735 TosaProfileCompliance profileComp;
736 tosa::TargetEnv targetEnv;
740LogicalResult TosaValidation::levelCheckRanks(tosa::ArgMaxOp tosaOp) {
741 auto *op = tosaOp.getOperation();
742 if (
failed(levelCheckRank(op, tosaOp.getInput(),
"operand",
747 if (
failed(levelCheckRank(op, tosaOp.getOutput(),
"result",
755LogicalResult TosaValidation::levelCheckRanks(tosa::ArgMinOp tosaOp) {
756 auto *op = tosaOp.getOperation();
757 if (
failed(levelCheckRank(op, tosaOp.getInput(),
"operand",
762 if (
failed(levelCheckRank(op, tosaOp.getOutput(),
"result",
770LogicalResult TosaValidation::levelCheckRanks(tosa::IfOp tosaOp) {
771 auto *op = tosaOp.getOperation();
774 if (
failed(levelCheckRank(op, tosaOp.getCondition(),
"operand",
782LogicalResult TosaValidation::levelCheckRanks(tosa::VariableOp tosaOp) {
783 auto *op = tosaOp.getOperation();
785 if (
failed(levelCheckRank(op, variableType,
"variable type",
793LogicalResult TosaValidation::levelCheckSizes(tosa::VariableOp tosaOp) {
794 auto *op = tosaOp.getOperation();
796 if (
failed(levelCheckSize(op, variableType,
"variable type")))
802LogicalResult TosaValidation::levelCheckRanksAndSizes(Operation *op) {
803#define CHECK_RANKS_AND_SIZES(tosaOp) \
804 if (isa<tosa::tosaOp##Op>(op)) { \
805 if (failed(levelCheckRanks(cast<tosa::tosaOp##Op>(op)))) \
807 if (failed(levelCheckSizes(cast<tosa::tosaOp##Op>(op)))) \
811#define CHECK_SIZES(tosaOp) \
812 if (isa<tosa::tosaOp##Op>(op)) { \
813 if (failed(levelCheckSizes(cast<tosa::tosaOp##Op>(op)))) \
817#define CHECK_SHAPE_LEN(tosaOp) \
818 if (isa<tosa::tosaOp##Op>(op)) { \
819 if (failed(levelCheckShapeLengths(cast<tosa::tosaOp##Op>(op)))) \
952#undef CHECK_RANKS_AND_SIZES
954#undef CHECK_SHAPE_LEN
959LogicalResult TosaValidation::levelCheckSize(Operation *op,
960 const Type &typeToCheck,
961 const StringRef operandOrResult) {
962 if (ShapedType type = dyn_cast<ShapedType>(typeToCheck)) {
964 return op->
emitOpError() <<
"failed level check: unranked tensor";
965 auto shape = type.getShape();
966 for (
auto dim : shape) {
967 const bool dimIsDynamic = mlir::ShapedType::isDynamic(dim);
968 const TosaSpecificationVersion targetVersion = targetEnv.
getSpecVersion();
969 const TosaSpecificationVersion minRequiredVersion(1, 1,
true);
979 return op->
emitOpError() <<
"failed level check: " << operandOrResult
980 <<
" shape dimension cannot be dynamic when"
981 <<
" targeting TOSA specification version 1.0"
986 int64_t elementBytes = std::max(INT64_C(1), elementBits / 8);
987 int64_t size = elementBytes * type.getNumElements();
994 const int64_t maxSize =
998 <<
"failed level check: " << operandOrResult
999 <<
" tensor size (in bytes) <= (1 << MAX_LOG2_SIZE - 1)";
1004LogicalResult TosaValidation::applyLevelCheck(Operation *op) {
1011 if (
failed(levelCheckRanksAndSizes(op)))
1014 if (
failed(levelCheckPool<tosa::AvgPool2dOp>(op)) ||
1015 failed(levelCheckAdaptivePool<tosa::AvgPool2dAdaptiveOp>(op)) ||
1016 failed(levelCheckConv<tosa::Conv2DOp>(op)) ||
1017 failed(levelCheckConv<tosa::Conv3DOp>(op)) ||
1018 failed(levelCheckConv<tosa::DepthwiseConv2DOp>(op)) ||
1019 failed(levelCheckFFT<tosa::FFT2dOp>(op)) ||
1020 failed(levelCheckPool<tosa::MaxPool2dOp>(op)) ||
1021 failed(levelCheckAdaptivePool<tosa::MaxPool2dAdaptiveOp>(op)) ||
1022 failed(levelCheckFFT<tosa::RFFT2dOp>(op)) ||
1023 failed(levelCheckTransposeConv2d(op)) ||
failed(levelCheckResize(op)) ||
1024 failed(levelCheckConv2DBlockScaled(op))) {
1029 if (
failed(levelCheckListSize(op))) {
1033 if (isa<tosa::IfOp>(op) || isa<tosa::WhileOp>(op)) {
1034 if (
failed(levelCheckMaxNesting(op))) {
1042LogicalResult TosaValidation::applyAttributeCheck(Operation *op) {
1043 if (
failed(attributeCheckRescale(op)))
1045 if (
failed(attributeCheckCast(op)))
1050inline bool CompatibleTypes(
const mlir::Type &type,
1051 const mlir::Type &declaredType) {
1053 return type == declaredType;
1056LogicalResult TosaValidation::CheckVariable(Operation *op) {
1057 if (
auto variableOp = dyn_cast<mlir::tosa::VariableOp>(op)) {
1058 mlir::StringAttr nameAttr = variableOp.getNameAttr();
1060 if (variablesMap.count(nameAttr))
1061 return op->
emitOpError() <<
"name has already been declared";
1063 auto elementType = variableOp.getType();
1064 DenseIntElementsAttr varShapeAttr = variableOp.getVarShape();
1065 SmallVector<int64_t> shape = to_vector(varShapeAttr.getValues<int64_t>());
1066 RankedTensorType variableType =
1067 RankedTensorType::get(ArrayRef<int64_t>(shape), elementType);
1069 variablesMap[nameAttr] = variableType;
1075LogicalResult TosaValidation::CheckVariableReadOrWrite(Operation *op) {
1076 if (isa<mlir::tosa::VariableReadOp>(op) ||
1077 isa<mlir::tosa::VariableWriteOp>(op)) {
1078 mlir::StringAttr nameAttr =
1080 .Case<mlir::tosa::VariableReadOp, mlir::tosa::VariableWriteOp>(
1081 [](
auto variableOp) {
return variableOp.getNameAttr(); });
1082 if (!variablesMap.count(nameAttr))
1083 return op->
emitOpError() <<
"name has not been declared";
1085 auto varType = variablesMap[nameAttr];
1088 auto type = v.getType();
1089 if (!CompatibleTypes(type, varType))
1090 return op->
emitOpError() <<
"operand type does not equal variable type";
1094 auto type = v.getType();
1095 if (!CompatibleTypes(type, varType))
1096 return op->
emitOpError() <<
"result type does not equal variable type";
1103LogicalResult TosaValidation::applyVariableCheck(Operation *op) {
1104 if (
failed(CheckVariable(op)) ||
failed(CheckVariableReadOrWrite(op)))
1109LogicalResult checkErrorIfResize(Operation *op,
1110 bool checkStrictSpecConformance) {
1111 auto resize = dyn_cast<tosa::ResizeOp>(op);
1115 const Value input = resize.getInput();
1116 const Value output = resize.getOutput();
1117 const RankedTensorType inputType =
1118 llvm::dyn_cast<RankedTensorType>(input.
getType());
1119 const RankedTensorType outputType =
1120 llvm::dyn_cast<RankedTensorType>(output.
getType());
1122 if (!inputType || !outputType)
1123 return op->
emitOpError(
"expect ranked input/output tensor");
1127 if (checkStrictSpecConformance && inputType.hasStaticShape() &&
1128 outputType.hasStaticShape()) {
1129 const SmallVector<int64_t, 4> sizes = {
1130 outputType.getDimSize(1), outputType.getDimSize(2),
1131 inputType.getDimSize(1), inputType.getDimSize(2)};
1132 const int64_t *maxDim = llvm::max_element(sizes);
1133 if (maxDim != sizes.end() && *maxDim >= 16384)
1135 "expect input/output height/width dims to be < 16384, ")
1136 <<
"got [OH, OW, IH, IW] = " << sizes;
1139 SmallVector<int64_t> scale;
1144 if (llvm::any_of(scale, [](int64_t s) {
return s <= 0; }))
1145 return op->
emitOpError(
"expect all scale values to be > 0, got ") << scale;
1147 const int64_t scaleYN = scale[0];
1148 const int64_t scaleYD = scale[1];
1149 const int64_t scaleXN = scale[2];
1150 const int64_t scaleXD = scale[3];
1153 if (scaleYN > (1 << 11) || scaleXN > (1 << 11))
1155 "expect all scale numerator values to be <= (1 << 11), "
1157 << scaleYN <<
", scale_x_n=" << scaleXN;
1159 if (scaleYD >= 16 * scaleYN || scaleXD >= 16 * scaleXN)
1160 return op->
emitOpError(
"expect a downscale ratio larger than 1/16, got y=")
1161 << scaleYN <<
"/" << scaleYD <<
", x=" << scaleXN <<
"/" << scaleXD;
1163 SmallVector<int64_t> offset;
1164 SmallVector<int64_t> border;
1169 const int64_t offsetY = offset[0];
1170 const int64_t offsetX = offset[1];
1171 const int64_t borderY = border[0];
1172 const int64_t borderX = border[1];
1176 if (checkStrictSpecConformance) {
1177 if (offsetY < -scaleYN || offsetY >= 16 * scaleYN)
1178 return op->
emitOpError(
"expect offsetY / scaleYNumerator to be in range "
1180 << offsetY <<
"/" << scaleYN;
1181 if (offsetX < -scaleXN || offsetX >= 16 * scaleXN)
1182 return op->
emitOpError(
"expect offsetX / scaleXNumerator to be in range "
1184 << offsetX <<
"/" << scaleXN;
1186 if (borderY < -16 * scaleYN || borderY >= scaleYN)
1187 return op->
emitOpError(
"expect borderY / scaleYNumerator to be in range "
1189 << borderY <<
"/" << scaleYN;
1190 if (borderX < -16 * scaleXN || borderX >= scaleXN)
1191 return op->
emitOpError(
"expect borderX / scaleXNumerator to be in range "
1193 << borderX <<
"/" << scaleXN;
1199 const int64_t
rhs) -> std::optional<int64_t> {
1201 return std::nullopt;
1205 const int64_t oh = outputType.getDimSize(1);
1206 const int64_t ow = outputType.getDimSize(2);
1207 const int64_t ih = inputType.getDimSize(1);
1208 const int64_t iw = inputType.getDimSize(2);
1210 if (ih != ShapedType::kDynamic) {
1211 const std::optional<int64_t> calculatedOutHeightMinusOne =
1212 idivCheck((ih - 1) * scaleYN - offsetY + borderY, scaleYD);
1213 if (!calculatedOutHeightMinusOne.has_value())
1215 "expected (input_height - 1) * scale_y_n - offset_y + "
1217 <<
"to be wholly divisible by scale_y_d, got ((" << ih
1218 <<
" - 1) * " << scaleYN <<
" - " << offsetY <<
" + " << borderY
1219 <<
") / " << scaleYD;
1220 const int64_t calculatedOutHeight = calculatedOutHeightMinusOne.value() + 1;
1221 if (oh != ShapedType::kDynamic && calculatedOutHeight != oh)
1223 "calculated output height did not match expected: ")
1224 <<
"calculated=" << calculatedOutHeight <<
", expected=" << oh;
1227 if (iw != ShapedType::kDynamic) {
1228 const std::optional<int64_t> calculatedOutWidthMinusOne =
1229 idivCheck((iw - 1) * scaleXN - offsetX + borderX, scaleXD);
1230 if (!calculatedOutWidthMinusOne.has_value())
1232 "expected (input_width - 1) * scale_x_n - offset_x + "
1234 <<
"to be wholly divisible by scale_x_d, got ((" << iw
1235 <<
" - 1) * " << scaleXN <<
" - " << offsetX <<
" + " << borderX
1236 <<
") / " << scaleXD;
1237 const int64_t calculatedOutWidth = calculatedOutWidthMinusOne.value() + 1;
1238 if (ow != ShapedType::kDynamic && calculatedOutWidth != ow)
1239 return op->
emitOpError(
"calculated output width did not match expected: ")
1240 <<
"calculated=" << calculatedOutWidth <<
", expected=" << ow;
1246LogicalResult checkErrorIfMul(Operation *op) {
1247 auto mul = dyn_cast<tosa::MulOp>(op);
1253 ElementsAttr shift_elem;
1256 int32_t shift = shift_elem.getValues<IntegerAttr>()[0].getInt();
1258 if (inputElemType.isInteger(32)) {
1260 if (shift < 0 || shift > 63)
1262 <<
"requires 0 <= shift && shift <= 63, but got: " << shift;
1267 <<
"requires shift = 0 for all input data types that "
1268 "are not int32_t, but got: "
1275LogicalResult checkErrorIfTable(Operation *op) {
1276 auto table = dyn_cast<tosa::TableOp>(op);
1282 const int tableSize = inputElemType.isInteger(8) ? 256 : 513;
1284 const ShapeAdaptor tableShape(table.getTable().getType());
1285 if (tableShape.hasStaticShape()) {
1286 const auto numElements = tableShape.getNumElements();
1287 if (numElements != tableSize)
1288 return op->
emitOpError() <<
"requires table size of " << tableSize
1289 <<
", got " << numElements;
1295LogicalResult checkErrorIfRescale(Operation *op) {
1296 auto rescale = dyn_cast<tosa::RescaleOp>(op);
1300 auto inputType = llvm::dyn_cast<ShapedType>(rescale.getInput().getType());
1301 auto outputType = llvm::dyn_cast<ShapedType>(rescale.getOutput().getType());
1302 if (!inputType || !outputType || !inputType.getElementType().isInteger() ||
1303 !outputType.getElementType().isInteger())
1306 auto inElemType = inputType.getElementType();
1307 auto outElemType = outputType.getElementType();
1308 auto inWidth = inElemType.getIntOrFloatBitWidth();
1309 auto outWidth = outElemType.getIntOrFloatBitWidth();
1311 bool inputUnsigned = rescale.getInputUnsigned();
1312 bool outputUnsigned = rescale.getOutputUnsigned();
1314 bool scale32 = rescale.getScale32();
1315 auto roundingMode = rescale.getRoundingMode();
1318 if (scale32 && inWidth == 48)
1319 return op->
emitOpError() <<
"scale32 is not allowed with 48-bit input.";
1322 if (!scale32 && roundingMode == RoundingMode::DOUBLE_ROUND)
1324 <<
"DOUBLE_ROUND is only allowed with scale32=true.";
1327 if (inputUnsigned && outputUnsigned)
1328 return op->
emitOpError() <<
"input and output cannot be both unsigned.";
1331 if (outWidth == 32 && inputUnsigned)
1333 <<
"i32 output type is not allowed with unsigned input.";
1336 if (inWidth == 32 && outputUnsigned)
1338 <<
"i32 input type is not allowed with unsigned output.";
1341 if (inWidth == 48 && outputUnsigned)
1343 <<
"i48 input type is not allowed with unsigned output.";
1346 if (inWidth == 48 && inputUnsigned)
1347 return op->
emitOpError() <<
"i48 input type cannot be unsigned.";
1350 if (inWidth == 32 && inputUnsigned)
1351 return op->
emitOpError() <<
"i32 input type cannot be unsigned.";
1354 if (outWidth == 32 && outputUnsigned)
1355 return op->
emitOpError() <<
"i32 output type cannot be unsigned.";
1359 if (FailureOr<int64_t> maybeIZp = rescale.getInputZeroPoint();
1360 succeeded(maybeIZp) && rescale.verifyInputZeroPoint(*maybeIZp).failed())
1363 if (FailureOr<int64_t> maybeOZp = rescale.getOutputZeroPoint();
1364 succeeded(maybeOZp) && rescale.verifyOutputZeroPoint(*maybeOZp).failed())
1370LogicalResult checkErrorIfPad(Operation *op) {
1371 auto pad = dyn_cast<tosa::PadOp>(op);
1375 DenseIntElementsAttr paddingAttr;
1380 for (
const APInt &val : paddingAttr.getValues<APInt>()) {
1381 if (val.getSExtValue() < 0)
1382 return op->
emitOpError() <<
"padding value must all be non-negative, got "
1383 << val.getSExtValue();
1389LogicalResult checkErrorIfReshape(Operation *op) {
1390 auto reshapeOp = dyn_cast<tosa::ReshapeOp>(op);
1394 SmallVector<int64_t> shapeValues;
1400 return op->
emitOpError(
"shape input contains inferable dimension (")
1403 "which does not conform to the TOSA specification";
1408LogicalResult checkErrorIfSlice(Operation *op) {
1409 auto sliceOp = dyn_cast<tosa::SliceOp>(op);
1413 SmallVector<int64_t> startValues;
1414 SmallVector<int64_t> sizeValues;
1416 sliceOp.getStart().getDefiningOp(), startValues);
1417 const bool hasSizeValues =
1423 <<
") which does not conform to the TOSA specification";
1428 "does not conform to the TOSA specification";
1431 if (hasStartValues &&
1432 llvm::any_of(startValues, [](
int64_t v) {
return v < 0; }))
1434 << startValues <<
"]";
1437 if (hasSizeValues &&
1438 llvm::any_of(sizeValues, [](
int64_t v) {
return v <= 0; }))
1439 return op->
emitOpError(
"size values must be > 0, got [")
1440 << sizeValues <<
"]";
1443 if (hasSizeValues) {
1444 const auto outputType = sliceOp.getOutput().getType();
1445 if (
const auto rankedOutput = dyn_cast<RankedTensorType>(outputType)) {
1448 "expected output shape to match size values, got ")
1449 << outputType <<
" vs [" << sizeValues <<
"]";
1454 if (hasStartValues && hasSizeValues) {
1455 if (
const auto inputType =
1456 dyn_cast<RankedTensorType>(sliceOp.getInput1().getType())) {
1457 for (
const auto &[
index, vals] : llvm::enumerate(llvm::zip_equal(
1458 startValues, sizeValues, inputType.getShape()))) {
1459 const auto &[start, size, inputDim] = vals;
1460 if (ShapedType::isDynamic(inputDim))
1464 if (start > inputDim || size > inputDim - start)
1466 "start + size must be less than or equal to input "
1467 "dimension size, got start=")
1468 << start <<
", size=" << size
1469 <<
" vs input dim size=" << inputDim <<
" at dimension "
1477 if (hasStartValues && !startValues.empty()) {
1479 if (
auto blockScaledType = dyn_cast<BlockScaledType>(elemType)) {
1480 const int64_t startBlock = startValues.back();
1482 BlockShapeAttr::getBlockShapeValue(blockScaledType.getBlockShape());
1483 if (startBlock % scaleBlock != 0)
1485 "expected start innermost block size to match data type "
1486 "for block scaled input, got start block=")
1487 << startBlock <<
", scale block=" << scaleBlock;
1495 return llvm::all_of(op->
getOperands(), [&](
auto operand) {
1496 Region *operandRegion = operand.getParentRegion();
1497 return operandRegion && region->isAncestor(operandRegion);
1501static LogicalResult isRegionIsolatedFromAbove(
Region ®ionToCheck) {
1502 bool noLiveInValue =
true;
1503 regionToCheck.
walk([&noLiveInValue, ®ionToCheck](
Operation *op) {
1504 if (!isOpIsolatedWithinRegion(op, ®ionToCheck)) {
1505 noLiveInValue =
false;
1510 return noLiveInValue ?
success() : failure();
1513LogicalResult checkIsolatedRegion(Operation *op, Region ®ionToCheck,
1514 StringRef regionName) {
1515 if (succeeded(isRegionIsolatedFromAbove(regionToCheck)))
1518 <<
"is not conformant to the TOSA specification. It requires the '"
1519 << regionName <<
"' region is isolated from above.\n";
1522LogicalResult checkErrorIfCondIf(Operation *op) {
1523 auto ifOp = dyn_cast<tosa::IfOp>(op);
1556 if (
failed(checkIsolatedRegion(op, ifOp.getThenGraph(),
"then")) ||
1557 failed(checkIsolatedRegion(op, ifOp.getElseGraph(),
"else")))
1562LogicalResult checkErrorIfWhileLoop(Operation *op) {
1563 auto whileOp = dyn_cast<tosa::WhileOp>(op);
1567 if (
failed(checkIsolatedRegion(op, whileOp.getCondGraph(),
"cond")) ||
1568 failed(checkIsolatedRegion(op, whileOp.getBodyGraph(),
"body")))
1573LogicalResult checkErrorIfScatter(Operation *op) {
1574 auto scatterOp = dyn_cast<tosa::ScatterOp>(op);
1579 DenseIntElementsAttr indicesAttr;
1583 auto const indicesType =
1584 dyn_cast<ShapedType>(scatterOp.getIndices().getType());
1585 if (!indicesType || !indicesType.hasRank()) {
1591 op->
emitOpError(
"indices values contain duplicates");
1598LogicalResult TosaValidation::applyErrorIfCheck(Operation *op) {
1599 if (
failed(checkErrorIfResize(op, strictOpSpecAlignment)) ||
1600 failed(checkErrorIfMul(op)) ||
failed(checkErrorIfTable(op)) ||
1601 failed(checkErrorIfRescale(op)) ||
failed(checkErrorIfPad(op)) ||
1602 failed(checkErrorIfReshape(op)) ||
failed(checkErrorIfSlice(op)) ||
1603 failed(checkErrorIfCondIf(op)) ||
failed(checkErrorIfWhileLoop(op)) ||
1604 failed(checkErrorIfScatter(op)))
1609LogicalResult TosaValidation::applyFunctionSignatureCheck(func::FuncOp op) {
1611 const auto isTensorType = [](Type type) {
return isa<TensorType>(type); };
1612 if (!llvm::all_of(op.getArgumentTypes(), isTensorType))
1613 return op.emitOpError()
1614 <<
"Function argument types must be a tensor type to be TOSA "
1615 "compliant, got !tosa.shape type";
1616 if (!llvm::all_of(op.getResultTypes(), isTensorType))
1617 return op.emitOpError()
1618 <<
"Function return types must be a tensor type to be TOSA "
1619 "compliant, got !tosa.shape type";
1622 if (
failed(validateOperationElementTypes(op, !strictOpSpecAlignment)))
1626 const TosaLevel tosaLevel = targetEnv.
getLevel();
1627 for (
const auto &[idx, argType] : llvm::enumerate(op.getArgumentTypes())) {
1628 const std::string inputDesc = llvm::formatv(
"input argument {0}", idx);
1629 if (
failed(levelCheckRank(op, argType, inputDesc, tosaLevel.
MAX_RANK)))
1631 if (
failed(levelCheckSize(op, argType, inputDesc)))
1634 for (
const auto &[idx, resultType] : llvm::enumerate(op.getResultTypes())) {
1635 const std::string resultDesc = llvm::formatv(
"return value {0}", idx);
1636 if (
failed(levelCheckRank(op, resultType, resultDesc, tosaLevel.
MAX_RANK)))
1638 if (
failed(levelCheckSize(op, resultType, resultDesc)))
1645 for (
const Type &argType :
1646 llvm::concat<const Type>(op.getArgumentTypes(), op.getResultTypes())) {
1647 if (
auto shapedType = dyn_cast<ShapedType>(argType)) {
1648 if (llvm::any_of(shapedType.getShape(),
1649 [](int64_t dim) { return dim == 0; }))
1650 return op.emitOpError() <<
"Function argument or return types must not "
1651 "have zero dimensions";
1658LogicalResult TosaValidation::validateValidElementType(Operation *op, Type type,
1659 bool allowUnsigned) {
1660 if (isa<FloatType>(type)) {
1661 if (isa<Float32Type, Float16Type, BFloat16Type, Float8E4M3FNType,
1662 Float8E5M2Type, Float4E2M1FNType, Float6E2M3FNType,
1663 Float6E3M2FNType, Float8E8M0FNUType>(type))
1665 }
else if (
auto intTy = dyn_cast<IntegerType>(type)) {
1666 if (intTy.isSignless()) {
1667 switch (intTy.getWidth()) {
1677 }
else if (allowUnsigned && intTy.isUnsigned()) {
1678 switch (intTy.getWidth()) {
1685 }
else if (isa<tosa::shapeType>(type))
1687 else if (isa<MXI8Type, tosa::mxint8Type, tosa::BlockScaledType>(type))
1690 return op->
emitOpError() <<
"is not profile-aligned: element type " << type
1695TosaValidation::validateOperationElementTypes(TosaOp op,
bool allowUnsigned) {
1696 for (Value operand : op->getOperands()) {
1698 if (
failed(validateValidElementType(op, elementTy, allowUnsigned)))
1702 for (Type resultTy : op->getResultTypes()) {
1704 if (
failed(validateValidElementType(op, elementTy, allowUnsigned)))
1708 if (
auto variableOp = dyn_cast<tosa::VariableOp>(*op)) {
1710 validateValidElementType(op, variableOp.getType(), allowUnsigned)))
1717TosaValidation::validateOperationElementTypes(func::FuncOp op,
1718 bool allowUnsigned) {
1719 for (
const Type &argType :
1720 llvm::concat<const Type>(op.getArgumentTypes(), op.getResultTypes())) {
1722 if (
failed(validateValidElementType(op, elementTy, allowUnsigned)))
1729void TosaValidation::runOnOperation() {
1730 ModuleOp modOp = getOperation();
1731 TosaDialect *tosaDialect =
getContext().getLoadedDialect<TosaDialect>();
1736 const auto maybeTargetEnv =
1738 if (
failed(maybeTargetEnv))
1739 return signalPassFailure();
1740 targetEnv = *maybeTargetEnv;
1742 const auto functions = modOp.getOps<func::FuncOp>();
1743 if (validateFunctionSignature &&
1744 llvm::any_of(functions, [&](func::FuncOp func) {
1745 return failed(applyFunctionSignatureCheck(func));
1747 return signalPassFailure();
1749 modOp.walk([&](TosaOp op) {
1755 const bool allowUnsigned =
1756 !strictOpSpecAlignment && isa<tosa::RescaleOp>(op);
1757 if (
failed(validateOperationElementTypes(op, allowUnsigned)))
1758 return signalPassFailure();
1760 if (strictOpSpecAlignment &&
1762 return signalPassFailure();
1764 if (strictOpSpecAlignment &&
1766 return signalPassFailure();
1768 if (strictOpSpecAlignment &&
1769 failed(checkSpecificationVersionConstraint(op, targetEnv)))
1770 return signalPassFailure();
1772 if (!allowInvalidOpDatatypeCombinations &&
1774 return signalPassFailure();
1778 if (
failed(applyConstantOperandCheck(op)))
1779 return signalPassFailure();
1782 if (
failed(applyLevelCheck(op)))
1783 return signalPassFailure();
1786 if (
failed(applyAttributeCheck(op)))
1787 return signalPassFailure();
1790 if (
failed(applyVariableCheck(op)))
1791 return signalPassFailure();
1794 if (
failed(applyErrorIfCheck(op)))
1795 return signalPassFailure();
static llvm::ManagedStatic< PassManagerOptions > options
static std::optional< int64_t > idivCheck(const int64_t lhs, const int64_t rhs)
#define CHECK_RANKS_AND_SIZES(tosaOp)
#define CHECK_SIZES(tosaOp)
#define CHECK_SHAPE_LEN(tosaOp)
Attributes are known-constant values of operations.
Operation is the basic unit of execution within MLIR.
Value getOperand(unsigned idx)
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
operand_range getOperands()
Returns an iterator on the underlying Value's.
result_range getResults()
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
RetT walk(FnT &&callback)
Walk all nested operations, blocks or regions (including this region), depending on the type of callb...
Type getType() const
Return the type of this value.
static WalkResult advance()
static WalkResult interrupt()
This class represents the capability enabled in the target implementation such as profile,...
TosaLevel getLevel() const
static FailureOr< TargetEnv > createTargetEnvFromAttr(TargetEnvAttr targetAttr, Location targetEnvAttrLoc)
bool allows(Profile prof) const
TosaSpecificationVersion getSpecVersion() const
LogicalResult checkExtension(Operation *op, const tosa::TargetEnv &targetEnv)
LogicalResult checkInvalid(Operation *op)
LogicalResult checkProfile(Operation *op, const tosa::TargetEnv &targetEnv)
A thin wrapper around the SpecificationVersion enum to represent and provide utilities around the TOS...
bool isBackwardsCompatibleWith(TosaSpecificationVersion baseVersion) const
SmallVector< AffineExpr, 4 > concat(ArrayRef< AffineExpr > a, ArrayRef< AffineExpr > b)
Return the vector that is the concatenation of a and b.
llvm::SmallString< 4 > stringifyVersion(TosaSpecificationVersion version)
RankedTensorType getVariableType(VariableOp variableOp)
static constexpr TosaLevel TOSA_LEVEL_NONE
bool hasUniqueConstantScatterIndices(ShapedType indicesType, DenseIntElementsAttr indicesAttr)
constexpr int64_t kInferableDimSize
Represents a dimension in the shape of a tensor that can be inferred based on the other provided dime...
unsigned getBitWidth(Type type)
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
bool getConstShapeValues(Operation *op, llvm::SmallVector< int64_t > &result_shape)
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
@ Mul
RHS of mul is always a constant or a symbolic expression.
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
LogicalResult verifyCompatibleDims(ArrayRef< int64_t > dims)
Dimensions are compatible if all non-dynamic dims are equal.
llvm::TypeSwitch< T, ResultT > TypeSwitch
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
LogicalResult verifyCompatibleShape(ArrayRef< int64_t > shape1, ArrayRef< int64_t > shape2)
Returns success if the given two shapes are compatible.
detail::constant_op_matcher m_Constant()
Matches a constant foldable operation.