verify_compact_buffer.cc 1.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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 verify_compact_buffer.cc
 * \brief Verify if there was any compact buffer bound to a statement.
 */
24 25 26 27
#include <tvm/tir/buffer.h>
#include <tvm/tir/expr.h>
#include <tvm/tir/stmt.h>
#include <tvm/tir/stmt_functor.h>
28
#include <tvm/te/tensor.h>
29 30 31 32

#include <unordered_map>

namespace tvm {
33
namespace tir {
34

35
class VerifyBuffer : public StmtVisitor {
36 37
 public:
  bool Verify(const Stmt& stmt) {
38
    this->VisitStmt(stmt);
39 40 41
    return is_compact_;
  }

42
  void VisitStmt_(const AttrStmtNode* op) final {
43
    StmtVisitor::VisitStmt_(op);
44 45 46 47 48 49 50 51 52 53 54 55 56 57
    if (op->attr_key == attr::buffer_bind_scope) {
      is_compact_ = true;
    }
  }

 private:
  bool is_compact_{false};
};

bool VerifyCompactBuffer(Stmt stmt) {
  VerifyBuffer verifier;
  return verifier.Verify(stmt);
}

58
}  // namespace tir
59
}  // namespace tvm