-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This draft supports CircleGRU in compiler. ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
- Loading branch information
Artem Balyshev
committed
Dec 18, 2023
1 parent
e2df8b3
commit 586baac
Showing
27 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
compiler/luci/import/include/luci/Import/Nodes/CircleGRU.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2023 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 __LUCI_IMPORT_OP_CIRCLE_GRU_H__ | ||
#define __LUCI_IMPORT_OP_CIRCLE_GRU_H__ | ||
|
||
#include "luci/Import/GraphBuilder.h" | ||
|
||
namespace luci | ||
{ | ||
|
||
class CircleGRUGraphBuilder : public GraphBuilder | ||
{ | ||
public: | ||
bool validate(const ValidateArgs &args) const final; | ||
|
||
private: | ||
CircleNode *build_node(const circle::OperatorT &op, const std::vector<CircleNode *> &inputs, | ||
loco::Graph *graph) const final; | ||
}; | ||
|
||
} // namespace luci | ||
|
||
#endif // __LUCI_IMPORT_OP_CIRCLE_GRU_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2023 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/Import/Nodes/CircleGRU.h" | ||
|
||
#include <luci/IR/Nodes/CircleHardSwish.h> | ||
|
||
#include <loco.h> | ||
|
||
namespace luci | ||
{ | ||
|
||
bool CircleGRUGraphBuilder::validate(const ValidateArgs &args) const | ||
{ | ||
return GraphBuilder::validate(args, 4); | ||
} | ||
|
||
CircleNode *CircleGRUGraphBuilder::build_node(const circle::OperatorT &, | ||
const std::vector<CircleNode *> &inputs, | ||
loco::Graph *graph) const | ||
{ | ||
auto *node = graph->nodes()->create<CircleGRU>(); | ||
node->input(inputs.at(0)); | ||
node->hidden_hidden(inputs.at(1)); | ||
node->hidden_input(inputs.at(2)); | ||
node->state(inputs.at(3)); | ||
|
||
return node; | ||
} | ||
|
||
} // namespace luci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2023 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 __LUCI_IR_CIRCLEGRU_H__ | ||
#define __LUCI_IR_CIRCLEGRU_H__ | ||
|
||
#include "luci/IR/CircleNodeDecl.h" | ||
#include "luci/IR/CircleOpcode.h" | ||
|
||
#include "luci/IR/CircleNodeMixins.h" | ||
|
||
namespace luci | ||
{ | ||
|
||
/** | ||
* @brief GRU in Circle | ||
*/ | ||
class CircleGRU final : public FixedArityNode<4, CircleNodeImpl<CircleOpcode::CIR_GRU>> | ||
{ | ||
public: | ||
loco::Node *input(void) const { return at(0)->node(); } | ||
void input(loco::Node *node) { at(0)->node(node); } | ||
|
||
loco::Node *hidden_hidden(void) const { return at(1)->node(); } | ||
void hidden_hidden(loco::Node *node) { at(1)->node(node); } | ||
|
||
loco::Node *hidden_input(void) const { return at(2)->node(); } | ||
void hidden_input(loco::Node *node) { at(2)->node(node); } | ||
|
||
loco::Node *state(void) const { return at(3)->node(); } | ||
void state(loco::Node *node) { at(3)->node(node); } | ||
|
||
public: | ||
FusedActFunc fusedActivationFunction() const { return _fused_act_fun; } | ||
void fusedActivationFunction(FusedActFunc fused_act_fun) { _fused_act_fun = fused_act_fun; } | ||
|
||
bool returnSequences() const { return _return_sequences; } | ||
void returnSequences(bool return_sequences) { _return_sequences = return_sequences; } | ||
|
||
bool timeMajor() const { return _time_major; } | ||
void timeMajor(bool time_major) { _time_major = time_major; } | ||
|
||
private: | ||
FusedActFunc _fused_act_fun = FusedActFunc::UNDEFINED; | ||
bool _return_sequences = false; | ||
bool _time_major = false; | ||
}; | ||
|
||
} // namespace luci | ||
|
||
#endif // __LUCI_IR_CIRCLEGRU_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2023 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/IR/Nodes/CircleGRU.h" | ||
|
||
#include "luci/IR/CircleDialect.h" | ||
#include "luci/IR/CircleNodeVisitor.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
TEST(CircleGRUTest, constructor_P) | ||
{ | ||
luci::CircleGRU gru_node; | ||
|
||
ASSERT_EQ(luci::CircleDialect::get(), gru_node.dialect()); | ||
ASSERT_EQ(luci::CircleOpcode::CIR_GRU, gru_node.opcode()); | ||
|
||
ASSERT_EQ(nullptr, gru_node.input()); | ||
ASSERT_EQ(nullptr, gru_node.hidden_hidden()); | ||
ASSERT_EQ(nullptr, gru_node.hidden_input()); | ||
ASSERT_EQ(nullptr, gru_node.state()); | ||
} | ||
|
||
TEST(CircleGRUTest, input_NEG) | ||
{ | ||
luci::CircleGRU gru_node; | ||
luci::CircleGRU node; | ||
|
||
gru_node.input(&node); | ||
ASSERT_NE(nullptr, gru_node.input()); | ||
|
||
gru_node.input(nullptr); | ||
ASSERT_EQ(nullptr, gru_node.input()); | ||
} | ||
|
||
TEST(CircleGRUTest, arity_NEG) | ||
{ | ||
luci::CircleGRU gru_node; | ||
|
||
ASSERT_NO_THROW(gru_node.arg(0)); | ||
ASSERT_NO_THROW(gru_node.arg(1)); | ||
ASSERT_NO_THROW(gru_node.arg(2)); | ||
ASSERT_NO_THROW(gru_node.arg(3)); | ||
ASSERT_THROW(gru_node.arg(5), std::out_of_range); | ||
} | ||
|
||
TEST(CircleGRUTest, visit_mutable_NEG) | ||
{ | ||
struct TestVisitor final : public luci::CircleNodeMutableVisitor<void> | ||
{ | ||
}; | ||
|
||
luci::CircleGRU gru_node; | ||
|
||
TestVisitor tv; | ||
ASSERT_THROW(gru_node.accept(&tv), std::exception); | ||
} | ||
|
||
TEST(CircleGRUTest, visit_NEG) | ||
{ | ||
struct TestVisitor final : public luci::CircleNodeVisitor<void> | ||
{ | ||
}; | ||
|
||
luci::CircleGRU gru_node; | ||
|
||
TestVisitor tv; | ||
ASSERT_THROW(gru_node.accept(&tv), std::exception); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2023 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::CircleGRU *node) | ||
{ | ||
auto *cloned = loco::must_cast<luci::CircleGRU *>(cn->find_clone(node)); | ||
|
||
luci::CircleNode *input = loco::must_cast<luci::CircleNode *>(node->input()); | ||
luci::CircleNode *hidden_input = loco::must_cast<luci::CircleNode *>(node->hidden_input()); | ||
luci::CircleNode *hidden_hidden = loco::must_cast<luci::CircleNode *>(node->hidden_hidden()); | ||
luci::CircleNode *state = loco::must_cast<luci::CircleNode *>(node->state()); | ||
|
||
cloned->input(cn->find_clone(input)); | ||
cloned->hidden_input(cn->find_clone(hidden_input)); | ||
cloned->hidden_hidden(cn->find_clone(hidden_hidden)); | ||
cloned->state(cn->find_clone(state)); | ||
} | ||
|
||
} // namespace | ||
|
||
namespace luci | ||
{ | ||
|
||
void ConnectNode::visit(const luci::CircleGRU *node) { connect(this, node); } | ||
|
||
} // namespace luci |
Oops, something went wrong.