Skip to content

Commit

Permalink
[Relay] Create header file for realize.cc (apache#11093)
Browse files Browse the repository at this point in the history
* Move class definitions to header file

* Trim out unnecessary includes

* Run clang-format-10

* Remove unnecessary class declarations

* Adjust grammar to trigger CI

* Change comment phrasing again to trigger CI

Co-authored-by: Jonathan Sparling <jsparling@westus2-ml-vm-sg01.2xo54b0zdm3epgab0khwgzehke.xx.internal.cloudapp.net>
  • Loading branch information
2 people authored and Sergey Shtin committed May 17, 2022
1 parent aa3a0e9 commit 4d62b2f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 39 deletions.
41 changes: 2 additions & 39 deletions src/relay/quantize/realize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* graph.
*/

#include "./realize.h"

#include <tvm/relay/analysis.h>
#include <tvm/relay/attrs/annotation.h>
#include <tvm/relay/transform.h>
Expand All @@ -39,45 +41,6 @@ namespace quantize {

using namespace relay::transform;

class QRealizeExpr;
class QRealizeIntExpr;

class QRealizeExprNode : public TempExprNode {
public:
Expr data;
static constexpr const char* _type_key = "relay.quantize.QRealizeExpr";
TVM_DECLARE_BASE_OBJECT_INFO(QRealizeExprNode, TempExprNode);
};

class QRealizeExpr : public TempExpr {
public:
TVM_DEFINE_OBJECT_REF_METHODS(QRealizeExpr, TempExpr, QRealizeExprNode);
};

class QRealizeIntExprNode : public QRealizeExprNode {
public:
Expr dom_scale;
DataType dtype;

void VisitAttrs(tvm::AttrVisitor* v) {
v->Visit("data", &data);
v->Visit("dom_scale", &dom_scale);
v->Visit("dtype", &dtype);
}

Expr Realize() const final;

static constexpr const char* _type_key = "relay.quantize.QRealizeIntExpr";
TVM_DECLARE_FINAL_OBJECT_INFO(QRealizeIntExprNode, QRealizeExprNode);
};

class QRealizeIntExpr : public QRealizeExpr {
public:
TVM_DLL QRealizeIntExpr(Expr data, Expr dom_scale, DataType dtype);

TVM_DEFINE_OBJECT_REF_METHODS(QRealizeIntExpr, QRealizeExpr, QRealizeIntExprNode);
};

Expr QRealizeIntExprNode::Realize() const {
Expr data = this->data;
// dequantize
Expand Down
77 changes: 77 additions & 0 deletions src/relay/quantize/realize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 realize.h
*
* \brief Header of definitions for op realizations
*
*/
#ifndef TVM_RELAY_QUANTIZE_REALIZE_H_
#define TVM_RELAY_QUANTIZE_REALIZE_H_

#include <tvm/relay/transform.h>

namespace tvm {
namespace relay {
namespace quantize {

class QRealizeExprNode : public TempExprNode {
public:
Expr data;
static constexpr const char* _type_key = "relay.quantize.QRealizeExpr";
TVM_DECLARE_BASE_OBJECT_INFO(QRealizeExprNode, TempExprNode);
};

class QRealizeExpr : public TempExpr {
public:
TVM_DEFINE_OBJECT_REF_METHODS(QRealizeExpr, TempExpr, QRealizeExprNode);
};

class QRealizeIntExprNode : public QRealizeExprNode {
public:
Expr dom_scale;
DataType dtype;

void VisitAttrs(tvm::AttrVisitor* v) {
v->Visit("data", &data);
v->Visit("dom_scale", &dom_scale);
v->Visit("dtype", &dtype);
}

Expr Realize() const final;

static constexpr const char* _type_key = "relay.quantize.QRealizeIntExpr";
TVM_DECLARE_FINAL_OBJECT_INFO(QRealizeIntExprNode, QRealizeExprNode);
};

class QRealizeIntExpr : public QRealizeExpr {
public:
TVM_DLL QRealizeIntExpr(Expr data, Expr dom_scale, DataType dtype);

TVM_DEFINE_OBJECT_REF_METHODS(QRealizeIntExpr, QRealizeExpr, QRealizeIntExprNode);
};

Expr FoldConstantOpt(const Expr& expr);

} // namespace quantize
} // namespace relay
} // namespace tvm
#endif // TVM_RELAY_QUANTIZE_REALIZE_H_

0 comments on commit 4d62b2f

Please sign in to comment.