Abstract
Neural networks have been successfully applied in various resource-constrained edge devices, where usually central processing units (CPUs) instead of graphics processing units exist due to limited power availability. State-of-the-art research still focuses on efficiently executing enormous numbers of multiply-accumulate (MAC) operations. However, CPUs themselves are not good at executing such mathematical operations on a large scale, since they are more suited to execute control flow logic, i.e., computer algorithms. To enhance the computation efficiency of neural networks on CPUs, in this paper, we propose to convert them into logic flows for execution. Specifically, neural networks are first converted into equivalent decision trees, from which decision paths with constant leaves are then selected and compressed into logic flows. Such logic flows consist of if and else structures and a reduced number of MAC operations. Experimental results demonstrate that the latency can be reduced by up to 14.9 % on a simulated RISC-V CPU without any accuracy degradation. The code is open source at https://github.com/TUDa-HWAI/NN2Logic
Introduction: Playing to the CPU's Strengths
Deep learning is rapidly migrating to the "edge"—powering smart sensors, wearables, and IoT devices. However, a fundamental hardware mismatch persists: while neural networks are built on millions of Multiply-Accumulate (MAC) operations optimized for the massive parallelism of Graphics Processing Units (GPUs), edge devices typically rely on simple Central Processing Units (CPUs).
CPUs are not "math monsters"; they are "logic masters" designed to execute control flow—deciding what to do next based on specific conditions. Forcing a tiny edge CPU to crunch massive amounts of MAC math leads to high latency and excessive power consumption. This research proposes a paradigm shift: instead of treating the CPU like an inefficient GPU, we should convert neural networks into logic flows that leverage the CPU's robust branch prediction and logical units.
Methodology: The NN2Logic Framework
The proposed NN2Logic framework converts a standard neural network into a high-efficiency "logic flow" through a three-stage process:
- Decision Tree Conversion: The neural network is mapped to an equivalent decision tree. To prevent the tree from becoming computationally unmanageable, the authors only construct branches that are actually traversed by the training data.
- Logic Extraction via Optimization: The researchers identify "constant leaves"—paths where the classification result remains identical regardless of certain input variations. Using Mixed Integer Programming (MIP) and the Gurobi solver, they find the Irreducible Infeasible Subsystem (IIS). This identifies the minimum set of logical conditions (e.g., "if $x_0 < 0$") required to guarantee a specific output.
- Hybrid Execution: The final output is C code that implements a hybrid approach. When an input arrives, the system first checks these simplified logic flows. If the input matches a simplified path, the CPU returns the answer immediately—an "early exit." If no match is found, the system falls back to the standard neural network layers.
Experimental Results
The approach was evaluated using three benchmarks: MNIST (simplified to binary even/odd classification) and two Occupancy datasets for environmental sensor-based room detection. The hybrid C code was tested on a simulated Ibex RISC-V CPU*.
As shown in the results table, the framework achieved significant performance gains:
- Latency Reduction: Average latency was reduced by up to 14.9%. In best-case scenarios (minimum latency), the speedup reached a remarkable 52.2%.
- High Exit Rates: For the Occupancy I dataset, 34.1% of all samples were able to "exit" through the logic flows, bypassing the full neural network math entirely.
- Zero Accuracy Loss: Because the logic flows are mathematically equivalent to the original network for the paths they represent, these speedups are achieved with no degradation in model accuracy.
Discussion and Future Work
The core insight of this work is the "early exit" advantage: for many real-world inputs, the full mathematical depth of a network is unnecessary. If a single sensor reading being below a threshold guarantees a specific classification, the CPU should be allowed to stop calculating immediately. By converting ReLU activation decisions into if-else structures, the computational burden is moved from limited multipliers to efficient logic units.
While currently focused on binary classification and 3-layer fully connected networks, future work will explore scaling this method to multi-class problems and deeper architectures like Convolutional Neural Networks (CNNs). Although the MIP optimization is computationally expensive during the compilation phase, it provides a "free" performance boost during runtime on the edge device.
The code is open source and available at https://github.com/TUDa-HWAI/NN2Logic.
Summary updated