TVM学习笔记(三)逻辑体系结构组件

TVM体系结构

上图展示了TVM的主要逻辑组件[1],以下主要介绍组件内容及其之间的关系。

各个组件之间依赖关系:

  1. 接口级依赖
  2. 实现级依赖,如:TIR pass 会使用 arith 进行分析

Relay [2] [3]

Rela相关代码~Github镜像

Relay 是用于表示完整模型的高级函数式中间表达( IR,Intermediate Representation)。

  • transforms 中定义了许多优化
  • qnn 用于导入预先量化的模型
  • vm for lowering to dynamic virtual machine
  • memory 用于内存优化

相关文档:

  • Introduction to Relay IR
  • Relay Operator Strategy
  • Convert Layout Pass

AutoTVM 及 AutoScheduler [4]

AutoTVM 和 AutoScheduler模块都是基于搜索的程序优化组件,AutoScheduler是 template-free 自动调优模块,AutoTVM是 template-based 自动调优模块。主要包括:

  • Cost models and feature extraction.
  • A record format for storing program benchmark results for cost model construction.
  • A set of search policies over program transformations.

TOPI,Tensor Operator Inventory

TOPI相关代码~Github镜像
TOPI模块提供了许多在深度学习中常见的由 numpy 预定义的算子

Target

Target相关代码~Github镜像
target 即 后端设备或者称之为硬件目标(Hardwaer target),target模块中包含了将IR模块翻译成 runtime.Module 的代码生成器(code generators),同时其中提供 Target 类,用于描述硬件目标。根据设备不同,target模块可以通过读取设备属性自定义编译流程。

TIR,Tensor IR

TIR相关代码~Github镜像

TE,Tensor Expression

TE相关代码~Github镜像

Arith

This module is closely tied to the TIR. One of the key problems in the low-level code generation is the analysis of the indices' arithmetic properties — the positiveness, variable bound, and the integer set that describes the iterator space. arith module provides a collection of tools that do (primarily integer) analysis. A TIR pass can use these analyses to simplify and optimize the code.

Arith模块提供了一组分析工具,TIR pass 可以使用这些工具进行分析并简化和优化代码。

Runtime

Runtime相关代码~Github镜像
Runtime 模块是TVM编译栈的基础,提供了编译结果的加载和执行机制,同时提供了一组 Python 和 Rust 的API。

Node

Node模块在 runtime::Object 上为IR数据结构添加了其他特征,其中主要包含 reflection, serialization, structural equivalence, and hashing。

IR:IRModule / Type / Pass / Op

IR tvm\ir文件夹中包含 IR function variants 的统一数据结构和接口,同时适用于tvm/relaytvm/ir,其中值得注意的components 有:

  • IRModule
  • Type
  • PassContext and Pass
  • Op

IRModule

Type

不同的 function variants(relay.Function 和 tir.PrimFunc)可以共存于IRModule中,尽管这些函数变体可能具有不同的内容表达,但它们使用了相同的数据结构用来表示类型(Type),因此TVM使用相同的数据结构作为这些变体的函数签名 Signature。一旦清晰地定义调用规约(calling convention),统一的type 系统允许一个函数变量去调用另一个函数,这为后续的跨函数变量优化打开的大门。

Pass

TVM系统同样提供了统一的PassContext用于配置流程Pass的行为和常用的复合Pass用来执行Pass Pipeline。
相关文档:
Pass Infrastructure

Op,Operator

Op 表示TVM系统内部基本算子(内部函数),开发者可以自己注册Op及其属性

Support

Support模块提供了TVM的公共基础支持,如:generic arena allocator, socket, and logging.

Driver

后端设备的驱动模块


  1. Logical Architecture Components https://tvm.apache.org/docs/dev/index.html#logical-architecture-components ↩

  2. Introduction to Relay IR https://tvm.apache.org/docs/dev/relay_intro.html ↩

  3. Github~tvm/src/relay/ https://hub.fastgit.org/apache/tvm/tree/main/src/relay ↩

  4. GitHub~tvm/main/src~Code Organization https://hub.fastgit.org/apache/tvm/tree/main/src ↩

你可能感兴趣的:(TVM学习笔记(三)逻辑体系结构组件)