From 4d62b2fccdef2a594be671f3f41b21bdd7b82c18 Mon Sep 17 00:00:00 2001 From: jonathansparling <87545750+jonathansparling@users.noreply.github.com> Date: Sat, 30 Apr 2022 18:46:54 -0700 Subject: [PATCH] [Relay] Create header file for realize.cc (#11093) * 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 --- src/relay/quantize/realize.cc | 41 +------------------ src/relay/quantize/realize.h | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 src/relay/quantize/realize.h diff --git a/src/relay/quantize/realize.cc b/src/relay/quantize/realize.cc index 408c23161771..301dc1a09f39 100644 --- a/src/relay/quantize/realize.cc +++ b/src/relay/quantize/realize.cc @@ -25,6 +25,8 @@ * graph. */ +#include "./realize.h" + #include #include #include @@ -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 diff --git a/src/relay/quantize/realize.h b/src/relay/quantize/realize.h new file mode 100644 index 000000000000..16fdf79b246e --- /dev/null +++ b/src/relay/quantize/realize.h @@ -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 + +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_