From a794790703dec896d92cf44b36b4adaeb45183e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=91=D0=B0=D1=80?= =?utf8?q?=D0=B0=D0=BD=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2/AI=20Tools=20Lab=20/S?= =?utf8?q?RR/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 17 Jun 2019 07:18:22 +0300 Subject: [PATCH] Disallow copying of model::Operation class (#5383) Mark copy constructor and copy assignment operator as deleted to avoid unintentional copying. Signed-off-by: Sergei Barannikov --- runtimes/neurun/core/include/model/Operation.h | 8 +++++++- runtimes/neurun/core/src/exec/interp/operations/Add.cc | 4 ++-- runtimes/neurun/core/src/exec/interp/operations/AvgPool2D.cc | 8 +++----- runtimes/neurun/core/src/exec/interp/operations/Concat.cc | 4 ++-- runtimes/neurun/core/src/exec/interp/operations/Conv2D.cc | 4 +--- runtimes/neurun/core/src/exec/interp/operations/FullyConnected.cc | 4 +--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/runtimes/neurun/core/include/model/Operation.h b/runtimes/neurun/core/include/model/Operation.h index f8a5edc..029684d 100644 --- a/runtimes/neurun/core/include/model/Operation.h +++ b/runtimes/neurun/core/include/model/Operation.h @@ -54,7 +54,13 @@ class Operation public: Operation(OperandConstraint input_constr, const OperandIndexSequence &inputs, const OperandIndexSequence &outputs); - Operation(OperandConstraint input_constr); + explicit Operation(OperandConstraint input_constr); + + Operation(const Operation &) = delete; + Operation(Operation &&) = default; + Operation &operator=(const Operation &) = delete; + Operation &operator=(Operation &&) = default; + virtual ~Operation(); public: diff --git a/runtimes/neurun/core/src/exec/interp/operations/Add.cc b/runtimes/neurun/core/src/exec/interp/operations/Add.cc index 791b3c0..374da97 100644 --- a/runtimes/neurun/core/src/exec/interp/operations/Add.cc +++ b/runtimes/neurun/core/src/exec/interp/operations/Add.cc @@ -33,7 +33,7 @@ namespace add void prepareAdd(ExecEnv *env, const model::Operation &node) { - auto add_node = reinterpret_cast(node); + const auto &add_node = dynamic_cast(node); const auto lhs_index = node.getInputs().at(add_node.LHS); const auto rhs_index = node.getInputs().at(add_node.RHS); @@ -110,7 +110,7 @@ void invoke(const ITensor *lhs_tensor, const ITensor *rhs_tensor, const ITensor void invokeAdd(const ExecEnv *env, const model::Operation &node) { - auto add_node = reinterpret_cast(node); + const auto &add_node = dynamic_cast(node); const auto lhs_index = node.getInputs().at(add_node.LHS); const auto rhs_index = node.getInputs().at(add_node.RHS); diff --git a/runtimes/neurun/core/src/exec/interp/operations/AvgPool2D.cc b/runtimes/neurun/core/src/exec/interp/operations/AvgPool2D.cc index 9afb1b3..6e7b3b8 100644 --- a/runtimes/neurun/core/src/exec/interp/operations/AvgPool2D.cc +++ b/runtimes/neurun/core/src/exec/interp/operations/AvgPool2D.cc @@ -34,8 +34,6 @@ namespace avgpool2d void prepareAvgPool2D(ExecEnv *env, const model::Operation &node) { - auto maxpool_node = reinterpret_cast(node); - const auto in_index = node.getInputs().at(0); const auto out_index = node.getOutputs().at(0); @@ -86,7 +84,7 @@ void invoke(const ITensor *in_tensor, const ITensor *out_tensor, void invokeAvgPool2D(const ExecEnv *env, const model::Operation &node) { - auto maxpool_node = reinterpret_cast(node); + const auto &avgpool_node = dynamic_cast(node); const auto in_index = node.getInputs().at(0); const auto out_index = node.getOutputs().at(0); @@ -98,14 +96,14 @@ void invokeAvgPool2D(const ExecEnv *env, const model::Operation &node) const auto data_type = in_tensor->data_type(); if (data_type == model::DataType::FLOAT32) { - invoke(in_tensor, out_tensor, maxpool_node.param()); + invoke(in_tensor, out_tensor, avgpool_node.param()); } else { throw std::runtime_error{"NYI: Support float only"}; } } -} // namespace maxpool2d +} // namespace avgpool2d OpKernel *getAvgPool2DNode() { diff --git a/runtimes/neurun/core/src/exec/interp/operations/Concat.cc b/runtimes/neurun/core/src/exec/interp/operations/Concat.cc index 6dc90a6..2c80bea 100644 --- a/runtimes/neurun/core/src/exec/interp/operations/Concat.cc +++ b/runtimes/neurun/core/src/exec/interp/operations/Concat.cc @@ -34,7 +34,7 @@ namespace concat void prepareConcat(ExecEnv *env, const model::Operation &node) { - auto concat_node = reinterpret_cast(node); + const auto &concat_node = dynamic_cast(node); const auto first_index = node.getInputs().at(0); const auto out_index = node.getOutputs().at(0); @@ -116,7 +116,7 @@ void invoke(const std::vector in_tensors, const ITensor *out_te void invokeConcat(const ExecEnv *env, const model::Operation &node) { - auto concat_node = reinterpret_cast(node); + const auto &concat_node = dynamic_cast(node); const auto axis_index{concat_node.param().axis_index}; const int32_t axis_raw = env->model().operands.at(axis_index).asScalar(); diff --git a/runtimes/neurun/core/src/exec/interp/operations/Conv2D.cc b/runtimes/neurun/core/src/exec/interp/operations/Conv2D.cc index 61188aa..41991d2 100644 --- a/runtimes/neurun/core/src/exec/interp/operations/Conv2D.cc +++ b/runtimes/neurun/core/src/exec/interp/operations/Conv2D.cc @@ -34,8 +34,6 @@ namespace conv2d void prepareConv2D(ExecEnv *env, const model::Operation &node) { - auto maxpool_node = reinterpret_cast(node); - const auto in_index = node.getInputs().at(model::operation::Conv2DNode::INPUT); const auto kernel_index = node.getInputs().at(model::operation::Conv2DNode::KERNEL); const auto bias_index = node.getInputs().at(model::operation::Conv2DNode::BIAS); @@ -105,7 +103,7 @@ void invoke(const ITensor *ifm_tensor, const ITensor *ker_tensor, const ITensor void invokeConv2D(const ExecEnv *env, const model::Operation &node) { - auto conv_node = reinterpret_cast(node); + const auto &conv_node = dynamic_cast(node); const auto ifm_index = node.getInputs().at(model::operation::Conv2DNode::INPUT); const auto ker_index = node.getInputs().at(model::operation::Conv2DNode::KERNEL); diff --git a/runtimes/neurun/core/src/exec/interp/operations/FullyConnected.cc b/runtimes/neurun/core/src/exec/interp/operations/FullyConnected.cc index 5bf6701..25ed84a 100644 --- a/runtimes/neurun/core/src/exec/interp/operations/FullyConnected.cc +++ b/runtimes/neurun/core/src/exec/interp/operations/FullyConnected.cc @@ -34,8 +34,6 @@ namespace fc void prepareFC(ExecEnv *env, const model::Operation &node) { - auto maxpool_node = reinterpret_cast(node); - const auto in_index = node.getInputs().at(model::operation::FullyConnectedNode::INPUT); const auto kernel_index = node.getInputs().at(model::operation::FullyConnectedNode::WEIGHT); const auto bias_index = node.getInputs().at(model::operation::FullyConnectedNode::BIAS); @@ -104,7 +102,7 @@ void invoke(const ITensor *ifm_tensor, const ITensor *ker_tensor, const ITensor void invokeFC(const ExecEnv *env, const model::Operation &node) { - auto conv_node = reinterpret_cast(node); + const auto &conv_node = dynamic_cast(node); const auto ifm_index = node.getInputs().at(model::operation::FullyConnectedNode::INPUT); const auto ker_index = node.getInputs().at(model::operation::FullyConnectedNode::WEIGHT); -- 2.7.4