About
A real-time kernel fusion compiler with innovative support for dynamic workloads, including dynamic shapes and eager execution.
Languages & RuntimesMeasured star growth
- in 24h
- 0
- in 7 days
- +18
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalDevice Virtual Machine (DVM)
Microsecond-Scale Compilation · Dynamic Tensor Execution
English | 简体中文
Introduction
DVM (Device Virtual Machine) is currently the industry's only framework for microsecond-scale real-time AI operator compilation and execution. It compiles and executes handwritten or fused operators in deep neural networks at runtime based on their concrete shapes. Through real-time compilation, DVM natively supports high-performance operator fusion and execution in dynamic scenarios, including dynamic shapes and dynamic graphs. DVM also supports conventional operator optimization scenarios, such as static-shape graph fusion and custom handwritten operators. DVM is currently used by downstream AI frameworks including MindSpore and TorchNPU for automatic operator fusion in graph and eager modes. For most model workloads, this fusion can deliver significant end-to-end performance gains.
DVM supports Huawei Ascend NPU hardware, covering the c220 and c310 chip architectures, as well as NVIDIA GPUs. The GPU backend supports V100 and newer NVIDIA GPUs.
Core Design
- Compilation for runtime shapes: Generate operators using the shapes available at execution time, enabling shape-specific optimization for dynamic workloads.
- Tile-level bytecode: The host compiler translates operator graphs into tile-level bytecode, which the device virtual machine interprets to execute the computation.
- Fusion across execution modes: Support operator fusion for static graphs, dynamic shapes, and eager execution, with vector and matrix computation.
- Python and C++ interfaces: Express custom operators and fused computations through Python or C++, and integrate DVM into the compilation and execution paths of downstream frameworks.
See the operator development guide for the architecture and execution flow.
🛠️ Installation
Environment requirements
The following requirements and build steps apply to the Ascend backend:
| Component | Requirement |
|---|---|
| Operating system | Linux |
| Hardware | Huawei Ascend A2, A3, or A5 |
| Runtime | CANN 8.5 or later |
| C++ compiler | C++17 support; tested with GCC 7.3.0 and Clang 18.1 |
| Python | Python 3.7 or later. See the wheel build requirements and development dependencies. |
Build from source
In an activated Python environment, clone the repository and install its Python dependencies:
git clone https://github.com/mindspore-ai/dvm.git
cd dvm
python -m pip install -r requirements.txt 'setuptools>=64' wheel 'pybind11>=2.10'
Replace the CANN path below with your installation path, then configure and build DVM from the repository root:
source /path/to/ascend-toolkit/set_env.sh
bash build.sh -b npu -j8
python -m pip install dist/dvm_py-*.whl
python -c "import dvm; print(dvm.__file__)"
The default Ascend build writes the dvm_py wheel to dist/. The wheel includes libdvm.so, the Python extension and the public headers.
To compile the host code with Clang, run the following command.
CXX=clang++ make -j8
See the Contribution Guide for backend setup and testing.
🚀 Quick Start
Run a Python example
After building DVM, run the addition example from the repository root.
Set DEVICE_ID to an available device:
DEVICE_ID=0 python examples/01_add.py
Use the DVM API
The same example defines an addition kernel with @dvm.kernel and executes it on NumPy inputs:
import numpy as np
import dvm
@dvm.kernel
def my_add(k, x, y):
a = k.load(x, dvm.float32)
b = k.load(y, dvm.float32)
c = k.add(a, b)
d = k.store(c)
return d
x = np.full([32, 32], 0.1, np.float32)
y = np.full([32, 32], 0.3, np.float32)
z = my_add(x, y)
print(z)
More examples cover batch normalization, attention, and matrix multiplication with post-fusion.
For C++ applications, include the DVM headers and link libdvm.a as shown in the C++ example.
For graph-mode and eager-mode fusion in TorchNPU, follow the integration guide.
📖 Documentation
- Operator Development Guide — Architecture, C++ API usage, and execution modes (Chinese)
- TorchNPU Integration — Graph-mode fusion, eager fusion, and custom operators (Chinese)
- Development Notes — Operator restrictions and simulator debugging (Chinese)
- Development Skills — Design and development, debugging, and codebase quality (Chinese)
- Knowledge Base — APIs, fusion rules, optimization methods, and debug output (Chinese)
- Examples — Python kernels and C++ integration
- C++ API · Python API — Interface definitions
- Contributing — Development setup, testing, pull requests, and review
- Release Notes — Version history
🤝 Join Us
Issues and pull requests are welcome, including bug reports, documentation, tests, new operators, and compilation or execution optimizations. Start with the Contribution Guide for development setup, validation, and the review workflow. Discuss substantial features in an issue before implementation.
AKG SIG
If you are interested in DVM's technical direction, scan the QR code below to join the AKG SIG group and discuss usage and development with the community.

📄 Technical Reports
- DVM: A Bytecode Virtual Machine Approach for Dynamic Tensor Computation [paper]
⚖️ License
Explore related projects
Loading…