From beff011a33d28efe556d97149b499df70785020c Mon Sep 17 00:00:00 2001 From: xiebaiyuan Date: Wed, 26 Dec 2018 22:58:36 +0800 Subject: [PATCH] run android gpu for super -- update test and fix bug with wh changed --- CMakeLists.txt | 6 +-- src/framework/executor.cpp | 12 +++--- test/net/test_super.cpp | 82 ++++++++++++++++++++++++++++++++++---- 3 files changed, 84 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e33b71509..cfe02e8807 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,15 @@ cmake_minimum_required(VERSION 3.0.0) -option(USE_OPENMP "openmp support" ON) +option(USE_OPENMP "openmp support" OFF) option(DEBUGING "enable debug mode" ON) option(USE_EXCEPTION "use std exception" ON) option(SYMBOL_HIDDEN "symbol hidden" OFF) # on when use jni or ios io -option(LOG_PROFILE "log profile" OFF) +option(LOG_PROFILE "log profile" ON) # select the platform to build option(CPU "armv7 with neon" ON) option(GPU_MALI "mali gpu" OFF) -option(GPU_CL "opencl gpu" OFF) +option(GPU_CL "opencl gpu" ON) option(FPGA "fpga" OFF) if(FPGA) diff --git a/src/framework/executor.cpp b/src/framework/executor.cpp index 81b2ca985f..f6c4678370 100644 --- a/src/framework/executor.cpp +++ b/src/framework/executor.cpp @@ -551,13 +551,12 @@ void Executor::SetInput(const Tensor &input, DLOG << "target_tensor->IsInitialized() " << target_tensor->IsInitialized(); DLOG << "target_tensor->dims() " << target_tensor->dims(); DLOG << "input.dims() " << input.dims(); + DLOG << "input_dim_last_ " << input_dim_last_; if (config_.load_when_predict) { if (input_dim_last_ != input.dims()) { - if (!target_tensor->IsInitialized()) { - DLOG << "SetInput ---- > resize1"; - target_tensor->Resize(input.dims()); - target_tensor->mutable_data(); - } + DLOG << "SetInput ---- > resize1"; + target_tensor->Resize(input.dims()); + target_tensor->mutable_data(); InitNoPersistableMemory(*target_tensor); } } else { @@ -566,7 +565,8 @@ void Executor::SetInput(const Tensor &input, DLOG << "SetInput ---- > ShareDataWith"; } target_tensor->ShareDataWith(input); - input_dim_last_ = input.dims(); + auto &dim = input.dims(); + input_dim_last_ = static_cast(dim); } template diff --git a/test/net/test_super.cpp b/test/net/test_super.cpp index 3828910247..7a10f826c4 100644 --- a/test/net/test_super.cpp +++ b/test/net/test_super.cpp @@ -37,7 +37,7 @@ int main() { auto time2 = paddle_mobile::time(); std::cout << "load cost :" << paddle_mobile::time_diff(time1, time2) << "ms" << std::endl; - + // 300*300 std::vector input; std::vector dims{1, 1, 300, 300}; GetInput(g_test_image_1x3x224x224, &input, dims); @@ -51,22 +51,90 @@ int main() { auto time5 = paddle_mobile::time(); vec_result = paddle_mobile.Predict(input, dims); auto time6 = paddle_mobile::time(); - std::cout << "predict cost :第" << i << ": " + std::cout << "300 predict cost :第" << i << ": " << paddle_mobile::time_diff(time5, time6) << "ms" << std::endl; } auto time4 = paddle_mobile::time(); - std::cout << "predict cost :" + std::cout << "300 predict cost :" << paddle_mobile::time_diff(time3, time4) / max << "ms" << std::endl; auto biggest = std::max_element(std::begin(vec_result), std::end(vec_result)); - std::cout << " Max element is " << *biggest << " at position " + std::cout << "300 Max element is " << *biggest << " at position " << std::distance(std::begin(vec_result), biggest) << std::endl; + + // 500*500 + std::vector vec_result2; + + std::vector input2; + std::vector dims2{1, 1, 500, 500}; + GetInput(g_test_image_1x3x224x224, &input2, dims2); + + time3 = paddle_mobile::time(); + for (int i = 0; i < max; ++i) { + auto time5 = paddle_mobile::time(); + vec_result2 = paddle_mobile.Predict(input2, dims2); + auto time6 = paddle_mobile::time(); + std::cout << "500 predict cost :第" << i << ": " + << paddle_mobile::time_diff(time5, time6) << "ms" << std::endl; + } + + time4 = paddle_mobile::time(); + std::cout << "500 predict cost :" + << paddle_mobile::time_diff(time3, time4) / max << "ms" + << std::endl; + biggest = std::max_element(std::begin(vec_result2), std::end(vec_result2)); + std::cout << "500 Max element is " << *biggest << " at position " + << std::distance(std::begin(vec_result2), biggest) << std::endl; + + // 1000*1000 + + std::vector vec_result3; + std::vector input3; + std::vector dims3{1, 1, 1000, 1000}; + GetInput(g_test_image_1x3x224x224, &input3, dims3); + + time3 = paddle_mobile::time(); + + for (int i = 0; i < max; ++i) { + auto time5 = paddle_mobile::time(); + vec_result3 = paddle_mobile.Predict(input3, dims3); + auto time6 = paddle_mobile::time(); + std::cout << "1000*1000 predict cost :第" << i << ": " + << paddle_mobile::time_diff(time5, time6) << "ms" << std::endl; + } + time4 = paddle_mobile::time(); + std::cout << "1000*1000 predict cost :" + << paddle_mobile::time_diff(time3, time4) / max << "ms" + << std::endl; + biggest = std::max_element(std::begin(vec_result3), std::end(vec_result3)); + std::cout << "1000*1000 Max element is " << *biggest << " at position " + << std::distance(std::begin(vec_result3), biggest) << std::endl; + + // 224*224 + std::vector vec_result4; + std::vector input4; + std::vector dims4{1, 1, 224, 224}; + GetInput(g_test_image_1x3x224x224, &input4, dims4); + + time3 = paddle_mobile::time(); + for (int i = 0; i < max; ++i) { + auto time5 = paddle_mobile::time(); + vec_result4 = paddle_mobile.Predict(input4, dims4); + auto time6 = paddle_mobile::time(); + std::cout << "224*224 predict cost :第" << i << ": " + << paddle_mobile::time_diff(time5, time6) << "ms" << std::endl; + } + + time4 = paddle_mobile::time(); + std::cout << "224*224 predict cost :" + << paddle_mobile::time_diff(time3, time4) / max << "ms" + << std::endl; + biggest = std::max_element(std::begin(vec_result4), std::end(vec_result4)); + std::cout << "224*224 Max element is " << *biggest << " at position " + << std::distance(std::begin(vec_result4), biggest) << std::endl; } - std::cout << "如果结果Nan请查看: test/images/g_test_image_1x3x224x224_banana " - "是否存在?" - << std::endl; return 0; } -- GitLab