From: 김수진/동작제어Lab(SR)/Engineer/삼성전자 Date: Thu, 22 Nov 2018 08:21:34 +0000 (+0900) Subject: [neurun] Introduce internal IFunction class (#3672) X-Git-Tag: 0.3~351 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=39dd788b1b12092c525b8453282717d63d44c896;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Introduce internal IFunction class (#3672) * [neurun] Introduce internal IFunction class Related : #3273 Part of : #3484 This commit introduces internal `IFunction` class. Signed-off-by: sjsujinkim * Change directory --- diff --git a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc index 4bc975d..eb2fe62 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc @@ -16,6 +16,8 @@ #include "backend/acl_cl/StageGenerator.h" +#include "kernel/acl_cl/CLFunction.h" + #include #include #include @@ -37,6 +39,13 @@ template std::unique_ptr make_layer(void) { return std::unique_ptr{new T}; } +std::unique_ptr<::neurun::kernel::acl_cl::CLFunction> +make_cl_function(std::unique_ptr<::arm_compute::IFunction> &&layer) +{ + return std::unique_ptr<::neurun::kernel::acl_cl::CLFunction>( + new ::neurun::kernel::acl_cl::CLFunction(std::move(layer))); +} + ::arm_compute::PadStrideInfo asPadStringInfo(const ::internal::Padding &padding, const ::internal::Stride &stride) { @@ -86,7 +95,9 @@ void ActivationBuilder::appendReLU(::arm_compute::ICLTensor *ifm_alloc) fn->configure(ifm_alloc, nullptr, act_info); - _builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + _builder.append(std::move(acl_fn)); } void ActivationBuilder::append(FuseCode code, ::arm_compute::ICLTensor *ifm_alloc) @@ -193,7 +204,9 @@ void StageGenerator::visit(const graph::operation::Conv2DNode &node) fn->configure(ifm_alloc, ker_alloc, bias_alloc, ofm_alloc, conv_info); - builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + builder.append(std::move(acl_fn)); ActivationBuilder{builder}.append(param.activation, ofm_alloc); }); @@ -281,7 +294,9 @@ void StageGenerator::visit(const graph::operation::MaxPool2DNode &node) fn->configure(ifm_alloc, ofm_alloc, info); - builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + builder.append((std::move(acl_fn))); }); } @@ -371,7 +386,9 @@ void StageGenerator::visit(const graph::operation::AvgPool2DNode &node) fn->configure(ifm_alloc, ofm_alloc, info); - builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + builder.append((std::move(acl_fn))); }); } @@ -429,7 +446,9 @@ void StageGenerator::visit(const graph::operation::ConcatNode &node) fn->configure(input_allocs, param.axis, output_alloc); - builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + builder.append(std::move(acl_fn)); }); } @@ -476,7 +495,9 @@ void StageGenerator::visit(const graph::operation::FullyConnectedNode &node) fn->configure(input_alloc, weight_alloc, bias_alloc, output_alloc); - builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + builder.append((std::move(acl_fn))); ActivationBuilder{builder}.append(param.activation, output_alloc); }); @@ -508,7 +529,9 @@ void StageGenerator::visit(const graph::operation::ReshapeNode &node) fn->configure(input_alloc, output_alloc); - builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + builder.append((std::move(acl_fn))); }); } @@ -543,7 +566,9 @@ void StageGenerator::visit(const graph::operation::SoftmaxNode &node) fn->configure(input_alloc, output_alloc, param.scale); - builder.append(std::move(fn)); + auto acl_fn = make_cl_function(std::move(fn)); + + builder.append((std::move(acl_fn))); }); } diff --git a/runtimes/neurun/src/backend/interface/IStageGenerator.h b/runtimes/neurun/src/backend/interface/IStageGenerator.h index 383dd06..4a6a7d2 100644 --- a/runtimes/neurun/src/backend/interface/IStageGenerator.h +++ b/runtimes/neurun/src/backend/interface/IStageGenerator.h @@ -20,7 +20,7 @@ #include #include -#include +#include "exec/interface/IFunction.h" #include "backend/interface/ITensorBuilder.h" #include "graph/operation/NodeVisitor.h" @@ -29,7 +29,7 @@ struct IExecutionBuilder { virtual ~IExecutionBuilder() = default; - virtual void append(std::unique_ptr<::arm_compute::IFunction> &&f) = 0; + virtual void append(std::unique_ptr<::neurun::exec::IFunction> &&f) = 0; }; using Stage = std::function; diff --git a/runtimes/neurun/src/codegen/operation/Sequence.h b/runtimes/neurun/src/codegen/operation/Sequence.h index 83403fe..36a7aa7 100644 --- a/runtimes/neurun/src/codegen/operation/Sequence.h +++ b/runtimes/neurun/src/codegen/operation/Sequence.h @@ -18,7 +18,7 @@ #define __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__ #include -#include +#include "exec/interface/IFunction.h" #include #include @@ -35,17 +35,17 @@ public: uint32_t size(void) const { return _functions.size(); } public: - Sequence &append(std::unique_ptr<::arm_compute::IFunction> &&func) + Sequence &append(std::unique_ptr<::neurun::exec::IFunction> &&func) { _functions.emplace_back(std::move(func)); return (*this); } public: - ::arm_compute::IFunction &at(uint32_t n) const { return *(_functions.at(n)); } + ::neurun::exec::IFunction &at(uint32_t n) const { return *(_functions.at(n)); } private: - std::vector> _functions; + std::vector> _functions; }; } // namespace operation diff --git a/runtimes/neurun/src/compiler/PlanBuilder.h b/runtimes/neurun/src/compiler/PlanBuilder.h index 60413cd..68caae8 100644 --- a/runtimes/neurun/src/compiler/PlanBuilder.h +++ b/runtimes/neurun/src/compiler/PlanBuilder.h @@ -35,7 +35,7 @@ public: } public: - void append(std::unique_ptr<::arm_compute::IFunction> &&f) override + void append(std::unique_ptr<::neurun::exec::IFunction> &&f) override { _plan.operations().append(std::move(f)); } diff --git a/runtimes/neurun/src/exec/interface/IFunction.h b/runtimes/neurun/src/exec/interface/IFunction.h new file mode 100644 index 0000000..b7a721d --- /dev/null +++ b/runtimes/neurun/src/exec/interface/IFunction.h @@ -0,0 +1,36 @@ +/* + * 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 __NEURUN_EXEC_I_FUNCTION_H__ +#define __NEURUN_EXEC_I_FUNCTION_H__ + +namespace neurun +{ +namespace exec +{ + +class IFunction +{ +public: + virtual ~IFunction() = default; + virtual void run() = 0; + virtual void prepare() {} +}; + +} // namespace exec +} // namespace neurun + +#endif // __NEURUN_EXEC_I_FUNCTION_H__ diff --git a/runtimes/neurun/src/kernel/acl_cl/CLFunction.h b/runtimes/neurun/src/kernel/acl_cl/CLFunction.h new file mode 100644 index 0000000..f34210c --- /dev/null +++ b/runtimes/neurun/src/kernel/acl_cl/CLFunction.h @@ -0,0 +1,55 @@ +/* + * 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 __NEURUN_KERNEL_ACL_CL_CL_FUNCTION_H__ +#define __NEURUN_KERNEL_ACL_CL_CL_FUNCTION_H__ + +#include "exec/interface/IFunction.h" +#include +#include + +namespace neurun +{ +namespace kernel +{ +namespace acl_cl +{ + +class CLFunction : public ::neurun::exec::IFunction +{ +public: + CLFunction() = delete; + +public: + CLFunction(std::unique_ptr<::arm_compute::IFunction> &&func) + : _func(std::forward>(func)) + { + // DO NOTHING + } + +public: + void run() override { _func->run(); } + void prepare() override { _func->prepare(); } + +private: + std::unique_ptr<::arm_compute::IFunction> _func; +}; + +} // namespace acl_cl +} // namespace kernel +} // namespace neurun + +#endif // __NEURUN_KERNEL_ACL_CL_CL_FUNCTION_H__ diff --git a/runtimes/neurun/src/kernel/cpu/AvgPoolLayer.h b/runtimes/neurun/src/kernel/cpu/AvgPoolLayer.h index 9f390a9..280f7ae 100644 --- a/runtimes/neurun/src/kernel/cpu/AvgPoolLayer.h +++ b/runtimes/neurun/src/kernel/cpu/AvgPoolLayer.h @@ -19,7 +19,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include "kernel/cpu/OperationUtils.h" @@ -30,7 +30,7 @@ namespace kernel namespace cpu { -class AvgPoolLayer : public ::arm_compute::IFunction +class AvgPoolLayer : public ::neurun::exec::IFunction { public: AvgPoolLayer(); diff --git a/runtimes/neurun/src/kernel/cpu/ConcatLayer.h b/runtimes/neurun/src/kernel/cpu/ConcatLayer.h index 9aacab5..64f8135 100644 --- a/runtimes/neurun/src/kernel/cpu/ConcatLayer.h +++ b/runtimes/neurun/src/kernel/cpu/ConcatLayer.h @@ -20,7 +20,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include "kernel/cpu/OperationUtils.h" @@ -31,7 +31,7 @@ namespace kernel namespace cpu { -class ConcatLayer : public ::arm_compute::IFunction +class ConcatLayer : public ::neurun::exec::IFunction { public: ConcatLayer(); diff --git a/runtimes/neurun/src/kernel/cpu/ConvolutionLayer.h b/runtimes/neurun/src/kernel/cpu/ConvolutionLayer.h index b7afbce..9b7f55f 100644 --- a/runtimes/neurun/src/kernel/cpu/ConvolutionLayer.h +++ b/runtimes/neurun/src/kernel/cpu/ConvolutionLayer.h @@ -19,7 +19,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include "kernel/cpu/OperationUtils.h" @@ -30,7 +30,7 @@ namespace kernel namespace cpu { -class ConvolutionLayer : public ::arm_compute::IFunction +class ConvolutionLayer : public ::neurun::exec::IFunction { public: ConvolutionLayer(); diff --git a/runtimes/neurun/src/kernel/cpu/FullyConnectedLayer.h b/runtimes/neurun/src/kernel/cpu/FullyConnectedLayer.h index b1ba172..20a3883 100644 --- a/runtimes/neurun/src/kernel/cpu/FullyConnectedLayer.h +++ b/runtimes/neurun/src/kernel/cpu/FullyConnectedLayer.h @@ -19,7 +19,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include "kernel/cpu/OperationUtils.h" @@ -30,7 +30,7 @@ namespace kernel namespace cpu { -class FullyConnectedLayer : public ::arm_compute::IFunction +class FullyConnectedLayer : public ::neurun::exec::IFunction { public: FullyConnectedLayer(); diff --git a/runtimes/neurun/src/kernel/cpu/MaxPoolLayer.h b/runtimes/neurun/src/kernel/cpu/MaxPoolLayer.h index b42efb9..2b18555 100644 --- a/runtimes/neurun/src/kernel/cpu/MaxPoolLayer.h +++ b/runtimes/neurun/src/kernel/cpu/MaxPoolLayer.h @@ -19,7 +19,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include "kernel/cpu/OperationUtils.h" @@ -30,7 +30,7 @@ namespace kernel namespace cpu { -class MaxPoolLayer : public ::arm_compute::IFunction +class MaxPoolLayer : public ::neurun::exec::IFunction { public: MaxPoolLayer(); diff --git a/runtimes/neurun/src/kernel/cpu/PermuteLayer.h b/runtimes/neurun/src/kernel/cpu/PermuteLayer.h index e4836f8..293e995 100644 --- a/runtimes/neurun/src/kernel/cpu/PermuteLayer.h +++ b/runtimes/neurun/src/kernel/cpu/PermuteLayer.h @@ -19,7 +19,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include #include "util/feature/nhwc/View.h" @@ -32,7 +32,7 @@ namespace kernel namespace cpu { -class PermuteLayer : public ::arm_compute::IFunction +class PermuteLayer : public ::neurun::exec::IFunction { public: enum class Type diff --git a/runtimes/neurun/src/kernel/cpu/ReshapeLayer.h b/runtimes/neurun/src/kernel/cpu/ReshapeLayer.h index 395cc1d..51d0bac 100644 --- a/runtimes/neurun/src/kernel/cpu/ReshapeLayer.h +++ b/runtimes/neurun/src/kernel/cpu/ReshapeLayer.h @@ -19,7 +19,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include "kernel/cpu/OperationUtils.h" @@ -30,7 +30,7 @@ namespace kernel namespace cpu { -class ReshapeLayer : public ::arm_compute::IFunction +class ReshapeLayer : public ::neurun::exec::IFunction { public: ReshapeLayer(); diff --git a/runtimes/neurun/src/kernel/cpu/SoftMaxLayer.h b/runtimes/neurun/src/kernel/cpu/SoftMaxLayer.h index 8057be5..df1aa40 100644 --- a/runtimes/neurun/src/kernel/cpu/SoftMaxLayer.h +++ b/runtimes/neurun/src/kernel/cpu/SoftMaxLayer.h @@ -19,7 +19,7 @@ #include -#include +#include "exec/interface/IFunction.h" #include "kernel/cpu/OperationUtils.h" @@ -30,7 +30,7 @@ namespace kernel namespace cpu { -class SoftMaxLayer : public ::arm_compute::IFunction +class SoftMaxLayer : public ::neurun::exec::IFunction { public: SoftMaxLayer();