Skip to content

Commit 66e03b1

Browse files
Merge pull request #4 from coolguy525/dev
Enhanced README with comprehensive usage documentation
2 parents b7969a8 + 318360d commit 66e03b1

1 file changed

Lines changed: 134 additions & 1 deletion

File tree

README.md

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,142 @@ Rust bindings for the Rockchip RKNN Runtime API (librknnrt.so), enabling deploym
44

55
> These bindings do **not** require redistributing the C headers from the Rockchip rknpu2 SDK. The sys crate contains bindgen bindings, but bindgen is not part of the build process.
66
7+
## Overview
8+
9+
This crate provides safe, idiomatic Rust abstractions over the Rockchip RKNN runtime API, enabling efficient deployment and inference of deep learning models on Rockchip NPU hardware. It's designed for production use in embedded systems, IoT devices, and edge computing applications where Rockchip NPUs are deployed.
10+
711
## Requirements
812

913
- Rockchip NPU compatible with `librknnrt` or `librknnmrt` libraries
1014
- Rust 1.70+ (edition 2021)
15+
- Linux environment (primary target)
16+
- Supported NPU families: RK35xx, RK3576, and others compatible with RKNN API v2.3.2
17+
18+
## Features
19+
20+
- **Safe Rust Abstractions**: Memory-safe wrappers around the C API with proper error handling
21+
- **Model Management**: Load, query, and manage RKNN models with type-safe interfaces
22+
- **Inference Pipeline**: Set inputs, run inference, and retrieve outputs with zero-copy buffer support
23+
- **Hardware Optimization**: Configure NPU core usage and batch processing for optimal performance
24+
- **Flexible API Loading**: Choose between linked and runtime-loaded RKNN libraries
25+
- **Comprehensive Querying**: Access model metadata, tensor attributes, and performance information
26+
- **Multi-format Support**: Handle various tensor formats (NCHW, NHWC) and data types
27+
- **Production Ready**: Based on the stable **rknpu2 SDK v2.3.2**
28+
- **Comprehensive Error Handling**: Custom error types with detailed error information
29+
- **Memory-safe Operations**: Safe tensor operations and buffer management
30+
31+
## Project Structure
32+
33+
```
34+
crates/
35+
├── rknpu2/ # High-level Rust API wrapper
36+
├── rknpu2-sys/ # Low-level FFI bindings
37+
└── rktensor/ # Tensor operations and utilities
38+
```
39+
40+
## Installation
41+
42+
Add to your `Cargo.toml`:
43+
44+
```toml
45+
[dependencies]
46+
rknpu2 = { version = "0.1", features = ["rk35xx"] }
47+
48+
# For runtime library loading (optional)
49+
rknpu2 = { version = "0.1", features = ["rk35xx", "libloading"] }
50+
51+
# For RK3576 specific features
52+
rknpu2 = { version = "0.1", features = ["rk3576"] }
53+
```
54+
55+
## API Overview
56+
57+
### Core Types
58+
59+
- **`RKNN<A>`**: Main struct for model management and inference
60+
- **`Input`**: Represents model input tensors with various data types and formats
61+
- **`Output`**: Handles model output retrieval with flexible buffer management
62+
- **`Query`**: Trait for querying model metadata and attributes
63+
64+
### Key Methods
65+
66+
- **`RKNN::new()`**: Create RKNN context from model data
67+
- **`set_inputs()`**: Configure model inputs before inference
68+
- **`run()`**: Execute model inference
69+
- **`get_outputs()`**: Retrieve inference results
70+
- **`query()`**: Get model information and attributes
71+
72+
### Supported Data Types
73+
74+
- **Input**: `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `f16`, `f32`
75+
- **Output**: `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `f16`, `f32`
76+
- **Tensor Formats**: NCHW, NHWC, NC1HWC2
77+
78+
## Examples
79+
80+
The crate includes several examples demonstrating different use cases:
81+
82+
- **MobileNet Classification**: Complete image classification pipeline
83+
- **Model Querying**: How to inspect model properties and performance
84+
- **Custom Input/Output**: Advanced buffer management techniques
85+
86+
Run examples with:
87+
88+
```bash
89+
# Basic MobileNet example
90+
cargo run --example mobilenet --features rk35xx
91+
92+
# With runtime library loading
93+
cargo run --example mobilenet --features "rk35xx,libloading"
94+
```
95+
96+
## Performance Considerations
97+
98+
- **Zero-copy Buffers**: Use preallocated buffers when possible for optimal performance
99+
- **Core Selection**: Configure appropriate NPU cores based on your workload
100+
- **Batch Processing**: Leverage batch inference for multiple inputs
101+
- **Memory Management**: Reuse input/output buffers across inference calls
102+
103+
## Troubleshooting
104+
105+
### Common Issues
106+
107+
1. **Library Not Found**: Ensure `librknnrt.so` is in your library path
108+
2. **Feature Flags**: Verify you're using the correct feature flags for your NPU
109+
3. **Model Format**: Ensure your model is in the correct RKNN format
110+
4. **Memory Alignment**: Check that input/output buffers meet alignment requirements
111+
112+
## Development Status
113+
114+
This project is actively maintained and follows Rust best practices. Contributions are welcome!
115+
116+
## Contributing
117+
118+
Contributions are welcome! Please see our contributing guidelines for:
119+
120+
- Code style and formatting
121+
- Testing requirements
122+
- Documentation standards
123+
- Feature request process
124+
125+
## Related Projects
126+
127+
- [rknpu2-sys](crates/rknpu2-sys/): Low-level FFI bindings
128+
- [rktensor](crates/rktensor/): Tensor operations and utilities
129+
- [RKNN Toolkit2](https://github.com/airockchip/rknn-toolkit2): Official Python toolkit
130+
131+
## Support
132+
133+
For issues and questions:
134+
135+
- Check the [examples](crates/rknpu2/examples/) directory
136+
- Review the [API documentation](https://docs.rs/rknpu2)
137+
- Open an issue on GitHub
138+
- Consult the [RKNN API reference](https://github.com/airockchip/rknn-toolkit2)
139+
140+
## License
141+
142+
This project is licensed under either of:
11143

12144
## Features
13145

@@ -39,7 +171,8 @@ rknpu2 = { git = "https://github.com/CodeVoyager15/RKNN", package = "rknpu2" }
39171
rktensor = { git = "https://github.com/CodeVoyager15/RKNN", package = "rktensor" }
40172
```
41173

42-
## Usage
174+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
175+
- MIT License ([LICENSE-MIT](LICENSE-MIT))
43176

44177
Coming soon! The library will provide a simple and intuitive API for:
45178

0 commit comments

Comments
 (0)