From fc60286744af6d7e2e1169b0d21a83fe729c63cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 29 Aug 2018 16:13:18 +0900 Subject: [PATCH] [enco] Create and start ANN exeution (#1230) With this commit, enco now emits ANeuralNetworksExecution_create and ANeuralNetworksExecution_startCompute calls. Signed-off-by: Jonghyun Park --- contrib/enco/core/src/CppCode.cpp | 11 +++++++++++ contrib/enco/core/src/CppGen/Subnet.cpp | 14 +++++++++++++- contrib/enco/core/src/CppGen/Subnet.h | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/contrib/enco/core/src/CppCode.cpp b/contrib/enco/core/src/CppCode.cpp index e008649..1dda353 100644 --- a/contrib/enco/core/src/CppCode.cpp +++ b/contrib/enco/core/src/CppCode.cpp @@ -22,6 +22,8 @@ namespace struct SubnetInfo { std::string struct_name; + // @brief The field name (in this subnet struct) of ANeuralNetworksCompilation value + std::string compilation_field; // @brief The field name (in Network struct) for this subnet std::string field_name; @@ -141,6 +143,7 @@ void CppCode::dump(std::ostream &os) const SubnetInfo subnet_info; subnet_info.struct_name = subnet_struct_name; + subnet_info.compilation_field = subnet_struct_content->compilation(); subnet_info.field_name = subnet_field_name; assert(subnet_ctx.find(subnet_binder) == subnet_ctx.end()); @@ -177,6 +180,14 @@ void CppCode::dump(std::ostream &os) const // Create Code Block Builder SubnetBlockCompiler subnet_compiler{mem}; + + for (auto it = subnet_ctx.begin(); it != subnet_ctx.end(); ++it) + { + // Specify how to access ANeuralNetworksCompilation + const auto &info = it->second; + subnet_compiler.bind(it->first, pp::fmt("net->", info.field_name, ".", info.compilation_field)); + } + HostBlockCompiler host_compiler{mem}; for (auto blk = m->block()->head(); blk; blk = blk->next()) diff --git a/contrib/enco/core/src/CppGen/Subnet.cpp b/contrib/enco/core/src/CppGen/Subnet.cpp index 33007e6..c3629f1 100644 --- a/contrib/enco/core/src/CppGen/Subnet.cpp +++ b/contrib/enco/core/src/CppGen/Subnet.cpp @@ -235,9 +235,21 @@ std::unique_ptr SubnetBlockCompiler::compile(const ANNBinder { auto res = nncc::foundation::make_unique(); - // TODO Generate appropriate code + const auto compilation = _compilation_ctx.at(binder); + + res->append("ANeuralNetworksExecution *execution;"); + res->append("ANeuralNetworksEvent *event;"); + res->append(); + res->append("ANeuralNetworksExecution_create(", compilation, ", &execution);"); + + // TODO Invoke setInput & setOutput method res->append(S(assert("NYI");)); + res->append("ANeuralNetworksExecution_startCompute(execution, &event);"); + res->append("ANeuralNetworksEvent_wait(event);"); + + res->append("ANeuralNetworksExecution_free(execution);"); + return std::move(res); } diff --git a/contrib/enco/core/src/CppGen/Subnet.h b/contrib/enco/core/src/CppGen/Subnet.h index 1fe615a..3161aaf 100644 --- a/contrib/enco/core/src/CppGen/Subnet.h +++ b/contrib/enco/core/src/CppGen/Subnet.h @@ -6,6 +6,7 @@ #include "CppGen/MemoryContext.h" #include +#include namespace enco { @@ -54,10 +55,15 @@ public: } public: + // @brief Specify how to access ANeuralNetworksCompilation value (C expression) + void bind(const ANNBinder *binder, const std::string &exp) { _compilation_ctx[binder] = exp; } + +public: std::unique_ptr compile(const ANNBinder *binder) const; private: const enco::MemoryContext &_mem; + std::map _compilation_ctx; }; } // namespace enco -- 2.7.4