From 6f28f2c5836709c9c572e60de434c2ca9aa59b70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladimir=20Plazun/AI=20Tools=20Lab/Engineer/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 24 May 2018 17:06:16 +0300 Subject: [PATCH] Add class "IR::model::OpDescription" (#158) * Add class "IR::model::OpDescription" This commits adds "IR::model::OpDescription" class which used to represent any operation in computation graph Signed-off-by: Vladimir Plazun * Fix minor issues Add missing newline in CMakeLists.txt Fix newline after contrib::core::IR::model namespace Signed-off-by: Vladimir Plazun * Fix issues Remove duplicate check after assert Add const where applicable Signed-off-by: Vladimir Plazun * Rename nnc_core into core Update includes structure to evade header collisions Update CMakeLists.txt Signed-off-by: Vladimir Plazun --- contrib/nnc/libs/CMakeLists.txt | 1 + contrib/nnc/libs/core/CMakeLists.txt | 12 ++++++ .../nnc/core/IR/model/operations/operation.h | 47 ++++++++++++++++++++++ .../src/core/IR/model/operations/operation.cpp | 45 +++++++++++++++++++++ .../core/IR/model/operations/operation.test.cpp | 19 +++++++++ 5 files changed, 124 insertions(+) create mode 100644 contrib/nnc/libs/core/CMakeLists.txt create mode 100644 contrib/nnc/libs/core/include/nnc/core/IR/model/operations/operation.h create mode 100644 contrib/nnc/libs/core/src/core/IR/model/operations/operation.cpp create mode 100644 contrib/nnc/libs/core/src/core/IR/model/operations/operation.test.cpp diff --git a/contrib/nnc/libs/CMakeLists.txt b/contrib/nnc/libs/CMakeLists.txt index 0d5e2ed..a628110 100644 --- a/contrib/nnc/libs/CMakeLists.txt +++ b/contrib/nnc/libs/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(frontend) +add_subdirectory(core) add_subdirectory(plugin) diff --git a/contrib/nnc/libs/core/CMakeLists.txt b/contrib/nnc/libs/core/CMakeLists.txt new file mode 100644 index 0000000..c432225 --- /dev/null +++ b/contrib/nnc/libs/core/CMakeLists.txt @@ -0,0 +1,12 @@ +file(GLOB_RECURSE HEADERS "include/*.h") +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE TESTS "src/*.test.cpp") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_nncc_library(nnc_core SHARED ${HEADERS} ${SOURCES}) +set_target_properties(nnc_core PROPERTIES LINKER_LANGUAGE CXX) +target_include_directories(nnc_core PUBLIC include) +target_link_libraries(nnc_core PRIVATE nncc_core) + +add_nncc_test(nnc_core_test ${TESTS}) +nncc_target_link_libraries(nnc_core_test nnc_core nncc_core) diff --git a/contrib/nnc/libs/core/include/nnc/core/IR/model/operations/operation.h b/contrib/nnc/libs/core/include/nnc/core/IR/model/operations/operation.h new file mode 100644 index 0000000..8d5dc67 --- /dev/null +++ b/contrib/nnc/libs/core/include/nnc/core/IR/model/operations/operation.h @@ -0,0 +1,47 @@ +#ifndef _NNC_CORE_IR_MODEL_OPERATION_H_ +#define _NNC_CORE_IR_MODEL_OPERATION_H_ + +#include +#include + +#include "nncc/core/ADT/tensor/Shape.h" + +namespace nncc +{ +namespace contrib +{ +namespace core +{ +namespace IR +{ +namespace model +{ + +class OpDescription { + public: + explicit OpDescription(const size_t max_inputs, const size_t max_outputs); + + size_t getNumInputs() const; + size_t getNumOutputs() const; + + const nncc::core::ADT::tensor::Shape &getInputShape(const size_t index) const; + virtual void setInputShape(const size_t index, const nncc::core::ADT::tensor::Shape &shape); + + virtual const nncc::core::ADT::tensor::Shape &getOutputShape(const size_t index) const; + void setOutputShape(const size_t index, const nncc::core::ADT::tensor::Shape &shape); + + private: + size_t _max_inputs; + size_t _max_outputs; + + std::map _inputShapes; + std::map _outputShapes; +}; + +} // namespace model +} // namespace IR +} // namespace core +} // namespace contrib +} // namespace nncc + +#endif //_NNC_CORE_IR_MODEL_OPERATION_H_ diff --git a/contrib/nnc/libs/core/src/core/IR/model/operations/operation.cpp b/contrib/nnc/libs/core/src/core/IR/model/operations/operation.cpp new file mode 100644 index 0000000..493ec21 --- /dev/null +++ b/contrib/nnc/libs/core/src/core/IR/model/operations/operation.cpp @@ -0,0 +1,45 @@ +#include + +#include "nnc/core/IR/model/operations/operation.h" + +namespace nncc { +namespace contrib { +namespace core { +namespace IR { +namespace model { + +using namespace nncc::core::ADT; + +const tensor::Shape &OpDescription::getInputShape(const size_t index) const { + assert(index < getNumInputs()); + return _inputShapes.at(index); +} + +void OpDescription::setInputShape(const size_t index, const tensor::Shape &shape) { + assert(index < getNumInputs()); + _inputShapes[index] = shape; +} + +const tensor::Shape &OpDescription::getOutputShape(const size_t index) const { + assert(index < getNumOutputs()); + return _outputShapes.at(index); +} + +void OpDescription::setOutputShape(const size_t index, const tensor::Shape &shape) { + assert(index < getNumOutputs()); + _outputShapes[index] = shape; +} + +OpDescription::OpDescription(const size_t max_inputs, const size_t max_outputs) + : _max_inputs(max_inputs), _max_outputs(max_outputs) { +} + +size_t OpDescription::getNumInputs() const { return _max_inputs; } + +size_t OpDescription::getNumOutputs() const { return _max_outputs; } + +} // namespace model +} // namespace IR +} // namespace core +} // namespace contrib +} // namespace nncc diff --git a/contrib/nnc/libs/core/src/core/IR/model/operations/operation.test.cpp b/contrib/nnc/libs/core/src/core/IR/model/operations/operation.test.cpp new file mode 100644 index 0000000..a11e3fc --- /dev/null +++ b/contrib/nnc/libs/core/src/core/IR/model/operations/operation.test.cpp @@ -0,0 +1,19 @@ +#include "nnc/core/IR/model/operations/operation.h" +#include "nncc/core/ADT/feature/Shape.h" + +#include + +using namespace nncc::contrib::core::IR::model; +using namespace nncc::core::ADT::tensor; + +TEST(OpDescription, InputOutputShapeTest) { + Shape inShape{1,2,3}; + Shape outShape{3,2,1}; + + OpDescription op(1, 1); + op.setInputShape(0, inShape ); + op.setOutputShape(0, outShape ); + + ASSERT_EQ(inShape, op.getInputShape(0)); + ASSERT_EQ(outShape, op.getOutputShape(0)); +} -- 2.7.4