From b9c198330ea64cd59582e93b427c4dc7b59298c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 31 Oct 2019 18:15:08 +0900 Subject: [PATCH] [neurun] Allow same inputs multiple times (#8567) Allow same inputs multiple times for an operation. Remove redundant assertion Signed-off-by: Hanjoung Lee --- runtimes/neurun/core/include/model/OperationIndexList.h | 9 ++++++++- runtimes/neurun/core/src/model/Operand.cc | 14 ++------------ tests/nnapi/specs/V1_0/mul_float_square_nnfw.mod.py | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 tests/nnapi/specs/V1_0/mul_float_square_nnfw.mod.py diff --git a/runtimes/neurun/core/include/model/OperationIndexList.h b/runtimes/neurun/core/include/model/OperationIndexList.h index 924af79..50d9155 100644 --- a/runtimes/neurun/core/include/model/OperationIndexList.h +++ b/runtimes/neurun/core/include/model/OperationIndexList.h @@ -17,6 +17,8 @@ #ifndef __NEURUN_MODEL_OPERATION_INDEX_LIST_H__ #define __NEURUN_MODEL_OPERATION_INDEX_LIST_H__ +#include +#include #include #include @@ -35,7 +37,12 @@ public: public: void append(const OperationIndex &index) { _list.push_back(index); } - void remove(const OperationIndex &index) { _list.remove(index); } + void remove(const OperationIndex &index) + { + auto itr = std::find(_list.begin(), _list.end(), index); + assert(itr != _list.end()); + _list.erase(itr); + } public: uint32_t size() const { return static_cast(_list.size()); } diff --git a/runtimes/neurun/core/src/model/Operand.cc b/runtimes/neurun/core/src/model/Operand.cc index 4d72fac..d5970cd 100644 --- a/runtimes/neurun/core/src/model/Operand.cc +++ b/runtimes/neurun/core/src/model/Operand.cc @@ -38,19 +38,9 @@ size_t Operand::operandSize(void) const return element_size * elements; } -void Operand::appendUse(const ::neurun::model::OperationIndex &idx) -{ - assert(!_uses.contains(idx)); - - _uses.append(idx); -} +void Operand::appendUse(const ::neurun::model::OperationIndex &idx) { _uses.append(idx); } -void Operand::removeUse(const ::neurun::model::OperationIndex &idx) -{ - assert(_uses.contains(idx)); - - _uses.remove(idx); -} +void Operand::removeUse(const ::neurun::model::OperationIndex &idx) { _uses.remove(idx); } void Operand::appendDef(const ::neurun::model::OperationIndex &idx) { diff --git a/tests/nnapi/specs/V1_0/mul_float_square_nnfw.mod.py b/tests/nnapi/specs/V1_0/mul_float_square_nnfw.mod.py new file mode 100644 index 0000000..2945e5b --- /dev/null +++ b/tests/nnapi/specs/V1_0/mul_float_square_nnfw.mod.py @@ -0,0 +1,16 @@ +# model +model = Model() +i1 = Input("op1", "TENSOR_FLOAT32", "{1, 2, 2, 1}") +act = Int32Scalar("act", 0) # an int32_t scalar fuse_activation +i3 = Output("op3", "TENSOR_FLOAT32", "{1, 2, 2, 1}") +model = model.Operation("MUL", i1, i1, act).To(i3) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + [2, -4, 8, -16]} + +output0 = {i3: # output 0 + [4, 16, 64, 256]} + +# Instantiate an example +Example((input0, output0)) -- 2.7.4