[Mlir-commits] [llvm] [mlir] [mlir][tosa] Add profile-based operation validation (PR #126992)
TatWai Chong
llvmlistbot at llvm.org
Wed Feb 19 11:51:02 PST 2025
================
@@ -0,0 +1,163 @@
+//===- TosaProfileCompliance.h - Tosa Profile-based Compliance Validation -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_DIALECT_TOSA_TRANSFORMS_TOSAPROFILECOMPILANCE_H
+#define MLIR_DIALECT_TOSA_TRANSFORMS_TOSAPROFILECOMPILANCE_H
+
+#include "mlir/Dialect/Tosa/IR/TargetEnv.h"
+#include "mlir/Dialect/Tosa/Transforms/Passes.h"
+
+#include "mlir/Support/TypeID.h"
+
+using namespace mlir;
+using namespace mlir::tosa;
+
+//===----------------------------------------------------------------------===//
+// Type Compilance Definition
+//===----------------------------------------------------------------------===//
+
+typedef struct {
+ mlir::TypeID typeID;
+ uint32_t bitWidth;
+} TypeInfo;
+
+enum CheckCondition {
+ // Valid when any of the profile (extension) requirement is meet.
+ anyOf,
+ // Valid when all of the profile (extension) requirement are meet.
+ allOf,
+ invalid
+};
+
+template <typename T>
+struct OpComplianceInfo {
+ // Certain operations require multiple modes enabled.
+ // e.g. cast bf16 to fp8e4m3 requires EXT-BF16 and EXT-FP8E4M3.
+ SmallVector<T> mode;
+ SmallVector<SmallVector<TypeInfo>> operandTypeInfoSet;
+ CheckCondition condition = CheckCondition::anyOf;
+};
+
+using OperationProfileComplianceMap =
+ std::unordered_map<std::string, SmallVector<OpComplianceInfo<Profile>>>;
+using OperationExtensionComplianceMap =
+ std::unordered_map<std::string, SmallVector<OpComplianceInfo<Extension>>>;
+
+//===----------------------------------------------------------------------===//
+// Tosa Profile And Extension Information Depot
+//===----------------------------------------------------------------------===//
+
+class ProfileInfoDepot {
+public:
+ ProfileInfoDepot(Operation *op) {
+ if (failed(populatationDispatch(op)))
+ op->emitOpError() << "fail to populate the profile info\n";
+ }
+
+ void addType(Type t) { tyInfo.push_back(convertTypeToInfo(t)); }
+ void addValue(Value v) { tyInfo.push_back(convertValueToInfo(v)); }
+ SmallVector<TypeInfo> getInfo() { return tyInfo; }
+
+private:
+ TypeInfo convertTypeToInfo(Type type) {
+ return {type.getTypeID(), type.getIntOrFloatBitWidth()};
+ }
+
+ TypeInfo convertValueToInfo(Value value) {
+ return convertTypeToInfo(getElementTypeOrSelf(value.getType()));
+ }
+
+ LogicalResult populatationDispatch(Operation *op);
+
+ void populateProfileInfo(ValueRange operands, Value output);
+
+ // Base
+ template <typename T>
+ void populateProfileInfo(T op) {
+ op->emitOpError() << "profile requirement for this op has not been defined";
+ }
+ // For conv2d, conv3d, transpose_conv2d, and depthwise_conv2d.
+ template <typename T>
+ void populateProfileInfoConv(T op);
+
+ // For pad, reshap, slice, tile, and transpose.
----------------
tatwaichong wrote:
Done.
https://github.com/llvm/llvm-project/pull/126992
More information about the Mlir-commits
mailing list