Browse Source

set openmp blocktime 20 for reducing power consumption, blocktime option

tags/20200727
nihuini 5 years ago
parent
commit
4e4f0baa73
5 changed files with 40 additions and 1 deletions
  1. +19
    -1
      src/cpu.cpp
  2. +3
    -0
      src/cpu.h
  3. +11
    -0
      src/net.cpp
  4. +2
    -0
      src/option.cpp
  5. +5
    -0
      src/option.h

+ 19
- 1
src/cpu.cpp View File

@@ -602,11 +602,29 @@ void set_omp_dynamic(int dynamic)

int get_omp_thread_num()
{
#if _OPENMP
#ifdef _OPENMP
return omp_get_thread_num();
#else
return 0;
#endif
}

int get_kmp_blocktime()
{
#if defined(_OPENMP) && __clang__
return kmp_get_blocktime();
#else
return 0;
#endif
}

void set_kmp_blocktime(int time_ms)
{
#if defined(_OPENMP) && __clang__
kmp_set_blocktime(time_ms);
#else
(void)time_ms;
#endif
}

} // namespace ncnn

+ 3
- 0
src/cpu.h View File

@@ -59,6 +59,9 @@ void set_omp_dynamic(int dynamic);

int get_omp_thread_num();

int get_kmp_blocktime();
void set_kmp_blocktime(int time_ms);

} // namespace ncnn

#endif // NCNN_CPU_H

+ 11
- 0
src/net.cpp View File

@@ -16,6 +16,7 @@

#include "convolution.h"
#include "convolutiondepthwise.h"
#include "cpu.h"
#include "datareader.h"
#include "layer_type.h"
#include "modelbin.h"
@@ -2556,6 +2557,9 @@ int Extractor::extract(int blob_index, Mat& feat)
if (blob_index < 0 || blob_index >= (int)blob_mats.size())
return -1;

int old_blocktime = get_kmp_blocktime();
set_kmp_blocktime(opt.openmp_blocktime);

int ret = 0;

if (blob_mats[blob_index].dims == 0)
@@ -2660,6 +2664,8 @@ int Extractor::extract(int blob_index, Mat& feat)
feat = bottom_blob_unpacked;
}

set_kmp_blocktime(old_blocktime);

return ret;
}

@@ -2751,6 +2757,9 @@ int Extractor::extract(int blob_index, VkImageMat& feat, VkCompute& cmd)
if (blob_index < 0 || blob_index >= (int)blob_mats.size())
return -1;

int old_blocktime = get_kmp_blocktime();
set_kmp_blocktime(opt.openmp_blocktime);

int ret = 0;

if (blob_mats_gpu_image[blob_index].dims == 0)
@@ -2767,6 +2776,8 @@ int Extractor::extract(int blob_index, VkImageMat& feat, VkCompute& cmd)

feat = blob_mats_gpu_image[blob_index];

set_kmp_blocktime(old_blocktime);

return ret;
}
#endif // NCNN_VULKAN


+ 2
- 0
src/option.cpp View File

@@ -32,6 +32,8 @@ Option::Option()
pipeline_cache = 0;
#endif // NCNN_VULKAN

openmp_blocktime = 20;

use_winograd_convolution = true;
use_sgemm_convolution = true;
use_int8_inference = true;


+ 5
- 0
src/option.h View File

@@ -61,6 +61,11 @@ public:
PipelineCache* pipeline_cache;
#endif // NCNN_VULKAN

// the time openmp threads busy-wait for more work before going to sleep
// default value is 20ms to keep the cores enabled
// without too much extra power consumption afterwards
int openmp_blocktime;

// enable winograd convolution optimization
// improve convolution 3x3 stride1 performace, may consume more memory
// changes should be applied before loading network structure and weight


Loading…
Cancel
Save