High Performance Im2win and Direct Convolutions using Three Tensor Layouts on SIMD Architectures

Xiang Fu, Xinpeng Zhang, Jixiang Ma, Peng Zhao, Shuai Lü, Tony Liu · DOI

Abstract

Convolution is the core component within deep neural networks and it is computationally intensive and time consuming. Tensor data layouts significantly impact convolution operations in terms of memory access and computational efficiency. Yet, there is still a lack of comprehensive performance characterization on data layouts on SIMD architectures concerning convolution methods. This paper proposes three novel data layouts for im2win convolution: NHWC, CHWN, and CHWN8, and introduces a set of general optimization techniques for both direct and im2win convolutions. We compare the optimized im2win convolution with the direct convolution and PyTorch's im2col-based convolution across the aforementioned layouts on SIMD machines. The experiments demonstrated that the im2win convolution with the new NHWC layout achieved up to 355% performance speedup over NCHW layout. Our optimizations also significantly improve the performance of both im2win and direct convolutions. Our optimized im2win and direct convolutions achieved up to 95% and 94% of machine's theoretical peak performance, respectively.

Introduction

Convolution operations are the computational backbone of deep learning, often accounting for over 90% of a neural network's execution time. To handle this load, developers typically use one of three methods: Direct Convolution, Im2col-based Convolution, or Im2win (Image-to-Window). While Im2col is the industry standard due to its speed, it suffers from a massive memory footprint. Im2win offers a middle-ground approach by reorganizing tensors into dot-product windows to improve memory access without the extreme overhead of im2col. This paper addresses the lack of comprehensive understanding regarding how tensor data layouts—the physical arrangement of data in memory—impact these algorithms on modern SIMD CPU architectures.

Methodology

We propose three novel layouts for the im2win algorithm:

  • NHWC (Channel-Last): Prioritizes the channel dimension in the innermost memory stride.
  • CHWN (Batch-Last): Prioritizes the batch dimension.
  • CHWN8: A hybrid layout that groups the batch dimension into blocks of 8, aligning perfectly with 256-bit vector registers (AVX2).

Beyond layouts, we implement several SIMD-specific optimizations:

  • Loop Reordering and Coalescing: Ensures unit-stride memory access and balances workloads across CPU cores.
  • Register and Cache Blocking: Minimizes cache misses by keeping high-speed cache filled.
  • Vectorization: Utilizes AVX2 and FMA instructions for multi-calculation clock cycles.
  • Memory Alignment: Ensures data starts at 512-bit boundaries to optimize memory requests.

Experimental Results

The researchers evaluated these methods using a benchmark of 12 unique convolution layers (conv1-conv12) on dual Intel Xeon Gold 6330 CPUs.

Performance and Efficiency

The optimized im2win convolution achieved the best performance in 8 out of the 12 benchmarks. As shown in Figure 5, the system reached up to 95% of theoretical peak performance for im2win and 94% for direct convolution. Compared to the standard NCHW layout, the new NHWC layout for im2win provided speedups ranging from 11% to 355%.

Performance comparison of different convolution methods and layouts in TFLOPS.

Memory Footprint

Im2win proves to be a highly efficient compromise in terms of memory. On average, it uses only 39% of the memory required by the standard im2col (GEMM) method. In heavy layers like conv4, the memory savings are particularly pronounced, as illustrated in Figure 6.

Memory usage comparison (GB) across convolution layers.

Conclusion

This study demonstrates that tensor layout is a critical performance multiplier for convolution algorithms. By switching to optimized layouts like NHWC and employing SIMD-specific tuning, software can approach the hardware's theoretical maximum performance. Future work will explore extending these optimizations to specialized convolution types and newer instruction sets like AVX-512.

Summary updated

BibTeX
@misc{fu2024high,
  author = {Xiang Fu and Xinpeng Zhang and Jixiang Ma and Peng Zhao and Shuai Lü and Tony Liu},
  title = {{High Performance Im2win and Direct Convolutions using Three Tensor Layouts on SIMD Architectures}},
  year = {2024},
  eprint = {2408.00278},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.00278},
}
Figure