From 15d9856938ddf38dbaba1de424f8fd6c98e95406 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/=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: Wed, 11 Jul 2018 18:24:25 +0900 Subject: [PATCH] [newrt] Let the user select backend per operation (#1929) By default, arm_compute backend will be used for all operations. Resolve #1878 Signed-off-by: Hanjoung Lee --- runtimes/new_runtime/src/compilation.cc | 22 ++++++++++----------- runtimes/new_runtime/src/internal/op/Op.lst | 30 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 runtimes/new_runtime/src/internal/op/Op.lst diff --git a/runtimes/new_runtime/src/compilation.cc b/runtimes/new_runtime/src/compilation.cc index 9984d3e..494aa80 100644 --- a/runtimes/new_runtime/src/compilation.cc +++ b/runtimes/new_runtime/src/compilation.cc @@ -14,6 +14,7 @@ #include "internal/Padding.h" #include "internal/IInitializerGenerator.h" #include "internal/IStageGenerator.h" +#include "util/EnvVar.h" #include "compilation.h" #include "model.h" @@ -76,17 +77,16 @@ class BackendResolver public: BackendResolver(::internal::BackendManager &backend_manager) { - auto acl_gen = backend_manager.get("arm_compute"); - // auto cpu_gen = backend_manager.get("cpu"); // Unused for now - - // TODO Set generator map according to environment variable - _gen_map[typeid(::internal::tflite::op::Conv2D::implicit::Node)] = acl_gen; - _gen_map[typeid(::internal::tflite::op::MaxPool2D::implicit::Node)] = acl_gen; - _gen_map[typeid(::internal::tflite::op::AvgPool2D::implicit::Node)] = acl_gen; - _gen_map[typeid(::internal::tflite::op::Concat::Node)] = acl_gen; - _gen_map[typeid(::internal::tflite::op::FullyConnected::Node)] = acl_gen; - _gen_map[typeid(::internal::tflite::op::Reshape::Node)] = acl_gen; - _gen_map[typeid(::internal::tflite::op::Softmax::Node)] = acl_gen; +#define OP(InternalName, NnApiName) \ + { \ + const auto &backend_str = \ + ::nnfw::util::EnvVar{std::string("OP_BACKEND_") + #NnApiName}.asString("arm_compute"); \ + auto backend = backend_manager.get(backend_str); \ + _gen_map[typeid(::internal::tflite::op::InternalName::Node)] = backend; \ + } + +#include "internal/op/Op.lst" +#undef OP } std::shared_ptr<::internal::IInitializerGenerator> diff --git a/runtimes/new_runtime/src/internal/op/Op.lst b/runtimes/new_runtime/src/internal/op/Op.lst new file mode 100644 index 0000000..b468067 --- /dev/null +++ b/runtimes/new_runtime/src/internal/op/Op.lst @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OP +#error Define OP before including this file +#endif + +// NOTE The relation between "Internal Name" and "NN API Name" is "1 : N". + +// Internal Name | NN API Name +OP(Conv2D::implicit , CONV_2D) +OP(AvgPool2D::implicit , AVERAGE_POOL_2D) +OP(MaxPool2D::implicit , MAX_POOL_2D) +OP(Concat , CONCATENATION) +OP(FullyConnected , FULLY_CONNECTED) +OP(Reshape , RESHAPE) +OP(Softmax , SOFTMAX) -- 2.7.4