Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
4524138a
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
338
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看板
提交
4524138a
编写于
4月 17, 2020
作者:
B
baolei.an
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[LITE][BM] multi thread ok, test=develop
上级
e414f352
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
10 deletion
+39
-10
lite/api/test_classify_lite_bm.cc
lite/api/test_classify_lite_bm.cc
+29
-10
lite/kernels/bm/bridges/graph.cc
lite/kernels/bm/bridges/graph.cc
+5
-0
lite/kernels/bm/bridges/graph.h
lite/kernels/bm/bridges/graph.h
+3
-0
lite/kernels/bm/subgraph_compute.cc
lite/kernels/bm/subgraph_compute.cc
+2
-0
未找到文件。
lite/api/test_classify_lite_bm.cc
浏览文件 @
4524138a
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#include <gflags/gflags.h>
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <pthread.h>
#include <fstream>
#include <fstream>
#include <vector>
#include <vector>
#include "lite/api/cxx_api.h"
#include "lite/api/cxx_api.h"
...
@@ -30,14 +31,18 @@ DEFINE_string(input_img_txt_path,
...
@@ -30,14 +31,18 @@ DEFINE_string(input_img_txt_path,
namespace
paddle
{
namespace
paddle
{
namespace
lite
{
namespace
lite
{
void
TestModel
(
const
std
::
vector
<
Place
>&
valid_places
)
{
const
int
g_batch_size
=
4
;
const
int
g_thread_num
=
10
;
void
instance_run
()
{
lite
::
Predictor
predictor
;
lite
::
Predictor
predictor
;
std
::
vector
<
std
::
string
>
passes
;
std
::
vector
<
std
::
string
>
passes
;
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kBM
),
PRECISION
(
kFloat
)},
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)}});
predictor
.
Build
(
FLAGS_model_dir
,
""
,
""
,
valid_places
,
passes
);
predictor
.
Build
(
FLAGS_model_dir
,
""
,
""
,
valid_places
,
passes
);
auto
*
input_tensor
=
predictor
.
GetInput
(
0
);
auto
*
input_tensor
=
predictor
.
GetInput
(
0
);
input_tensor
->
Resize
(
DDim
(
input_tensor
->
Resize
(
DDim
(
std
::
vector
<
DDim
::
value_type
>
(
std
::
vector
<
DDim
::
value_type
>
({
1
,
3
,
FLAGS_im_height
,
FLAGS_im_width
})));
{
g_batch_size
,
3
,
FLAGS_im_height
,
FLAGS_im_width
})));
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
auto
item_size
=
input_tensor
->
dims
().
production
();
auto
item_size
=
input_tensor
->
dims
().
production
();
if
(
FLAGS_input_img_txt_path
.
empty
())
{
if
(
FLAGS_input_img_txt_path
.
empty
())
{
...
@@ -45,12 +50,15 @@ void TestModel(const std::vector<Place>& valid_places) {
...
@@ -45,12 +50,15 @@ void TestModel(const std::vector<Place>& valid_places) {
data
[
i
]
=
1
;
data
[
i
]
=
1
;
}
}
}
else
{
}
else
{
std
::
fstream
fs
(
FLAGS_input_img_txt_path
,
std
::
ios
::
in
);
for
(
int
j
=
0
;
j
<
g_batch_size
;
j
++
)
{
if
(
!
fs
.
is_open
())
{
std
::
fstream
fs
(
FLAGS_input_img_txt_path
,
std
::
ios
::
in
);
LOG
(
FATAL
)
<<
"open input_img_txt error."
;
if
(
!
fs
.
is_open
())
{
}
LOG
(
FATAL
)
<<
"open input_img_txt error."
;
for
(
int
i
=
0
;
i
<
item_size
;
i
++
)
{
}
fs
>>
data
[
i
];
for
(
int
i
=
0
;
i
<
item_size
/
g_batch_size
;
i
++
)
{
fs
>>
data
[
i
];
}
data
+=
j
*
item_size
/
g_batch_size
;
}
}
}
}
for
(
int
i
=
0
;
i
<
FLAGS_warmup
;
++
i
)
{
for
(
int
i
=
0
;
i
<
FLAGS_warmup
;
++
i
)
{
...
@@ -72,6 +80,7 @@ void TestModel(const std::vector<Place>& valid_places) {
...
@@ -72,6 +80,7 @@ void TestModel(const std::vector<Place>& valid_places) {
FILE
*
fp
=
fopen
(
"result.txt"
,
"wb"
);
FILE
*
fp
=
fopen
(
"result.txt"
,
"wb"
);
for
(
int
i
=
0
;
i
<
out
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
out
.
size
();
i
++
)
{
auto
*
out_data
=
out
[
i
]
->
data
<
float
>
();
auto
*
out_data
=
out
[
i
]
->
data
<
float
>
();
LOG
(
INFO
)
<<
out
[
i
]
->
numel
();
for
(
int
j
=
0
;
j
<
out
[
i
]
->
numel
();
j
++
)
{
for
(
int
j
=
0
;
j
<
out
[
i
]
->
numel
();
j
++
)
{
fprintf
(
fp
,
"%f
\n
"
,
out_data
[
j
]);
fprintf
(
fp
,
"%f
\n
"
,
out_data
[
j
]);
}
}
...
@@ -79,6 +88,16 @@ void TestModel(const std::vector<Place>& valid_places) {
...
@@ -79,6 +88,16 @@ void TestModel(const std::vector<Place>& valid_places) {
fclose
(
fp
);
fclose
(
fp
);
}
}
void
TestModel
(
const
std
::
vector
<
Place
>&
valid_places
)
{
std
::
vector
<
std
::
unique_ptr
<
std
::
thread
>>
instances_vec
;
for
(
int
i
=
0
;
i
<
g_thread_num
;
++
i
)
{
instances_vec
.
emplace_back
(
new
std
::
thread
(
&
instance_run
));
}
for
(
int
i
=
0
;
i
<
g_thread_num
;
++
i
)
{
instances_vec
[
i
]
->
join
();
}
}
TEST
(
Classify
,
test_bm
)
{
TEST
(
Classify
,
test_bm
)
{
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kBM
),
PRECISION
(
kFloat
)},
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kBM
),
PRECISION
(
kFloat
)},
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)}});
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)}});
...
...
lite/kernels/bm/bridges/graph.cc
浏览文件 @
4524138a
...
@@ -20,11 +20,14 @@ namespace lite {
...
@@ -20,11 +20,14 @@ namespace lite {
namespace
subgraph
{
namespace
subgraph
{
namespace
bm
{
namespace
bm
{
pthread_mutex_t
Graph
::
mutex_compiler_
=
PTHREAD_MUTEX_INITIALIZER
;
void
Graph
::
AddNode
(
const
std
::
string
&
name
)
{
void
Graph
::
AddNode
(
const
std
::
string
&
name
)
{
nodes_
.
insert
(
std
::
make_pair
(
name
,
name
));
nodes_
.
insert
(
std
::
make_pair
(
name
,
name
));
}
}
void
Graph
::
CreateCompilerHandle
()
{
void
Graph
::
CreateCompilerHandle
()
{
pthread_mutex_lock
(
&
mutex_compiler_
);
#ifdef BM1682
#ifdef BM1682
compiler_handle_
=
create_bmcompiler
(
"BM1682"
);
compiler_handle_
=
create_bmcompiler
(
"BM1682"
);
#else
#else
...
@@ -33,6 +36,8 @@ void Graph::CreateCompilerHandle() {
...
@@ -33,6 +36,8 @@ void Graph::CreateCompilerHandle() {
CHECK
(
compiler_handle_
!=
nullptr
);
CHECK
(
compiler_handle_
!=
nullptr
);
}
}
void
Graph
::
UnlockCompilerMutex
()
{
pthread_mutex_unlock
(
&
mutex_compiler_
);
}
}
// namespace bm
}
// namespace bm
}
// namespace subgraph
}
// namespace subgraph
}
// namespace lite
}
// namespace lite
...
...
lite/kernels/bm/bridges/graph.h
浏览文件 @
4524138a
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#pragma once
#pragma once
#include <pthread.h>
#include <memory>
#include <memory>
#include <string>
#include <string>
#include <unordered_map>
#include <unordered_map>
...
@@ -36,10 +37,12 @@ class Graph {
...
@@ -36,10 +37,12 @@ class Graph {
}
}
void
CreateCompilerHandle
();
void
CreateCompilerHandle
();
void
*
GetCompilerHandle
()
{
return
compiler_handle_
;
}
void
*
GetCompilerHandle
()
{
return
compiler_handle_
;
}
void
UnlockCompilerMutex
();
private:
private:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
nodes_
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
nodes_
;
void
*
compiler_handle_
;
void
*
compiler_handle_
;
static
pthread_mutex_t
mutex_compiler_
;
};
};
}
// namespace bm
}
// namespace bm
...
...
lite/kernels/bm/subgraph_compute.cc
浏览文件 @
4524138a
...
@@ -40,6 +40,7 @@ int SubgraphEngine::BuildDeviceProgram() {
...
@@ -40,6 +40,7 @@ int SubgraphEngine::BuildDeviceProgram() {
op
->
CheckShape
();
op
->
CheckShape
();
op
->
InferShape
();
op
->
InferShape
();
std
::
string
op_type
=
op
->
op_info
()
->
Type
();
std
::
string
op_type
=
op
->
op_info
()
->
Type
();
LOG
(
INFO
)
<<
op_type
;
if
(
!
bridges
.
Exists
(
op_type
,
TARGET
(
kBM
)))
{
if
(
!
bridges
.
Exists
(
op_type
,
TARGET
(
kBM
)))
{
return
subgraph
::
FAILED
;
return
subgraph
::
FAILED
;
}
}
...
@@ -59,6 +60,7 @@ int SubgraphEngine::BuildDeviceProgram() {
...
@@ -59,6 +60,7 @@ int SubgraphEngine::BuildDeviceProgram() {
unsigned
int
data_size
=
0
;
unsigned
int
data_size
=
0
;
bm_hd_
=
static_cast
<
bm_handle_t
>
(
ctx
.
GetHandle
());
bm_hd_
=
static_cast
<
bm_handle_t
>
(
ctx
.
GetHandle
());
finish_bmcompiler_data
(
graph
.
GetCompilerHandle
(),
&
bmodel_data
,
&
data_size
);
finish_bmcompiler_data
(
graph
.
GetCompilerHandle
(),
&
bmodel_data
,
&
data_size
);
graph
.
UnlockCompilerMutex
();
bmrt_hd_
=
bmrt_create
(
bm_hd_
);
bmrt_hd_
=
bmrt_create
(
bm_hd_
);
if
(
false
==
bmrt_load_bmodel_data
(
bmrt_hd_
,
bmodel_data
,
data_size
))
{
if
(
false
==
bmrt_load_bmodel_data
(
bmrt_hd_
,
bmodel_data
,
data_size
))
{
return
subgraph
::
FAILED
;
return
subgraph
::
FAILED
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录