Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
6181acca
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6181acca
编写于
7月 13, 2018
作者:
W
wangliu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add interface to dynamic set omp thread num
上级
8747dd62
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
27 addition
and
31 deletion
+27
-31
src/io/executor.cpp
src/io/executor.cpp
+0
-11
src/io/executor.h
src/io/executor.h
+0
-2
src/io/paddle_mobile.cpp
src/io/paddle_mobile.cpp
+10
-0
src/io/paddle_mobile.h
src/io/paddle_mobile.h
+4
-0
test/net/test_googlenet.cpp
test/net/test_googlenet.cpp
+13
-18
未找到文件。
src/io/executor.cpp
浏览文件 @
6181acca
...
...
@@ -26,9 +26,6 @@ limitations under the License. */
#include "framework/program/var_desc.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#ifdef _OPENMP
#include <omp.h>
#endif // _OPENMP
#ifdef PADDLE_EXECUTOR_MULTITHREAD
#include <queue>
#include <utility>
...
...
@@ -407,14 +404,6 @@ std::vector<typename Executor<Dtype, P>::Ptype> Executor<Dtype, P>::Predict(
return
result_vector
;
}
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
SetThreadNum
(
int
num
)
{
#ifdef _OPENMP
// omp_set_dynamic(0);
omp_set_num_threads
(
num
);
#endif
}
template
class
Executor
<
CPU
,
Precision
::
FP32
>;
template
class
Executor
<
FPGA
,
Precision
::
FP32
>;
template
class
Executor
<
GPU_MALI
,
Precision
::
FP32
>;
...
...
src/io/executor.h
浏览文件 @
6181acca
...
...
@@ -58,8 +58,6 @@ class Executor {
std
::
vector
<
Ptype
>
Predict
(
const
std
::
vector
<
Ptype
>
&
input
,
const
std
::
vector
<
int64_t
>
&
dims
);
void
SetThreadNum
(
int
num
);
protected:
Executor
()
=
default
;
void
InitMemory
();
...
...
src/io/paddle_mobile.cpp
浏览文件 @
6181acca
...
...
@@ -16,6 +16,14 @@ limitations under the License. */
namespace
paddle_mobile
{
template
<
typename
Dtype
,
Precision
P
>
void
PaddleMobile
<
Dtype
,
P
>::
SetThreadNum
(
int
num
)
{
#ifdef _OPENMP
// omp_set_dynamic(0);
omp_set_num_threads
(
num
);
#endif
};
template
<
typename
Dtype
,
Precision
P
>
bool
PaddleMobile
<
Dtype
,
P
>::
Load
(
const
std
::
string
&
dirname
,
bool
optimize
,
int
batch_size
)
{
...
...
@@ -81,7 +89,9 @@ PaddleMobile<Dtype, P>::~PaddleMobile() {
}
template
class
PaddleMobile
<
CPU
,
Precision
::
FP32
>;
template
class
PaddleMobile
<
FPGA
,
Precision
::
FP32
>;
template
class
PaddleMobile
<
GPU_MALI
,
Precision
::
FP32
>;
}
// namespace paddle_mobile
src/io/paddle_mobile.h
浏览文件 @
6181acca
...
...
@@ -17,6 +17,9 @@ limitations under the License. */
#include <memory>
#include <string>
#include <vector>
#ifdef _OPENMP
#include <omp.h>
#endif // _OPENMP
#include "common/types.h"
#include "framework/tensor.h"
...
...
@@ -44,6 +47,7 @@ class PaddleMobile {
* */
bool
Load
(
const
std
::
string
&
model_path
,
const
std
::
string
&
para_path
,
bool
optimize
=
false
,
int
batch_size
=
1
);
void
SetThreadNum
(
int
num
);
/*
* @b to predict
...
...
test/net/test_googlenet.cpp
浏览文件 @
6181acca
...
...
@@ -17,26 +17,21 @@ limitations under the License. */
#include "../test_include.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
.
SetThreadNum
(
4
);
bool
optimize
=
true
;
auto
time1
=
time
();
// auto program = loader.Load(g_googlenet, optimize);
auto
program
=
loader
.
Load
(
g_googlenet_combine
+
"/model"
,
g_googlenet_combine
+
"/params"
,
optimize
);
auto
time2
=
time
();
DLOG
<<
"load cost :"
<<
time_diff
(
time1
,
time2
)
<<
"ms
\n
"
;
paddle_mobile
::
Executor
<
paddle_mobile
::
CPU
>
executor
(
program
,
1
,
optimize
);
executor
.
SetThreadNum
(
4
);
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
GetInput
<
float
>
(
g_test_image_1x3x224x224
,
&
input
,
dims
);
auto
time3
=
time
();
int
count
=
1
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
executor
.
Predict
(
input
,
dims
);
}
if
(
paddle_mobile
.
Load
(
g_googlenet
,
optimize
))
{
auto
time2
=
time
();
DLOG
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
;
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
GetInput
<
float
>
(
g_test_image_1x3x224x224
,
&
input
,
dims
);
auto
time3
=
time
();
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
auto
time4
=
time
();
auto
time4
=
time
()
;
DLOG
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
/
count
<<
"ms
\n
"
;
DLOG
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
<<
"ms"
;
}
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录