Skip to content
Merged
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
56 changes: 56 additions & 0 deletions circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,36 @@ def CIR_PadV2Op : CIR_Op<"padv2", [
let hasFolder = 1;
}

def CIR_PowOp : CIR_Op<"pow", [
ResultsBroadcastableShape,
Pure,
CIR_OperandsHaveSameShapesOrBroadcastableShape<[0, 1], 4>]> {
let summary = "Power operator";

let description = [{
Element-wise power operation.
}];

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

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

let hasCustomAssemblyFormat = 1;

let extraClassDefinition = [{
ParseResult $cppClass::parse(OpAsmParser &parser, OperationState &result) {
return parseOneResultSameOperandTypeOp(parser, result);
}
void $cppClass::print(OpAsmPrinter &p) {
return printOneResultOp(getOperation(), p);
}
}];

let builders = [CIR_BroadcastableBinaryBuilder];
}

def CIR_PReluOp : CIR_Op<"prelu", [
Pure,
//QuantizableResult,
Expand Down Expand Up @@ -1860,6 +1890,32 @@ def CIR_ShapeOp: CIR_Op<"shape", [
let hasFolder = 1;
}

def CIR_SinOp: CIR_Op<"sin", [
Pure,
/*TF_SameOperandsAndResultTypeResolveRef*/
DeclareOpInterfaceMethods<CIR_ShapeInferenceOpInterface>,
SameOperandsAndResultShape]> {
let summary = "Sine operator";

let description = [{
Computes element-wise Sine of input
}];

let arguments = (ins CIR_FpTensor:$x);

let results = (outs CIR_FpTensor:$y);

let hasFolder = 1;

// TODO enable TF::ArraysAreCastCompatible
//let extraClassDeclaration = [{
// // Returns whether the return types are compatible.
// static bool isCompatibleReturnTypes(TypeRange l, TypeRange r) {
// return TF::ArraysAreCastCompatible(l, r);
// }
//}];
}

def CIR_SliceOp : CIR_Op<"slice", [
/*QuantizableResult,*/
PredOpTrait<"input and output must have same element type",
Expand Down
1 change: 1 addition & 0 deletions circle-mlir/circle-mlir/lib/dialect/src/CircleDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ void ConstBytesAttr::print(mlir::AsmPrinter &printer) const
#include "ops/SelectOp.h"
#include "ops/SelectV2Op.h"
#include "ops/ShapeOp.h"
#include "ops/SinOp.h"
#include "ops/SliceOp.h"
#include "ops/SqrtOp.h"
#include "ops/StridedSliceOp.h"
Expand Down
22 changes: 22 additions & 0 deletions circle-mlir/circle-mlir/lib/dialect/src/ShapeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,28 @@ void ResizeNearestNeighborOp::inferShapes()
getResult().setType(inferred_type);
}

//===----------------------------------------------------------------------===//
// SinOp
//===----------------------------------------------------------------------===//

void SinOp::inferShapes(void)
{
SinOp op = *this;
auto output_type = op.getY().getType().cast<ShapedType>();
if (output_type.hasStaticShape())
return;

// follow input shape
auto input_type = op.getX().getType().cast<TensorType>();
auto input_shape = input_type.getShape();
llvm::SmallVector<int64_t, 4> inferred(input_shape.begin(), input_shape.end());

dumpShape<SinOp>(op, inferred);

RankedTensorType inferred_type = RankedTensorType::get(inferred, input_type.getElementType());
getResult().setType(inferred_type);
}

//===----------------------------------------------------------------------===//
// SqrtOp
//===----------------------------------------------------------------------===//
Expand Down
53 changes: 53 additions & 0 deletions circle-mlir/circle-mlir/lib/dialect/src/ops/SinOp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
* Copyright 2019 The TensorFlow Authors. 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.
*/

// from tensorflow/compiler/mlir/lite/ir/tfl_ops.cc

#ifndef __CIRCLE_MLIR_DIALECT_OPS_SIN_OP_H__
#define __CIRCLE_MLIR_DIALECT_OPS_SIN_OP_H__

#include "circle-mlir/dialect/CircleDialect.h"

namespace mlir
{
namespace Circle
{

//===----------------------------------------------------------------------===//
// SinOp
//===----------------------------------------------------------------------===//

OpFoldResult SinOp::fold(FoldAdaptor adaptor)
{
auto operands = adaptor.getOperands();
Type result_type = getType();
// Only constant fold for tensor of f32 is implemented.
if (!IsF32ShapedType(result_type))
return nullptr;

auto compute = [](APFloat value) -> APFloat {
float f = value.convertToFloat();
float result = std::sin(f);
return APFloat(result);
};
return ConstFoldUnaryOp(result_type, operands[0], compute);
}

} // namespace Circle
} // namespace mlir

#endif // __CIRCLE_MLIR_DIALECT_OPS_SIN_OP_H__