summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>2019-09-17 23:46:10 (GMT)
committerGitHub Enterprise <noreply-CODE@samsung.com>2019-09-17 23:46:10 (GMT)
commit995a7e45859444ab7b3d3af17d37603682fa75e0 (patch)
tree07ec59a55bcf706e1d7605bdd5e2308ff3ab2353
parent3e621afddd5eb99e7d1fcfb3f3c253698f833461 (diff)
downloadnnfw-995a7e45859444ab7b3d3af17d37603682fa75e0.zip
nnfw-995a7e45859444ab7b3d3af17d37603682fa75e0.tar.gz
nnfw-995a7e45859444ab7b3d3af17d37603682fa75e0.tar.bz2
[locop] Introduce GenericNodeSummaryBuilder (#7518)
This commit introduces GenericNodeSummaryBuilder which uses "dialect" address and opnum as opname. Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
-rw-r--r--compiler/locop/include/locop/GenericNodeSummaryBuilder.h45
-rw-r--r--compiler/locop/src/GenericNodeSummaryBuilder.cpp38
-rw-r--r--compiler/locop/src/GenericNodeSummaryBuilder.test.cpp58
3 files changed, 141 insertions, 0 deletions
diff --git a/compiler/locop/include/locop/GenericNodeSummaryBuilder.h b/compiler/locop/include/locop/GenericNodeSummaryBuilder.h
new file mode 100644
index 0000000..cdfe45a
--- /dev/null
+++ b/compiler/locop/include/locop/GenericNodeSummaryBuilder.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LOCOP_GENERIC_NODE_SUMMARY_BUILDER_H__
+#define __LOCOP_GENERIC_NODE_SUMMARY_BUILDER_H__
+
+#include "locop/NodeSummaryBuilder.h"
+
+namespace locop
+{
+
+/**
+ * @brief Dialect-agnostic Node Summary Builder
+ */
+class GenericNodeSummaryBuilder final : public NodeSummaryBuilder
+{
+public:
+ GenericNodeSummaryBuilder(const SymbolTable *tbl) : _tbl{tbl}
+ {
+ // DO NOTHING
+ }
+
+public:
+ bool build(const loco::Node *node, locop::NodeSummary &out) const final;
+
+private:
+ const SymbolTable *_tbl;
+};
+
+} // namespace locop
+
+#endif // __LOCOP_GENERIC_NODE_SUMMARY_BUILDER_H__
diff --git a/compiler/locop/src/GenericNodeSummaryBuilder.cpp b/compiler/locop/src/GenericNodeSummaryBuilder.cpp
new file mode 100644
index 0000000..e3bbe5a
--- /dev/null
+++ b/compiler/locop/src/GenericNodeSummaryBuilder.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "locop/GenericNodeSummaryBuilder.h"
+
+#include <pp/Format.h>
+
+namespace locop
+{
+
+bool GenericNodeSummaryBuilder::build(const loco::Node *node, locop::NodeSummary &out) const
+{
+ out.opname(pp::fmt(node->dialect(), ".op_", node->opnum()));
+
+ for (uint32_t n = 0; n < node->arity(); ++n)
+ {
+ out.args().append(pp::fmt("arg", n), _tbl->lookup(node->arg(n)));
+ }
+
+ out.state(NodeDesc::State::PartiallyKnown);
+
+ return true;
+}
+
+} // namespace locop
diff --git a/compiler/locop/src/GenericNodeSummaryBuilder.test.cpp b/compiler/locop/src/GenericNodeSummaryBuilder.test.cpp
new file mode 100644
index 0000000..d688b54
--- /dev/null
+++ b/compiler/locop/src/GenericNodeSummaryBuilder.test.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "locop/GenericNodeSummaryBuilder.h"
+#include "locop/FormattedGraph.h"
+
+#include <stdex/Memory.h>
+
+#include <stdexcept>
+
+#include <gtest/gtest.h>
+
+TEST(GenericNodeSummaryBuilderTest, simple)
+{
+ struct MockDialect final : public loco::Dialect
+ {
+ static Dialect *get(void)
+ {
+ static MockDialect d;
+ return &d;
+ }
+ };
+
+ struct MockNode : public loco::FixedArity<0>::Mixin<loco::Node>
+ {
+ const loco::Dialect *dialect(void) const final { return MockDialect::get(); };
+ uint32_t opnum(void) const final { return 0; }
+ };
+
+ struct MockFactory final : public locop::NodeSummaryBuilderFactory
+ {
+ std::unique_ptr<locop::NodeSummaryBuilder> create(const locop::SymbolTable *tbl) const final
+ {
+ return stdex::make_unique<locop::GenericNodeSummaryBuilder>(tbl);
+ }
+ };
+
+ auto g = loco::make_graph();
+
+ g->nodes()->create<MockNode>();
+
+ std::cout << locop::fmt<locop::LinearV1>(g).with(stdex::make_unique<MockFactory>()) << std::endl;
+
+ SUCCEED();
+}