Repository navigation
Releases
0.4.0
Added
Extractor::extract_matreturns an output as an independently ownedMatwithout copying it:
the native extractor already detaches the tensor from its own blob pool, and this form takes that
buffer instead of duplicating it.OutputGuard::into_matis the same form through a scoped guard,
andextract_matwithTensorWidth::Storeduses it for stored storage.api_benchmarkgained theowned-mat,guard-into,native-bufferandnative-ownedmodes.- A
rawfeature exposes the generated bindings asncnn_rust::sys. The default build no longer
publishes them, so the crate's default surface carries no generated C ABI. - Prebuilt SDK archives on the
sdk-20261020release: one shared-library
ncnn-rust-sdk-20261020-<platform>.tar.gzeach forlinux-x64-cpu,linux-x64-vulkan,
windows-x64-cpuandmacos-arm64-cpu, next to aSHA256SUMSfile.tools/install-sdk.py
installs one and checks it against that digest and against the release stamped in
include/ncnn/platform.h, so a machine needs neither CMake, glslang nor a C++ build of ncnn, and
--listprints the platform names.
Changed
extract_matwith either width andOutputGuard::into_matcopy only when the storage cannot be owned: a
network built withNetBuilder::reuse_blob_memoryreturns tensors inside its pools, and an
extractor that submitted a borrowed input returns caller storage.- The native request reference in
api_benchmarknow runs the options each wrapper row uses
(native-requestborrows its input and keeps light mode off, the owned variants enable it) and
releases its input handle before the request. The request-path figures in the performance page were
measured again: the wrapper matches the C API on every form that borrows or reuses its output, and
the forms that return copied storage cost one or two 256 KB buffers per request. - The request forms collapse onto one storage decision per side.
extractandextract_mattake a
TensorWidth, so FP32 and stored width no longer need separate methods, andextract_intoappends
rather than replaces, so the separate append form is gone. OnNet,infer,infer_storedand
infer_intotake anInput, which folds the owned, borrowed-slice and sub-view forms into them.
The extractor request surface drops from eight methods to four and the network from six to three,
and no capability is lost. Extractor::extract_ownedis now the sugar form ofextract_into: it allocates the vector and
delegates, so the FP32 conversion has one implementation instead of two.- The loading methods take a source instead of a parameter shape.
load_paramaccepts
ParamSource::{Text, Binary, File, Reader},load_modelaccepts
WeightSource::{Bytes, File, Reader}plusWeightSource::EMPTY, andNet::loadruns both stages
in one call.Fromconversions keepload_param("…")andload_model(&bytes)unchanged.
Removed
Extractor::extract_stored,Extractor::extract_stored_owned,Extractor::extract_append,
Net::infer_borrowed,Net::infer_borrowed_intoandNet::infer_view_into, replaced by the
TensorWidthandInputarguments thatdocs/migration.mdmaps from the old names.Extractor::inputsandExtractor::outputs_with, which only looped overinputandextract;
the caller writes that loop and keeps the error policy visible.OutputGuard::detach, the copying twin ofinto_mat:into_matalready copies when it cannot
own the storage, so the guard keeps one ownership path.Net::load_param_file,Net::load_param_binary,Net::load_param_reader,Net::load_model_file
andNet::load_model_reader. Their capability moves intoParamSourceandWeightSource, which
also removes the four near-identical parameter loaders and the three weight loaders.
Net::load_model_file_nativestays separate because mapped loading changes the lifetime contract.Mat::append_f32_to, whose behaviourMat::to_f32_intonow has: it appends, leaves the vector
untouched on failure, and keeps the capacity, so the replace form was the special case a caller
writes withclear().Mat::read_f32_unchecked, which ran the same validation and the same native copy asMat::to_f32:
anunsafemarker promised nothing the safe form does not already do, soto_f32is the only
FP32 copy.PoolAllocator, which is nowalloc::Pool: the crate carried two types calledAllocator(the
CPU pool andgpu::Allocator), and the per-extractor and option setters read ambiguously.
ncnn 20261020 SDK
Prebuilt ncnn 20261020 SDKs: the shared library, the feature set ncnn-rust requires and the project patches. Install with 'python3 tools/install-sdk.py --platform --dest
'; --list prints the names. SHA256SUMS detects a corrupted transfer, not a substituted release.0.3.0
Added
Net::layersandNet::blobsdescribe the loaded graph: layer names, registered types, type
indices, blob counts and the support flags ncnn declares per layer type, plus the wiring and
recorded shape of every blob.LayerInfoalso carries the shape each layer recorded for its inputs and outputs, and
layer_type_indexresolves a type name to the index the registry uses.ParamDict::kindreports how an entry is stored throughParamKind, which is what a custom layer
needs before it picks a getter, andversion_numberreturns the pinned release date as the integer
ncnn encodes.- Zero-copy input:
Mat::from_externalborrows caller storage,Extractor::input_borrowedsubmits it
without a copy andNet::infer_borrowedbounds the borrow to one request.
Net::infer_borrowed_intofuses that with the reusable output buffer, which is the request form
that allocates no data buffers. - Consuming tensor helpers that keep the storage a tensor already owns:
Mat::into_reshaperewrites
the header instead of duplicating aliased storage, andMat::into_normalizednormalizes in place
instead of copying first. - Batched tensors:
Mat::from_f32_batchbuilds storage with a batch count above one,TensorInfo::n
reports it andMat::to_f32reads the batches back. - Layout helpers
Mat::flattenandMat::with_packing, and the four-axis border helpers
Mat::copy_make_border_3dandMat::copy_cut_border_3dwith theBordersargument. DataReader::from_filestreams a file through the native stdio reader, and the file loaders
Net::load_param_fileandNet::load_model_filenow read natively instead of copying the file
into a Rust buffer first.Device::pipeline_cacheandDevice::set_pipeline_cachemove the serialized Vulkan pipeline cache
through memory, next to the existing path helpers.image::affine_transform,image::invert_affine,image::warp_affineandimage::WarpBorder
cover the affine preprocessing path.Options::set_blob_allocator,Options::set_workspace_allocatorand
Options::set_kvcache_allocatorattach caller-owned pools to a network.crates/ncnn/examples/fast_allocator.rsmeasures the request path with a drop-in allocator, and the
performance page records what it changes: on Windows the owned-output form is dominated by the
process heap, while the forms that reuse a buffer do not move.heap::retain_pageskeeps the pages of a freed output buffer mapped on glibc Linux, which removes
the per-request page faults of the forms that return independent storage.
heap::set_mapping_limit,heap::disable_trimmingandheap::retain_pages_up_toset the two
thresholds individually, and every function reports whether the heap accepted them, so portable
code calls the preset and ignores afalseon other targets. The crate applies the settings
itself because a service cannot always set the environment of its own process. The Windows heap
needs no threshold and exposes none, so the call reportsfalsethere, and the heap test asserts
both hosts: the faults and their removal on glibc, the absent faults and thefalseresult on
Windows.crates/ncnn/examples/heap_retention.rsprints the owned-output and reused-buffer figures before
and after that call plus the raw two-buffer cost of the host, and CI runs it next to the allocator
example.NetBuilder::reuse_blob_memorygives a network one pool allocator for intermediate blobs and one
for layer workspace, and the network keeps both alive, so every extractor takes its scratch memory
from the pools instead of allocating it per request.Net::reuses_blob_memoryreports whether a
network was built that way. Theapi_benchmark pooled-requestmode times the four request forms on
a pooled network next to a default one, and the owned form drops by about ten times on glibc and by
two to three times on the Windows host that the performance page records.Net::optionreads the option value a loaded network actually uses.- Tensor helpers that run on the native kernels:
Mat::fill,Mat::normalize_in_place,
Mat::to_pixels,Mat::to_pixels_resize,Mat::copy_make_border,Mat::copy_cut_borderand the
BorderModeargument. Net::load_param_readerandNet::load_model_readerload from aDataReader, and
register_custom_layer_by_typeindexregisters a factory for a type index.Extractor::clearrestarts a handle so the next request starts from an empty cache,
Extractor::continue_sessionkeeps the cached state for the next input, which is what
token-by-token decoding needs, and
Extractor::{set_light_mode, set_blob_allocator, set_workspace_allocator, set_kvcache_allocator, set_kvcache_max_seqlen_hint}override the network options for one request path. A restart
re-applies them, so a reused handle keeps the settings it was given.Mat::{channel, channel_range, depth, depth_range, column_range, row_range, batch, batch_range}
return aMatView, a read-only alias of part of the tensor that copies only when it goes back in
as an input.Mat::is_emptyreports a tensor without storage, andTensorInfo::totaland
TensorInfo::shapereport the native storage slots and the extent of each axis.Net::layer_handlereturns aGraphLayer, the layer the loaded graph holds at an index, for the
native layer calls the raw module exposes, next to theNet::layersdescription of the same layer.
The guard owns the C handle and releases it on drop, while the layer stays with the network.Net::shared_blobslists the blobs more than one layer reads.Extractor::set_light_modeand
Net::extractorreturnError::Invalidwhile that list is not empty, because light mode releases
a bottom blob after its first consumer and the graph would otherwise return the values of that
consumer; an explicitSplitlayer keeps a graph compatible.MatView::as_matexposes the tensor a view aliases, andNet::infer_view_intoruns one request
over sub views and appends the outputs to a caller buffer. It is the zero-copy form for a model
that takes a crop, a channel or one batch item, and it replaces the copy that
Extractor::inputperforms on a view.crates/ncnn/examples/threads.rsruns one network per worker thread and reports the aggregate
throughput next to a single network that uses every core.- The nightly fuzz workflow also fuzzes the pixel view and the typed tensor paths, so the buffer
checks, region arithmetic, element decoding and reshape validation are covered next to the model
loaders. - CI compares the public API with the published release, resolves every documentation link and
anchor offline, and av*tag publishes both packages in dependency order before creating the
GitHub release from the changelog section.
Changed
Mat::normalize_in_placeapplies the same per-channel view asMat::normalized, so both forms
agree on tensors below three dimensions, which the native call otherwise treats as per-row
coefficients.- Normalization writes one pass over the destination instead of copying and then running a native
Scalelayer, soMat::normalizedcosts about as much as a bare clone. The scale and bias match
the native layer; the last bit can differ when the compiler contracts the multiply and the add. Mat::flattenreturns unpacked storage, so its result reads throughMat::to_f32without a typed
conversion.DataReader::from_bytesbuilds a bounded memory reader: a read is clamped to the bytes that
remain instead of failing, and the same handle scans parameter text, which the reader-based
loaders rely on.- A borrowed input now returns
Error::Invalidwhen the network runs with light mode. The native
forward path reads the storage refcount before an in-place layer may write, and an external tensor
has none, so the previous combination reached a native null read; owned input is unaffected. - The fuzz target also feeds the binary parameter loader and the reader loaders.
- The coverage job writes an lcov with per-line records, prints the summary, fails below 85 percent
line coverage, and rejects a report withoutDArecords. - The nightly fuzz workflow runs its target on the nightly toolchain, which
rust-toolchain.toml
otherwise shadows, and the version matrix resolves tags withGITHUB_TOKEN, imports the shared SDK
into the loader path, and reports the declaration gap for tags that cannot link the adapter. A
passing matrix run comments on the open tracking issue and closes it. - Both CPU examples and both device examples run in CI, and rustdoc builds with
-D warningson
every push instead of only during the documentation deploy. - The README drops its validation section and gains single-layer and preprocessing tables next to
the trained-model table; the CI description stays indocs/support-matrix.md. - The
Net,NetBuilder,Extractor,OutputGuard,Matview,gpuandCpuOptionitems state
their preconditions, error cases and layout requirements instead of one summary line. - A probe test prints the finiteness of three attention configurations. The
ubuntu-24.04-arm
runner matches x86-64 for the two-dimensional operand, while a three-dimensional operand with one
channel returnsNaNfor one sequence row there, so the layer case uses the two-dimensional form
and every case asserts finite output on every target again. Allocator::upload, imports and command recording name the failing operation
(Error::NativeAt), so a refused allocation reads asVulkan uploadinstead of a bare status.docs/contracts.md,docs/troubleshooting.mdanddocs/evidence-history.mdrecord the measured
device-memory exhaustion behaviour, andMat::to_i8states that it reads signed storage.- The performance page records a Linux run of the request-path modes: the modes that reuse storage
match the C API, and the forms that ret...
0.2.0
Added
ElementKind,Mat::to_f32_typed,Mat::to_i8,Mat::from_typedandMat::from_i8read and
build packed, 16-bit and quantized storage.Extractor::extract_stored,Extractor::extract_stored_ownedandNet::infer_storedkeep the
element width a layer wrote, including on Vulkan networks, whose extraction detaches its download
copy from the pool allocator.examples/typed_tensors.rsandexamples/vulkan_resident.rs.- Runnable documentation examples for
Mat::from_f32,Net::inferandExtractor::extract_stored. CHANGELOG.md,SECURITY.md,docs/troubleshooting.md,docs/migration.md,
docs/native-abi.mdanddocs/layer-coverage.md.- Every push compares the generated INT8 and operator fixtures against a native C++ reference, a
coverage job reports line coverage of the wrapper, and a nightly workflow fuzzes the text
parameter loader and the bounded weight reader.
Changed
- Every conformance layer case runs one inference; the parameter-only tier is gone.
NCNN_TEST_DEVICE=vulkanrepeats the operator families, graph pairs and layer cases on the
default device.- Layer cases cover the key/value cache, channels inside depth copies, negative slice starts and
requantizing convolutions. Error::Invalidcarries formatted detail, so shape, name and width mismatches name the values.Mat::to_f32validates the storage it reads, and the copy-count messages name
Extractor::extract_storedas the path that avoids a conversion.- Public enums are
#[non_exhaustive], and the guard requirements are stated as remedies. - Thread-affinity requirements are stated on
Net,MatandDevice.
Fixed
- The layer suite selected its child test by a bare name that matched no test, so no case ran.
LSTMfixtures supplied half of the recurrent weight block.InverseSpectrogramfixtures supplied one channel where the transform reads one channel per
frequency bin.ROIAlignfixtures placed the region in a channel-padded tensor that the layer reads flat.
ncnn-rust 0.1.1
Patch release that fixes the Windows link-kind detection and widens the test surface.
Install
cargo add ncnn-rust@0.1.1Fixes
- Link kind detection. MSVC names a static library and a DLL import library
ncnn.lib, so the
static default silently linkedncnn.dlland a consumer build failed at launch with
STATUS_DLL_NOT_FOUND. The build script now derives the kind from the SDK layout, rejects an
explicit contradiction with the expected setting, and names the directory that holds the DLL.
The READMEs describe the Windowsbinlayout.
Tests
- Vulkan contracts. One test covers device selection, allocator accounting, resident
inference, guard descriptors, external buffer import, persistent pipeline caches and
cross-device rejection. It runs on a physical RTX 3060 and on the CI lavapipe device. - Every layer type. The conformance suite now has a case for each of the 108 layer types the
SDK ships; 40 of them reach a forward pass and the rest assert that the type registers and its
parameters parse. - Public API paths. File loading, custom readers, parameter dictionaries, unchecked reads,
reshape views, the three endpoint forms and concatenated output ranges. - Packaged crate build. A job now builds and runs a separate crate that depends on the two
published archives, which is the only check that sees the published manifest and file list.
Documentation
README_zh.mdmirrors the English README, and both files link to each other.- The version matrix runs monthly; topics are
rustandncnn.
Verification
The v0.1.1 tag passed all eight CI jobs: ubuntu-latest, ubuntu-24.04-arm, windows-latest,
macos-15, macos-15-intel, the 1.85.1 MSRV job, the Vulkan lavapipe job and the packaged crate
build. API reference: https://edwardssss.github.io/ncnn.rust/ncnn_rust/.
ncnn-rust 0.1.0
First release of the safe ncnn-rust API and the ncnn-rust-sys bindings.
Install
cargo add ncnn-rustncnn-rust supplies the safe API and ncnn-rust-sys supplies the bindings. Both crates ship Rust
code only; building them compiles the C++ adapters against an ncnn 20261020 SDK that the build
environment supplies through NCNN_INSTALL_DIR. The README covers the SDK feature set, the Vulkan
feature and the runtime loader path.
Contents
- Owned-input inference with final-vector or reusable-buffer output, and scoped read-only CPU
output guards that reserve the network without copying. - Tensors, image preprocessing, custom layers, readers, allocators and explicit native option
mapping. - Optional Vulkan backend: device selection, resident tensors, allocator, recording commands,
completed guards, buffer import and persistent pipeline caches. - An in-repo conformance suite that covers shapes, elementwise semantics and a zero-allocation
steady-state gate without external model files.
Documentation
The API reference is published at https://edwardssss.github.io/ncnn.rust/ncnn_rust/. docs.rs
cannot build these crates because its sandbox has no ncnn SDK.
Verification
The v0.1.0 tag passed the CI matrix before publication: ubuntu-latest, ubuntu-24.04-arm,
windows-latest, macos-15, macos-15-intel, the 1.85.1 MSRV job and a Vulkan job on Mesa
lavapipe.