From 02b6da1b05d690b932b2e98a04a0a65ae7617374 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=84=B8=ED=9D=AC/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 3 Jun 2019 13:13:32 +0900 Subject: [PATCH] [locomotiv] Support S32 type for ConstGen (#3656) * [locomotiv] Support S32 type for ConstGen This will enable S32 type for ConstGen node Signed-off-by: SaeHie Park * fix format --- contrib/locomotiv/src/Node/ConstGen.cpp | 16 ++++++++++++++ contrib/locomotiv/src/Node/ConstGen.test.cpp | 32 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/contrib/locomotiv/src/Node/ConstGen.cpp b/contrib/locomotiv/src/Node/ConstGen.cpp index d55a90e..ad6efe6 100644 --- a/contrib/locomotiv/src/Node/ConstGen.cpp +++ b/contrib/locomotiv/src/Node/ConstGen.cpp @@ -71,6 +71,22 @@ void NodeExecution::execute(loco::ConstGen *constgen) switch (constgen->dtype()) { + case loco::DataType::S32: + { + assert(volume == constgen->size()); + + auto buf = make_buffer(shape); + + for (IndexEnumerator e{shape}; e.valid(); e.advance()) + { + const auto &index = e.current(); + uint32_t offset = ::offset_by_index(shape, index); + buf.at(index) = constgen->at(offset); + } + + data = locomotiv::make_data(buf); + break; + } case loco::DataType::FLOAT32: { assert(volume == constgen->size()); diff --git a/contrib/locomotiv/src/Node/ConstGen.test.cpp b/contrib/locomotiv/src/Node/ConstGen.test.cpp index e099d56..5128be9 100644 --- a/contrib/locomotiv/src/Node/ConstGen.test.cpp +++ b/contrib/locomotiv/src/Node/ConstGen.test.cpp @@ -30,6 +30,38 @@ using nncc::core::ADT::tensor::Shape; using nncc::core::ADT::tensor::LexicalLayout; using nncc::core::ADT::tensor::make_buffer; +TEST(NodeExecution_ConstGen, s32) +{ + // Make ConstGen node + loco::ConstGen constgen; + + constgen.dtype(loco::DataType::S32); + constgen.shape({2, 3}); + constgen.size(6); + + constgen.at(0) = 0; // Set 0,0 + constgen.at(1) = 1; // Set 0,1 + constgen.at(2) = 2; // Set 0,2 + constgen.at(3) = -3; // Set 1,0 + constgen.at(4) = -4; // Set 1,1 + constgen.at(5) = -5; // Set 1,2 + + // run execution + locomotiv::NodeExecution::get().run(&constgen); + + // test + auto data = locomotiv::annot_data(&constgen); + ASSERT_NE(data, nullptr); + ASSERT_EQ(data->dtype(), loco::DataType::S32); + ASSERT_EQ(*data->shape(), Shape({2, 3})); + ASSERT_FLOAT_EQ(data->as_s32_bufptr()->at(Index{0, 0}), 0); + ASSERT_FLOAT_EQ(data->as_s32_bufptr()->at(Index{0, 1}), 1); + ASSERT_FLOAT_EQ(data->as_s32_bufptr()->at(Index{0, 2}), 2); + ASSERT_FLOAT_EQ(data->as_s32_bufptr()->at(Index{1, 0}), -3); + ASSERT_FLOAT_EQ(data->as_s32_bufptr()->at(Index{1, 1}), -4); + ASSERT_FLOAT_EQ(data->as_s32_bufptr()->at(Index{1, 2}), -5); +} + TEST(NodeExecution_ConstGen, f32) { // Make ConstGen node -- 2.7.4