Skip to content

Conversation

@0130w
Copy link
Contributor

@0130w 0130w commented Aug 26, 2025

Previous implementation required benchncnn to be run from the directory containing the model files. This often caused failures and inconvenience when executed from an arbitrary working directory.​​

​This change embeds the model files directly into the executable by compiling them as C arrays. Consequently, benchncnn now becomes fully self-contained and can be run from any location without dependency on external model files.​

@github-actions github-actions bot added the cmake label Aug 26, 2025
@github-actions
Copy link

github-actions bot commented Aug 26, 2025

The binary size change of libncnn.so (bytes)

architecture base size pr size difference
x86_64 15328640 15212648 -115992 😘
armhf 6229904 6206656 -23248 😘
aarch64 9527568 9524560 -3008 😘

@tencent-adm
Copy link
Member

tencent-adm commented Aug 31, 2025

CLA assistant check
All committers have signed the CLA.

@0130w
Copy link
Contributor Author

0130w commented Aug 31, 2025

run

cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
make -j$(nproc)
cd benchmark
./benchncnn 4 8 0 -1 1

result before

./benchncnn 4 8 0 -1 1
loop_count = 4
num_threads = 8
powersave = 0
gpu_device = -1
cooling_down = 1
fopen squeezenet.param failed
network graph not ready
          squeezenet  min =    0.00  max =    0.00  avg =    0.00
fopen squeezenet_int8.param failed
...

after

loop_count = 4
num_threads = 8
powersave = 0
gpu_device = -1
cooling_down = 1
          squeezenet  min =   12.68  max =   13.12  avg =   12.94
     squeezenet_int8  min =    8.39  max =    9.11  avg =    8.88
           mobilenet  min =   16.69  max =   17.01  avg =   16.83
      mobilenet_int8  min =   15.41  max =   16.59  avg =   15.86
        mobilenet_v2  min =   16.33  max =   17.03  avg =   16.67
        mobilenet_v3  min =   13.08  max =   15.00  avg =   14.34
          shufflenet  min =   10.04  max =   12.69  avg =   10.88
       shufflenet_v2  min =   10.14  max =   13.40  avg =   11.20
             mnasnet  min =   12.67  max =   16.30  avg =   14.48
     proxylessnasnet  min =   14.56  max =   16.55  avg =   15.68
     efficientnet_b0  min =   23.54  max =   25.99  avg =   24.56
   efficientnetv2_b0  min =   25.69  max =   28.93  avg =   27.90
...

@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.29%. Comparing base (dce28a0) to head (85399e8).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #6286    +/-   ##
========================================
  Coverage   93.28%   93.29%            
========================================
  Files         845      845            
  Lines      265939   266146   +207     
========================================
+ Hits       248086   248305   +219     
+ Misses      17853    17841    -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nihui nihui requested a review from Copilot September 1, 2025 02:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces file-based model loading with memory-based loading in the benchncnn tool by embedding model parameter files directly into the executable as C arrays. This eliminates the dependency on external .param files and allows the benchmark to run from any directory.

  • Introduces a CMake macro to convert .param files into C header files containing hex data arrays
  • Updates benchncnn.cpp to use load_param_mem() instead of load_param() with embedded data
  • Normalizes model names by replacing hyphens with underscores to ensure valid C identifiers

Reviewed Changes

Copilot reviewed 6 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmake/ncnn_generate_model_data_header.cmake Adds CMake macro to convert .param files to C arrays with validation
benchmark/model_param_spv_data.h.in Template for including generated model parameter headers
benchmark/model_param_registry.h.in Template for model parameter registry data
benchmark/benchncnn.cpp Updates to use embedded model data with registry lookup function
benchmark/README.md Updates documentation to reflect new param usage without .param suffix
benchmark/CMakeLists.txt Integrates model data generation into build process

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@0130w
Copy link
Contributor Author

0130w commented Jan 8, 2026

System: macos
modify vgg16.param

InnerProduct             fc8                      1 1 fc7_drop7 fc8 -23330=4,1,1000,1,1 0=1000 1=1 2=4096000
InnerProduct             fc9                      1 1 fc8 fc9 0=1000 1=1 2=1000000
Softmax                  prob                     1 1 fc9 output -23330=4,1,1000,1,1

run make -j4

[  0%] Built target GenericCodeGen
[  0%] Built target MachineIndependent
[  1%] Built target SPIRV
[  1%] Built target OSDependent
[ 38%] Built target ncnn-generate-spirv
[ 38%] Built target glslang-default-resource-limits
[ 38%] Preprocessing param source vgg16.param
[ 38%] Built target ncnnmerge
[ 39%] Built target caffe2ncnn
[ 45%] Built target ncnn-generate-param
[ 52%] Built target glslang
[ 52%] Built target mxnet2ncnn
[ 52%] Built target darknet2ncnn
[ 98%] Built target ncnn
[ 98%] Built target ncnn2mem
[100%] Built target ncnnoptimize
[100%] Building CXX object benchmark/CMakeFiles/benchncnn.dir/benchncnn.cpp.o
[100%] Built target ncnn2table
[100%] Built target ncnn2int8
[100%] Linking CXX executable benchncnn
[100%] Built target benchncnn

@tencent-adm
Copy link
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ 0130w
❌ nihui
You have signed the CLA already but the status is still pending? Let us recheck it.

@nihui nihui merged commit 6b4f6f9 into Tencent:master Jan 8, 2026
109 of 110 checks passed
@nihui
Copy link
Member

nihui commented Jan 8, 2026

Thanks for your contribution !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants