Abstract
The rapid evolution of deep neural networks (DNNs) presents a significant challenge for hardware vendors, who must constantly update their software stacks to support new architectures. This paper introduces a framework, integrated into Apache TVM as "Bring Your Own Codegen" (BYOC), that allows hardware vendors to plug proprietary code generation tools directly into existing deep learning compilers. By decoupling hardware-agnostic graph optimizations from vendor-specific execution, the framework enables accelerators to support state-of-the-art models with minimal engineering effort, often requiring only a few thousand lines of code.
Introduction
The "Cambrian Explosion" of DNN architectures has created a software bottleneck for hardware accelerators. Traditional approaches require vendors to build "full-stack" compilers, handling everything from model parsing to low-level code generation. This process is redundant, as most high-level optimizations are hardware-agnostic. Furthermore, many accelerators are optimized for heavy tensor math but struggle with the complex control flow or non-tensor operations found in models like Mask R-CNN. Without an efficient way to partition models between a host CPU and an accelerator, hardware utilization remains suboptimal.
Methodology
The proposed framework splits the compilation process into a shared, hardware-agnostic component and an accelerator-exclusive component. This allows the compiler to leverage existing front-ends (like PyTorch or TensorFlow) while offloading specific subgraphs to specialized hardware backends.
Graph Partitioning
A core contribution of the framework is its multi-step graph partitioning logic. The process identifies regions of the computational graph that can be executed more efficiently on the target accelerator.
- Pattern-based Grouping: Identifies common operator sequences (e.g.,
Conv2D + Add + ReLU) that can be fused into single hardware instructions. - Annotation: Developers mark specific operators supported by their hardware.
- Cost-based Partitioning: This critical step evaluates whether the performance gain of offloading a region outweighs the data transfer overhead between the host and the accelerator.
Accelerator-Specific Processing and Codegen
Once subgraphs are identified, vendors can apply proprietary optimizations such as specialized quantization or layout transformations (e.g., NCHW to NHWC). The framework supports flexible code generation, allowing offloaded code to be represented as JSON graphs, C code, or custom bitstreams. A unified runtime manages the host CPU and invokes accelerator kernels as external function calls.
Evaluation
The framework was evaluated using standard classification (ResNet, Inception, MobileNet) and detection (SSD, Faster R-CNN) models on NVIDIA Jetson AGX Xavier and Xilinx FPGAs.
- Engineering Efficiency: Integration of complex toolchains like NVIDIA TensorRT or Xilinx Vitis AI was achieved with only 2,000 to 4,400 lines of code (LOC), significantly reducing development time.
- Performance Gains: On the NVIDIA Jetson, offloading to TensorRT via BYOC achieved up to a 25.5x speedup for Faster R-CNN using FP16 precision compared to standard CUDA baselines. On Xilinx edge FPGAs, speedups reached up to 77x for Inception V3 compared to ARM CPU execution.
- Partitioning Impact: Cost-based partitioning proved vital for object detection, reducing the number of offloaded subgraphs from 21 to 2, thereby minimizing initialization and communication overhead.
Conclusion
BYOC provides a scalable path for hardware vendors to support the rapidly changing landscape of deep learning. By sharing infrastructure and focusing on modular offloading, the framework minimizes redundant engineering while maximizing hardware performance. Future work includes automating target selection for multi-accelerator systems and exploring the offloading of complex control flow logic.
Summary updated