Be CIM or Be Memory: A Dual-mode-aware DNN Compiler for CIM Accelerators

Shixin Zhao, Yuming Li, Bing Li, Yintao He, Mengdi Wang, Yinhe Han, Ying Wang

Abstract

Computing-In-Memory (CIM) architectures offer a promising solution to the "memory wall" by performing computations directly within memory arrays. However, traditional CIM compilers treat hardware resources as static, failing to exploit the potential of dual-mode hardware that can switch between compute and memory functions. This paper introduces CMSwitch, a dual-mode-aware compiler that dynamically balances hardware arrays between "compute mode" and "memory mode" based on the specific arithmetic intensity of the workload. By integrating mode-switching into the optimization process, CMSwitch achieves an average speedup of 1.31× over state-of-the-art compilers, with performance gains reaching 2.03× for Large Language Models (LLMs).

Introduction

As Deep Neural Networks (DNNs) evolve, their hardware requirements have become increasingly bifurcated. Convolutional Neural Networks (CNNs) like ResNet-50 are characterized by high arithmetic intensity, requiring significant computational throughput. In contrast, Large Language Models (LLMs) like LLaMA often face memory bottlenecks due to massive activation sizes and KV cache requirements.

While Computing-In-Memory (CIM) accelerators are designed to mitigate data movement, most existing compilers treat CIM arrays as fixed-function units. This static allocation leads to inefficiencies: either the system lacks the math power for compute-heavy layers or, more frequently, it lacks the on-chip storage to prevent slow off-chip DRAM accesses. CMSwitch addresses this gap by treating the hardware as a flexible resource, capable of reconfiguring its arrays on the fly to meet the shifting demands of a model's execution.

Methodology

CMSwitch introduces a comprehensive compiler stack designed to optimize the "spatial-temporal" flexibility of dual-mode CIM hardware. The system consists of three primary components:

1. Dual-mode Enhanced Hardware Abstraction (DEHA)

To effectively schedule tasks, the compiler must understand the underlying hardware's constraints. DEHA models the CIM chip as a grid of reconfigurable arrays. It explicitly accounts for the latencies involved in switching modes and the specific bandwidth available for read/write operations when an array is acting as a scratchpad (memory mode).

2. Dual-mode Aware Compilation Optimization (DACO)

DACO serves as the optimization engine, employing a two-step strategy to minimize total execution latency:

  • Network Segmentation: Using Dynamic Programming, the compiler partitions the DNN into segments that fit within the available on-chip resources. This process factors in the "switch cost"—the time required to save intermediate data, reconfigure the hardware, and load new weights.
  • Resource Allocation: Within each segment, DACO utilizes Mixed-Integer Programming (MIP) to determine the optimal ratio of compute-mode arrays to memory-mode arrays. This ensures that the hardware configuration matches the specific arithmetic intensity of that segment.

3. Meta-Operator (DMO)

To ensure portability across different CIM backends (such as Dynaplasia or PRIME), CMSwitch generates a generalized meta-operator flow. This abstraction allows the compiler's high-level optimizations to be mapped onto various specific hardware implementations without redesigning the core logic.

Experimental Evaluation

The researchers evaluated CMSwitch against a diverse set of benchmarks, including CNNs (MobileNet, ResNet, VGG-16) and Transformers/LLMs (BERT-large, LLaMA2-7B, OPT-13B). The evaluation covered various batch sizes and sequence lengths to simulate real-world inference scenarios.

Performance Gains

CMSwitch demonstrated a consistent performance advantage, achieving an average speedup of 1.31× over the previous state-of-the-art compiler, CIM-MLC. The most significant improvements were observed in LLMs; for the OPT-13B model, CMSwitch outperformed the baseline by up to 2.03×.

Resource Adaptation

The compiler's primary strength lies in its adaptability. For high-intensity CNN workloads, CMSwitch automatically allocated approximately 80% of the arrays to compute mode. Conversely, for memory-bound LLM workloads, it shifted up to 90% of the arrays to memory mode. This shift effectively transformed the CIM arrays into a large on-chip scratchpad, drastically reducing the need for energy-expensive off-chip DRAM traffic.

Discussion and Limitations

While CMSwitch significantly improves execution performance, it introduces a trade-off in compilation time. Due to the expanded search space required to optimize mode-switching, compilation takes 2.8× to 6.3× longer than simpler, static compilers. However, as compilation is typically a one-time cost per model, this overhead is often justified by the resulting inference speedups.

Furthermore, the study found that the hardware overhead for switching modes is relatively low, accounting for only 3-5% of total execution time. This suggests that aggressive reconfiguration is a viable strategy for modern DNN accelerators.

Conclusion

CMSwitch represents a significant step forward in CIM compiler design by breaking the paradigm of static resource allocation. By making the compiler "dual-mode aware," CMSwitch allows hardware to pivot between being a high-throughput math engine and a high-capacity memory buffer. This flexibility is essential for the efficient execution of modern, large-scale neural networks, particularly as the industry moves toward increasingly memory-intensive models.

Summary updated

BibTeX
@inproceedings{zhao2025be,
  author = {Shixin Zhao and Yuming Li and Bing Li and Yintao He and Mengdi Wang and Yinhe Han and Ying Wang},
  title = {{Be CIM or Be Memory: A Dual-mode-aware DNN Compiler for CIM Accelerators}},
  booktitle = {ASPLOS},
  year = {2025},
  doi = {10.1145/3676641.3716248},
}
Figure