Rust bindings for ncnn.
Open Github pages
Or cargo doc
and open with browser byself
$ cd /path/to/rust-ncnn
$ cargo doc --open
$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
Rust cmake needs --parallel
option thus CMake>=3.12 is complusory
$ pip install cmake --upgrade --user
Rust bindgen uses clang
to generate bindings.rs
from c_api.h
$ sudo apt install clang-3.9 libclang-3.9-dev
$ sudo apt install clang-10 libclang-10-dev # use clang-10 for ubuntu 20.04
ncnn build from source:
$ cd rust-ncnn/
$ cargo run --example get_version
Use specific ncnn release:
$ export NCNN_TAG="20220420"
Use prebuilt ncnn:
$ export NCNN_DIR="/path/to/your/ncnn/lib"
Or use vcpkg
vcpkg install ncnn:x64-windows-static-md
cargo run --example get_version
By default library uses dynamic linking on linux and static linking on windows.
To explicitly use static linking:
$ cargo build --example benchmark --features ncnn-bind/static
To explicitly use dynamic linking:
$ cargo build --example benchmark --features ncnn-bind/dynamic
Build with Vulkan support (requires Vulkan SDK):
$ cargo build --example benchmark --features ncnn-bind/vulkan
$ cargo test
$ cargo run --example get_version
$ cargo run --example benchmark --release
Finished release [optimized] target(s) in 0.01s
Running `target/release/examples/benchmark`
squeezenet.param 2 ms
squeezenet_int8.param 5 ms
mobilenet.param 3 ms
mobilenet_int8.param 7 ms
mobilenet_v2.param 3 ms
mobilenet_v3.param 2 ms
shufflenet.param 2 ms
shufflenet_v2.param 2 ms
mnasnet.param 2 ms
proxylessnasnet.param 3 ms
efficientnet_b0.param 5 ms
regnety_400m.param 6 ms
blazeface.param 0 ms
googlenet.param 10 ms
googlenet_int8.param 19 ms
resnet18.param 9 ms
resnet18_int8.param 16 ms
alexnet.param 7 ms
vgg16.param 49 ms
vgg16_int8.param 71 ms
resnet50.param 18 ms
resnet50_int8.param 40 ms
squeezenet_ssd.param 17 ms
squeezenet_ssd_int8.param 13 ms
mobilenet_ssd.param 8 ms
mobilenet_ssd_int8.param 15 ms
mobilenet_yolo.param 30 ms
mobilenetv2_yolov3.param 13 ms
yolov4-tiny.param 20 ms
nanodet-plus-m_416.param 11 ms
nanodet-plus-m_416-int8.param 20 ms