From 8e4ab68213ed68ee90a2909dfea029463fcfb564 Mon Sep 17 00:00:00 2001 From: Goose Bomb Date: Tue, 4 Jan 2022 14:35:17 +0800 Subject: [PATCH] Fix warnings relating to inheritance (#256) * Remove unnecessary compiler flags * Refactor CMakeLists.txt * Tweak CMakeLists.txt for libtim_internal * Tweak CMakeLists.txt for libtim-vx * Make TIM_VX_ENABLE_TEST defaults to OFF * Eliminate usage of include_directories * Fix CI unit test * Fix warnings relating to inheritance --- include/tim/vx/ops/rnn_cell.h | 21 +++++++++-------- src/tim/vx/direct_map_op_impl.cc | 32 ++++++++++++------------- src/tim/vx/direct_map_op_impl.h | 9 ++++--- src/tim/vx/op_impl.cc | 10 ++++---- src/tim/vx/op_impl.h | 5 ++-- src/tim/vx/ops/rnn_cell.cc | 40 ++++++++++++++++---------------- 6 files changed, 59 insertions(+), 58 deletions(-) diff --git a/include/tim/vx/ops/rnn_cell.h b/include/tim/vx/ops/rnn_cell.h index 1419803..d5f1e0d 100644 --- a/include/tim/vx/ops/rnn_cell.h +++ b/include/tim/vx/ops/rnn_cell.h @@ -29,19 +29,20 @@ namespace tim { namespace vx { namespace ops { -class RNNCell : public Operation{ +class RNNCell : public Operation { public: enum ActivationType { - kNONE = 0, - kRELU = 1, - kRELU1 = 2, - kRELU6 = 3, - kTANH = 4, - kSIGMOID = 6, - kHARDSIGMOID = 31, /* temporary use 31*/ - }; + kNONE = 0, + kRELU = 1, + kRELU1 = 2, + kRELU6 = 3, + kTANH = 4, + kSIGMOID = 6, + kHARDSIGMOID = 31, /* temporary use 31 */ + }; RNNCell(Graph* graph, ActivationType activation); - std::shared_ptr Clone(std::shared_ptr& graph) const override; + std::shared_ptr Clone( + std::shared_ptr& graph) const override; protected: const ActivationType activation_; diff --git a/src/tim/vx/direct_map_op_impl.cc b/src/tim/vx/direct_map_op_impl.cc index 1701604..7ea0bcb 100644 --- a/src/tim/vx/direct_map_op_impl.cc +++ b/src/tim/vx/direct_map_op_impl.cc @@ -24,11 +24,11 @@ #include "direct_map_op_impl.h" #include "type_utils.h" -namespace tim{ -namespace vx{ +namespace tim { +namespace vx { DirectMapOpImpl::DirectMapOpImpl(Graph* graph, uint32_t kind, int input_cnt, - int output_cnt, DataLayout layout) + int output_cnt, DataLayout layout) : OpImpl(graph, kind, input_cnt, output_cnt, layout), node_(vsi_nn_AddNode(graph_->graph(), kind_, input_cnt_, output_cnt_, NULL)) { @@ -36,7 +36,8 @@ DirectMapOpImpl::DirectMapOpImpl(Graph* graph, uint32_t kind, int input_cnt, node_->uid = graph_->graph()->cur_nid; } -DirectMapOpImpl& DirectMapOpImpl::BindInput(const std::shared_ptr& tensor) { +DirectMapOpImpl& DirectMapOpImpl::BindInput( + const std::shared_ptr& tensor) { inputs_tensor_.push_back(tensor); uint32_t tensor_id = tensor->GetId(); node_->input.tensors[input_tensor_index++] = tensor_id; @@ -59,17 +60,16 @@ DirectMapOpImpl& DirectMapOpImpl::BindOutput( return *this; } -void DirectMapOpImpl::SetRoundingPolicy( - OverflowPolicy overflow_policy, - RoundingPolicy rounding_policy, - RoundType down_scale_size_rounding, - uint32_t accumulator_bits) { - node_->vx_param.overflow_policy = TranslateOverflowPolicy(overflow_policy); - node_->vx_param.rounding_policy = TranslateRoundingPolicy(rounding_policy); - node_->vx_param.down_scale_size_rounding = - TranslateDownScaleSizeRounding(down_scale_size_rounding); - node_->vx_param.accumulator_bits = accumulator_bits; +void DirectMapOpImpl::SetRoundingPolicy(OverflowPolicy overflow_policy, + RoundingPolicy rounding_policy, + RoundType down_scale_size_rounding, + uint32_t accumulator_bits) { + node_->vx_param.overflow_policy = TranslateOverflowPolicy(overflow_policy); + node_->vx_param.rounding_policy = TranslateRoundingPolicy(rounding_policy); + node_->vx_param.down_scale_size_rounding = + TranslateDownScaleSizeRounding(down_scale_size_rounding); + node_->vx_param.accumulator_bits = accumulator_bits; } -} -} \ No newline at end of file +} // namespace vx +} // namespace tim \ No newline at end of file diff --git a/src/tim/vx/direct_map_op_impl.h b/src/tim/vx/direct_map_op_impl.h index e4ff432..88c49c5 100644 --- a/src/tim/vx/direct_map_op_impl.h +++ b/src/tim/vx/direct_map_op_impl.h @@ -24,7 +24,6 @@ #ifndef TIM_VX_DIRECT_MAP_OP_IMPL_H_ #define TIM_VX_DIRECT_MAP_OP_IMPL_H_ - #include "vsi_nn_pub.h" #include "graph_private.h" @@ -38,7 +37,7 @@ class DirectMapOpImpl : public OpImpl { // DirectMapOpImpl(Graph* graph, uint32_t kind, int input_cnt = 0, // int output_cnt = 0); DirectMapOpImpl(Graph* graph, uint32_t kind, int input_cnt = 0, - int output_cnt = 0, DataLayout layout = DataLayout::ANY); + int output_cnt = 0, DataLayout layout = DataLayout::ANY); ~DirectMapOpImpl() {} DirectMapOpImpl& BindInput(const std::shared_ptr& tensor) override; @@ -50,12 +49,12 @@ class DirectMapOpImpl : public OpImpl { OverflowPolicy overflow_policy = OverflowPolicy::SATURATE, RoundingPolicy rounding_policy = RoundingPolicy::RTNE, RoundType down_scale_size_rounding = RoundType::FLOOR, - uint32_t accumulator_bits =0); + uint32_t accumulator_bits = 0); - std::vector> InputsTensor() { + std::vector> InputsTensor() override { return inputs_tensor_; } - std::vector> OutputsTensor() { + std::vector> OutputsTensor() override { return outputs_tensor_; } diff --git a/src/tim/vx/op_impl.cc b/src/tim/vx/op_impl.cc index 3d60375..a0366b2 100644 --- a/src/tim/vx/op_impl.cc +++ b/src/tim/vx/op_impl.cc @@ -23,15 +23,15 @@ *****************************************************************************/ #include "op_impl.h" -namespace tim{ -namespace vx{ +namespace tim { +namespace vx { OpImpl::OpImpl(Graph* graph, uint32_t kind, int input_cnt, int output_cnt, - DataLayout layout) + DataLayout layout) : graph_(reinterpret_cast(graph)), kind_(kind), input_cnt_(input_cnt), output_cnt_(output_cnt), layout_(layout) {} -} -} +} // namespace vx +} // namespace tim diff --git a/src/tim/vx/op_impl.h b/src/tim/vx/op_impl.h index 582ba79..637deee 100644 --- a/src/tim/vx/op_impl.h +++ b/src/tim/vx/op_impl.h @@ -34,14 +34,15 @@ namespace vx { class OpImpl { public: OpImpl(Graph* graph, uint32_t kind, int input_cnt, int output_cnt, - DataLayout layout); + DataLayout layout); + virtual ~OpImpl() = default; virtual OpImpl& BindInput(const std::shared_ptr& tensor) = 0; virtual OpImpl& BindOutput(const std::shared_ptr& tensor) = 0; virtual std::vector> InputsTensor() = 0; virtual std::vector> OutputsTensor() = 0; virtual vsi_nn_node_t* node() = 0; - GraphImpl* graph_; + GraphImpl* graph_{nullptr}; uint32_t kind_{0}; int32_t input_cnt_{0}; int32_t output_cnt_{0}; diff --git a/src/tim/vx/ops/rnn_cell.cc b/src/tim/vx/ops/rnn_cell.cc index 6b784a7..e5ec74f 100644 --- a/src/tim/vx/ops/rnn_cell.cc +++ b/src/tim/vx/ops/rnn_cell.cc @@ -30,9 +30,8 @@ namespace tim { namespace vx { namespace ops { -class RNNCellImpl : public OpImpl{ +class RNNCellImpl : public OpImpl { public: - enum { // signature FULLY_CONNECTED_0_IN = 0, @@ -49,20 +48,19 @@ class RNNCellImpl : public OpImpl{ // signature end }; - RNNCellImpl(Graph* graph, int input_cnt, - int output_cnt, DataLayout layout = DataLayout::ANY) - : OpImpl(graph, -1, input_cnt, output_cnt, layout){ - fc0_ = graph->CreateOperation(0, 4); - fc1_ = graph->CreateOperation(0, 4); - add_ = graph->CreateOperation(); - tanh_ = graph->CreateOperation(); - data_convert_ = graph->CreateOperation(); + RNNCellImpl(Graph* graph, int input_cnt, int output_cnt, + DataLayout layout = DataLayout::ANY) + : OpImpl(graph, -1, input_cnt, output_cnt, layout) { + fc0_ = graph->CreateOperation(0, 4); + fc1_ = graph->CreateOperation(0, 4); + add_ = graph->CreateOperation(); + tanh_ = graph->CreateOperation(); + data_convert_ = graph->CreateOperation(); } ~RNNCellImpl() {} - RNNCellImpl& BindInput(const std::shared_ptr& tensor) override - { + RNNCellImpl& BindInput(const std::shared_ptr& tensor) override { in_tensors_[input_tensor_index] = tensor; if (this->input_tensor_index == INPUT_CNT - 1) { @@ -75,7 +73,6 @@ class RNNCellImpl : public OpImpl{ tim::vx::TensorSpec add_spec(tim::vx::DataType::FLOAT32, shape, tim::vx::TensorAttribute::TRANSIENT); - auto FC0_tensor = graph_->CreateTensor(FC0_spec); auto FC1_tensor = graph_->CreateTensor(FC1_spec); auto add_tensor = graph_->CreateTensor(add_spec); @@ -99,22 +96,24 @@ class RNNCellImpl : public OpImpl{ return *this; } - RNNCellImpl& BindOutput(const std::shared_ptr& tensor) override{ + RNNCellImpl& BindOutput(const std::shared_ptr& tensor) override { out_tensors_[output_tensor_index] = tensor; tanh_->BindOutput(out_tensors_[OUT]); data_convert_->BindInput(out_tensors_[OUT]); - if (this->output_tensor_index == OUT_CNT - 1){ + if (this->output_tensor_index == OUT_CNT - 1) { data_convert_->BindOutput(out_tensors_[STATE_OUT]); } this->output_tensor_index++; return *this; } - vsi_nn_node_t* node() override{ return nullptr; } + vsi_nn_node_t* node() override { return nullptr; } - std::vector> InputsTensor() { return inputs_tensor_; } - std::vector> OutputsTensor() { + std::vector> InputsTensor() override { + return inputs_tensor_; + } + std::vector> OutputsTensor() override { return outputs_tensor_; } @@ -129,8 +128,9 @@ class RNNCellImpl : public OpImpl{ std::array, OUT_CNT> out_tensors_; }; -RNNCell::RNNCell(Graph* graph, ActivationType activation) : activation_(activation){ - impl_ = std::make_unique(graph, 0, 0, DataLayout::ANY); +RNNCell::RNNCell(Graph* graph, ActivationType activation) + : activation_(activation) { + impl_ = std::make_unique(graph, 0, 0, DataLayout::ANY); } std::shared_ptr RNNCell::Clone(std::shared_ptr& graph) const {