From 9f4d03990c13f7ed45ff7e7bf3bd453affbacbea Mon Sep 17 00:00:00 2001 From: Matthew Barrett Date: Mon, 26 Oct 2020 14:56:24 +0000 Subject: [PATCH] Remove ccompiler constant updater Change-Id: Iea9ee0f689683512fa114afeadeccb7fc9048e4f --- .../backend/contrib/codegen_c/codegen.cc | 29 ------------------- .../backend/contrib/codegen_c/codegen_c.h | 2 +- tests/python/relay/test_external_codegen.py | 5 ++++ 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/relay/backend/contrib/codegen_c/codegen.cc b/src/relay/backend/contrib/codegen_c/codegen.cc index ea1ba50f7645a..935ac16efb23f 100644 --- a/src/relay/backend/contrib/codegen_c/codegen.cc +++ b/src/relay/backend/contrib/codegen_c/codegen.cc @@ -290,37 +290,8 @@ runtime::Module CCompiler(const ObjectRef& ref) { return csource.CreateCSourceModule(ref); } -/*! - * \brief A visitor to add the constants used as params for MetadataModule. - */ -struct CCompilerConstantUpdater : public ExprVisitor { - public: - explicit CCompilerConstantUpdater(const std::string& symbol) : symbol_(symbol) {} - - Map GetConstants(const Expr& expr) { - VisitExpr(expr); - return this->params_; - } - - void VisitExpr_(const ConstantNode* cn) final { - std::string name = symbol_ + "_p" + std::to_string(const_idx_++); - params_.Set(name, cn->data); - } - - private: - int const_idx_{0}; - std::string symbol_; - Map params_; -}; - -Map GetConstants(const Expr& expr, const std::string symbol) { - return CCompilerConstantUpdater(symbol).GetConstants(expr); -} - TVM_REGISTER_GLOBAL("relay.ext.ccompiler").set_body_typed(CCompiler); -TVM_REGISTER_GLOBAL("relay.ext.ccompiler.constant_updater").set_body_typed(GetConstants); - } // namespace contrib } // namespace relay } // namespace tvm diff --git a/src/relay/backend/contrib/codegen_c/codegen_c.h b/src/relay/backend/contrib/codegen_c/codegen_c.h index 759831c5f184f..9448b4d0738d2 100644 --- a/src/relay/backend/contrib/codegen_c/codegen_c.h +++ b/src/relay/backend/contrib/codegen_c/codegen_c.h @@ -334,7 +334,7 @@ class CodegenCBase { * \return The created variable name */ std::string CreateConstVar(const std::string& symbol, int const_id) const { - return symbol + "_p" + std::to_string(const_id++); + return symbol + "_const_" + std::to_string(const_id++); } /*! \brief The external function source code stream. */ diff --git a/tests/python/relay/test_external_codegen.py b/tests/python/relay/test_external_codegen.py index c602c87e93a46..72b47c9195393 100644 --- a/tests/python/relay/test_external_codegen.py +++ b/tests/python/relay/test_external_codegen.py @@ -220,6 +220,11 @@ def test_extern_gcc(): def test_extern_gcc_consts(): + @tvm._ffi.register_func("relay.ext.ccompiler.constant_updater") + def constant_updater(expr, symbol): + """A dummy constant updater just to test that a custom one works.""" + return {"ccompiler_0_p0": tvm.nd.array(y0_data)} + x = relay.var("x", shape=(8, 8)) y0_data = np.random.uniform(0, 1, (8, 8)).astype("float32")