Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,23 @@ def CIR_ShapeOp: CIR_Op<"shape", [
let hasFolder = 1;
}

def CIR_SignOp: CIR_Op<"sign", [
Pure,
SameOperandsAndResultType]> {
let summary = "Sign operation";
let description = [{
Returns NaN if x is NaN, 0 if x is 0, -1 if x < 0 and 1 if x > 0.
}];

let arguments = (ins
CIR_TensorOf<[F32, F64, I32]>:$x
);

let results = (outs
CIR_TensorOf<[F32, F64, I32]>:$output
);
}

def CIR_SinOp: CIR_Op<"sin", [
Pure,
/*TF_SameOperandsAndResultTypeResolveRef*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "ops/ResizeOp.h"
#include "ops/ShapeOp.h"
#include "ops/SigmoidOp.h"
#include "ops/SignOp.h"
#include "ops/SinOp.h"
#include "ops/SliceOp.h"
#include "ops/SoftmaxOp.h"
Expand Down Expand Up @@ -263,6 +264,7 @@ void ConvertONNXToCirclePass::runOnOperation()
patterns.insert<ConvResizeV13>(typeConverter, context);
patterns.insert<ConvShape>(typeConverter, context);
patterns.insert<ConvSigmoid>(typeConverter, context);
patterns.insert<ConvSign>(typeConverter, context);
patterns.insert<ConvSin>(typeConverter, context);
patterns.insert<ConvSlice>(typeConverter, context);
patterns.insert<ConvSoftmax>(typeConverter, context);
Expand Down
53 changes: 53 additions & 0 deletions circle-mlir/circle-mlir/lib/pass/src/ops/SignOp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2026 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 __CIRCLE_MLIR_PASS_OPS_SIGN_OP_H__
#define __CIRCLE_MLIR_PASS_OPS_SIGN_OP_H__

#include <circle-mlir/dialect/CircleDialect.h>

#include "ConvertHelper.h"

#include <mlir/Transforms/DialectConversion.h>

#include <src/Dialect/ONNX/ONNXOps.hpp>

namespace mlir
{
namespace Circle
{

class ConvSign : public mlir::OpConversionPattern<mlir::ONNXSignOp>
{
public:
using mlir::OpConversionPattern<mlir::ONNXSignOp>::OpConversionPattern;
using OpAdaptor = typename mlir::ONNXSignOp::Adaptor;

mlir::LogicalResult matchAndRewrite(mlir::ONNXSignOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const override
{
mlir::Value input = adaptor.getInput();

rewriter.replaceOpWithNewOp<SignOp>(op, op.getType(), input);

return mlir::success();
}
};

} // namespace Circle
} // namespace mlir

#endif // __CIRCLE_MLIR_PASS_OPS_SIGN_OP_H__
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ AddModel(Pow_F32_R2)
AddModel(Pow_F32_R2_3)
AddModel(Pow_F32_R4)
AddModel(PReLU_F32_R4)
AddModel(Range_F32_R0_1)
AddModel(Reciprocal_F32_R4)
AddModel(ReduceMax_F32_R2)
AddModel(ReduceMax_F32_R2_d0)
Expand Down Expand Up @@ -166,6 +167,7 @@ AddModel(Resize_F32_R4_nearest)
AddModel(Shape_F32_R4)
AddModel(Sigmoid_F32_R2)
AddModel(Sigmoid_F32_R4)
AddModel(Sign_F32_R4)
AddModel(Sin_F32_R4)
AddModel(Slice_F32_R2_4) # Rank2 of Slice_F32_R4_4
AddModel(Slice_F32_R3_4) # Rank3 of Slice_F32_R4_4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ AddModel(QuantizeLinear_F32_R3_ui8)
AddModel(QuantizeLinear_F32_R3_ui8_fq)
AddModel(QuantizeLinear_F32_R4_i16_cw)
AddModel(QuantizeLinear_F32_R4_ui8_cw)
AddModel(Range_F32_R0_1)
AddModel(Reciprocal_F32_R4)
AddModel(ReduceMax_F32_R2)
AddModel(ReduceMax_F32_R2_d0)
Expand Down Expand Up @@ -175,6 +176,7 @@ AddModel(Rsqrt_F32_R4)
AddModel(Shape_F32_R4)
AddModel(Sigmoid_F32_R2)
AddModel(Sigmoid_F32_R4)
AddModel(Sign_F32_R4)
AddModel(Sin_F32_R4)
AddModel(Slice_F32_R2_4) # Rank2 of Slice_F32_R4_4
AddModel(Slice_F32_R3_4) # Rank3 of Slice_F32_R4_4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ AddModel(PReLU_F32_R4)
# AddModel(QuantizeLinear_F32_R3_ui8_fq)
# AddModel(QuantizeLinear_F32_R4_i16_cw)
# AddModel(QuantizeLinear_F32_R4_ui8_cw)
AddModel(Range_F32_R0_1)
AddModel(Reciprocal_F32_R4)
AddModel(ReduceMax_F32_R2)
AddModel(ReduceMax_F32_R2_d0)
Expand Down Expand Up @@ -175,6 +176,7 @@ AddModel(Rsqrt_F32_R4)
AddModel(Shape_F32_R4)
AddModel(Sigmoid_F32_R2)
AddModel(Sigmoid_F32_R4)
AddModel(Sign_F32_R4)
AddModel(Sin_F32_R4)
AddModel(Slice_F32_R2_4) # Rank2 of Slice_F32_R4_4
AddModel(Slice_F32_R3_4) # Rank3 of Slice_F32_R4_4
Expand Down
20 changes: 20 additions & 0 deletions circle-mlir/models/unit/Range_F32_R0_1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import torch


# Generate Range operator with Float32, scalar
class net_Range(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, input):
limit = input
return torch.arange(0, limit, 1, dtype=torch.float32)

def onnx_opset_version(self):
return 11


_model_ = net_Range()

# produce float32 scalar with fixed number
_inputs_ = torch.tensor(10, dtype=torch.float32)
19 changes: 19 additions & 0 deletions circle-mlir/models/unit/Range_F32_R0_2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import torch


# Generate Range operator with Float32, scalar
class net_Range(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, limit, delta):
return torch.arange(0, limit, delta, dtype=torch.float32)

def onnx_opset_version(self):
return 11


_model_ = net_Range()

# produce float32 scalar with fixed number
_inputs_ = (torch.tensor(10, dtype=torch.float32), torch.tensor(1, dtype=torch.float32))
19 changes: 19 additions & 0 deletions circle-mlir/models/unit/Range_F32_R0_3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import torch


# Generate Range operator with Float32, scalar
class net_Range(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, start, limit, delta):
return torch.arange(start, limit, delta, dtype=torch.float32)

def onnx_opset_version(self):
return 11


_model_ = net_Range()

# produce float32 scalar with fixed number
_inputs_ = (torch.tensor(0, dtype=torch.float32), torch.tensor(10, dtype=torch.float32), torch.tensor(1, dtype=torch.float32))
19 changes: 19 additions & 0 deletions circle-mlir/models/unit/Sign_F32_R4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import torch


# Generate Sign operator with Float32, Rank-4
class net_Sign(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, input):
return torch.sign(input)

def onnx_opset_version(self):
# TODO set to appropriate value
return 14


_model_ = net_Sign()

_inputs_ = torch.randn(1, 2, 3, 3)
2 changes: 1 addition & 1 deletion circle-mlir/models/unit/Unsqueeze_F32_R0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ def onnx_opset_version(self):

_model_ = net_Unsqueeze()

# produuce float32 scalar
# produce float32 scalar
_inputs_ = torch.randn(1)[0]
2 changes: 1 addition & 1 deletion circle-mlir/models/unit/Unsqueeze_F32_R0_v11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def onnx_opset_version(self):

_model_ = net_Unsqueeze()

# produuce float32 scalar
# produce float32 scalar
_inputs_ = torch.randn(1)[0]
Loading