Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
59b80b23
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看板
提交
59b80b23
编写于
10月 31, 2019
作者:
N
nhzlx
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/PaddlePaddle/Paddle-Lite
into develop
上级
20ba19fe
fd9ceec8
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
139 addition
and
186 deletion
+139
-186
lite/api/CMakeLists.txt
lite/api/CMakeLists.txt
+5
-5
lite/api/test_googlenet_lite.cc
lite/api/test_googlenet_lite.cc
+22
-19
lite/api/test_inceptionv4_lite_x86.cc
lite/api/test_inceptionv4_lite_x86.cc
+25
-43
lite/api/test_mobilenetv1_lite_x86.cc
lite/api/test_mobilenetv1_lite_x86.cc
+25
-41
lite/api/test_mobilenetv2_lite_x86.cc
lite/api/test_mobilenetv2_lite_x86.cc
+25
-44
lite/api/test_resnet50_lite_x86.cc
lite/api/test_resnet50_lite_x86.cc
+26
-29
lite/core/program.cc
lite/core/program.cc
+4
-1
lite/kernels/xpu/bridges/conv_op.cc
lite/kernels/xpu/bridges/conv_op.cc
+1
-1
lite/kernels/xpu/bridges/elementwise_ops.cc
lite/kernels/xpu/bridges/elementwise_ops.cc
+1
-1
lite/kernels/xpu/bridges/mul_op.cc
lite/kernels/xpu/bridges/mul_op.cc
+5
-2
未找到文件。
lite/api/CMakeLists.txt
浏览文件 @
59b80b23
...
...
@@ -119,27 +119,27 @@ if(WITH_TESTING)
add_dependencies
(
test_cxx_api extern_lite_download_lite_naive_model_tar_gz
)
if
(
NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
)
lite_cc_test
(
test_googlenet SRCS test_googlenet_lite.cc
DEPS
cxx_api mir_passes lite_api_test_helper
DEPS
mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils
${
ops
}
${
host_kernels
}
${
x86_kernels
}
ARGS --model_dir=
${
LITE_MODEL_DIR
}
/googlenet
)
add_dependencies
(
test_googlenet extern_lite_download_GoogleNet_inference_tar_gz
)
lite_cc_test
(
test_mobilenetv1_lite_x86 SRCS test_mobilenetv1_lite_x86.cc
DEPS
cxx_api mir_passes lite_api_test_helper
DEPS
mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils
${
ops
}
${
host_kernels
}
${
x86_kernels
}
ARGS --model_dir=
${
LITE_MODEL_DIR
}
/mobilenet_v1
)
add_dependencies
(
test_mobilenetv1_lite_x86 extern_lite_download_mobilenet_v1_tar_gz
)
lite_cc_test
(
test_mobilenetv2_lite_x86 SRCS test_mobilenetv2_lite_x86.cc
DEPS
cxx_api mir_passes lite_api_test_helper
DEPS
mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils
${
ops
}
${
host_kernels
}
${
x86_kernels
}
ARGS --model_dir=
${
LITE_MODEL_DIR
}
/mobilenet_v2_relu
)
add_dependencies
(
test_mobilenetv2_lite_x86 extern_lite_download_mobilenet_v2_relu_tar_gz
)
lite_cc_test
(
test_inceptionv4_lite_x86 SRCS test_inceptionv4_lite_x86.cc
DEPS
cxx_api mir_passes lite_api_test_helper
DEPS
mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils
${
ops
}
${
host_kernels
}
${
x86_kernels
}
ARGS --model_dir=
${
LITE_MODEL_DIR
}
/inception_v4_simple
)
add_dependencies
(
test_inceptionv4_lite_x86 extern_lite_download_inception_v4_simple_tar_gz
)
lite_cc_test
(
test_resnet50_lite_x86 SRCS test_resnet50_lite_x86.cc
DEPS
cxx_api mir_passes lite_api_test_helper
DEPS
mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils
${
ops
}
${
host_kernels
}
${
x86_kernels
}
ARGS --model_dir=
${
LITE_MODEL_DIR
}
/resnet50
)
add_dependencies
(
test_resnet50_lite_x86 extern_lite_download_resnet50_tar_gz
)
...
...
lite/api/test_googlenet_lite.cc
浏览文件 @
59b80b23
...
...
@@ -15,40 +15,43 @@
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <vector>
#include "lite/api/cxx_api.h"
#include "lite/api/lite_api_test_helper.h"
#include "lite/api/paddle_api.h"
#include "lite/api/paddle_use_kernels.h"
#include "lite/api/paddle_use_ops.h"
#include "lite/api/paddle_use_passes.h"
#include "lite/api/test_helper.h"
#include "lite/core/op_registry.h"
#include "lite/core/tensor.h"
#include "lite/utils/cp_logging.h"
namespace
paddle
{
namespace
lite
{
#ifdef LITE_WITH_X86
TEST
(
CXXApi
,
test_lite_googlenet
)
{
lite
::
Predictor
predictor
;
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)}});
lite_api
::
CxxConfig
config
;
config
.
set_model_dir
(
FLAGS_model_dir
);
config
.
set_valid_places
({
lite_api
::
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
lite_api
::
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
auto
predictor
=
lite_api
::
CreatePaddlePredictor
(
config
);
// LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir;
std
::
string
model_dir
=
FLAGS_model_dir
;
predictor
.
Build
(
model_dir
,
""
,
""
,
valid_places
);
auto
*
input_tensor
=
predictor
.
GetInput
(
0
);
input_tensor
->
Resize
(
DDim
(
std
::
vector
<
DDim
::
value_type
>
({
1
,
3
,
224
,
224
})));
auto
input_tensor
=
predictor
->
GetInput
(
0
);
std
::
vector
<
int64_t
>
input_shape
{
1
,
3
,
224
,
224
};
input_tensor
->
Resize
(
input_shape
);
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
input_tensor
->
dims
().
production
();
i
++
)
{
int
input_num
=
1
;
for
(
int
i
=
0
;
i
<
input_shape
.
size
();
++
i
)
{
input_num
*=
input_shape
[
i
];
}
for
(
int
i
=
0
;
i
<
input_num
;
i
++
)
{
data
[
i
]
=
1
;
}
for
(
int
i
=
0
;
i
<
FLAGS_warmup
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
auto
start
=
GetCurrentUS
();
for
(
int
i
=
0
;
i
<
FLAGS_repeats
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
LOG
(
INFO
)
<<
"================== Speed Report ==================="
;
...
...
@@ -56,8 +59,8 @@ TEST(CXXApi, test_lite_googlenet) {
<<
", warmup: "
<<
FLAGS_warmup
<<
", repeats: "
<<
FLAGS_repeats
<<
", spend "
<<
(
GetCurrentUS
()
-
start
)
/
FLAGS_repeats
/
1000.0
<<
" ms in average."
;
auto
*
out
=
predictor
.
GetOutput
(
0
);
// TODO(FrostML): open this check.
/*auto out = predictor->
GetOutput(0);
std::vector<float> results(
{0.00034298553, 0.0008200012, 0.0005046297, 0.000839279,
0.00052616704, 0.0003447803, 0.0010877076, 0.00081762316,
...
...
@@ -67,9 +70,9 @@ TEST(CXXApi, test_lite_googlenet) {
for (size_t i = 0; i < results.size(); ++i) {
EXPECT_NEAR(out->data<float>()[i * 51], results[i], 1e-5);
}
ASSERT_EQ
(
out
->
dims
().
size
(),
2
);
ASSERT_EQ
(
out
->
dims
()[
0
],
1
);
ASSERT_EQ
(
out
->
dims
()[
1
],
1000
);
ASSERT_EQ(out->
shape
().size(), 2);
ASSERT_EQ(out->
shape
()[0], 1);
ASSERT_EQ(out->
shape()[1], 1000);*/
}
#endif
}
// namespace lite
...
...
lite/api/test_inceptionv4_lite_x86.cc
浏览文件 @
59b80b23
...
...
@@ -12,64 +12,46 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <vector>
#include "lite/api/cxx_api.h"
#include "lite/api/lite_api_test_helper.h"
#include "lite/api/paddle_api.h"
#include "lite/api/paddle_use_kernels.h"
#include "lite/api/paddle_use_ops.h"
#include "lite/api/paddle_use_passes.h"
#include "lite/api/test_helper.h"
#include "lite/core/op_registry.h"
#include "lite/core/tensor.h"
#include "lite/utils/cp_logging.h"
namespace
paddle
{
namespace
lite
{
TEST
(
InceptionV4
,
test_inceptionv4_lite_x86
)
{
lite
::
Predictor
predictor
;
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)}});
lite_api
::
CxxConfig
config
;
config
.
set_model_dir
(
FLAGS_model_dir
);
config
.
set_valid_places
({
lite_api
::
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
lite_api
::
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
auto
predictor
=
lite_api
::
CreatePaddlePredictor
(
config
);
// LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir;
std
::
string
model_dir
=
FLAGS_model_dir
;
std
::
vector
<
std
::
string
>
passes
({
"static_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"type_target_cast_pass"
,
"variable_place_inference_pass"
,
"io_copy_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"runtime_context_assign_pass"
});
predictor
.
Build
(
model_dir
,
""
,
""
,
valid_places
,
passes
);
auto
*
input_tensor
=
predictor
.
GetInput
(
0
);
input_tensor
->
Resize
(
DDim
(
std
::
vector
<
DDim
::
value_type
>
({
1
,
3
,
224
,
224
})));
auto
input_tensor
=
predictor
->
GetInput
(
0
);
std
::
vector
<
int64_t
>
input_shape
{
1
,
3
,
224
,
224
};
input_tensor
->
Resize
(
input_shape
);
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
input_tensor
->
dims
().
production
();
i
++
)
{
int
input_num
=
1
;
for
(
int
i
=
0
;
i
<
input_shape
.
size
();
++
i
)
{
input_num
*=
input_shape
[
i
];
}
for
(
int
i
=
0
;
i
<
input_num
;
i
++
)
{
data
[
i
]
=
1
;
}
for
(
int
i
=
0
;
i
<
FLAGS_warmup
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
auto
start
=
GetCurrentUS
();
for
(
int
i
=
0
;
i
<
FLAGS_repeats
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
LOG
(
INFO
)
<<
"================== Speed Report ==================="
;
...
...
@@ -77,8 +59,8 @@ TEST(InceptionV4, test_inceptionv4_lite_x86) {
<<
", repeats: "
<<
FLAGS_repeats
<<
", spend "
<<
(
GetCurrentUS
()
-
start
)
/
FLAGS_repeats
/
1000.0
<<
" ms in average."
;
std
::
vector
<
std
::
vector
<
float
>>
results
;
// TODO(FrostML): open this check.
/*
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.0011684548, 0.0010390386, 0.0011301535, 0.0010133048,
...
...
@@ -87,19 +69,19 @@ TEST(InceptionV4, test_inceptionv4_lite_x86) {
0.0009782845, 0.0009230255, 0.0010548076, 0.0010974824,
0.0010612885, 0.00089107914, 0.0010112736, 0.00097655767}));
auto
*
out
=
predictor
.
GetOutput
(
0
);
ASSERT_EQ
(
out
->
dims
().
size
(),
2
);
ASSERT_EQ
(
out
->
dims
()[
0
],
1
);
ASSERT_EQ
(
out
->
dims
()[
1
],
1000
);
auto
out = predictor->
GetOutput(0);
ASSERT_EQ(out->
shape
().size(), 2);
ASSERT_EQ(out->
shape
()[0], 1);
ASSERT_EQ(out->
shape
()[1], 1000);
int step = 50;
for (int i = 0; i < results.size(); ++i) {
for (int j = 0; j < results[i].size(); ++j) {
EXPECT_NEAR
(
out
->
data
<
float
>
()[
j
*
step
+
(
out
->
dims
()[
1
]
*
i
)],
EXPECT_NEAR(out->data<float>()[j * step + (out->
shape
()[1] * i)],
results[i][j],
1e-6);
}
}
}
*/
}
}
// namespace lite
...
...
lite/api/test_mobilenetv1_lite_x86.cc
浏览文件 @
59b80b23
...
...
@@ -12,62 +12,46 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <vector>
#include "lite/api/cxx_api.h"
#include "lite/api/lite_api_test_helper.h"
#include "lite/api/paddle_api.h"
#include "lite/api/paddle_use_kernels.h"
#include "lite/api/paddle_use_ops.h"
#include "lite/api/paddle_use_passes.h"
#include "lite/api/test_helper.h"
#include "lite/core/op_registry.h"
#include "lite/core/tensor.h"
#include "lite/utils/cp_logging.h"
namespace
paddle
{
namespace
lite
{
TEST
(
Mobilenet_v1
,
test_mobilenetv1_lite_x86
)
{
lite
::
Predictor
predictor
;
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)}});
lite_api
::
CxxConfig
config
;
config
.
set_model_dir
(
FLAGS_model_dir
);
config
.
set_valid_places
({
lite_api
::
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
lite_api
::
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
auto
predictor
=
lite_api
::
CreatePaddlePredictor
(
config
);
std
::
string
model_dir
=
FLAGS_model_dir
;
std
::
vector
<
std
::
string
>
passes
({
"static_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"type_target_cast_pass"
,
"variable_place_inference_pass"
,
"io_copy_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"runtime_context_assign_pass"
});
predictor
.
Build
(
model_dir
,
""
,
""
,
valid_places
,
passes
);
auto
*
input_tensor
=
predictor
.
GetInput
(
0
);
input_tensor
->
Resize
(
DDim
(
std
::
vector
<
DDim
::
value_type
>
({
1
,
3
,
224
,
224
})));
auto
input_tensor
=
predictor
->
GetInput
(
0
);
std
::
vector
<
int64_t
>
input_shape
{
1
,
3
,
224
,
224
};
input_tensor
->
Resize
(
input_shape
);
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
input_tensor
->
dims
().
production
();
i
++
)
{
int
input_num
=
1
;
for
(
int
i
=
0
;
i
<
input_shape
.
size
();
++
i
)
{
input_num
*=
input_shape
[
i
];
}
for
(
int
i
=
0
;
i
<
input_num
;
i
++
)
{
data
[
i
]
=
1
;
}
for
(
int
i
=
0
;
i
<
FLAGS_warmup
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
auto
start
=
GetCurrentUS
();
for
(
int
i
=
0
;
i
<
FLAGS_repeats
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
LOG
(
INFO
)
<<
"================== Speed Report ==================="
;
...
...
@@ -75,8 +59,8 @@ TEST(Mobilenet_v1, test_mobilenetv1_lite_x86) {
<<
", repeats: "
<<
FLAGS_repeats
<<
", spend "
<<
(
GetCurrentUS
()
-
start
)
/
FLAGS_repeats
/
1000.0
<<
" ms in average."
;
std
::
vector
<
std
::
vector
<
float
>>
results
;
// TODO(FrostML): open this check.
/*
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.00019130898, 9.467885e-05, 0.00015971427, 0.0003650665,
...
...
@@ -84,19 +68,19 @@ TEST(Mobilenet_v1, test_mobilenetv1_lite_x86) {
0.0010323516, 0.00010079765, 0.00011006987, 0.0017364529,
0.0048292773, 0.0013995157, 0.0018453331, 0.0002428986,
0.00020211363, 0.00013668182, 0.0005855956, 0.00025901722}));
auto
*
out
=
predictor
.
GetOutput
(
0
);
ASSERT_EQ
(
out
->
dims
().
size
(),
2
);
ASSERT_EQ
(
out
->
dims
()[
0
],
1
);
ASSERT_EQ
(
out
->
dims
()[
1
],
1000
);
auto
out = predictor->
GetOutput(0);
ASSERT_EQ(out->
shape
().size(), 2);
ASSERT_EQ(out->
shape
()[0], 1);
ASSERT_EQ(out->
shape
()[1], 1000);
int step = 50;
for (int i = 0; i < results.size(); ++i) {
for (int j = 0; j < results[i].size(); ++j) {
EXPECT_NEAR
(
out
->
data
<
float
>
()[
j
*
step
+
(
out
->
dims
()[
1
]
*
i
)],
EXPECT_NEAR(out->data<float>()[j * step + (out->
shape
()[1] * i)],
results[i][j],
1e-6);
}
}
}
*/
}
}
// namespace lite
...
...
lite/api/test_mobilenetv2_lite_x86.cc
浏览文件 @
59b80b23
...
...
@@ -12,66 +12,47 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <vector>
#include "lite/api/cxx_api.h"
#include "lite/api/lite_api_test_helper.h"
#include "lite/api/paddle_api.h"
#include "lite/api/paddle_use_kernels.h"
#include "lite/api/paddle_use_ops.h"
#include "lite/api/paddle_use_passes.h"
#include "lite/api/test_helper.h"
#include "lite/core/op_registry.h"
#include "lite/core/tensor.h"
#include "lite/utils/cp_logging.h"
// for googlenet
namespace
paddle
{
namespace
lite
{
TEST
(
Mobilenet_v2
,
test_mobilenetv2_lite_x86
)
{
lite
::
Predictor
predictor
;
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
lite_api
::
CxxConfig
config
;
config
.
set_model_dir
(
FLAGS_model_dir
);
config
.
set_valid_places
({
lite_api
::
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
lite_api
::
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
auto
predictor
=
lite_api
::
CreatePaddlePredictor
(
config
);
// LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir;
std
::
string
model_dir
=
FLAGS_model_dir
;
std
::
vector
<
std
::
string
>
passes
({
"static_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"type_target_cast_pass"
,
"variable_place_inference_pass"
,
"io_copy_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"runtime_context_assign_pass"
});
predictor
.
Build
(
model_dir
,
""
,
""
,
valid_places
,
passes
);
auto
*
input_tensor
=
predictor
.
GetInput
(
0
);
input_tensor
->
Resize
(
DDim
(
std
::
vector
<
DDim
::
value_type
>
({
1
,
3
,
224
,
224
})));
auto
input_tensor
=
predictor
->
GetInput
(
0
);
std
::
vector
<
int64_t
>
input_shape
{
1
,
3
,
224
,
224
};
input_tensor
->
Resize
(
input_shape
);
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
input_tensor
->
dims
().
production
();
i
++
)
{
int
input_num
=
1
;
for
(
int
i
=
0
;
i
<
input_shape
.
size
();
++
i
)
{
input_num
*=
input_shape
[
i
];
}
for
(
int
i
=
0
;
i
<
input_num
;
i
++
)
{
data
[
i
]
=
1
;
}
for
(
int
i
=
0
;
i
<
FLAGS_warmup
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
auto
start
=
GetCurrentUS
();
for
(
int
i
=
0
;
i
<
FLAGS_repeats
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
LOG
(
INFO
)
<<
"================== Speed Report ==================="
;
...
...
@@ -79,8 +60,8 @@ TEST(Mobilenet_v2, test_mobilenetv2_lite_x86) {
<<
", repeats: "
<<
FLAGS_repeats
<<
", spend "
<<
(
GetCurrentUS
()
-
start
)
/
FLAGS_repeats
/
1000.0
<<
" ms in average."
;
std
::
vector
<
std
::
vector
<
float
>>
results
;
// TODO(FrostML): open this check.
/*
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.00017082224, 5.699624e-05, 0.000260885, 0.00016412718,
...
...
@@ -88,19 +69,19 @@ TEST(Mobilenet_v2, test_mobilenetv2_lite_x86) {
0.0009059976, 9.5378724e-05, 5.386537e-05, 0.0006427285,
0.0070957416, 0.0016094646, 0.0018807327, 0.00010506048,
6.823785e-05, 0.00012269315, 0.0007806194, 0.00022354358}));
auto
*
out
=
predictor
.
GetOutput
(
0
);
ASSERT_EQ
(
out
->
dims
().
size
(),
2
);
ASSERT_EQ
(
out
->
dims
()[
0
],
1
);
ASSERT_EQ
(
out
->
dims
()[
1
],
1000
);
auto
out = predictor->
GetOutput(0);
ASSERT_EQ(out->
shape
().size(), 2);
ASSERT_EQ(out->
shape
()[0], 1);
ASSERT_EQ(out->
shape
()[1], 1000);
int step = 50;
for (int i = 0; i < results.size(); ++i) {
for (int j = 0; j < results[i].size(); ++j) {
EXPECT_NEAR
(
out
->
data
<
float
>
()[
j
*
step
+
(
out
->
dims
()[
1
]
*
i
)],
EXPECT_NEAR(out->data<float>()[j * step + (out->
shape
()[1] * i)],
results[i][j],
1e-6);
}
}
}
*/
}
}
// namespace lite
...
...
lite/api/test_resnet50_lite_x86.cc
浏览文件 @
59b80b23
...
...
@@ -15,47 +15,43 @@
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <vector>
#include "lite/api/cxx_api.h"
#include "lite/api/lite_api_test_helper.h"
#include "lite/api/paddle_api.h"
#include "lite/api/paddle_use_kernels.h"
#include "lite/api/paddle_use_ops.h"
#include "lite/api/paddle_use_passes.h"
#include "lite/api/test_helper.h"
#include "lite/
core/op_registry
.h"
#include "lite/
utils/cp_logging
.h"
namespace
paddle
{
namespace
lite
{
TEST
(
Resnet50
,
test_resnet50_lite_x86
)
{
// DeviceInfo::Init()
;
// DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads
);
lite
::
Predictor
predictor
;
std
::
vector
<
Place
>
valid_places
({
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}}
);
lite_api
::
CxxConfig
config
;
config
.
set_model_dir
(
FLAGS_model_dir
);
config
.
set_valid_places
({
lite_api
::
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
lite_api
::
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
auto
predictor
=
lite_api
::
CreatePaddlePredictor
(
config
);
std
::
string
model_dir
=
FLAGS_model_dir
;
std
::
vector
<
std
::
string
>
passes
({
"static_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"type_target_cast_pass"
,
"variable_place_inference_pass"
,
"io_copy_kernel_pick_pass"
,
"variable_place_inference_pass"
,
"runtime_context_assign_pass"
});
predictor
.
Build
(
model_dir
,
""
,
""
,
valid_places
,
passes
);
auto
*
input_tensor
=
predictor
.
GetInput
(
0
);
input_tensor
->
Resize
(
DDim
(
std
::
vector
<
DDim
::
value_type
>
({
1
,
3
,
224
,
224
})));
auto
input_tensor
=
predictor
->
GetInput
(
0
);
std
::
vector
<
int64_t
>
input_shape
{
1
,
3
,
224
,
224
};
input_tensor
->
Resize
(
input_shape
);
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
auto
item_size
=
input_tensor
->
dims
().
production
();
for
(
int
i
=
0
;
i
<
item_size
;
i
++
)
{
int
input_num
=
1
;
for
(
int
i
=
0
;
i
<
input_shape
.
size
();
++
i
)
{
input_num
*=
input_shape
[
i
];
}
for
(
int
i
=
0
;
i
<
input_num
;
i
++
)
{
data
[
i
]
=
1
;
}
for
(
int
i
=
0
;
i
<
FLAGS_warmup
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
auto
start
=
GetCurrentUS
();
for
(
int
i
=
0
;
i
<
FLAGS_repeats
;
++
i
)
{
predictor
.
Run
();
predictor
->
Run
();
}
LOG
(
INFO
)
<<
"================== Speed Report ==================="
;
...
...
@@ -64,7 +60,8 @@ TEST(Resnet50, test_resnet50_lite_x86) {
<<
", spend "
<<
(
GetCurrentUS
()
-
start
)
/
FLAGS_repeats
/
1000.0
<<
" ms in average."
;
std
::
vector
<
std
::
vector
<
float
>>
results
;
// TODO(FrostML): open this check.
/*std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.00024139918, 0.00020566184, 0.00022418296, 0.00041731037,
...
...
@@ -72,19 +69,19 @@ TEST(Resnet50, test_resnet50_lite_x86) {
0.00072681636, 8.531815e-05, 0.0002129998, 0.0021168243,
0.006387163, 0.0037145028, 0.0012812682, 0.00045948103,
0.00013535398, 0.0002483765, 0.00076759676, 0.0002773295}));
auto
*
out
=
predictor
.
GetOutput
(
0
);
ASSERT_EQ
(
out
->
dims
().
size
(),
2
);
ASSERT_EQ
(
out
->
dims
()[
0
],
1
);
ASSERT_EQ
(
out
->
dims
()[
1
],
1000
);
auto
out = predictor->
GetOutput(0);
ASSERT_EQ(out->
shape
().size(), 2);
ASSERT_EQ(out->
shape
()[0], 1);
ASSERT_EQ(out->
shape
()[1], 1000);
int step = 50;
for (int i = 0; i < results.size(); ++i) {
for (int j = 0; j < results[i].size(); ++j) {
EXPECT_NEAR
(
out
->
data
<
float
>
()[
j
*
step
+
(
out
->
dims
()[
1
]
*
i
)],
EXPECT_NEAR(out->data<float>()[j * step + (out->
shape
()[1] * i)],
results[i][j],
1e-6);
}
}
}
*/
}
}
// namespace lite
...
...
lite/core/program.cc
浏览文件 @
59b80b23
...
...
@@ -196,11 +196,14 @@ void Instruction::Run() {
if
(
op_
->
run_once
()
&&
has_run_
)
{
return
;
}
#ifndef LITE_SHUTDOWN_LOG
VLOG
(
4
)
<<
"kernel launch"
;
#endif
op_
->
InferShape
();
#ifndef LITE_SHUTDOWN_LOG
VLOG
(
4
)
<<
">> Running kernel: "
<<
op_
->
op_info
()
->
Repr
()
<<
" on Target "
<<
TargetToStr
(
kernel_
->
target
());
#endif
kernel_
->
Launch
();
has_run_
=
true
;
}
...
...
lite/kernels/xpu/bridges/conv_op.cc
浏览文件 @
59b80b23
...
...
@@ -136,7 +136,7 @@ node_map_type ConvConverter(const std::shared_ptr<lite::OpLite> op,
std
::
shared_ptr
<
xtcl
::
xExpr
>
add_node
=
nullptr
;
if
(
is_channel_bias
)
{
add_node
=
std
::
make_shared
<
xtcl
::
xExpr
>
(
graph_ctx
->
builder
->
CreateBiasAdd
(
*
conv_node
,
*
bias_node
,
1
));
graph_ctx
->
builder
->
CreateBiasAdd
(
*
conv_node
,
1
,
*
bias_node
));
}
else
{
add_node
=
std
::
make_shared
<
xtcl
::
xExpr
>
(
graph_ctx
->
builder
->
CreateBinaryOp
(
"add"
,
*
conv_node
,
*
bias_node
));
...
...
lite/kernels/xpu/bridges/elementwise_ops.cc
浏览文件 @
59b80b23
...
...
@@ -69,7 +69,7 @@ node_map_type ElementwiseConverter(const std::shared_ptr<lite::OpLite> op,
std
::
shared_ptr
<
xtcl
::
xExpr
>
elementwise_node
=
nullptr
;
if
(
y_dims
.
size
()
==
1
)
{
elementwise_node
=
std
::
make_shared
<
xtcl
::
xExpr
>
(
graph_ctx
->
builder
->
CreateBiasAdd
(
*
x_node
,
*
y_node
,
axis
));
graph_ctx
->
builder
->
CreateBiasAdd
(
*
x_node
,
axis
,
*
y_node
));
}
else
if
(
x_dims
.
size
()
==
y_dims
.
size
())
{
elementwise_node
=
std
::
make_shared
<
xtcl
::
xExpr
>
(
graph_ctx
->
builder
->
CreateBinaryOp
(
"add"
,
*
x_node
,
*
y_node
));
...
...
lite/kernels/xpu/bridges/mul_op.cc
浏览文件 @
59b80b23
...
...
@@ -78,8 +78,11 @@ node_map_type MulConverter(const std::shared_ptr<lite::OpLite> op,
// create mul node and set params from op
std
::
shared_ptr
<
xtcl
::
xExpr
>
mul_node
=
nullptr
;
mul_node
=
std
::
make_shared
<
xtcl
::
xExpr
>
(
graph_ctx
->
builder
->
CreateDense
(
*
x_node
,
*
y_const_node
,
static_cast
<
int
>
(
y_dims
[
1
])));
mul_node
=
std
::
make_shared
<
xtcl
::
xExpr
>
(
graph_ctx
->
builder
->
CreateDense
(
*
x_node
,
static_cast
<
int
>
(
y_dims
[
1
]),
::
xtcl
::
NullValue
<::
xtcl
::
DataType
>
(),
*
y_const_node
));
graph_ctx
->
builder
->
SetLayer
(
unique_op_type
);
// output converted nodes
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录