[论文解读] The Indirect Convolution Algorithm
Indirect Convolution 算法用指向输入张量行的指针间接缓冲区,替代了基于 GEMM 的卷积中内存密集型的 im2col 转换,实现了类似 GEMM 的性能,且无需数据重排。它通过消除 im2col 存储减少了内存开销,在非 1x1 卷积上相比基于 GEMM 的方法最高可提升 62% 的性能,而在 1x1 步长为 1 的卷积上仅带来轻微开销。
Deep learning frameworks commonly implement convolution operators with GEMM-based algorithms. In these algorithms, convolution is implemented on top of matrix-matrix multiplication (GEMM) functions, provided by highly optimized BLAS libraries. Convolutions with 1x1 kernels can be directly represented as a GEMM call, but convolutions with larger kernels require a special memory layout transformation - im2col or im2row - to fit into GEMM interface. The Indirect Convolution algorithm provides the efficiency of the GEMM primitive without the overhead of im2col transformation. In contrast to GEMM-based algorithms, the Indirect Convolution does not reshuffle the data to fit into the GEMM primitive but introduces an indirection buffer - a buffer of pointers to the start of each row of image pixels. This broadens the application of our modified GEMM function to convolutions with arbitrary kernel size, padding, stride, and dilation. The Indirect Convolution algorithm reduces memory overhead proportionally to the number of input channels and outperforms the GEMM-based algorithm by up to 62% on convolution parameters which involve im2col transformations in GEMM-based algorithms. This, however, comes at cost of minor performance reduction on 1x1 stride-1 convolutions.
研究动机与目标
- 解决基于 GEMM 的卷积实现中 im2col 转换带来的高内存和带宽开销问题。
- 在无需昂贵数据重组的前提下,实现对各种卷积核大小、填充、步长和空洞率的高效通用卷积计算。
- 提供一种与 GEMM 兼容的原 primitive,保持高性能的同时减少内存占用。
- 探索一种新算法范式,在保留基于 GEMM 方法通用性的同时,消除 im2col 的开销。
提出的方法
- 引入一个间接缓冲区,其中包含每个输出像素对应输入感受野在输入张量中起始位置的指针。
- 用使用间接缓冲区访问输入数据的修改版 GEMM 原 primitive 替代标准 GEMM 操作,避免 im2col 内存布局转换。
- 通过利用支持间接寻址的标准 GEMM 内核,保持与高度优化的 BLAS 库的兼容性。
- 采用计算密集型的 GEMM 原 primitive,可良好扩展至多核环境,与 im2col 不同,后者受内存带宽限制。
- 设计算法时对卷积核大小、填充、步长和空洞率保持透明,实现广泛适用性。
- 采用混合策略:根据卷积参数在传统 GEMM 和 Indirect GEMM 之间切换,以优化整体性能。
实验结果
研究问题
- RQ1能否设计一种基于 GEMM 的卷积算法,在不牺牲性能或通用性的情况下,完全消除 im2col 转换?
- RQ2基于指针间接寻址的 GEMM 原 primitive 在不同卷积超参数下,与传统 GEMM 和基于 im2col 的 GEMM 相比,性能表现如何?
- RQ3与 im2col 缓冲区相比,维护间接缓冲区的内存和计算开销是多少?
- RQ4由于其计算密集型特性,Indirect Convolution 算法在多线程环境中的可扩展性是否优于基于 GEMM 的方法?
- RQ5该算法能否在当前需要 im2col 转换的卷积上实现显著加速,特别是在较大卷积核上?
主要发现
- Indirect Convolution 算法通过消除 im2col 转换,使内存开销与输入通道数成比例降低。
- 在需要 im2col 转换的卷积上,其性能相比基于 GEMM 的卷积最高可提升 62%,尤其在较大卷积核上表现更优。
- 大于 1x1 的卷积核在减少内存带宽压力后,性能提升范围为 2.7% 至 23.3%。
- 1x1 步长为 2 的卷积,同样需要 im2col,性能提升较小,为 0.5% 至 8.0%,因其对缓存局部性依赖较低。
- 1x1 步长为 1 的卷积,无需 im2col,由于增加了间接寻址的复杂性,性能出现轻微下降,范围为 0.3% 至 1.9%。
- 该算法的性能优势随系统算术强度的增加而提升,表明其在未来的硬件世代中将受益更大。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。