expr_builder.h 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * Copyright 2020 Huawei Technologies Co., Ltd
 *
 * 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 UT_BASE_EXPR_BUILDER_H_
#define UT_BASE_EXPR_BUILDER_H_
#include <string>
#include <vector>
#include "tvm/expr.h"
#include "tvm/operation.h"
L
LuoYin 已提交
22
#include "tvm/tensor.h"
23 24 25 26 27 28 29

namespace akg {
class UTExprBuilder {
 public:
  UTExprBuilder() = default;
  ~UTExprBuilder() = default;

L
LuoYin 已提交
30 31 32
  static air::Expr IntImm(int64_t value, air::DataType dtype = air::Int(32));
  static air::Expr UIntImm(uint64_t value, air::DataType dtype = air::UInt(32));
  static air::Expr BoolImm(bool value);
33 34 35
  static air::Array<air::Expr> CreateShape(const std::vector<int32_t> &shapes);
  static air::Var CreateVar(const std::string &name);
  static air::Array<air::Expr> CreateVars(const std::vector<std::string> &names);
L
LuoYin 已提交
36 37 38
  static air::Range CreateRange(int32_t min, int32_t max);
  static air::Region CreateRegion(const std::vector<int32_t> &shapes);
  static air::Region CreateRegion(const air::Array<air::Expr> &shapes);
39
  static air::Operation PlaceholderOpNode(
40 41
      const std::string &name,
      const std::vector<int32_t> &shapes,
42 43
      air::DataType dtype = air::Float(16));
  static air::Expr TensorElement(
44 45 46
      const std::string &name,
      const std::vector<int32_t> &shapes,
      const std::vector<std::string> &axis_names,
47
      air::DataType dtype = air::Float(16));
L
LuoYin 已提交
48 49 50 51 52 53 54 55 56 57 58 59
  static air::Expr ElementOf(
      const air::Operation &op,
      const std::vector<std::string> &axis_names);
  static air::Expr ElementOfPlaceholderOp(
      const air::Operation &op,
      const std::vector<std::string> &axis_names);
  static air::Expr CreateCall(
      const air::ir::FunctionRef func,
      air::Array<air::Expr> args,
      air::ir::Call::CallType call_type = air::ir::Call::Halide,
      int value_index = 0);
  static air::Tensor CreateTensorByPlaceholder(const air::Operation op);
60 61 62 63 64 65 66
};  // UTExprBuilder

class UTTensorElementHelper {
 public:
  UTTensorElementHelper(const std::vector<int32_t> &shapes,
                        const std::string &axis_name_prefix = "ax");
  ~UTTensorElementHelper() = default;
67
  air::Expr Elem(const std::string &name,
L
LuoYin 已提交
68 69
                 uint32_t dim,
                 air::DataType dtype = air::Float(16)) const;
70 71 72 73 74

 private:
  std::vector<int32_t> shapes_;
  std::string axis_name_prefix_;
  std::vector<std::string> axis_names_;
L
LuoYin 已提交
75
};  // class UTTensorElementHelper
76 77
}  // namespace akg
#endif  // UT_BASE_EXPR_BUILDER_H_