diff --git a/compiler/luci/partition/include/luci/ConnectNode.h b/compiler/luci/partition/include/luci/ConnectNode.h index 592dd3b4d29..edce0a1f272 100644 --- a/compiler/luci/partition/include/luci/ConnectNode.h +++ b/compiler/luci/partition/include/luci/ConnectNode.h @@ -188,6 +188,7 @@ class ConnectNode final : public luci::CircleNodeVisitor void visit(const luci::CircleGRU *) final; void visit(const luci::CircleInstanceNorm *) final; void visit(const luci::CircleRmsNorm *) final; + void visit(const luci::CircleRoPE *) final; // NOTE CircleInput and CircleOutput are not handled here as these need // link with graph I/O diff --git a/compiler/luci/partition/src/Nodes/CircleRoPE.cpp b/compiler/luci/partition/src/Nodes/CircleRoPE.cpp new file mode 100644 index 00000000000..4f4ba3b1fa8 --- /dev/null +++ b/compiler/luci/partition/src/Nodes/CircleRoPE.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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 "luci/ConnectNode.h" + +namespace +{ + +void connect(luci::ConnectNode *cn, const luci::CircleRoPE *node) +{ + auto *cloned = loco::must_cast(cn->find_clone(node)); + + luci::CircleNode *input = loco::must_cast(node->input()); + luci::CircleNode *sin_table = loco::must_cast(node->sin_table()); + luci::CircleNode *cos_table = loco::must_cast(node->cos_table()); + + cloned->input(cn->find_clone(input)); + cloned->sin_table(cn->find_clone(sin_table)); + cloned->cos_table(cn->find_clone(cos_table)); +} + +} // namespace + +namespace luci +{ + +void ConnectNode::visit(const luci::CircleRoPE *node) { connect(this, node); } + +} // namespace luci diff --git a/compiler/luci/partition/src/Nodes/CircleRoPE.test.cpp b/compiler/luci/partition/src/Nodes/CircleRoPE.test.cpp new file mode 100644 index 00000000000..12a4370ce1e --- /dev/null +++ b/compiler/luci/partition/src/Nodes/CircleRoPE.test.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 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 "luci/ConnectNode.h" + +#include "ConnectNode.test.h" + +#include + +#include + +namespace +{ + +using namespace luci::test; + +class NodeGraphlet : public NodeGraphletT +{ +public: + NodeGraphlet() = default; + +public: + void init(loco::Graph *g) override + { + NodeGraphletT::init(g); + + _node->mode(luci::RoPEMode::GPT_NEOX); + } +}; + +class TestNodeGraph : public TestIsOGraph<3>, public NodeGraphlet +{ +public: + TestNodeGraph() = default; + +public: + void init(const ShapeU32 shape) + { + TestIsOGraph<3>::init({shape, shape, shape}, shape); + NodeGraphlet::init(g()); + + node()->input(input(0)); + node()->sin_table(input(1)); + node()->cos_table(input(2)); + + output()->from(node()); + } +}; + +} // namespace + +TEST(ConnectNodeTest, connect_RoPE) +{ + TestNodeGraph tng; + tng.init({2, 3}); + + ConnectionTestHelper cth; + cth.prepare_inputs(&tng); + + auto *node = tng.node(); + ASSERT_NO_THROW(loco::must_cast(node)); + + auto *clone = luci::clone_node(node, cth.graph_clone()); + ASSERT_NO_THROW(loco::must_cast(clone)); + + cth.clone_connect(node, clone); + + ASSERT_EQ(3, clone->arity()); + ASSERT_EQ(cth.inputs(0), clone->arg(0)); + ASSERT_EQ(cth.inputs(1), clone->arg(1)); + ASSERT_EQ(cth.inputs(2), clone->arg(2)); +}