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

[tflchef] Introduce a op util function to check custom codes #11813

Merged
merged 1 commit into from
Oct 30, 2023
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
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/AddV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "AddV2.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ AddV2Chef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "AddV2");
check_custom_op_value(operation, "AddV2");

/**
* REGISTER_OP("AddV2")
Expand Down
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/All.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "All.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ AllChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "All");
check_custom_op_value(operation, "All");

/**
* REGISTER_OP("All")
Expand Down
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/BatchMatMulV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "BatchMatMulV2.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ BatchMatMulV2Chef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "BatchMatMulV2");
check_custom_op_value(operation, "BatchMatMulV2");

/**
* REGISTER_OP("BatchMatMulV2")
Expand Down
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/BroadcastTo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "BroadcastTo.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ BroadcastToChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "BroadcastTo");
check_custom_op_value(operation, "BroadcastTo");

/**
* REGISTER_OP("BroadcastTo")
Expand Down
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/Erf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "Erf.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ ErfChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "Erf");
check_custom_op_value(operation, "Erf");

/**
* REGISTER_OP("Erf")
Expand Down
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/MatMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "MatMul.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ MatMulChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "MatMul");
check_custom_op_value(operation, "MatMul");

/**
* REGISTER_OP("MatMul")
Expand Down
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/MatrixBandPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "MatrixBandPart.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ MatrixBandPartChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "MatrixBandPart");
check_custom_op_value(operation, "MatrixBandPart");

/**
* REGISTER_OP("MatrixBandPart")
Expand Down
3 changes: 2 additions & 1 deletion compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "MaxPoolWithArgmax.h"
#include "OpUtils.h"

#include <flatbuffers/flexbuffers.h>

Expand All @@ -29,7 +30,7 @@ MaxPoolWithArgmaxChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
{
auto &operation = (*_operation);

assert(operation.type() == "MaxPoolWithArgmax");
check_custom_op_value(operation, "MaxPoolWithArgmax");

/**
* REGISTER_OP("MaxPoolWithArgmax")
Expand Down
28 changes: 28 additions & 0 deletions compiler/tflchef/core/src/OpUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 "OpUtils.h"

#include <stdexcept>

void check_custom_op_value(const tflchef::Operation operation, std::string op_type)
{
if ((operation.has_extype() && operation.extype() == "Custom") || operation.type() == "Custom")
{
assert(operation.has_custom_code());
assert(operation.custom_code() == op_type);
}
}
28 changes: 28 additions & 0 deletions compiler/tflchef/core/src/OpUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

/**
* @file OpUtils.h
* @brief This header declares various op_utils functions
*/
#ifndef __OPUTILS_H__
#define __OPUTILS_H__

#include <tflchef.pb.h>

void check_custom_op_value(const tflchef::Operation operation, std::string op_type);

#endif // __OPUTILS_H__