当前位置: 首页 > news >正文

mlir-tblgen 的应用渐进式示例

示例01 -gen-dialect-decls

toy_dia.1.toy

include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"

def Toy_Dialect : Dialect {
	let name = "toy";
	let summary = "A high-level dialect for analyzing and optimizing the Toy language";
	let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];
	let cppNamespace = "toy";
}

命令:

../../../llvm-project/build_mlir_15/bin/mlir-tblgen -gen-dialect-decls ./toy_dia.1.td -I ../../../llvm-project/mlir/include

生成:

示例02 no def -gen-op-decls

源码:

toy_op.1.td:

include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"

def Toy_Dialect : Dialect {
	let name = "toy";
	let summary = "A high-level dialect for analyzing and optimizing the Toy language";
	let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];
	let cppNamespace = "toy";
}

class Toy_Op<string mnemonic, list<Trait> traits = []> :
    Op<Toy_Dialect, mnemonic, traits>;

命令:

$ mlir-tblgen -gen-op-decls ./toy_op.1.td -I ../../../llvm-project/mlir/include/

生成:

示例03 -gen-op-decls

toy_dia.2.toy:

include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"

def Toy_Dialect : Dialect {
	let name = "toy";
	let summary = "A high-level dialect for analyzing and optimizing the Toy language";
	let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];
	let cppNamespace = "toy";
}

class Toy_Op<string mnemonic, list<Trait> traits = []> :
    Op<Toy_Dialect, mnemonic, traits>;

def ConstantOp : Toy_Op<"constant"> {
}

命令:

$ mlir-tblgen -gen-op-decls ./toy_dia.2.td -I ../../../llvm-project/mlir/include/

生成:

示例04

源码:

include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"

def Toy_Dialect : Dialect {
	let name = "toy";
	let summary = "A high-level dialect for analyzing and optimizing the Toy language";
	let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];
	let cppNamespace = "toy";
}

class Toy_Op<string mnemonic, list<Trait> traits = []> :
    Op<Toy_Dialect, mnemonic, traits>;

def ConstantOp : Toy_Op<"constant"> {
	let arguments = (ins F64ElementsAttr:$value);
	let results = (outs F64Tensor);
}

命令: 

llvm-project/build_mlir_15/bin/mlir-tblgen -gen-op-decls ./toy_op.3.td -I ../../../llvm-project/mlir/include

生成:

$ ../../../llvm-project/build_mlir_15/bin/mlir-tblgen -gen-op-decls ./toy_op.3.td -I ../../../llvm-project/mlir/include
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|*                                                                            *|
|* Op Declarations                                                            *|
|*                                                                            *|
|* Automatically generated file, do not edit!                                 *|
|*                                                                            *|
\*===----------------------------------------------------------------------===*/

#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES)
#undef GET_OP_FWD_DEFINES
namespace toy {
class ConstantOp;
} // namespace toy
#endif

#ifdef GET_OP_CLASSES
#undef GET_OP_CLASSES


//===----------------------------------------------------------------------===//
// Local Utility Method Definitions
//===----------------------------------------------------------------------===//

namespace toy {

//===----------------------------------------------------------------------===//
// toy::ConstantOp declarations
//===----------------------------------------------------------------------===//

class ConstantOpAdaptor {
public:
  ConstantOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs = nullptr, ::mlir::RegionRange regions = {});

  ConstantOpAdaptor(ConstantOp op);

  ::mlir::ValueRange getOperands();
  std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index);
  ::mlir::ValueRange getODSOperands(unsigned index);
  ::mlir::DictionaryAttr getAttributes();
  ::mlir::DenseElementsAttr valueAttr();
  ::mlir::DenseElementsAttr value();
  ::mlir::LogicalResult verify(::mlir::Location loc);
private:
  ::mlir::ValueRange odsOperands;
  ::mlir::DictionaryAttr odsAttrs;
  ::mlir::RegionRange odsRegions;
  ::llvm::Optional<::mlir::OperationName> odsOpName;
};
class ConstantOp : public ::mlir::Op<ConstantOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::TensorType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants> {
public:
  using Op::Op;
  using Op::print;
  using Adaptor = ConstantOpAdaptor;
public:
  static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() {
    static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")};
    return ::llvm::makeArrayRef(attrNames);
  }

  ::mlir::StringAttr valueAttrName() {
    return getAttributeNameForIndex(0);
  }

  static ::mlir::StringAttr valueAttrName(::mlir::OperationName name) {
    return getAttributeNameForIndex(name, 0);
  }

  static constexpr ::llvm::StringLiteral getOperationName() {
    return ::llvm::StringLiteral("toy.constant");
  }

  std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index);
  ::mlir::Operation::operand_range getODSOperands(unsigned index);
  std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index);
  ::mlir::Operation::result_range getODSResults(unsigned index);
  ::mlir::DenseElementsAttr valueAttr();
  ::mlir::DenseElementsAttr value();
  void valueAttr(::mlir::DenseElementsAttr attr);
  static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value);
  static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value);
  static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
  ::mlir::LogicalResult verifyInvariantsImpl();
  ::mlir::LogicalResult verifyInvariants();
private:
  ::mlir::StringAttr getAttributeNameForIndex(unsigned index) {
    return getAttributeNameForIndex((*this)->getName(), index);
  }

  static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) {
    assert(index < 1 && "invalid attribute index");
    return name.getRegisteredInfo()->getAttributeNames()[index];
  }

public:
};
} // namespace toy
MLIR_DECLARE_EXPLICIT_TYPE_ID(toy::ConstantOp)


#endif  // GET_OP_CLASSES

相关文章:

  • JS location对象
  • 【SQL】子查询详解(附例题)
  • 【C++DFS 马拉车】3327. 判断 DFS 字符串是否是回文串|2454
  • RFID手持机读写器功能模块硬件定制专属方案
  • Python 之 Pandas 常用操作
  • 从零开始学习Python游戏编程14-随机数1
  • 【AI】高效地使用 AI 模型的 Prompt(提示词)
  • 面试题汇总06-场景题线上问题排查难点亮点
  • Linux网络编程——https的协议及其加密解密方式
  • 面试题ing
  • 智谛达科技:以创新为翼,翱翔AI人形机器人蓝海
  • 企业如何解决供应商风控难题?
  • 保安员考试考哪些内容呢?
  • 51.评论日记
  • 【Vue-路由案例】面经基础版
  • 把.bat文件转换成EXE文件
  • 为什么使用了CDN源服务器需要关闭防火墙?
  • C++类型转换详解
  • C语言内存函数和数据在内存的存储
  • 第一章:Pandas 基础
  • 车险保险网站/友情链接多少钱一个
  • 电商网站推广渠道/免费发布广告信息平台
  • bootstrop新闻网站开发/长春seo
  • 如何在百度里做推广网站/网站收录教程
  • wordpress 站长统计/软文广告500字
  • 安卓系统上怎样做网站前端开发/厦门网络营销推广