-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[feat](benchmark): replace load_param with load_param_mem #6286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
The binary size change of libncnn.so (bytes)
|
|
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 1result before after |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6286 +/- ##
==========================================
+ Coverage 95.89% 95.91% +0.02%
==========================================
Files 841 844 +3
Lines 266337 267021 +684
==========================================
+ Hits 255409 256122 +713
+ Misses 10928 10899 -29 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 ofload_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.
There was a problem hiding this 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.
| #endif | ||
|
|
||
| if (fixed_path) | ||
| const char* model_param = NULL; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable model_param is declared but never used. This should be removed to clean up the code.
| const char* model_param = NULL; |
There was a problem hiding this 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.
There was a problem hiding this 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.
| #else | ||
| #define MODEL_DIR "" | ||
| #endif | ||
| const char* model_param = NULL; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable model_param is declared but never used. It can be safely removed as it appears to be leftover from the refactoring.
| const char* model_param = NULL; |
| string(REGEX REPLACE "\n +" "\n" param_file_data ${param_file_data}) | ||
|
|
||
| # remove empty line | ||
| string(REGEX REPLACE "\n\n" "\n" param_file_data ${param_file_data}) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex replacement only removes one occurrence of double newlines at a time. If there are multiple consecutive empty lines (e.g., \n\n\n), only one will be removed, leaving \n\n. Consider using a loop or a regex pattern like "\n\n+" to remove all consecutive empty lines in a single pass.
| string(REGEX REPLACE "\n\n" "\n" param_file_data ${param_file_data}) | |
| string(REGEX REPLACE "\n\n+" "\n" param_file_data ${param_file_data}) |
| # Use a macro to convert the contents of a single parameter file into memory content | ||
| file(READ ${PARAM_FILE} param_file_data) | ||
|
|
||
| # remove whitespace |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "remove whitespace" is misleading. The regex "\n +" only removes spaces that follow newlines (i.e., leading whitespace on lines), not all whitespace. Consider updating the comment to "remove leading whitespace from lines" or "strip indentation" for clarity.
| # remove whitespace | |
| # remove leading whitespace from lines |
| # remove whitespace | ||
| string(REGEX REPLACE "\n +" "\n" param_file_data ${param_file_data}) | ||
|
|
||
| # remove empty line |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "remove empty line" should be pluralized to "remove empty lines" for grammatical correctness, as the operation attempts to remove multiple occurrences of empty lines (though the current implementation only removes one pair at a time - see related bug comment on line 10).
| # remove empty line | |
| # remove empty lines |
Previous implementation required
benchncnnto 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,
benchncnnnow becomes fully self-contained and can be run from any location without dependency on external model files.