ncnn ios 限制线程数

Created on 30 Jan 2019  ·  4Comments  ·  Source: Tencent/ncnn

IOS App编译使用release下预编译的ncnn和openmp framework。

现状是每次跑模型都会把CPU占满。 使用下面代码去限制CPU thread num, 但是无效,CPU load没改变。 当opt.num_threads 为1的时候, 从profie上看至少有2-5个threads(看不同机型)在跑模型。

ncnn::Option opt;
opt.lightmode = true;
opt.num_threads = 1;
ncnn::set_default_option(opt);

ncnn::set_cpu_powersave(0);
ncnn::set_omp_dynamic(0);
ncnn::set_omp_num_threads(1);

这有什么解决方法么?

Most helpful comment

找到原因了:

ncnn::Mat::substract_mean_normalize 函数里面的omp 并行,没有用opt.num_threads 限制。

去除掉后,CPU就正常了。 @nihui

All 4 comments

找到原因了:

ncnn::Mat::substract_mean_normalize 函数里面的omp 并行,没有用opt.num_threads 限制。

去除掉后,CPU就正常了。 @nihui

新的ncnn中,没有找到
ncnn::set_default_option(opt);

ncnn::set_cpu_powersave(0);
ncnn::set_omp_dynamic(0);
ncnn::set_omp_num_threads(1);
请问一下大佬,我想用多线程调用,应该怎么设置?

新的ncnn中,没有找到
ncnn::set_default_option(opt);

ncnn::set_cpu_powersave(0);
ncnn::set_omp_dynamic(0);
ncnn::set_omp_num_threads(1);
请问一下大佬,我想用多线程调用,应该怎么设置?

已解决~

最新代码 substract_mean_normalize 线程数量已设置为1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xhappy picture xhappy  ·  5Comments

baiyecha picture baiyecha  ·  3Comments

soham24 picture soham24  ·  3Comments

wanzghen0123 picture wanzghen0123  ·  3Comments

zsliaoming picture zsliaoming  ·  3Comments