[论文解读] Low-memory GEMM-based convolution algorithms for deep neural networks
本文提出两种基于 GEMM 的新型卷积算法,通过将卷积重新组织为多个小规模 1×1 卷积的累加,显著降低了内存开销。这些方法仅需 O(MHW) 和 O(KW) 的额外内存——远低于标准 im2col 方法的 O(CHWK²) 或先前基于 GEMM 方法的 O(CHWK)——同时在性能上达到相当或更优水平,尤其在多核系统中由于更优的数据局部性而表现更佳。
Deep neural networks (DNNs) require very large amounts of computation both for training and for inference when deployed in the field. A common approach to implementing DNNs is to recast the most computationally expensive operations as general matrix multiplication (GEMM). However, as we demonstrate in this paper, there are a great many different ways to express DNN convolution operations using GEMM. Although different approaches all perform the same number of operations, the size of temporary data structures differs significantly. Convolution of an input matrix with dimensions $C imes H imes W$, requires $O(K^2CHW)$ additional space using the classical im2col approach. More recently memory-efficient approaches requiring just $O(KCHW)$ auxiliary space have been proposed. We present two novel GEMM-based algorithms that require just $O(MHW)$ and $O(KW)$ additional space respectively, where $M$ is the number of channels in the result of the convolution. These algorithms dramatically reduce the space overhead of DNN convolution, making it much more suitable for memory-limited embedded systems. Experimental evaluation shows that our low-memory algorithms are just as fast as the best patch-building approaches despite requiring just a fraction of the amount of additional memory. Our low-memory algorithms have excellent data locality which gives them a further edge over patch-building algorithms when multiple cores are used. As a result, our low memory algorithms often outperform the best patch-building algorithms using multiple threads.
研究动机与目标
- 为解决现有基于 GEMM 的 DNN 卷积方法中较高的内存开销问题,特别是广泛使用的 im2col 方法所需的 O(CHWK²) 空间。
- 设计适用于嵌入式系统和内存受限系统的内存高效型基于 GEMM 的卷积算法。
- 探索基于 GEMM 的 DNN 卷积实现中内存使用、计算量与数据局部性之间的权衡。
- 评估低内存占用的基于 GEMM 的算法是否能在多线程执行环境下与高内存占用的拼接构建方法性能相当或更优。
提出的方法
- 将多通道多核(MCMK)卷积重新表述为 K² 个独立 1×1 卷积的累加,每个均通过 GEMM 处理。
- 采用分块策略处理输入张量和核张量的小型、可管理的块,以减少临时存储需求。
- 应用数据布局转换,使 GEMM 调用能作用于紧凑且局部化的数据结构,而非完整的 im2col 矩阵。
- 优化内存访问模式,以提升缓存局部性并减少 L1/L3 缓存停顿周期,尤其在多核执行环境下。
- 实现两种变体:一种使用行主序布局进行 MHW 大小的累加(O(MHW) 空间),另一种使用列主序布局进行 KW 大小的累加(O(KW) 空间)。
- 利用现有高度优化的 BLAS/GEMM 库,在最小化自定义内核开发的同时保持高性能计算。
实验结果
研究问题
- RQ1是否可以在显著减少临时内存使用的同时,保持高性能地实现基于 GEMM 的卷积?
- RQ2减少内存占用如何影响 DNN 卷积中的数据局部性和多核性能?
- RQ3在多核架构中,低内存占用的基于 GEMM 的算法是否能在速度和效率上超越传统的拼接构建方法?
- RQ4在基于 GEMM 的 MCMK 卷积中,最小化内存使用的最优数据布局与分块策略是什么?
- RQ5所提算法在不同硬件平台上的内存与性能特性,与 im2col 和 lazy im2col 等现有方法相比如何?
主要发现
- 所提出的 O(MHW) 和 O(KW) 内存算法在仅使用远低于传统方法的临时内存情况下,性能与最佳拼接构建型 GEMM 基础方法相当或更优。
- 在 Intel Core i7 和 ARM Cortex A57 处理器上,低内存算法的 L1 和 L3 缓存停顿周期数少于竞争方法,其中 kn2row-aa 实现了最低的平均停顿次数。
- 在多核环境中,低内存算法因改善的数据局部性,性能优于拼接构建方法,通常因内存带宽压力降低而表现更佳。
- O(KW) 变体在 VGG16 的高层网络中表现出尤为出色的性能,其缓存效率甚至超过所有其他对比方法。
- 实验结果证实,内存减少并未以牺牲速度为代价,且内存效率可成为嵌入式系统中高性能推理的关键推动因素。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。