Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[circle-mlir/dialect] Add CustomOp #14722

Merged
merged 1 commit into from
Feb 20, 2025
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
26 changes: 26 additions & 0 deletions circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,32 @@ def CIR_ConstOp : Op<CIR_Dialect, "pseudo_const", [ConstantLike, Pure,
}];
}

def CIR_CustomOp : Op<CIR_Dialect, "custom", [
DeclareOpInterfaceMethods<CIR_RuntimeVerification>,
DeclareOpInterfaceMethods<CIR_ShapeInferenceOpInterface>
]> {
let summary = "Custom op";

let description = [{
A generic op for any Circle custom operation.

input: A list of inputs in the original op.
custom_code: A string used to identify which exactly this op is, which
corresponds to operator_codes.custom_code in the flatbuffer.
custom_option: a holder to save the op attributes in bytes fashion.
output: A list of outputs in the original op.
}];

let arguments = (ins
Variadic<CIR_TensorOfOrNone<[AnyType]>>:$input,
StrAttr:$custom_code,
CIR_ConstBytesAttr:$custom_option
);
let results = (outs Variadic<AnyTensor>:$output);

let hasVerifier = 1;
}

def CIR_NoValueOp : Op<CIR_Dialect, "no_value", [ConstantLike, Pure]> {
let summary = "constant representing no value.";

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 @@ -443,6 +443,7 @@ void ConstBytesAttr::print(mlir::AsmPrinter &printer) const
} // namespace mlir

// TODO add AddOp
#include "ops/CustomOp.h"

#include "mlir/CircleOpsDialect.cc.inc"
#include "mlir/CircleOpsEnums.cc.inc"
Expand Down
45 changes: 45 additions & 0 deletions circle-mlir/circle-mlir/lib/dialect/src/ops/CustomOp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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_CUSTOM_OP_H__
#define __CIRCLE_MLIR_DIALECT_OPS_CUSTOM_OP_H__

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

namespace mlir
{
namespace Circle
{

//===----------------------------------------------------------------------===//
// CustomOp
//===----------------------------------------------------------------------===//

// TODO(b/241745316): Confirm that this is always valid
mlir::LogicalResult CustomOp::verify()
{
// Currently, this is always valid as it is a wrapper around a StringRef of 0
// or more characters.
return success();
}

} // namespace Circle
} // namespace mlir

#endif // __CIRCLE_MLIR_DIALECT_OPS_CUSTOM_OP_H__
Loading