Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
2ef331f2
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看板
未验证
提交
2ef331f2
编写于
4月 27, 2020
作者:
H
huzhiqiang
提交者:
GitHub
4月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[demo][x86] Add cxx_demo for x86 backend (#3482)
上级
b99986a3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
196 addition
and
6 deletion
+196
-6
lite/CMakeLists.txt
lite/CMakeLists.txt
+12
-6
lite/demo/cxx/x86_mobilenetv1_full_demo/CMakeLists.txt
lite/demo/cxx/x86_mobilenetv1_full_demo/CMakeLists.txt
+21
-0
lite/demo/cxx/x86_mobilenetv1_full_demo/build.sh
lite/demo/cxx/x86_mobilenetv1_full_demo/build.sh
+6
-0
lite/demo/cxx/x86_mobilenetv1_full_demo/mobilenet_full_api.cc
.../demo/cxx/x86_mobilenetv1_full_demo/mobilenet_full_api.cc
+66
-0
lite/demo/cxx/x86_mobilenetv1_light_demo/CMakeLists.txt
lite/demo/cxx/x86_mobilenetv1_light_demo/CMakeLists.txt
+21
-0
lite/demo/cxx/x86_mobilenetv1_light_demo/build.sh
lite/demo/cxx/x86_mobilenetv1_light_demo/build.sh
+6
-0
lite/demo/cxx/x86_mobilenetv1_light_demo/mobilenet_light_api.cc
...emo/cxx/x86_mobilenetv1_light_demo/mobilenet_light_api.cc
+64
-0
未找到文件。
lite/CMakeLists.txt
浏览文件 @
2ef331f2
...
@@ -188,15 +188,17 @@ if (LITE_WITH_CUDA OR LITE_WITH_X86)
...
@@ -188,15 +188,17 @@ if (LITE_WITH_CUDA OR LITE_WITH_X86)
COMMAND cp
"
${
CMAKE_BINARY_DIR
}
/libpaddle_api_light_bundled.a"
"
${
INFER_LITE_PUBLISH_ROOT
}
/cxx/lib"
COMMAND cp
"
${
CMAKE_BINARY_DIR
}
/libpaddle_api_light_bundled.a"
"
${
INFER_LITE_PUBLISH_ROOT
}
/cxx/lib"
COMMAND cp
"
${
CMAKE_BINARY_DIR
}
/lite/api/*.so"
"
${
INFER_LITE_PUBLISH_ROOT
}
/cxx/lib"
COMMAND cp
"
${
CMAKE_BINARY_DIR
}
/lite/api/*.so"
"
${
INFER_LITE_PUBLISH_ROOT
}
/cxx/lib"
)
)
add_custom_target
(
publish_inference_third_party
${
TARGET
}
if
(
LITE_WITH_CUDA
)
COMMAND mkdir -p
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party"
add_custom_target
(
publish_inference_third_party
${
TARGET
}
COMMAND cp -r
"
${
CMAKE_BINARY_DIR
}
/third_party/install/*"
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party"
)
COMMAND mkdir -p
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party"
COMMAND cp -r
"
${
CMAKE_BINARY_DIR
}
/third_party/install/*"
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party"
)
add_dependencies
(
publish_inference publish_inference_third_party
)
endif
()
add_dependencies
(
publish_inference_cxx_lib bundle_full_api
)
add_dependencies
(
publish_inference_cxx_lib bundle_full_api
)
add_dependencies
(
publish_inference_cxx_lib bundle_light_api
)
add_dependencies
(
publish_inference_cxx_lib bundle_light_api
)
add_dependencies
(
publish_inference_cxx_lib paddle_full_api_shared
)
add_dependencies
(
publish_inference_cxx_lib paddle_full_api_shared
)
add_dependencies
(
publish_inference_cxx_lib paddle_light_api_shared
)
add_dependencies
(
publish_inference_cxx_lib paddle_light_api_shared
)
add_dependencies
(
publish_inference publish_inference_cxx_lib
)
add_dependencies
(
publish_inference publish_inference_cxx_lib
)
add_dependencies
(
publish_inference publish_inference_third_party
)
endif
()
endif
()
endif
()
endif
()
...
@@ -238,9 +240,13 @@ if (LITE_WITH_X86)
...
@@ -238,9 +240,13 @@ if (LITE_WITH_X86)
add_dependencies
(
publish_inference_x86_cxx_lib test_model_bin
)
add_dependencies
(
publish_inference_x86_cxx_lib test_model_bin
)
add_custom_target
(
publish_inference_x86_cxx_demos
${
TARGET
}
add_custom_target
(
publish_inference_x86_cxx_demos
${
TARGET
}
COMMAND rm -rf
"
${
INFER_LITE_PUBLISH_ROOT
}
/demo/cxx"
COMMAND mkdir -p
"
${
INFER_LITE_PUBLISH_ROOT
}
/demo/cxx"
COMMAND cp -r
"
${
CMAKE_SOURCE_DIR
}
/lite/demo/cxx/x86_mobilenetv1_light_demo"
"
${
INFER_LITE_PUBLISH_ROOT
}
/demo/cxx/mobilenetv1_light"
COMMAND cp -r
"
${
CMAKE_SOURCE_DIR
}
/lite/demo/cxx/x86_mobilenetv1_full_demo"
"
${
INFER_LITE_PUBLISH_ROOT
}
/demo/cxx/mobilenetv1_full"
COMMAND mkdir -p
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party"
COMMAND mkdir -p
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party"
COMMAND cp -r
"
${
CMAKE_BINARY_DIR
}
/third_party/
eigen3"
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party
"
COMMAND cp -r
"
${
CMAKE_BINARY_DIR
}
/third_party/
install/mklml"
"
${
INFER_LITE_PUBLISH_ROOT
}
/third_party/
"
)
)
add_dependencies
(
publish_inference_x86_cxx_lib publish_inference_x86_cxx_demos
)
add_dependencies
(
publish_inference_x86_cxx_lib publish_inference_x86_cxx_demos
)
add_dependencies
(
publish_inference_x86_cxx_demos paddle_full_api_shared eigen3
)
add_dependencies
(
publish_inference_x86_cxx_demos paddle_full_api_shared eigen3
)
add_dependencies
(
publish_inference publish_inference_x86_cxx_lib
)
add_dependencies
(
publish_inference publish_inference_x86_cxx_lib
)
...
...
lite/demo/cxx/x86_mobilenetv1_full_demo/CMakeLists.txt
0 → 100644
浏览文件 @
2ef331f2
cmake_minimum_required
(
VERSION 2.8
)
set
(
TARGET mobilenet_full_api
)
# 1. path to Paddle-Lite lib and mklml lib
set
(
LITE_DIR
"
${
PROJECT_SOURCE_DIR
}
/../../../cxx"
)
set
(
MKLML_DIR
"
${
PROJECT_SOURCE_DIR
}
/../../../third_party/mklml/"
)
# 2. link mklml and Paddle-Lite directory
link_directories
(
${
LITE_DIR
}
/lib
${
MKLML_DIR
}
/lib
)
include_directories
(
${
LITE_DIR
}
/include/
${
MKLML_DIR
}
/include
)
# 3. compile options
add_definitions
(
-std=c++11 -g -O3 -pthread
)
set
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_SOURCE_DIR
}
)
# 4.add executable output
add_executable
(
${
TARGET
}
${
TARGET
}
.cc
)
target_link_libraries
(
${
TARGET
}
-lpaddle_full_api_shared
)
target_link_libraries
(
${
TARGET
}
-lmklml_intel
)
target_link_libraries
(
${
TARGET
}
-ldl
)
lite/demo/cxx/x86_mobilenetv1_full_demo/build.sh
0 → 100644
浏览文件 @
2ef331f2
mkdir
./build
cd
./build
cmake ..
make
cd
..
rm
-rf
./build
lite/demo/cxx/x86_mobilenetv1_full_demo/mobilenet_full_api.cc
0 → 100644
浏览文件 @
2ef331f2
// Copyright (c) 2020 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 <iostream>
#include <vector>
#include "paddle_api.h" // NOLINT
using
namespace
paddle
::
lite_api
;
// NOLINT
int64_t
ShapeProduction
(
const
shape_t
&
shape
)
{
int64_t
res
=
1
;
for
(
auto
i
:
shape
)
res
*=
i
;
return
res
;
}
void
RunModel
(
std
::
string
model_dir
)
{
// 1. Create CxxConfig
CxxConfig
config
;
config
.
set_model_dir
(
model_dir
);
config
.
set_valid_places
({
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
// 2. Create PaddlePredictor by CxxConfig
std
::
shared_ptr
<
PaddlePredictor
>
predictor
=
CreatePaddlePredictor
<
CxxConfig
>
(
config
);
// 3. Prepare input data
std
::
unique_ptr
<
Tensor
>
input_tensor
(
std
::
move
(
predictor
->
GetInput
(
0
)));
input_tensor
->
Resize
({
1
,
3
,
224
,
224
});
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
ShapeProduction
(
input_tensor
->
shape
());
++
i
)
{
data
[
i
]
=
1
;
}
// 4. Run predictor
predictor
->
Run
();
// 5. Get output
std
::
unique_ptr
<
const
Tensor
>
output_tensor
(
std
::
move
(
predictor
->
GetOutput
(
0
)));
std
::
cout
<<
"Output shape "
<<
output_tensor
->
shape
()[
1
]
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
ShapeProduction
(
output_tensor
->
shape
());
i
+=
100
)
{
std
::
cout
<<
"Output["
<<
i
<<
"]: "
<<
output_tensor
->
data
<
float
>
()[
i
]
<<
std
::
endl
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
{
std
::
cerr
<<
"[ERROR] usage: ./"
<<
argv
[
0
]
<<
" naive_buffer_model_dir
\n
"
;
exit
(
1
);
}
std
::
string
model_dir
=
argv
[
1
];
RunModel
(
model_dir
);
return
0
;
}
lite/demo/cxx/x86_mobilenetv1_light_demo/CMakeLists.txt
0 → 100644
浏览文件 @
2ef331f2
cmake_minimum_required
(
VERSION 2.8
)
set
(
TARGET mobilenet_light_api
)
# 1. path to Paddle-Lite lib and mklml lib
set
(
LITE_DIR
"
${
PROJECT_SOURCE_DIR
}
/../../../cxx"
)
set
(
MKLML_DIR
"
${
PROJECT_SOURCE_DIR
}
/../../../third_party/mklml/"
)
# 2. link mklml and Paddle-Lite directory
link_directories
(
${
LITE_DIR
}
/lib
${
MKLML_DIR
}
/lib
)
include_directories
(
${
LITE_DIR
}
/include/
${
MKLML_DIR
}
/include
)
# 3. compile options
add_definitions
(
-std=c++11 -g -O3 -pthread
)
set
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_SOURCE_DIR
}
)
# 4.add executable output
add_executable
(
${
TARGET
}
${
TARGET
}
.cc
)
target_link_libraries
(
${
TARGET
}
-lpaddle_light_api_shared
)
target_link_libraries
(
${
TARGET
}
-lmklml_intel
)
target_link_libraries
(
${
TARGET
}
-ldl
)
lite/demo/cxx/x86_mobilenetv1_light_demo/build.sh
0 → 100644
浏览文件 @
2ef331f2
mkdir
./build
cd
./build
cmake ..
make
cd
..
rm
-rf
./build
lite/demo/cxx/x86_mobilenetv1_light_demo/mobilenet_light_api.cc
0 → 100644
浏览文件 @
2ef331f2
// Copyright (c) 2020 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 <iostream>
#include <vector>
#include "paddle_api.h" // NOLINT
using
namespace
paddle
::
lite_api
;
// NOLINT
int64_t
ShapeProduction
(
const
shape_t
&
shape
)
{
int64_t
res
=
1
;
for
(
auto
i
:
shape
)
res
*=
i
;
return
res
;
}
void
RunModel
(
std
::
string
model_dir
)
{
// 1. Create MobileConfig
MobileConfig
config
;
config
.
set_model_dir
(
model_dir
);
// 2. Create PaddlePredictor by CxxConfig
std
::
shared_ptr
<
PaddlePredictor
>
predictor
=
CreatePaddlePredictor
<
MobileConfig
>
(
config
);
// 3. Prepare input data
std
::
unique_ptr
<
Tensor
>
input_tensor
(
std
::
move
(
predictor
->
GetInput
(
0
)));
input_tensor
->
Resize
({
1
,
3
,
224
,
224
});
auto
*
data
=
input_tensor
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
ShapeProduction
(
input_tensor
->
shape
());
++
i
)
{
data
[
i
]
=
1
;
}
// 4. Run predictor
predictor
->
Run
();
// 5. Get output
std
::
unique_ptr
<
const
Tensor
>
output_tensor
(
std
::
move
(
predictor
->
GetOutput
(
0
)));
std
::
cout
<<
"Output shape "
<<
output_tensor
->
shape
()[
1
]
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
ShapeProduction
(
output_tensor
->
shape
());
i
+=
100
)
{
std
::
cout
<<
"Output["
<<
i
<<
"]: "
<<
output_tensor
->
data
<
float
>
()[
i
]
<<
std
::
endl
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
{
std
::
cerr
<<
"[ERROR] usage: ./"
<<
argv
[
0
]
<<
" naive_buffer_model_dir
\n
"
;
exit
(
1
);
}
std
::
string
model_dir
=
argv
[
1
];
RunModel
(
model_dir
);
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录