From 9a94c79544824237be351f5314fcc46c0daf487f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EA=B9=80=EC=88=98=EC=A7=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Mon, 3 Sep 2018 14:44:29 +0900 Subject: [PATCH] [neurun] Move CLSchedule default init to BackendManager (#2526) * [neurun] Move CLSchedule default init to BackendManager This commit moves CLSchedule default init to BackendManager, since it is ACL_CL specific code. Signed-off-by: sjsujinkim * Extract backend initializer * Add eol * Remove unnecessary variable * Remove unused include --- runtimes/neurun/src/backend/IBackendInitializer.h | 19 +++++++++++++++ .../src/backend/acl_cl/BackendInitializer.cc | 16 +++++++++++++ .../neurun/src/backend/acl_cl/BackendInitializer.h | 28 ++++++++++++++++++++++ .../neurun/src/backend/cpu/BackendInitializer.cc | 17 +++++++++++++ .../neurun/src/backend/cpu/BackendInitializer.h | 28 ++++++++++++++++++++++ runtimes/neurun/src/compilation.cc | 2 -- runtimes/neurun/src/internal/BackendManager.cc | 8 +++++-- runtimes/neurun/src/internal/BackendManager.h | 6 +++-- 8 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 runtimes/neurun/src/backend/IBackendInitializer.h create mode 100644 runtimes/neurun/src/backend/acl_cl/BackendInitializer.cc create mode 100644 runtimes/neurun/src/backend/acl_cl/BackendInitializer.h create mode 100644 runtimes/neurun/src/backend/cpu/BackendInitializer.cc create mode 100644 runtimes/neurun/src/backend/cpu/BackendInitializer.h diff --git a/runtimes/neurun/src/backend/IBackendInitializer.h b/runtimes/neurun/src/backend/IBackendInitializer.h new file mode 100644 index 0000000..6203427 --- /dev/null +++ b/runtimes/neurun/src/backend/IBackendInitializer.h @@ -0,0 +1,19 @@ +#ifndef __INTERNAL_IBACKEND_INITIALIZER_H__ +#define __INTERNAL_IBACKEND_INITIALIZER_H__ + +namespace neurun +{ +namespace backend +{ + +struct IBackendInitializer +{ + virtual ~IBackendInitializer() = default; + + virtual void initialize() = 0; +}; + +} // namespace backend +} // namespace neurun + +#endif // __INTERNAL_IBACKEND_INITIALIZER_H__ diff --git a/runtimes/neurun/src/backend/acl_cl/BackendInitializer.cc b/runtimes/neurun/src/backend/acl_cl/BackendInitializer.cc new file mode 100644 index 0000000..270263f --- /dev/null +++ b/runtimes/neurun/src/backend/acl_cl/BackendInitializer.cc @@ -0,0 +1,16 @@ +#include + +#include "backend/acl_cl/BackendInitializer.h" + +namespace neurun +{ +namespace backend +{ +namespace acl_cl +{ + +void BackendInitializer::initialize() { arm_compute::CLScheduler::get().default_init(); } + +} // namespace acl_cl +} // namespace backend +} // namespace neurun diff --git a/runtimes/neurun/src/backend/acl_cl/BackendInitializer.h b/runtimes/neurun/src/backend/acl_cl/BackendInitializer.h new file mode 100644 index 0000000..3e28442 --- /dev/null +++ b/runtimes/neurun/src/backend/acl_cl/BackendInitializer.h @@ -0,0 +1,28 @@ +#ifndef __NEURUN_BACKEND_ACL_CL_BACKEND_INITIALIZER_H__ +#define __NEURUN_BACKEND_ACL_CL_BACKEND_INITIALIZER_H__ + +#include "backend/IBackendInitializer.h" + +namespace neurun +{ +namespace backend +{ +namespace acl_cl +{ + +class BackendInitializer : public IBackendInitializer +{ +public: + BackendInitializer() + { + // DO NOTHING + } + + virtual void initialize() override; +}; + +} // namespace acl_cl +} // namespace backend +} // namespace neurun + +#endif // __NEURUN_BACKEND_ACL_CL_BACKEND_INITIALIZER_H__ diff --git a/runtimes/neurun/src/backend/cpu/BackendInitializer.cc b/runtimes/neurun/src/backend/cpu/BackendInitializer.cc new file mode 100644 index 0000000..ac2b4e2 --- /dev/null +++ b/runtimes/neurun/src/backend/cpu/BackendInitializer.cc @@ -0,0 +1,17 @@ +#include "backend/cpu/BackendInitializer.h" + +namespace neurun +{ +namespace backend +{ +namespace cpu +{ + +void BackendInitializer::initialize() +{ + // DO NOTHING +} + +} // namespace cpu +} // namespace backend +} // namespace neurun diff --git a/runtimes/neurun/src/backend/cpu/BackendInitializer.h b/runtimes/neurun/src/backend/cpu/BackendInitializer.h new file mode 100644 index 0000000..ede1c5f --- /dev/null +++ b/runtimes/neurun/src/backend/cpu/BackendInitializer.h @@ -0,0 +1,28 @@ +#ifndef __NEURUN_BACKEND_CPU_BACKEND_INITIALIZER_H__ +#define __NEURUN_BACKEND_CPU_BACKEND_INITIALIZER_H__ + +#include "backend/IBackendInitializer.h" + +namespace neurun +{ +namespace backend +{ +namespace cpu +{ + +class BackendInitializer : public IBackendInitializer +{ +public: + BackendInitializer() + { + // DO NOTHING + } + + virtual void initialize() override; +}; + +} // namespace cpu +} // namespace backend +} // namespace neurun + +#endif // __NEURUN_BACKEND_CPU_BACKEND_INITIALIZER_H__ diff --git a/runtimes/neurun/src/compilation.cc b/runtimes/neurun/src/compilation.cc index 014a4b4..7e9bff6 100644 --- a/runtimes/neurun/src/compilation.cc +++ b/runtimes/neurun/src/compilation.cc @@ -29,8 +29,6 @@ int ANeuralNetworksCompilation::finish() { - arm_compute::CLScheduler::get().default_init(); - auto &plan = this->plan(); const auto &operands = plan.model().operands(); diff --git a/runtimes/neurun/src/internal/BackendManager.cc b/runtimes/neurun/src/internal/BackendManager.cc index 603e3dd..bf5821c 100644 --- a/runtimes/neurun/src/internal/BackendManager.cc +++ b/runtimes/neurun/src/internal/BackendManager.cc @@ -1,8 +1,10 @@ #include "internal/BackendManager.h" +#include "backend/acl_cl/BackendInitializer.h" #include "backend/acl_cl/TensorBuilder.h" #include "backend/acl_cl/InitializerGenerator.h" #include "backend/acl_cl/StageGenerator.h" +#include "backend/cpu/BackendInitializer.h" #include "backend/cpu/TensorBuilder.h" #include "backend/cpu/InitializerGenerator.h" #include "backend/cpu/StageGenerator.h" @@ -17,23 +19,25 @@ BackendManager::BackendManager(neurun::codegen::Plan &plan) : _plan(plan) // Add arm_compute backend { using namespace ::neurun::backend::acl_cl; + auto acl_backend_initializer = std::make_shared(); auto acl_tensor_builder = std::make_shared(_plan); auto acl_initializer_gen = std::make_shared(operands); auto acl_stage_gen = std::make_shared(operands, acl_tensor_builder); // TODO Do not use magic string for backend id - _gen_map["acl_cl"] = {acl_initializer_gen, acl_stage_gen}; + _gen_map["acl_cl"] = {acl_backend_initializer, acl_initializer_gen, acl_stage_gen}; } // Add CPU backend { using namespace ::neurun::backend::cpu; + auto cpu_backend_initializer = std::make_shared(); auto cpu_tensor_builder = std::make_shared(_plan); auto cpu_initializer_gen = std::make_shared(operands); auto cpu_stage_gen = std::make_shared(operands, cpu_tensor_builder); // TODO Do not use magic string for backend id - _gen_map["cpu"] = {cpu_initializer_gen, cpu_stage_gen}; + _gen_map["cpu"] = {cpu_backend_initializer, cpu_initializer_gen, cpu_stage_gen}; } } diff --git a/runtimes/neurun/src/internal/BackendManager.h b/runtimes/neurun/src/internal/BackendManager.h index afe57b1..99137eb 100644 --- a/runtimes/neurun/src/internal/BackendManager.h +++ b/runtimes/neurun/src/internal/BackendManager.h @@ -4,6 +4,7 @@ #include #include "codegen/Plan.h" +#include "backend/IBackendInitializer.h" #include "backend/IInitializerGenerator.h" #include "backend/IStageGenerator.h" #include "backend/ITensorBuilder.h" @@ -16,11 +17,12 @@ struct Backend std::shared_ptr initializer_gen; std::shared_ptr stage_gen; - Backend(const std::shared_ptr &initializer_gen, + Backend(const std::shared_ptr &backend_initializer, + const std::shared_ptr &initializer_gen, const std::shared_ptr &stage_gen) : initializer_gen(initializer_gen), stage_gen(stage_gen) { - // DO NOTHING + backend_initializer->initialize(); } Backend(void) : initializer_gen(nullptr), stage_gen(nullptr) -- 2.7.4