81 Commits

Author SHA1 Message Date
nihui 8bc95a1e7f pnnx: store bool MemoryData attributes as raw int8 (#7006)
* pnnx: store bool MemoryData attributes as raw int8

Keep bool constants as one byte per element and select MemoryData
load_type=3. Implement the reserved raw int8 ModelBin loading mode and
pad exported bool data to four bytes so subsequent weights stay aligned.
This preserves the byte representation used by the proposed logical ops.

Add regression coverage for scalar and padded bool exports in both fp16
modes, multidimensional MemoryData, raw int8 loading through reference
and copy readers, trailing fp32 weights, and missing padding. Document
the format.

Based on the bool attribute serialization fixes proposed in:
https://github.com/Tencent/ncnn/pull/6956
https://github.com/Tencent/ncnn/pull/6866

Fixes #6855

* tools: preserve byte MemoryData when optimizing models

Save MemoryData load_type so raw int8 constants retain their byte
representation after ModelWriter saves the model. Skip fusion paths that
interpret MemoryData as float32 when its elements are not four bytes.

This change does not add bool arithmetic support or automatic type
promotion. Byte bool storage is intended for future logical, comparison
and selection operators.

Validated ncnnoptimize save and reload for scalar and one-to-five-element
bool constants in fp32 and fp16 storage modes, preserving byte values
and element size in all 12 cases.

---------

Co-authored-by: ktz03 <2484593937@qq.com>
Co-authored-by: Giulio Corradi <53930027+giuliocorradi@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 10:09:00 +08:00
nihui c189d88a8d modelbin bf16 storage type (#6900)
* fix modelwriter on big-endian
2026-08-13 17:19:50 +08:00
nihui 171b9d1bba use spdx license header, copyright Tencent (#6152) 2025-07-08 11:01:29 +08:00
nihui 6396a732ef reshape shape expression, drop reshape permute, test reshape oom (#5918) 2025-03-10 15:31:34 +08:00
nihui 1e4daff075 fix ncnn tools crash with compound layer creation, write gemm weight data (#5416)
* fix ncnn tools crash with compound layer creation

* write gemm weight data
2024-04-10 15:09:08 +08:00
zhiliu6 814f89ef1a Fuse HardSwish activation into Convolution and InnerProduct (#3233)
* add general fused activation
* add NCNN_FORCE_INLINE option
2021-10-11 15:55:43 +08:00
nihuini 618f0f70ac fuse 1x1xc broadcasting add into convolution 2021-07-26 14:56:37 +08:00
nihui 4f135e07bf implement convolution1d and pooling1d (#3035)
* implement convolution1d and pooling1d

* add conv1d pool1d test

* fuse convolution1d activation

* update operator doc

* fix vulkan adpative pooling
2021-06-30 20:19:19 +08:00
nihuini 1ad37fae1e generate random weight when null bin passed 2021-05-24 15:54:12 +08:00
nihuini 26dc9820e4 custom mlir ncnn optimize pass, add efficientnetv2_b0 benchmark 2021-05-19 16:34:18 +08:00
nihuini 56d74580a0 fix uninitialized input and weight 2021-04-15 17:45:12 +08:00
nihuini 2b1f8bea25 fix float locale issue in ncnn2mem, fix long line parsing in ncnn2int8 2021-04-14 18:59:28 +08:00
nihui 7e1aaa5828 cmake option NCNN_INT8 (#2839) 2021-04-14 12:49:35 +08:00
nihui 5fe75f19ef architecture changes for int8 packing (#2771)
* quantize and dequantize tests

* unify activation and usability function

* drop NCNN_REQUANT cmake option, test dequantize requantize pack8, fix webassembly build

* benchmark use requantize int8 model
2021-03-27 18:49:13 +08:00
restyled-io[bot] 5f00ba89d2 feat(ncnnoptimize): replace denormals to zero on layers with weights (#2690)
* feat(ncnnoptimize): replace denormals to zero on layers with weights

Co-authored-by: youngsoo.lee <youngsoo15.lee@gmail.com>
Co-authored-by: Restyled.io <commits@restyled.io>
2021-03-22 10:26:57 +08:00
nihui 19c183cacc fix ncnnoptimize default cut range 2021-03-21 22:47:35 +08:00
restyled-io[bot] 5e565cfa8a Restyle add net Cut Function (#2763)
* add ncnnoptimise cut net function

* add ncnnoptimise cut net function

* Restyled by clang-format

* Restyled by astyle

* Restyled by clang-format

* Restyled by astyle

Co-authored-by: chenty <admin@chenty.com>
Co-authored-by: Restyled.io <commits@restyled.io>
2021-03-19 22:14:37 +08:00
nihui d3d16d2413 fix ncnnoptimize crash on models with multiple custom layers 2021-02-18 21:46:06 +08:00
nihuini a1839f6bce fix ncnnoptimize shufflechannel reverse mode 2021-02-09 11:44:04 +08:00
nihui b01728a3be fix crash when eliminating memory footprint on undefined blobs, fix #2609 2021-01-23 11:59:47 +08:00
nihui 4f2907d129 arm neon optimization for rnn (#2601) 2021-01-15 15:40:45 +08:00
Guoxia Wang 609f63c57e support PyTorch AdaptiveAvgPool2d and AdaptiveMaxPool2d (#2546)
* support pytorch adaptive pool
* support onnx2ncnn adaptive pool convert
* support ncnnoptimize adaptive pool param write

* fix adaptive pool out_shape order

* fix adaptive pool out_shape order, H and W can be either a int
add test case, set support_vulkan = false Pooling_vulkan::create_pipeline

* review adaptive pool

* fix typo

* add adaptive pool forward in pooling_x86.cpp pooling_arm.cpp
fix out_w, out_h id naming convention

* fix typo

* don't support packing, bf16, int8, image for adaptive pool

* Restyled by clang-format

* Restyled by astyle

* Restyled by clang-format

* Restyled by astyle

Co-authored-by: Restyled.io <commits@restyled.io>
2021-01-07 08:39:06 +08:00
nihui 54c0a13b9f build shared library (#2525)
* build shared lib and enable lto

* reserved for layer and option

* allocator pimpl

* datareader pimpl

* paramdict pimpl, disable copy assign for allocator and datareader

* modelbin pimpl

* net extractor pimpl

* gpu pimple

* disable copy assign vulkandevice, code format

* command pimpl, dummy image readonly

* pipeline pipelinecache pimpl, export platform class

* code format, export simple family

* update ci

* disable lto on android armv7, merge webassembly ci

* link libgcc, fix macos dylib version

* pipeline pimpl, gpu info pimpl

* destroy gpu info after vulkan device

* ignore msvc stl class warning

* fix ncnn_paramdict_get_float return type

* fix vktransfer upload fp16 without flatten, add command test
2021-01-01 22:55:10 +08:00
nihuini fbf0ffda53 pixelshuffle nhwc mode, convert onnx DepthToSpace mode DCR, convert mlir tf.DepthToSpace 2020-12-29 19:47:53 +08:00
nihuini b35b06be6d reorg nhwc mode, code format 2020-12-29 18:57:48 +08:00
nihui 343bc3b7dc single blob consumer (#2493) 2020-12-25 00:21:14 +08:00
nihui 0f7b3b4461 aborted is not error, use skipped instead 2020-12-25 00:13:46 +08:00
nihuini 38b6387bc5 ncnnoptimize and ncnn2mem now accepts weight-less custom layer 2020-12-17 15:54:33 +08:00
Zhuo Zhang d8866eba56 fix tools/ncnnoptimize.cpp sign-compare warning (#2393) 2020-12-05 17:22:29 +08:00
nihui ba364791e8 reshape x86 pack4 2020-11-26 00:07:14 +08:00
nihui 60b6cc32ef replace_reduction_with_global_pooling replace_prelu_with_leaky_relu 2020-11-22 18:35:40 +08:00
nihuini 7836a143ec print input and output blob names, print estimated runtime memory footprint 2020-11-12 16:58:07 +08:00
nihuini 88d1efc9b1 convert onnx MatMul to Gemm 2020-11-03 17:50:55 +08:00
nihuini d0e6b256f9 drop obsoleted aarch64 auto conv mode, print mac after ncnnoptimize shape inference 2020-10-29 14:22:12 +08:00
nihuini ac47a05488 fix onnx groupnorm conversion, ncnnoptimize support groupnorm, fix #2142 2020-10-26 20:09:15 +08:00
nihuini 0a533dcaac mlir2ncnn fuse keras batchnorm, handle instancenorm affine in ncnnoptimize 2020-10-26 16:11:55 +08:00
Zhuo Zhang 0fc5ee1383 fix #2056 (#2057) 2020-09-01 15:04:14 +08:00
nihuini ea17a46b34 fuse memorydata split binaryop 2020-08-24 15:13:32 +08:00
Tijmen Verhulsdonck a3f7d2d520 Fix padding in ncnnoptimize not outputting all the params (#1944) 2020-07-20 16:41:15 +08:00
nihui 6e340f5e79 MLIR converter (#1810)
* tf2sb

* wip

* wip

* concat maxpool avgpool

* StridedSlice

* handle stridedslice mask

* convert mlir deconvolution

* convert deconvolution output shape

* convert tanh

* code format
2020-07-02 14:15:28 +08:00
nihui 3ef995ed1e format code style and setup restyled.io (#1840) 2020-06-13 22:17:51 +08:00
JackieWu ce2251db05 Improve ROIAlign (accelerate ROIAlign, support sampling ratio and aligned ROIAlign) (#1820)
* update roialign

* update tool for roialign

* fix ceil for roialign

* fix ios build

* fix

* fix

* make it compatibile with the old version

* fix ios build

* trigger CI

* fix test

* order

* build

* remove code

* merge roialign

* accelerate ROIAlign

* update note

* rename func

* roialign version

* trigger CI

* fix roialign

* use ref for pre-calc in roialign

* retrigger CI

* pre-alloc
2020-06-08 21:40:24 +08:00
zhiliu6 3bfabf1d6a Add fused convolution and mish layer support. (#1761) 2020-05-17 13:14:09 +08:00
nihuini 092d529d66 fuse rsub rdiv with scalar 2020-05-15 13:35:01 +08:00
nihuini e6a04d1535 fuse_memorydata_binaryop fuse_binaryop_eltwise 2020-05-11 19:43:00 +08:00
nihui 8a84077429 ncnnoptimize lstm 2020-03-15 11:56:23 +08:00
nihui dba992c15c ncnnoptimize add pixelshuffle, fix #1608 2020-03-12 20:54:50 +08:00
nihui 0f7e7bca02 shader shape specialization constant and basic local group size partition (#1523)
* use Mat class for Shape description

* shape specialization constant in compute shader

* wip

* wip

* test forward_inplace, add binaryop unaryop sigmoid test

* fix arm unaryop test

* fix arm binaryop test

* make shape hint optional, cast int8 to fp32, add cast test

* wip

* follow the good and old local size setting for conv1x1

* the optimal local size rewrite

* fix build on msvc

* add permute shader for all packing layout, add permute test

* concat and slice patial shape constant, slice test

* fix slice test

* interp test

* add lrn test, test packing layout implicitly

* add eltwise test

* add normalize test

* add instancenorm test

* reorg shape constant

* simple local group size partition

* add shape constant param
2020-02-17 15:45:29 +08:00
kalcohol 01853010ea type conversion and MSVC _CRT_SECURE_NO_DEPRECATE warning fix (#1524)
* fix type conversion warning

* fix MSVC _CRT_SECURE_NO_DEPRECATE warning

* type conversion: missing one

* fix  MSVC _CRT_SECURE_NO_DEPRECATE warning and type warning

* reformat

* convert google::protobuf::int64 to size_t to avoid type impl between msvc and gcc gap

* remove C++11 auto

* tab -> space
2020-02-07 14:33:01 +08:00
nihui e2bd4eae6e write shape as 4-number tuple 2020-01-31 12:34:57 +08:00