Abstract
This paper proposes CodeX, an end-to-end framework that facilitates encoding, bitwidth customization, fine-tuning, and implementation of neural networks on FPGA platforms. CodeX incorporates nonlinear encoding to the computation flow of neural networks to save memory. The encoded features demand significantly lower storage compared to the raw full-precision activation values; therefore, the execution flow of CodeX hardware engine is completely performed within the FPGA using on-chip streaming buffers with no access to the off-chip DRAM. We further propose a fully-automated algorithm inspired by reinforcement learning which determines the customized encoding bitwidth across network layers. CodeX full-stack framework comprises of a compiler which takes a high-level Python description of an arbitrary neural network architecture. The compiler then instantiates the corresponding elements from CodeX Hardware library for FPGA implementation. Proof-of-concept evaluations on MNIST, SVHN, and CIFAR-10 datasets demonstrate an average of 4.65x throughput improvement compared to stand-alone weight encoding. We further compare CodeX with six existing full-precision DNN accelerators on ImageNet, showing an average of 3.6x and 2.54x improvement in throughput and performance-per-watt, respectively.
The Memory Wall in DNN Acceleration
Deploying modern Deep Neural Networks (DNNs) on embedded devices like FPGAs is primarily a "memory wall" problem. While FPGAs feature fast on-chip memory (BRAM), its capacity is extremely limited compared to the gigabytes required for weights and activations in typical models. Consequently, most accelerators are forced to constantly swap data between the FPGA and off-chip DRAM, creating a massive bottleneck in both latency and power consumption.
While weight quantization is a common research focus, activations—the intermediate data generated between layers—are often overlooked. As shown in the figure above, activations can account for over 50% of the total memory footprint in popular architectures like ResNet-50 and VGG. CodeX addresses this by targeting both weights and activations with nonlinear encoding.
The CodeX Framework
CodeX introduces a "full-stack" solution that bridges the gap between high-level software descriptions and optimized hardware implementation. The framework consists of three main components: a Software API, a Compiler, and a Hardware Library.
Key Innovations
- Nonlinear Encoding: Instead of standard linear quantization, CodeX uses K-means clustering to find optimal representative values (bins) for a specific layer's data distribution. This allows for higher precision with significantly fewer bits.
- Differentiable Fine-Tuning: To mitigate accuracy loss from quantization, the authors developed a custom back-propagation routine using a "smooth approximation" of the nonlinear encoding function during training.
- Automated Bitwidth Selection: CodeX employs a reinforcement-learning-inspired algorithm that performs a "diminishing search" to find a configuration that maximizes memory reduction while maintaining a user-defined accuracy threshold.
- Streaming Hardware Architecture: The framework generates a pipelined hardware design where data flows through on-chip "streaming buffers." Because the data is heavily compressed, it never has to leave the FPGA chip during execution, eliminating DRAM access entirely.
Evaluation and Results
The authors evaluated CodeX across a range of standard benchmarks, including MNIST (LeNet), SVHN/CIFAR-10 (VGG7), and ImageNet (AlexNet, ResNet-18).
- Throughput: CodeX achieved an average of 4.65× higher throughput compared to accelerators that only encode weights.
- Efficiency on ImageNet: Compared to six existing full-precision DNN accelerators, CodeX showed a 3.6× improvement in throughput and a 2.54× improvement in performance-per-watt.
- Resource Savings: For the MNIST dataset, CodeX reduced BRAM usage by 2.82× compared to a standard 8-bit fixed-point implementation.
- Accuracy Recovery: The custom fine-tuning method successfully restored accuracy to within ~1% of full-precision models, even under aggressive compression.
Conclusion
CodeX demonstrates that by treating activations as first-class citizens in the quantization process, it is possible to bypass the DRAM bottleneck and run entire DNN execution flows on-chip. While current implementations are optimized for Xilinx FPGAs, the framework's automated approach to bitwidth selection and nonlinear encoding provides a scalable path for future embedded AI acceleration. Future work may involve extending the framework to handle Recurrent Neural Networks (RNNs) or exploring more complex encoding schemes.
Summary updated