From d9f4724b2ac4afd18edc8a6e126048387ddcc46f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 8 Aug 2019 13:19:19 +0900 Subject: [PATCH] [loco] Add index getter (#6367) This commit extends GraphInput and GraphOutput class with "index" getter. Signed-off-by: Jonghyun Park --- compiler/loco/include/loco/IR/Graph.h | 8 +++++++ compiler/loco/include/loco/IR/GraphInputIndex.h | 29 ++++++++++++++++++++++++ compiler/loco/include/loco/IR/GraphOutputIndex.h | 29 ++++++++++++++++++++++++ compiler/loco/include/loco/IR/Nodes.h | 6 ++--- compiler/loco/src/IR/Graph.test.cpp | 2 ++ compiler/loco/src/IR/GraphInputIndex.cpp | 19 ++++++++++++++++ compiler/loco/src/IR/GraphOutputIndex.cpp | 19 ++++++++++++++++ 7 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 compiler/loco/include/loco/IR/GraphInputIndex.h create mode 100644 compiler/loco/include/loco/IR/GraphOutputIndex.h create mode 100644 compiler/loco/src/IR/GraphInputIndex.cpp create mode 100644 compiler/loco/src/IR/GraphOutputIndex.cpp diff --git a/compiler/loco/include/loco/IR/Graph.h b/compiler/loco/include/loco/IR/Graph.h index f228daf..0e576dc 100644 --- a/compiler/loco/include/loco/IR/Graph.h +++ b/compiler/loco/include/loco/IR/Graph.h @@ -20,6 +20,8 @@ #include "loco/IR/DataType.h" #include "loco/IR/Nodes.h" #include "loco/IR/NodePool.h" +#include "loco/IR/GraphInputIndex.h" +#include "loco/IR/GraphOutputIndex.h" #include "loco/ADT/ObjectPool.h" @@ -119,6 +121,9 @@ public: ~GraphInput() = default; +public: + GraphInputIndex index(void) const { return _index; } + private: uint32_t _index; @@ -160,6 +165,9 @@ public: ~GraphOutput() = default; +public: + GraphOutputIndex index(void) const { return _index; } + private: uint32_t _index; diff --git a/compiler/loco/include/loco/IR/GraphInputIndex.h b/compiler/loco/include/loco/IR/GraphInputIndex.h new file mode 100644 index 0000000..3c7ae98 --- /dev/null +++ b/compiler/loco/include/loco/IR/GraphInputIndex.h @@ -0,0 +1,29 @@ +/* + * 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 __LOCO_IR_GRAPH_INPUT_INDEX_H__ +#define __LOCO_IR_GRAPH_INPUT_INDEX_H__ + +#include + +namespace loco +{ + +using GraphInputIndex = uint32_t; + +} // namespace loco + +#endif // __LOCO_IR_GRAPH_INPUT_INDEX_H__ diff --git a/compiler/loco/include/loco/IR/GraphOutputIndex.h b/compiler/loco/include/loco/IR/GraphOutputIndex.h new file mode 100644 index 0000000..3231cbd --- /dev/null +++ b/compiler/loco/include/loco/IR/GraphOutputIndex.h @@ -0,0 +1,29 @@ +/* + * 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 __LOCO_IR_GRAPH_OUTPUT_INDEX_H__ +#define __LOCO_IR_GRAPH_OUTPUT_INDEX_H__ + +#include + +namespace loco +{ + +using GraphOutputIndex = uint32_t; + +} // namespace loco + +#endif // __LOCO_IR_GRAPH_OUTPUT_INDEX_H__ diff --git a/compiler/loco/include/loco/IR/Nodes.h b/compiler/loco/include/loco/IR/Nodes.h index fd7c051..a858ad0 100644 --- a/compiler/loco/include/loco/IR/Nodes.h +++ b/compiler/loco/include/loco/IR/Nodes.h @@ -31,6 +31,8 @@ #include "loco/IR/DepthwiseFilterCodec.h" #include "loco/IR/NodeMixins.h" #include "loco/IR/CanonicalNodeDecl.h" +#include "loco/IR/GraphInputIndex.h" +#include "loco/IR/GraphOutputIndex.h" namespace loco { @@ -38,10 +40,6 @@ namespace loco class GraphInput; class GraphOutput; -// TODO Find a proper location for these declarations -using GraphInputIndex = uint32_t; -using GraphOutputIndex = uint32_t; - /** * @brief Make a value visible to user */ diff --git a/compiler/loco/src/IR/Graph.test.cpp b/compiler/loco/src/IR/Graph.test.cpp index 90f9e9e..628621e 100644 --- a/compiler/loco/src/IR/Graph.test.cpp +++ b/compiler/loco/src/IR/Graph.test.cpp @@ -90,6 +90,7 @@ TEST(GraphTest, create_input) // TODO Add more checks ASSERT_EQ(input->shape(), nullptr); + ASSERT_EQ(input->index(), 0); } TEST(GraphTest, create_output) @@ -100,6 +101,7 @@ TEST(GraphTest, create_output) // TODO Add more checks ASSERT_EQ(output->shape(), nullptr); + ASSERT_EQ(output->index(), 0); } namespace diff --git a/compiler/loco/src/IR/GraphInputIndex.cpp b/compiler/loco/src/IR/GraphInputIndex.cpp new file mode 100644 index 0000000..0c94d70 --- /dev/null +++ b/compiler/loco/src/IR/GraphInputIndex.cpp @@ -0,0 +1,19 @@ +/* + * 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 "loco/IR/GraphInputIndex.h" + +// NOTE This file validates "GraphInputIndex.h". Please DO NOT remove this file. diff --git a/compiler/loco/src/IR/GraphOutputIndex.cpp b/compiler/loco/src/IR/GraphOutputIndex.cpp new file mode 100644 index 0000000..e6fdb9f --- /dev/null +++ b/compiler/loco/src/IR/GraphOutputIndex.cpp @@ -0,0 +1,19 @@ +/* + * 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 "loco/IR/GraphOutputIndex.h" + +// NOTE This file validates "GraphOutputIndex.h". Please DO NOT remove this file. -- 2.7.4