WO2022016860A1 - 一种基于tvm的并行卷积融合的方法和设备 - Google Patents

一种基于tvm的并行卷积融合的方法和设备 Download PDF

Info

Publication number
WO2022016860A1
WO2022016860A1 PCT/CN2021/076938 CN2021076938W WO2022016860A1 WO 2022016860 A1 WO2022016860 A1 WO 2022016860A1 CN 2021076938 W CN2021076938 W CN 2021076938W WO 2022016860 A1 WO2022016860 A1 WO 2022016860A1
Authority
WO
WIPO (PCT)
Prior art keywords
operator
operators
response
preset
input
Prior art date
Application number
PCT/CN2021/076938
Other languages
English (en)
French (fr)
Inventor
李柏宏
Original Assignee
苏州浪潮智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 苏州浪潮智能科技有限公司 filed Critical 苏州浪潮智能科技有限公司
Publication of WO2022016860A1 publication Critical patent/WO2022016860A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/25Fusion techniques
    • G06F18/251Fusion techniques of input or preprocessed data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • the art relates to the computer field, and more particularly to a method and device for parallel convolution fusion based on TVM.
  • the purpose of the embodiment of the present invention is to propose a method and device for parallel convolution fusion based on TVM (artificial intelligence model compiler). Improve the calculation speed of convolution, and can achieve a speedup of about 1.4 for different shapes.
  • TVM artificial intelligence model compiler
  • an aspect of the embodiments of the present invention provides a method for parallel convolution fusion based on TVM, comprising the following steps:
  • the first operator being the preset first operator, determine the types of the two input operators of the first operator;
  • the two parallel convolutions corresponding to the two input operators are combined into a new operator, and the new operator is defined by calculation and scheduling in TVM.
  • the preset first operator is an add (add) operator
  • the preset second operator is a bias (bias) operator
  • the preset third operator is conv2d (two-dimensional convolution). operation) operator.
  • judging whether the parameters of two corresponding input operators are the same includes:
  • the two weight parameters of the new operator are weights weight1 (convolution weight) and weight2 of the two original convolutions
  • the two inputs are the inputs input1 (input data) and input2
  • the output of the new operator is the result of adding the two convolutions.
  • the operators of the network model in the TVM are traversed subsequently, and the type of the operator is determined to include:
  • Another aspect of the embodiments of the present invention also provides a TVM-based parallel convolution fusion device, the device comprising:
  • the traversing module is configured to traverse the operator of the network model in the TVM subsequently, and determine the type of the operator;
  • the first judging module is configured to judge the types of the two input operators of the first operator in response to the first operator being the preset first operator;
  • the second judgment module is configured to determine the type of the corresponding input operator of the two input operators in response to the two input operators being both preset second operators;
  • the third judging module is configured to, in response to that the corresponding input operators of the two input operators are both preset third operators, to judge whether the parameters of the two corresponding input operators are the same;
  • the fourth judgment module is configured to, in response to the same parameters, judge whether two corresponding input operators are used by one operator;
  • the merging module is configured to combine the two parallel convolutions corresponding to the two input operators into a new operator and calculate the new operator in the TVM in response to the two corresponding input operators being used by one operator Definitions and scheduling definitions.
  • the preset first operator is an add operator
  • the preset second operator is a bias operator
  • the preset third operator is a conv2d operator
  • the third judgment module is further configured to:
  • the two weight parameters of the new operator are the weights weight1 and weight2 of the two original convolutions
  • the two inputs are the inputs input1 and input2 of the two original convolutions
  • the output of the new operator is two The result after adding the convolutions.
  • the traversal module is further configured to:
  • the TVM-based parallel convolution fusion method traverses the operators of the network model in the TVM subsequently, and determines the type of the operator; in response to the first operator In order to preset the first operator, determine the types of the two input operators of the first operator; in response to the two input operators being both preset second operators, determine the corresponding input operator of the two input operators In response to the corresponding input operators of the two input operators are both preset third operators, determine whether the parameters of the two corresponding input operators are the same; in response to the same parameters, determine whether the two corresponding input operators are One operator is used; in response to the use of two corresponding input operators as one operator, the two parallel convolutions corresponding to the two input operators are combined into a new operator, and the new operator is calculated and defined in TVM.
  • the technical solution defined by scheduling can reduce the amount of calculation and memory copy time, and significantly improve the speed of convolution calculation. For different shapes, a speedup ratio of about 1.4 can be achieved.
  • FIG. 1 is a schematic flowchart of a method for parallel convolution fusion based on TVM according to an embodiment of the present invention
  • FIG. 2 is a schematic diagram of a device for parallel convolution fusion based on TVM according to an embodiment of the present invention
  • FIG. 3 is a schematic diagram of a network model according to an embodiment of the present invention.
  • FIG. 4 is a schematic diagram of a combined new operator according to an embodiment of the present invention.
  • Figure 1 shows a schematic flow chart of the method.
  • the method may include the following steps:
  • S1 subsequently traverses the operators of the network model in the TVM, and determines the type of the operator, traverses the operators of the entire network model from the output end to the input end, and determines the type of each operator;
  • S6 responds that the two corresponding input operators are used by one operator, merge the two parallel convolutions corresponding to the two input operators into a new operator, and define the calculation and scheduling of the new operator in TVM, if If the two corresponding input operators are not used by one operator, repeat the first step to determine other operator types. The new operator needs to be defined and scheduled. Through this definition and scheduling, TVM will generate The corresponding CUDA (Compute Unified Device Architecture) code sets different parameters through AutoTVM (a tool for tuning and automatically selecting the best parameters in TVM) to find the optimal parameters, and finally through the most optimize parameters to generate optimal CUDA code, thereby improving performance.
  • CUDA Computer Unified Device Architecture
  • the method disclosed in the present invention is based on the AI (Artificial Intelligence, artificial intelligence) compilation system TVM.
  • TVM is a compiler stack for deep learning systems that provides end-to-end compilation for different backends.
  • the compilation process includes parts such as neural network graph optimization and single operation (operation) optimization.
  • an optimizer By adding an optimizer to the TVM front-end, the parallel convolutions are automatically merged during the compilation process to generate a new operator, and the computing performance can be improved by optimizing the CUDA (a computing architecture) code of the new operator. .
  • the calculation amount and the memory copy time can be reduced, the convolution calculation speed can be significantly improved, and a speedup ratio of about 1.4 can be achieved for different shapes.
  • the preset first operator is the add operator
  • the preset second operator is the bias operator
  • the preset third operator is the conv2d operator.
  • judging whether the parameters of two corresponding input operators are the same includes:
  • the two weight parameters of the new operator are the weights weight1 and weight2 of the two original convolutions
  • the two inputs are the inputs input1 and input2 of the two original convolutions
  • the output of the new operator is The result after adding the two convolutions.
  • the operator of the network model in the TVM is traversed subsequently, and the type of the operator is determined to include:
  • an optimizer is implemented in TVM.
  • the subsequent traversal algorithm is used to traverse each operator of the network model:
  • step 1. Determine the type of the operator. If the operator is an add operator, go to step 2. If not, repeat the judgment on the next operator until all operators are traversed;
  • step 3 Find out whether the inputs of the two bias operators are both conv2d operators, if so, go to step 3, if not, repeat step 1;
  • the original convolution algorithm needs to calculate the value of convolution 1 and convolution 2 separately through multiple loops, and then use a multiple loop to add convolution 1 and convolution 2 to generate the final output.
  • the newly generated operator only needs to be Perform all calculations in a multiple loop, and output the results to the final output, that is, calculate the sum of two convolutions at one time according to the conventional convolution calculation method, avoid multiple loop calculations, and avoid multiple memory copies, thereby improving performance.
  • N batch size
  • Hk The weight matrix is high
  • Wk weight matrix width
  • PaddingH Padding value in the high direction of the matrix
  • PaddingW Padding value in the width direction of the matrix.
  • the input channel, the convolution kernel height channel, and the convolution kernel width channel are divided into two dimensions, and the size of each dimension can be debugged by AutoTVM to find the optimal combination scheme, which are the input channels (rco, rci ), convolution kernel height channel (ryo, ryi), convolution kernel width (ryo, ryi), reordered as (rco, ryo, rxo, rci, ryi, rxi).
  • the calculation amount and the memory copy time can be reduced, the convolution calculation speed can be significantly improved, and a speedup ratio of about 1.4 can be achieved for different shapes.
  • the above-mentioned computer program embodiments can achieve the same or similar effects as any of the above-mentioned corresponding method embodiments.
  • the methods disclosed according to the embodiments of the present invention may also be implemented as a computer program executed by the CPU, and the computer program may be stored in a computer-readable storage medium.
  • the computer program is executed by the CPU, the above-mentioned functions defined in the methods disclosed in the embodiments of the present invention are executed.
  • the device 200 includes:
  • the traversing module 201 is configured to traverse the operators of the network model in the TVM subsequently, and determine the type of the operator;
  • the first judgment module 202 is configured to judge the types of the two input operators of the first operator in response to the first operator being the preset first operator;
  • the second judgment module 203 is configured to judge the type of the corresponding input operator of the two input operators in response to the two input operators being both preset second operators;
  • the third judgment module 204 is configured to judge whether the parameters of the two corresponding input operators are the same in response to that the corresponding input operators of the two input operators are both preset third operators;
  • the fourth judgment module 205 is configured to, in response to the same parameters, judge whether the two corresponding input operators are used by one operator;
  • the merging module 206 is configured to combine the two parallel convolutions corresponding to the two input operators into a new operator in response to the two corresponding input operators being used by one operator, and to compare the new operator in the TVM Make calculation definitions and schedule definitions.
  • the preset first operator is the add operator
  • the preset second operator is the bias operator
  • the preset third operator is the conv2d operator.
  • the third judgment module 204 is further configured to:
  • the two weight parameters of the new operator are the weights weight1 and weight2 of the two original convolutions
  • the two inputs are the inputs input1 and input2 of the two original convolutions
  • the output of the new operator The result after adding the two convolutions.
  • the traversal module 201 is further configured to:
  • the above-mentioned method steps and system units or modules can also be implemented by a controller and a computer-readable storage medium for storing a computer program that enables the controller to implement the functions of the above-mentioned steps or units or modules.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Artificial Intelligence (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Evolutionary Computation (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Computing Systems (AREA)
  • Molecular Biology (AREA)
  • General Health & Medical Sciences (AREA)
  • Evolutionary Biology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

一种基于TVM的并行卷积融合的方法和设备,包括以下步骤:后续遍历TVM中的网络模型的算子,并判断算子的类型(S1);响应于第一个算子为预设第一算子,判断第一个算子的两个输入算子的类型(S2);响应于两个输入算子都为预设第二算子,判断两个输入算子的对应输入算子的类型(S3);响应于对应输入算子都为预设第三算子,判断两个对应输入算子的参数是否相同(S4);响应于参数相同,判断两个对应输入算子是否为一个算子使用(S5);响应于两个对应输入算子均为一个算子使用,将两个并行卷积合并成新算子并对新算子进行计算定义和调度定义(S6)。通过使用该方法,能够减少计算量及内存拷贝时间,明显提升卷积计算速度,对于不同的形状可以达到1.4左右的加速比。

Description

一种基于TVM的并行卷积融合的方法和设备
本申请要求于2020年07月21日提交中国专利局、申请号为202010706463.5、发明名称为“一种基于TVM的并行卷积融合的方法和设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本领域涉及计算机领域,并且更具体地涉及一种基于TVM的并行卷积融合的方法和设备。
背景技术
随着人工智能技术的兴起,其在人脸识别,图像分类等领域有大规模应用,而计算速度急需提高,卷积作为其中最耗时的操作便成为其中的一个瓶颈,为了提升推理性能,需要通过算法更新等措施来提升速度。
发明内容
有鉴于此,本发明实施例的目的在于提出一种基于TVM(人工智能模型编译器)的并行卷积融合的方法和设备,通过使用本发明的方法,能够减少计算量及内存拷贝时间,明显提升卷积计算速度,对于不同的形状可以达到1.4左右的加速比。
基于上述目的,本发明的实施例的一个方面提供了一种基于TVM的并行卷积融合的方法,包括以下步骤:
后续遍历TVM中的网络模型的算子,并判断算子的类型;
响应于第一个算子为预设第一算子,判断第一个算子的两个输入算子的类型;
响应于两个输入算子都为预设第二算子,判断两个输入算子的对应输入算子的类型;
响应于两个输入算子的对应输入算子都为预设第三算子,判断两个对应输入算子的参数是否相同;
响应于参数相同,判断两个对应输入算子是否为一个算子使用;
响应于两个对应输入算子均为一个算子使用,将两个输入算子对应的两个并行卷积合并成新算子并在TVM中对新算子进行计算定义和调度定义。
根据本发明的一个实施例,预设第一算子为add(加)算子,预设第二算子为bias(偏置)算子,预设第三算子为conv2d(二维卷积运算)算子。
根据本发明的一个实施例,判断两个对应输入算子的参数是否相同包括:
将两个对应输入算子的步长、填充、输入的NCHW(数量、通道、矩阵长、矩阵宽)和权重的OIHW(输出通道、输入通道、内核长、内核宽)进行比较;
响应于两个对应输入算子的步长、填充、输入的NCHW和权重的OIHW完全相同,判断为两个对应输入算子的参数相同。
根据本发明的一个实施例,新算子的两个权重参数为两个原卷积的权重weight1(卷积权重)和weight2,两个输入为两个原卷积的输入input1(输入数据)和input2,新算子的输出为两个卷积相加后的结果。
根据本发明的一个实施例,后续遍历TVM中的网络模型的算子,并判断算子的类型包括:
从网络模型的输出端向输入端递归遍历网络模型;
查找网络模型中的所有算子并进行算子类型的判断。
本发明的实施例的另一个方面,还提供了一种基于TVM的并行卷积融合的设备,设备包括:
遍历模块,遍历模块配置为后续遍历TVM中的网络模型的算子,并判断算子的类型;
第一判断模块,第一判断模块配置为响应于第一个算子为预设第一算子,判断第一个算子的两个输入算子的类型;
第二判断模块,第二判断模块配置为响应于两个输入算子为都预设第二算子,判断两个输入算子的对应输入算子的类型;
第三判断模块,第三判断模块配置为响应于两个输入算子的对应输入算子都为预设第三算子,判断两个对应输入算子的参数是否相同;
第四判断模块,第四判断模块配置为响应于参数相同,判断两个对应输入算子是否为一个算子使用;
合并模块,合并模块配置为响应于两个对应输入算子均为一个算子使用,将两个输入算子对应的两个并行卷积合并成新算子并在TVM中对新算子进行计算定义和调度定义。
根据本发明的一个实施例,预设第一算子为add算子,预设第二算子为bias算子,预设第三算子为conv2d算子。
根据本发明的一个实施例,第三判断模块还配置为:
将两个对应输入算子的步长、填充、输入的NCHW和权重的OIHW进行比较;
响应于两个对应输入算子的步长、填充、输入的NCHW和权重的OIHW完全相同,判断为两个对应输入算子的参数相同。
根据本发明的一个实施例,新算子的两个权重参数为两个原卷积的权重weight1和weight2,两个输入为两个原卷积的输入input1和input2,新算子的输出为两个卷积相加后的结果。
根据本发明的一个实施例,遍历模块还配置为:
从网络模型的输出端向输入端递归遍历网络模型;
查找网络模型中的所有算子并进行算子类型的判断。
本发明具有以下有益技术效果:本发明实施例提供的基于TVM的并行卷积融合的方法,通过后续遍历TVM中的网络模型的算子,并判断算子的类型;响应于第一个算子为预设第一算子,判断第一个算子的两个输入算子的类型;响应于两个输入算子都为预设第二算子,判断两个输入算子的对应输入算子的类型;响应于两个输入算子的对应输入算子都为预设第三算子,判断两个对应输入算子的参数是否相同;响应于参数相同,判断两个对应输入算子是否为一个算子使用;响应于两个对应输入算子均为一个算子使用,将两个输入算子对应的两个并行卷积合并成新算子并在TVM中对新算子进行计算定义和调度定义的技术方案,能够减少计算量及内存拷贝时间,明显提升卷积计算速度,对于不同的形状可以达到1.4左右的加速比。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的实施例。
图1为根据本发明一个实施例的基于TVM的并行卷积融合的方法的示意性流程图;
图2为根据本发明一个实施例的基于TVM的并行卷积融合的设备的示意图;
图3为根据本发明一个实施例的网络模型的示意图;
图4为根据本发明一个实施例的合并后的新算子的示意图。
具体实施方式
为使本发明的目的、技术方案和优点更加清楚明白,以下结合具体实施例,并参照附图,对本发明实施例进一步详细说明。
基于上述目的,本发明的实施例的第一个方面,提出了一种基于TVM的并行卷积融合的方法的一个实施例。图1示出的是该方法的示意性流程图。
如图1中所示,该方法可以包括以下步骤:
S1后续遍历TVM中的网络模型的算子,并判断算子的类型,从输出端向输入端遍历整个网络模型的算子,并判断每个算子的类型;
S2响应于第一个算子为预设第一算子,判断第一个算子的两个输入算子的类型,如果第一个算子不是预设第一算子,则判断其他算子;
S3响应于两个输入算子都为预设第二算子,判断两个输入算子的对应 输入算子的类型,如果两个输入算子不是预设第二算子,则重复第一步骤判断其他算子类型;
S4响应于两个输入算子的对应输入算子都为预设第三算子,判断两个对应输入算子的参数是否相同,如果对应输入算子不是预设第三算子,则重复第一步骤判断其他算子类型;
S5响应于参数相同,判断两个对应输入算子是否为一个算子使用,如果参数不完全相同,则重复第一步骤判断其他算子类型;
S6响应于两个对应输入算子均为一个算子使用,将两个输入算子对应的两个并行卷积合并成新算子并在TVM中对新算子进行计算定义和调度定义,如果两个对应输入算子不都是被一个算子使用,则重复第一步骤判断其他算子类型,需要对新的算子进行计算的定义和调度的实现,通过这个定义和调度,TVM会生成对应的CUDA(Compute Unified Device Architecture,统一计算设备架构)代码,通过AutoTVM(TVM中用于调优并自动选择最佳参数的工具)来设置不同的参数,从而找出最优参数,最后通过最优参数来生成最优的CUDA代码,从而提高性能。
本发明公开的方法基于AI(Artificial Intelligence,人工智能)编译系统TVM。TVM是一个用于深度学习系统的编译器堆栈,为不同的后端提供端到端的编译,编译过程中包括对神经网络图优化和单个operation(操作)优化等部分。通过在TVM前端中加入一个优化器,从而在编译过程中对并行卷积自动进行合并,生成一个新的算子,并通过对新算子的CUDA(一种计算架构)代码优化达到提升计算性能。
通过使用本发明的技术方案,能够减少计算量及内存拷贝时间,明显提升卷积计算速度,对于不同的形状可以达到1.4左右的加速比。
在本发明的一个优选实施例中,预设第一算子为add算子,预设第二算子为bias算子,预设第三算子为conv2d算子。
在本发明的一个优选实施例中,判断两个对应输入算子的参数是否相同包括:
将两个对应输入算子的步长、填充、输入的NCHW和权重的OIHW 进行比较;
响应于两个对应输入算子的步长、填充、输入的NCHW和权重的OIHW完全相同,判断为两个对应输入算子的参数相同。
在本发明的一个优选实施例中,新算子的两个权重参数为两个原卷积的权重weight1和weight2,两个输入为两个原卷积的输入input1和input2,新算子的输出为两个卷积相加后的结果。
在本发明的一个优选实施例中,后续遍历TVM中的网络模型的算子,并判断算子的类型包括:
从网络模型的输出端向输入端递归遍历网络模型;
查找网络模型中的所有算子并进行算子类型的判断。
如图3所示,在TVM中实现一个优化器,对于任意给定的网络模型,采用后续遍历的算法遍历这个网络模型的每一个算子:
1.判断算子的类型,如果该算子为add算子,则进入第2步,如果不是,重复对下一个算子进行判断,直到所有算子均被遍历;
2.查找add算子的两个输入是否为bias算子,如果是,进行第3步,如果不是,重复第1步;
3.查找两个bias算子的输入是否都是conv2d算子,如果是进行第3步,如果不是重复第1步;
4.比较两个conv2d算子是否有相同的步长、填充、输入的NCHW是否相同,权重的OIHW是否相等,如果有一项不是则重复第1步,如果以上判断均为是,判断上述算子是否为多个算子使用,如果是则重复第1步,如果只为一个算子使用则满足合并条件,生成新算子,新算子的输入为input1和input2,两个权重分别为weight1和weight2,重复第一步直到所有算子均被遍历;
5.将使用原输出作为输入的所有算子,替换为新算子的输出,从而替换改模型中满足图3的算子为新并行卷积算子,替换后如图4所示。
然后需要在TVM中对新算子进行计算定义和调度定义:
1.计算定义:
原卷积算法需要通过多重循环分别计算卷积1的值和卷积2的值,再使用一个多重循环对卷积1和卷积2进行加法运算生成最后的输出,新生成的算子只需在一个多重循环里进行所有计算,并输出结果到最后的输出,即按照常规卷积计算方法一次计算两个卷积的和,避免了多次循环计算,也避免了多次内存拷贝,从而提升性能。
新算法伪代码描述如下:
nH=0
nR=0
For n=1to N step 1:
For o=0to O step 1:
For i=0to I step 1:
For hi=0to(H-Hk+2*paddingH)step stride:
nH++
nR=0
For wi=0to(W-Wk+2*paddingW)step stride:
nR++
For m=i-paddingH to(i+Hk-paddingH)step 1:
For n=j-paddingW to(j+Wk-paddingW)step 1:
If!(m<0or m>=H or n<0or n>=W):
Out[n][o][nH][nR]+=
input1[n][i][m][n]*weight1[o][i][m-hi+paddingH][n-wi+paddingW]+
input2[n][i][m][n]*weight2[o][i][m-hi+paddingH][n-wi+paddingW]
其中,N:批大小;
O:输出层数;
I:输入层数;
H:输入矩阵高;
W:输入矩阵宽;
Hk:权重矩阵高;
Wk:权重矩阵宽;
PaddingH:矩阵高方向填充值;
PaddingW:矩阵宽方向填充值。
2.调度定义
将input1、input2、weight1和weight2从全局内存写入共享内存,把输入通道、新输出高度、新输出宽度分别分成4个维度,分别为输入通道的四个维度(bf,vf,tf,fi),新输出高度的四个维度(by,vy,ty,yi),新输出宽度的四个维度(bx,vx,tx,xi),每个维度大小可调(通过AutoTVM可自动选择最优组合),将输入通道的第一维bf和批bathsize融合绑定到“blockIdx.z”,新输出高度的第一维by绑定到"blockIdx.y",新输出宽度的第一维bx绑定到“blockIdx.x”,将输入通道的第二维vf,新输出高度的第二维vy,新输出宽度的第二维vz分别绑定到“vthread”(可避免数据银行冲突),将输入通道的第三维tf绑定到“threadIdx.z”,新输出高度的第三维ty绑定到"threadIdx.y",新输出宽度的第三维tz绑定到“threadIdx.x”,最后对上述维度重排序为bf,by,bx,vf,vy,vx,tf,ty,tx,fi,yi,xi,(其中fi为输入通道的第四维,yi为新输出高度的第四维,xi为新输出宽度的第四维)。
最后把三个reduce轴:输入通道,卷积内核高度通道,卷积内核宽度通道分别分成两个维度,每个维度的大小可通过AutoTVM调试寻找最优组合方案,分别为输入通道(rco,rci),卷积内核高度通道(ryo,ryi),卷积内核宽度(ryo,ryi),重新排序为(rco,ryo,rxo,rci,ryi,rxi)。
通过本发明的技术方案,能够减少计算量及内存拷贝时间,明显提升卷积计算速度,对于不同的形状可以达到1.4左右的加速比。
需要说明的是,本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,可以通过计算机程序来指令相关硬件来完成,上述的程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中存储介质可为磁碟、光盘、只读存储器(Read-Only Memory,ROM)或随机存取存储器(Random Access Memory,RAM)等。上述计算机程序的实施例,可以达到与之对应的前述任意方法 实施例相同或者相类似的效果。
此外,根据本发明实施例公开的方法还可以被实现为由CPU执行的计算机程序,该计算机程序可以存储在计算机可读存储介质中。在该计算机程序被CPU执行时,执行本发明实施例公开的方法中限定的上述功能。
基于上述目的,本发明的实施例的第二个方面,提出了一种基于TVM的并行卷积融合的设备,如图2所示,设备200包括:
遍历模块201,遍历模块201配置为后续遍历TVM中的网络模型的算子,并判断算子的类型;
第一判断模块202,第一判断模块202配置为响应于第一个算子为预设第一算子,判断第一个算子的两个输入算子的类型;
第二判断模块203,第二判断模块203配置为响应于两个输入算子都为预设第二算子,判断两个输入算子的对应输入算子的类型;
第三判断模块204,第三判断模块204配置为响应于两个输入算子的对应输入算子都为预设第三算子,判断两个对应输入算子的参数是否相同;
第四判断模块205,第四判断模块205配置为响应于参数相同,判断两个对应输入算子是否为一个算子使用;
合并模块206,合并模块206配置为响应于两个对应输入算子均为一个算子使用,将两个输入算子对应的两个并行卷积合并成新算子并在TVM中对新算子进行计算定义和调度定义。
在本发明的一个优选实施例中,预设第一算子为add算子,预设第二算子为bias算子,预设第三算子为conv2d算子。
在本发明的一个优选实施例中,第三判断模块204还配置为:
将两个对应输入算子的步长、填充、输入的NCHW和权重的OIHW进行比较;
响应于两个对应输入算子的步长、填充、输入的NCHW和权重的OIHW完全相同,判断为两个对应输入算子的参数相同。
在本发明的一个优选实施例中,新算子的两个权重参数为两个原卷积的权重weight1和weight2,两个输入为两个原卷积的输入input1和input2, 新算子的输出为两个卷积相加后的结果。
在本发明的一个优选实施例中,遍历模块201还配置为:
从网络模型的输出端向输入端递归遍历网络模型;
查找网络模型中的所有算子并进行算子类型的判断。
需要特别指出的是,上述系统的实施例采用了上述方法的实施例来具体说明各模块的工作过程,本领域技术人员能够很容易想到,将这些模块应用到上述方法的其他实施例中。
此外,上述方法步骤以及系统单元或模块也可以利用控制器以及用于存储使得控制器实现上述步骤或单元或模块功能的计算机程序的计算机可读存储介质实现。
本领域技术人员还将明白的是,结合这里的公开所描述的各种示例性逻辑块、模块、电路和算法步骤可以被实现为电子硬件、计算机软件或两者的组合。为了清楚地说明硬件和软件的这种可互换性,已经就各种示意性组件、方块、模块、电路和步骤的功能对其进行了一般性的描述。这种功能是被实现为软件还是被实现为硬件取决于具体应用以及施加给整个系统的设计约束。本领域技术人员可以针对每种具体应用以各种方式来实现的功能,但是这种实现决定不应被解释为导致脱离本发明实施例公开的范围。
上述实施例,特别是任何“优选”实施例是实现的可能示例,并且仅为了清楚地理解本发明的原理而提出。可以在不脱离本文所描述的技术的精神和原理的情况下对上述实施例进行许多变化和修改。所有修改旨在被包括在本公开的范围内并且由所附权利要求保护。

Claims (10)

  1. 一种基于TVM的并行卷积融合的方法,其特征在于,包括以下步骤:
    后续遍历TVM中的网络模型的算子,并判断算子的类型;
    响应于第一个算子为预设第一算子,判断所述第一个算子的两个输入算子的类型;
    响应于所述两个输入算子都为预设第二算子,判断所述两个输入算子的对应输入算子的类型;
    响应于所述两个输入算子的对应输入算子都为预设第三算子,判断两个所述对应输入算子的参数是否相同;
    响应于所述参数相同,判断两个所述对应输入算子是否为一个算子使用;
    响应于两个所述对应输入算子均为一个算子使用,将所述两个输入算子对应的两个并行卷积合并成新算子并在所述TVM中对所述新算子进行计算定义和调度定义。
  2. 根据权利要求1所述的方法,其特征在于,所述预设第一算子为add算子,所述预设第二算子为bias算子,所述预设第三算子为conv2d算子。
  3. 根据权利要求1所述的方法,其特征在于,判断两个所述对应输入算子的参数是否相同包括:
    将两个所述对应输入算子的步长、填充、输入的NCHW和权重的OIHW进行比较;
    响应于两个所述对应输入算子的步长、填充、输入的NCHW和权重的OIHW完全相同,判断为两个所述对应输入算子的参数相同。
  4. 根据权利要求1所述的方法,其特征在于,所述新算子的两个权重参数为两个原卷积的权重weight1和weight2,两个输入为两个原卷积的输入input1和input2,所述新算子的输出为两个卷积相加后的结果。
  5. 根据权利要求1所述的方法,其特征在于,后续遍历TVM中的网络模型的算子,并判断算子的类型包括:
    从所述网络模型的输出端向输入端递归遍历所述网络模型;
    查找所述网络模型中的所有算子并进行算子类型的判断。
  6. 一种基于TVM的并行卷积融合的设备,其特征在于,所述设备包括:
    遍历模块,所述遍历模块配置为后续遍历TVM中的网络模型的算子,并判断算子的类型;
    第一判断模块,所述第一判断模块配置为响应于第一个算子为预设第一算子,判断所述第一个算子的两个输入算子的类型;
    第二判断模块,所述第二判断模块配置为响应于所述两个输入算子都为预设第二算子,判断所述两个输入算子的对应输入算子的类型;
    第三判断模块,所述第三判断模块配置为响应于所述两个输入算子的对应输入算子都为预设第三算子,判断两个所述对应输入算子的参数是否相同;
    第四判断模块,所述第四判断模块配置为响应于所述参数相同,判断两个所述对应输入算子是否为一个算子使用;
    合并模块,所述合并模块配置为响应于两个所述对应输入算子均为一个算子使用,将所述两个输入算子对应的两个并行卷积合并成新算子并在所述TVM中对所述新算子进行计算定义和调度定义。
  7. 根据权利要求6所述的设备,其特征在于,所述预设第一算子为add算子,所述预设第二算子为bias算子,所述预设第三算子为conv2d算子。
  8. 根据权利要求6所述的设备,其特征在于,所述第三判断模块还配置为:
    将两个所述对应输入算子的步长、填充、输入的NCHW和权重的OIHW进行比较;
    响应于两个所述对应输入算子的步长、填充、输入的NCHW和权重的OIHW完全相同,判断为两个所述对应输入算子的参数相同。
  9. 根据权利要求6所述的设备,其特征在于,所述新算子的两个权重参数为两个原卷积的权重weight1和weight2,两个输入为两个原卷积的输 入input1和input2,所述新算子的输出为两个卷积相加后的结果。
  10. 根据权利要求6所述的设备,其特征在于,所述遍历模块还配置为:
    从所述网络模型的输出端向输入端递归遍历所述网络模型;
    查找所述网络模型中的所有算子并进行算子类型的判断。
PCT/CN2021/076938 2020-07-21 2021-02-19 一种基于tvm的并行卷积融合的方法和设备 WO2022016860A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010706463.5 2020-07-21
CN202010706463.5A CN111860650A (zh) 2020-07-21 2020-07-21 一种基于tvm的并行卷积融合的方法和设备

Publications (1)

Publication Number Publication Date
WO2022016860A1 true WO2022016860A1 (zh) 2022-01-27

Family

ID=73001661

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/076938 WO2022016860A1 (zh) 2020-07-21 2021-02-19 一种基于tvm的并行卷积融合的方法和设备

Country Status (2)

Country Link
CN (1) CN111860650A (zh)
WO (1) WO2022016860A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111860650A (zh) * 2020-07-21 2020-10-30 苏州浪潮智能科技有限公司 一种基于tvm的并行卷积融合的方法和设备
CN115408568B (zh) * 2021-05-26 2024-04-05 中科寒武纪科技股份有限公司 一种对神经网络的算子进行融合的方法和相关产品
CN113687936A (zh) * 2021-05-31 2021-11-23 杭州云栖智慧视通科技有限公司 在tvm中加速调优收敛的调度方法、存储介质和电子设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013080152A1 (en) * 2011-12-01 2013-06-06 International Business Machines Corporation Dynamically configurable placement engine
CN110490309A (zh) * 2019-08-14 2019-11-22 北京中科寒武纪科技有限公司 一种用于神经网络的算子融合方法及其相关产品
CN111242321A (zh) * 2019-04-18 2020-06-05 中科寒武纪科技股份有限公司 一种数据处理方法及相关产品
CN111401537A (zh) * 2019-09-24 2020-07-10 上海寒武纪信息科技有限公司 一种数据处理方法、装置、计算机设备及存储介质
CN111860650A (zh) * 2020-07-21 2020-10-30 苏州浪潮智能科技有限公司 一种基于tvm的并行卷积融合的方法和设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013080152A1 (en) * 2011-12-01 2013-06-06 International Business Machines Corporation Dynamically configurable placement engine
CN111242321A (zh) * 2019-04-18 2020-06-05 中科寒武纪科技股份有限公司 一种数据处理方法及相关产品
CN110490309A (zh) * 2019-08-14 2019-11-22 北京中科寒武纪科技有限公司 一种用于神经网络的算子融合方法及其相关产品
CN111401537A (zh) * 2019-09-24 2020-07-10 上海寒武纪信息科技有限公司 一种数据处理方法、装置、计算机设备及存储介质
CN111860650A (zh) * 2020-07-21 2020-10-30 苏州浪潮智能科技有限公司 一种基于tvm的并行卷积融合的方法和设备

Also Published As

Publication number Publication date
CN111860650A (zh) 2020-10-30

Similar Documents

Publication Publication Date Title
WO2022016860A1 (zh) 一种基于tvm的并行卷积融合的方法和设备
CN109375601B (zh) 基于数据驱动建模与仿真优化的流水线规划方法及设备
EP4036803A1 (en) Neural network model processing method and apparatus, computer device, and storage medium
CN110134697B (zh) 一种面向键值对存储引擎的参数自动调优方法、装置、系统
Wu et al. Kernel weaver: Automatically fusing database primitives for efficient gpu computation
CN109960576B (zh) 一种面向cpu-gpu异构的低能耗任务调度策略
Kaduri et al. Algorithm selection for optimal multi-agent pathfinding
CN111539526B (zh) 一种神经网络卷积的方法和设备
US10956417B2 (en) Dynamic operation scheduling for distributed data processing
CN114037352A (zh) 基于数字孪生的自动化集装箱码头多agv动态调度方法
CN112348314A (zh) 一种带起重机的分布式柔性车间调度方法及系统
CN102799960B (zh) 面向数据模型的并行业务流程异常检测方法
Saha An incremental bisimulation algorithm
CN112884248B (zh) 一种大规模云服务流程的优化方法
CN107038244A (zh) 一种数据挖掘方法和装置、一种可读介质和存储控制器
Shah et al. New modeling and performance evaluation of tool sharing control in FMS using colored Petri nets
JPS63237165A (ja) 工程計画支援装置
Sasak-Okoń Speculative query execution in Relational databases with Graph Modelling
Lange et al. Multi agent system optimization in virtual vehicle testbeds
Gang et al. Deadlock-free scheduling method using Petri net model analysis and GA search
Hatono et al. Modeling of FMS under certainty using stochastic Petri nets-an application to rule-based on-line scheduling
Soma et al. Schedule optimization using fuzzy inference
Ansari et al. Modified Deep Q Optimizer with Updated SARSA for Improving Learning Efficiency through Optimum Resource Utilization in Reinforcement Learning
Gupta et al. Modified-multi objective firefly optimization algorithm for object oriented applications test suites optimization
Sotskov Software for production scheduling based on the mixed (multi) graph approach

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21845310

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21845310

Country of ref document: EP

Kind code of ref document: A1