From 307aba4bfdff97a267754057dbb2ffa28d08c3ad Mon Sep 17 00:00:00 2001 From: ice <1391525377@qq.com> Date: Fri, 1 Aug 2025 14:49:35 +0800 Subject: [PATCH] fix: use resnet to eval fastmath pipeline cache operator== --- src/pipelinecache.cpp | 4 +-- tests/test_fast_math.cpp | 59 ++++++++++++---------------------------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/src/pipelinecache.cpp b/src/pipelinecache.cpp index 59b4e12d6..f0fe9dd14 100644 --- a/src/pipelinecache.cpp +++ b/src/pipelinecache.cpp @@ -64,12 +64,12 @@ public: bool operator==(const pipeline_cache_digest& rhs) const { - return d0 == rhs.d0 && d1 == rhs.d1 && d2 == rhs.d2 && d3 == rhs.d3; + return d0 == rhs.d0 && d1 == rhs.d1 && d2 == rhs.d2 && d3 == rhs.d3 && d4 == rhs.d4; } bool operator!=(const pipeline_cache_digest& rhs) const { - return d0 != rhs.d0 || d1 != rhs.d1 || d2 != rhs.d2 || d3 != rhs.d3; + return d0 != rhs.d0 || d1 != rhs.d1 || d2 != rhs.d2 || d3 != rhs.d3 || d4 != rhs.d4; } union diff --git a/tests/test_fast_math.cpp b/tests/test_fast_math.cpp index 481b9638e..083ed398a 100644 --- a/tests/test_fast_math.cpp +++ b/tests/test_fast_math.cpp @@ -12,7 +12,7 @@ #include #include // For memset -int device_index = 0; +int device_index = 1; // A data reader that provides zero-filled data, useful for loading models without actual weights. class DataReaderFromEmpty : public ncnn::DataReader @@ -31,37 +31,6 @@ public: } }; -static const char* mish25_param = R"delimiter( -7767517 -26 26 -Input in0 0 1 in0 -Mish mish_0 1 1 in0 1 -Mish mish_1 1 1 1 2 -Mish mish_2 1 1 2 3 -Mish mish_3 1 1 3 4 -Mish mish_4 1 1 4 5 -Mish mish_5 1 1 5 6 -Mish mish_6 1 1 6 7 -Mish mish_7 1 1 7 8 -Mish mish_8 1 1 8 9 -Mish mish_9 1 1 9 10 -Mish mish_10 1 1 10 11 -Mish mish_11 1 1 11 12 -Mish mish_12 1 1 12 13 -Mish mish_13 1 1 13 14 -Mish mish_14 1 1 14 15 -Mish mish_15 1 1 15 16 -Mish mish_16 1 1 16 17 -Mish mish_17 1 1 17 18 -Mish mish_18 1 1 18 19 -Mish mish_19 1 1 19 20 -Mish mish_20 1 1 20 21 -Mish mish_21 1 1 21 22 -Mish mish_22 1 1 22 23 -Mish mish_23 1 1 23 24 -Mish mish_24 1 1 24 out0 -)delimiter"; - // The main test function to compare default vs. fast math performance. static int test_vulkan_fast_math() { @@ -70,6 +39,12 @@ static int test_vulkan_fast_math() ncnn::Mat input = RandomMat(512, 512, 3); DataReaderFromEmpty dr; +#ifdef __EMSCRIPTEN__ +#define MODEL_DIR "/working" +#else +#define MODEL_DIR "../../benchmark" +#endif + // ================================================== // 1. Setup Net with Default Options // ================================================== @@ -83,7 +58,7 @@ static int test_vulkan_fast_math() net_default.opt.use_fp16_storage = false; net_default.opt.use_fp16_packed = false; - net_default.load_param_mem(mish25_param); + net_default.load_param(MODEL_DIR "/resnet50.param"); net_default.load_model(dr); printf("Default net loaded successfully.\n"); @@ -104,7 +79,7 @@ static int test_vulkan_fast_math() net_fast_math.opt.use_fp16_packed = false; net_fast_math.opt.use_fp16_storage = false; - net_fast_math.load_param_mem(mish25_param); + net_fast_math.load_param(MODEL_DIR "/resnet50.param"); net_fast_math.load_model(dr); printf("Fast math net loaded successfully.\n"); @@ -117,13 +92,13 @@ static int test_vulkan_fast_math() ncnn::Mat output_default, output_fast_math; { ncnn::Extractor ex = net_default.create_extractor(); - ex.input("in0", input); - ex.extract("out0", output_default); + ex.input("data", input); + ex.extract("output", output_default); } { ncnn::Extractor ex = net_fast_math.create_extractor(); - ex.input("in0", input); - ex.extract("out0", output_fast_math); + ex.input("data", input); + ex.extract("output", output_fast_math); } printf("Warm-up complete.\n"); @@ -143,8 +118,8 @@ static int test_vulkan_fast_math() for (int i = 0; i < loop_count; i++) { ncnn::Extractor ex = net_default.create_extractor(); - ex.input("in0", input); - ex.extract("out0", output_default); + ex.input("data", input); + ex.extract("output", output_default); } double end = ncnn::get_current_time(); time_default = (end - start) / loop_count; @@ -157,8 +132,8 @@ static int test_vulkan_fast_math() for (int i = 0; i < loop_count; i++) { ncnn::Extractor ex = net_fast_math.create_extractor(); - ex.input("in0", input); - ex.extract("out0", output_fast_math); + ex.input("data", input); + ex.extract("output", output_fast_math); } double end = ncnn::get_current_time(); time_fast_math = (end - start) / loop_count;