Skip to content

Commit

Permalink
[circlechef] Support Quantize/Dequantize Ops (#14308)
Browse files Browse the repository at this point in the history
This supports Quantize, Dequantize Ops.

ONE-DCO-1.0-Signed-off-by: Hyukjin Jeong <[email protected]>
  • Loading branch information
jinevening authored Nov 6, 2024
1 parent 75f98dd commit f999023
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
29 changes: 29 additions & 0 deletions compiler/circlechef/core/src/Op/Dequantize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 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 "Dequantize.h"

#include "Convert.h"

flatbuffers::Offset<void> DequantizeChef::value(flatbuffers::FlatBufferBuilder &fbb) const
{
return flatbuffers::Offset<void>();
}

std::unique_ptr<OpChef> DequantizeChefFactory::create(const circlechef::Operation *operation) const
{
return std::unique_ptr<OpChef>{new DequantizeChef{operation}};
}
49 changes: 49 additions & 0 deletions compiler/circlechef/core/src/Op/Dequantize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 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 __OP_DEQUANTIZE_H__
#define __OP_DEQUANTIZE_H__

#include "OpChef.h"

class DequantizeChef final : public OpChef
{
public:
explicit DequantizeChef(const circlechef::Operation *operation) : _operation{operation}
{
// DO NOTHING
}

public:
circle::BuiltinOperator code(void) const override { return circle::BuiltinOperator_DEQUANTIZE; }

circle::BuiltinOptions type(void) const override
{
return circle::BuiltinOptions_DequantizeOptions;
}

flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override;

private:
const circlechef::Operation *_operation;
};

struct DequantizeChefFactory final : public OpChefFactory
{
std::unique_ptr<OpChef> create(const circlechef::Operation *operation) const override;
};

#endif // __OP_DEQUANTIZE_H__
29 changes: 29 additions & 0 deletions compiler/circlechef/core/src/Op/Quantize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 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 "Quantize.h"

#include "Convert.h"

flatbuffers::Offset<void> QuantizeChef::value(flatbuffers::FlatBufferBuilder &fbb) const
{
return flatbuffers::Offset<void>();
}

std::unique_ptr<OpChef> QuantizeChefFactory::create(const circlechef::Operation *operation) const
{
return std::unique_ptr<OpChef>{new QuantizeChef{operation}};
}
49 changes: 49 additions & 0 deletions compiler/circlechef/core/src/Op/Quantize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 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 __OP_QUANTIZE_H__
#define __OP_QUANTIZE_H__

#include "OpChef.h"

class QuantizeChef final : public OpChef
{
public:
explicit QuantizeChef(const circlechef::Operation *operation) : _operation{operation}
{
// DO NOTHING
}

public:
circle::BuiltinOperator code(void) const override { return circle::BuiltinOperator_QUANTIZE; }

circle::BuiltinOptions type(void) const override
{
return circle::BuiltinOptions_QuantizeOptions;
}

flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override;

private:
const circlechef::Operation *_operation;
};

struct QuantizeChefFactory final : public OpChefFactory
{
std::unique_ptr<OpChef> create(const circlechef::Operation *operation) const override;
};

#endif // __OP_QUANTIZE_H__
2 changes: 2 additions & 0 deletions compiler/circlechef/core/src/OpChef.def
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
OP_CHEF(BatchMatMul, BatchMatMulChefFactory)
OP_CHEF(BCQFullyConnected, BCQFullyConnectedChefFactory)
OP_CHEF(BCQGather, BCQGatherChefFactory)
OP_CHEF(Dequantize, DequantizeChefFactory)
OP_CHEF(FullyConnected, FullyConnectedChefFactory)
OP_CHEF(GRU, GRUChefFactory)
OP_CHEF(InstanceNorm, InstanceNormChefFactory)
OP_CHEF(RmsNorm, RmsNormChefFactory)
OP_CHEF(RoPE, RoPEChefFactory)
OP_CHEF(Quantize, QuantizeChefFactory)
2 changes: 2 additions & 0 deletions compiler/circlechef/core/src/OpChefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#include "Op/BatchMatMul.h"
#include "Op/BCQFullyConnected.h"
#include "Op/BCQGather.h"
#include "Op/Dequantize.h"
#include "Op/FullyConnected.h"
#include "Op/GRU.h"
#include "Op/InstanceNorm.h"
#include "Op/RmsNorm.h"
#include "Op/RoPE.h"
#include "Op/Quantize.h"

#endif // __OP_CHEFS_H__

0 comments on commit f999023

Please sign in to comment.