From commits-return-9137-archive-asf-public=cust-asf.ponee.io@tvm.apache.org Sat Mar 21 15:43:39 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 882CD180679 for ; Sat, 21 Mar 2020 16:43:39 +0100 (CET) Received: (qmail 78072 invoked by uid 500); 21 Mar 2020 15:43:38 -0000 Mailing-List: contact commits-help@tvm.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tvm.apache.org Delivered-To: mailing list commits@tvm.apache.org Received: (qmail 78027 invoked by uid 99); 21 Mar 2020 15:43:38 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Mar 2020 15:43:38 +0000 From: GitBox To: commits@tvm.apache.org Subject: [GitHub] [incubator-tvm] hzfan commented on a change in pull request #5092: [PASS] dtype rewrite for indexing variables Message-ID: <158480541879.2100.10324694516483690660.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Sat, 21 Mar 2020 15:43:38 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit hzfan commented on a change in pull request #5092: [PASS] dtype rewrite for indexing variables URL: https://github.com/apache/incubator-tvm/pull/5092#discussion_r396002858 ########## File path: src/tir/pass/narrow_datatype.cc ########## @@ -0,0 +1,363 @@ +/* + * 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 narrow_datatype.cc + * \brief narrow the datatype of indexing vars + */ + +#include +#include +#include "../../arith/ir_mutator_with_analyzer.h" +#include "../../arith/ir_visitor_with_analyzer.h" + +namespace tvm { +namespace tir { + +// This pass narrows indexing expressions (like StoreNode::Index) +// that trivially fit into i32 to i32. Considering that i32 indices +// may be more efficient on some backends (while i64 may be more +// efficient on others, like llvm), we may want this pass when i32 +// indices are more efficient. +// +// For Var v, we determine its dtype by examining all the PrimExpr +// that contains v, denoted by E = {e_0 = v, e_1, e_2, ..., e_k}. +// If all expressions in E fit into i32, then we think v can be narrowed +// to i32. +// +// To make an indexing expression i32, we must make sure that every +// component of that expression is of dtype i32. So besides Var, we +// rewrite the following inside an indexing expression +// - Var +// - IntImm +// - Cast +// +// Algorithm: +// - Use DataTypeVisitor to determine whether a Var can be narrowed or not. +// - Use DataTypeRewritter to rewrite the components of an indexing expression. + +using arith::Analyzer; +using arith::IRMutatorWithAnalyzer; +using arith::ConstIntBound; + +class DataTypeRewriter; + +class DataTypeVisitor final : public StmtExprVisitor { + public: + void VisitExpr(const PrimExpr& e) { + if (e.dtype().is_int()) { + int bits = 64; + if (e.dtype().bits() <= 32 || + analyzer_.CanProve(e <= max_value(DataType::Int(32)) && + e >= min_value(DataType::Int(32)))) { + bits = 32; + } + int tmp = bits_; Review comment: Fixed ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services