-
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
Open
0130w
wants to merge
4
commits into
Tencent:master
Choose a base branch
from
0130w:dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ | |
| #include "net.h" | ||
| #include "gpu.h" | ||
|
|
||
| #include "../benchmark/model_param_spv_data.h" | ||
|
|
||
| #ifndef NCNN_SIMPLESTL | ||
| #include <vector> | ||
| #endif | ||
|
|
@@ -40,12 +42,37 @@ static bool g_enable_cooling_down = true; | |
| static ncnn::UnlockedPoolAllocator g_blob_pool_allocator; | ||
| static ncnn::PoolAllocator g_workspace_pool_allocator; | ||
|
|
||
| struct model_param_registry_entry | ||
| { | ||
| const char* model_name; | ||
| const char* model_param; | ||
| }; | ||
|
|
||
| static const model_param_registry_entry model_param_registry[] = { | ||
| #include "../benchmark/model_param_registry.h" | ||
| }; | ||
|
|
||
| #if NCNN_VULKAN | ||
| static ncnn::VulkanDevice* g_vkdev = 0; | ||
| static ncnn::VkAllocator* g_blob_vkallocator = 0; | ||
| static ncnn::VkAllocator* g_staging_vkallocator = 0; | ||
| #endif // NCNN_VULKAN | ||
|
|
||
| const char* find_model_param(const char* model_name) | ||
| { | ||
| int param_num = sizeof(model_param_registry) / sizeof(model_param_registry_entry); | ||
| const char* model_param = NULL; | ||
| for (int i = 0; i < param_num; i++) | ||
| { | ||
| if (!strcmp(model_name, model_param_registry[i].model_name)) | ||
| { | ||
| model_param = model_param_registry[i].model_param; | ||
| break; | ||
| } | ||
| } | ||
| return model_param; | ||
| } | ||
|
|
||
| void benchmark(const char* comment, const std::vector<ncnn::Mat>& _in, const ncnn::Option& opt, bool fixed_path = true) | ||
| { | ||
| // Skip if int8 model name and using GPU | ||
|
|
@@ -84,17 +111,25 @@ void benchmark(const char* comment, const std::vector<ncnn::Mat>& _in, const ncn | |
| #define MODEL_DIR "" | ||
| #endif | ||
|
|
||
| const char* model_param = NULL; | ||
|
|
||
| if (fixed_path) | ||
| { | ||
| char parampath[256]; | ||
| sprintf(parampath, MODEL_DIR "%s.param", comment); | ||
| net.load_param(parampath); | ||
| model_param = find_model_param(comment); | ||
| } | ||
| else | ||
| { | ||
| net.load_param(comment); | ||
| // use load_param_mem | ||
| model_param = find_model_param(comment); | ||
| if (model_param == NULL) | ||
| { | ||
| fprintf(stderr, "can't find %s.param in model dir\n", comment); | ||
| return; | ||
| } | ||
| } | ||
|
Comment on lines
116
to
129
|
||
|
|
||
| net.load_param_mem(model_param); | ||
|
|
||
| DataReaderFromEmpty dr; | ||
| net.load_model(dr); | ||
|
|
||
|
|
@@ -452,13 +487,13 @@ int main(int argc, char** argv) | |
|
|
||
| benchmark("mobilenetv2_yolov3", ncnn::Mat(352, 352, 3), opt); | ||
|
|
||
| benchmark("yolov4-tiny", ncnn::Mat(416, 416, 3), opt); | ||
| benchmark("yolov4_tiny", ncnn::Mat(416, 416, 3), opt); | ||
|
|
||
| benchmark("nanodet_m", ncnn::Mat(320, 320, 3), opt); | ||
|
|
||
| benchmark("yolo-fastest-1.1", ncnn::Mat(320, 320, 3), opt); | ||
| benchmark("yolo_fastest_1_1", ncnn::Mat(320, 320, 3), opt); | ||
|
|
||
| benchmark("yolo-fastestv2", ncnn::Mat(352, 352, 3), opt); | ||
| benchmark("yolo_fastestv2", ncnn::Mat(352, 352, 3), opt); | ||
|
|
||
| benchmark("vision_transformer", ncnn::Mat(384, 384, 3), opt); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Model Param Registry header | ||
| // | ||
| // This file is auto-generated by cmake, don't edit it. | ||
|
|
||
| @model_param_registry@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Model Param Spv Data header | ||
| // | ||
| // This file is auto-generated by cmake, don't edit it. | ||
|
|
||
| @model_param_spv_data@ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
|
|
||
| macro(ncnn_convert_param_file PARAM_FILE) | ||
| # Use a macro to convert the contents of a single parameter file into memory content | ||
| file(READ ${PARAM_FILE} param_file_data) | ||
|
|
||
| # remove whitespace | ||
| 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}) | ||
|
|
||
| # Get the file name with extension | ||
| get_filename_component(PARAM_FILE_NAME ${PARAM_FILE} NAME) | ||
| # Manually remove ".param" since NAME_WE treats ".1.param" as a multi-extension | ||
| string(REPLACE ".param" "" PARAM_FILE_NAME_WE "${PARAM_FILE_NAME}") | ||
| # Check if the result is empty | ||
| if (NOT PARAM_FILE_NAME_WE) | ||
| message(FATAL_ERROR "Failed to extract valid filename from '${PARAM_FILE}'") | ||
| endif() | ||
| # Check if the extracted filename is a valid C identifier | ||
| string(REGEX MATCH "^[A-Za-z_][A-Za-z0-9_]*$" is_valid "${PARAM_FILE_NAME_WE}") | ||
| if (NOT is_valid) | ||
| message(FATAL_ERROR "Extracted filename '${PARAM_FILE_NAME_WE}' is not a valid C identifier") | ||
| endif() | ||
|
|
||
| # text to hex | ||
| file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/param_hex_data/${PARAM_FILE_NAME_WE}.text2hex.txt "${param_file_data}") | ||
| file(READ ${CMAKE_CURRENT_BINARY_DIR}/param_hex_data/${PARAM_FILE_NAME_WE}.text2hex.txt param_file_data_hex HEX) | ||
| string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," param_file_data_hex ${param_file_data_hex}) | ||
| string(FIND "${param_file_data_hex}" "," tail_comma REVERSE) | ||
| string(SUBSTRING "${param_file_data_hex}" 0 ${tail_comma} param_file_data_hex) | ||
|
|
||
| file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/model_param_header/${PARAM_FILE_NAME_WE}.comp.hex.h "static const char ${PARAM_FILE_NAME_WE}_param_data[] = {${param_file_data_hex},0x00};\n") | ||
| string(APPEND model_param_spv_data "#include \"model_param_header/${PARAM_FILE_NAME_WE}.comp.hex.h\"\n") | ||
| string(APPEND model_param_registry "{\"${PARAM_FILE_NAME_WE}\", ${PARAM_FILE_NAME_WE}_param_data},\n") | ||
| endmacro() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 error message references 'model dir' which is no longer accurate since models are now embedded in memory. Consider updating to 'can't find %s model in embedded data' or similar.