Skip to content

Commit b10ec45

Browse files
authored
[luci/lang,logex] Introduce Sign operation (#16389)
* [luci/lang] Introduce Sign operation This adds support for the Sign operation in luci/lang. ONE-DCO-1.0-Signed-off-by: Seungho Henry Park <shs.park@samsung.com>
1 parent 314cf12 commit b10ec45

File tree

6 files changed

+123
-0
lines changed

6 files changed

+123
-0
lines changed

compiler/luci/lang/include/luci/IR/CircleNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
#include "Nodes/CircleSelect.h"
110110
#include "Nodes/CircleSelectV2.h"
111111
#include "Nodes/CircleShape.h"
112+
#include "Nodes/CircleSign.h"
112113
#include "Nodes/CircleSin.h"
113114
#include "Nodes/CircleSlice.h"
114115
#include "Nodes/CircleSoftmax.h"

compiler/luci/lang/include/luci/IR/CircleNodes.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ CIRCLE_NODE(SEGMENT_SUM, CircleSegmentSum)
108108
CIRCLE_NODE(SELECT, CircleSelect)
109109
CIRCLE_NODE(SELECT_V2, CircleSelectV2)
110110
CIRCLE_NODE(SHAPE, CircleShape)
111+
CIRCLE_NODE(SIGN, CircleSign)
111112
CIRCLE_NODE(SIN, CircleSin)
112113
CIRCLE_NODE(SLICE, CircleSlice)
113114
CIRCLE_NODE(SOFTMAX, CircleSoftmax)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2026 Samsung Electronics Co., Ltd. All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef __LUCI_IR_CIRCLE_SIGN_H__
18+
#define __LUCI_IR_CIRCLE_SIGN_H__
19+
20+
#include "luci/IR/CircleNodeDecl.h"
21+
#include "luci/IR/CircleOpcode.h"
22+
23+
#include "luci/IR/CircleNodeMixins.h"
24+
25+
namespace luci
26+
{
27+
28+
/**
29+
* @brief SIGN in Circle
30+
*/
31+
class CircleSign final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SIGN>>
32+
{
33+
public:
34+
loco::Node *x(void) const { return at(0)->node(); }
35+
void x(loco::Node *node) { at(0)->node(node); }
36+
};
37+
38+
} // namespace luci
39+
40+
#endif // __LUCI_IR_CIRCLE_SIGN_H__
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2026 Samsung Electronics Co., Ltd. All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "luci/IR/Nodes/CircleSign.h"
18+
19+
#include "luci/IR/CircleDialect.h"
20+
#include "luci/IR/CircleNodeVisitor.h"
21+
22+
#include <gtest/gtest.h>
23+
24+
TEST(CircleSignTest, constructor)
25+
{
26+
luci::CircleSign sign_node;
27+
28+
ASSERT_EQ(luci::CircleDialect::get(), sign_node.dialect());
29+
ASSERT_EQ(luci::CircleOpcode::SIGN, sign_node.opcode());
30+
31+
ASSERT_EQ(nullptr, sign_node.x());
32+
}
33+
34+
TEST(CircleSignTest, input_NEG)
35+
{
36+
luci::CircleSign sign_node;
37+
luci::CircleSign node;
38+
39+
sign_node.x(&node);
40+
ASSERT_NE(nullptr, sign_node.x());
41+
42+
sign_node.x(nullptr);
43+
ASSERT_EQ(nullptr, sign_node.x());
44+
}
45+
46+
TEST(CircleSignTest, arity_NEG)
47+
{
48+
luci::CircleSign sign_node;
49+
50+
ASSERT_NO_THROW(sign_node.arg(0));
51+
ASSERT_THROW(sign_node.arg(1), std::out_of_range);
52+
}
53+
54+
TEST(CircleSignTest, visit_mutable_NEG)
55+
{
56+
struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
57+
{
58+
};
59+
60+
luci::CircleSign sign_node;
61+
62+
TestVisitor tv;
63+
ASSERT_THROW(sign_node.accept(&tv), std::exception);
64+
}
65+
66+
TEST(CircleSignTest, visit_NEG)
67+
{
68+
struct TestVisitor final : public luci::CircleNodeVisitor<void>
69+
{
70+
};
71+
72+
luci::CircleSign sign_node;
73+
74+
TestVisitor tv;
75+
ASSERT_THROW(sign_node.accept(&tv), std::exception);
76+
}

compiler/luci/logex/include/luci/CircleNodeSummaryBuilders.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ class CircleShapeSummaryBuilder final : public CircleNodeWithINPUTSummaryBuilder
636636
void build_attributes(const luci::CircleNode *node, locop::NodeSummary &s);
637637
};
638638

639+
class CircleSignSummaryBuilder final : public CircleNodeWithXSummaryBuilder
640+
{
641+
};
642+
639643
class CircleSinSummaryBuilder final : public CircleNodeWithXSummaryBuilder
640644
{
641645
};

compiler/luci/logex/src/CircleNodeSummaryBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ CircleNodeSummaryBuilder::create_builder(const luci::CircleNode *node)
232232
CIRCLE_NODE(SELECT, CircleSelectSummaryBuilder)
233233
CIRCLE_NODE(SELECT_V2, CircleSelectV2SummaryBuilder)
234234
CIRCLE_NODE(SHAPE, CircleShapeSummaryBuilder)
235+
CIRCLE_NODE(SIGN, CircleSignSummaryBuilder)
235236
CIRCLE_NODE(SIN, CircleSinSummaryBuilder)
236237
CIRCLE_NODE(SLICE, CircleSliceSummaryBuilder)
237238
CIRCLE_NODE(SOFTMAX, CircleSoftmaxSummaryBuilder)

0 commit comments

Comments
 (0)