Skip to content

Commit

Permalink
[tflchef] Introduce a op util function to check custom codes
Browse files Browse the repository at this point in the history
This introduces a function that check codes of CustomOp to avoid duplication.

ONE-DCO-1.0-Signed-off-by: SeungHui Lee <[email protected]>
  • Loading branch information
Seunghui98 committed Oct 30, 2023
1 parent b5d7ed0 commit 27a2acc
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 8 deletions.
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
29 changes: 29 additions & 0 deletions compiler/tflchef/core/src/OpUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.has_type() && 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__

0 comments on commit 27a2acc

Please sign in to comment.