aboutsummaryrefslogtreecommitdiff
path: root/tosa_checker/tosa_checker.h
diff options
context:
space:
mode:
authorThibaut Goetghebuer-Planchon <thibaut.goetghebuer-planchon@arm.com>2022-07-06 10:23:22 +0100
committerThibaut Goetghebuer-Planchon <thibaut.goetghebuer-planchon@arm.com>2022-08-18 14:35:45 +0100
commit52dacd6556d60815253d4e4938e218ea3d8084a2 (patch)
tree4c470c567da6f70f65987d5af161bf4f950d107b /tosa_checker/tosa_checker.h
parentcc5d89eea4ff3dc398cac3b6025450f48ac20c1e (diff)
downloadtosa_checker-52dacd6556d60815253d4e4938e218ea3d8084a2.tar.gz
Initial commit0.1.0-rc.1
Change-Id: I2fb0933d595a6ede6417d09dd905ef72d6c60c9b
Diffstat (limited to 'tosa_checker/tosa_checker.h')
-rw-r--r--tosa_checker/tosa_checker.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/tosa_checker/tosa_checker.h b/tosa_checker/tosa_checker.h
new file mode 100644
index 0000000..d7750ea
--- /dev/null
+++ b/tosa_checker/tosa_checker.h
@@ -0,0 +1,82 @@
+/*
+SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+SPDX-License-Identifier: Apache-2.0
+*/
+#ifndef TOSA_CHECKER_H_
+#define TOSA_CHECKER_H_
+
+#include <map>
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "mlir/include/mlir/IR/BuiltinOps.h"
+#include "mlir/include/mlir/IR/MLIRContext.h"
+#include "mlir/include/mlir/IR/OwningOpRef.h"
+
+namespace tosa_checker {
+
+class TOSAChecker {
+ public:
+ struct Operator {
+ Operator(std::string name, std::string location,
+ std::map<std::string, std::string> attributes,
+ bool is_tosa_compatible, std::string mlir_representation)
+ : name(std::move(name)),
+ location(std::move(location)),
+ attributes(std::move(attributes)),
+ is_tosa_compatible(is_tosa_compatible),
+ mlir_representation(std::move(mlir_representation)) {}
+
+ std::string name;
+ std::string location;
+ std::map<std::string, std::string> attributes;
+ bool is_tosa_compatible;
+ std::string mlir_representation;
+ };
+
+ TOSAChecker(const std::string& model_path);
+
+ bool IsTOSACompatible();
+
+ std::vector<Operator> GetTOSACompatibilityForOps(bool elide_large_attrs);
+
+ std::vector<Operator> GetUsedTOSAOps(bool elide_large_attrs);
+
+ std::string GetMLIRModelRepresentation(bool elide_large_attrs);
+ std::string GetMLIRTOSAModelRepresentation(bool elide_large_attrs);
+
+ private:
+ template <typename T>
+ static std::string GetMLIRRepresentation(T&& op);
+
+ template <typename T>
+ static std::string GetMLIRRepresentation(T&& op, bool elide_large_attrs);
+
+ static std::vector<mlir::Operation*> GetTOSAOps(mlir::ModuleOp model);
+
+ static Operator ToOperator(mlir::Operation& op, bool is_tosa_compatible,
+ bool elide_large_attrs);
+
+ static mlir::OwningOpRef<mlir::ModuleOp> TFLiteFileToMLIR(
+ const std::string& model_path, mlir::MLIRContext* context);
+
+ static void LegalizeTFLToTOSA(mlir::ModuleOp mlir_module);
+
+ static std::map<std::string, std::string> GetAttributes(
+ mlir::Operation& op, bool elide_large_attrs);
+
+ private:
+ static constexpr std::int64_t ELIDE_LARGE_ATTRS_LIMIT = 16;
+
+ mlir::MLIRContext m_context;
+ mlir::OwningOpRef<mlir::ModuleOp> m_model;
+ mlir::OwningOpRef<mlir::ModuleOp> m_tosa_model;
+};
+
+} // namespace tosa_checker
+
+std::ostream& operator<<(std::ostream& os,
+ const tosa_checker::TOSAChecker::Operator& op);
+
+#endif