Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
9867d6cd
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
未验证
提交
9867d6cd
编写于
11月 02, 2019
作者:
H
huzhiqiang
提交者:
GitHub
11月 02, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
x86 doc (#2349)
* x86 doc
上级
8c8d5ea8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
216 addition
and
0 deletion
+216
-0
_all_pages/develop/index.md
_all_pages/develop/index.md
+1
-0
_all_pages/develop/x86.md
_all_pages/develop/x86.md
+108
-0
_all_pages/v2.0.0/index.md
_all_pages/v2.0.0/index.md
+1
-0
_all_pages/v2.0.0/x86.md
_all_pages/v2.0.0/x86.md
+106
-0
未找到文件。
_all_pages/develop/index.md
浏览文件 @
9867d6cd
...
...
@@ -45,6 +45,7 @@ Paddle-Lite 框架是 PaddleMobile 新一代架构,重点支持移动端推理
-
[
使用Android GPU
](
{{site.baseurl}}/develop/opencl
)
-
[
使用FPGA
](
{{site.baseurl}}/develop/fpga
)
-
[
使用CUDA
](
{{site.baseurl}}/develop/cuda
)
-
[
使用X86预测库
](
{{site.baseurl}}/develop/x86
)
## 开发者文档
...
...
_all_pages/develop/x86.md
0 → 100644
浏览文件 @
9867d6cd
---
layout
:
post
title
:
Lite支持x86编译
---
Paddle-Lite 支持在Docker或Linux环境编译x86预测库。环境搭建参考
[
环境准备
](
../source_compile
)
。
## 编译
一: 下载代码
```
bash
git clone https://github.com/PaddlePaddle/Paddle-Lite.git
#需要切换到 release/v2.0.0之后版本
git checkout <release_tag>
```
二:源码编译
```
bash
cd
Paddle-Lite
./lite/tool/build.sh x86
```
## 编译结果说明
x86编译结果位于
`build.lite.x86/inference_lite_lib`
**具体内容**
说明:
1、
`bin`
文件夹:可执行工具文件
`test_model_bin`
2、
`cxx`
文件夹:包含c++的库文件与相应的头文件
-
`include`
: 头文件
-
`lib`
: 库文件
-
打包的静态库文件:
-
`libpaddle_api_full_bundled.a`
:包含 full_api 和 light_api 功能的静态库
-
`libpaddle_api_light_bundled.a`
:只包含 light_api 功能的静态库
-
打包的动态态库文件:
-
`libpaddle_full_api_shared.so`
:包含 full_api 和 light_api 功能的动态库
-
`libpaddle_light_api_shared.so`
:只包含 light_api 功能的动态库
3、
`third_party`
文件夹:第三方库文件
## x86预测API使用示例
```
c++
#include <gflags/gflags.h>
#include <iostream>
#include <vector>
#include "paddle_api.h" // NOLINT
#include "paddle_use_kernels.h" // NOLINT
#include "paddle_use_ops.h" // NOLINT
#include "paddle_use_passes.h" // NOLINT
using
namespace
paddle
::
lite_api
;
// NOLINT
DEFINE_string
(
model_dir
,
""
,
"Model dir path."
);
DEFINE_string
(
optimized_model_dir
,
""
,
"Optimized model dir."
);
DEFINE_bool
(
prefer_int8_kernel
,
false
,
"Prefer to run model with int8 kernels"
);
int64_t
ShapeProduction
(
const
shape_t
&
shape
)
{
int64_t
res
=
1
;
for
(
auto
i
:
shape
)
res
*=
i
;
return
res
;
}
void
RunModel
()
{
// 1. Set CxxConfig
CxxConfig
config
;
config
.
set_model_file
(
FLAGS_model_dir
+
"model"
);
config
.
set_param_file
(
FLAGS_model_dir
+
"params"
);
config
.
set_valid_places
({
lite_api
::
Place
{
TARGET
(
kX86
),
PRECISION
(
kFloat
)},
lite_api
::
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
(
shape_t
({
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 dim: "
<<
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
)
{
google
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
RunModel
();
return
0
;
}
```
_all_pages/v2.0.0/index.md
浏览文件 @
9867d6cd
...
...
@@ -45,6 +45,7 @@ Paddle-Lite 框架是 PaddleMobile 新一代架构,重点支持移动端推理
-
[
使用Android GPU
](
{{site.baseurl}}/v2.0.0/opencl
)
-
[
使用FPGA
](
{{site.baseurl}}/v2.0.0/fpga
)
-
[
使用CUDA
](
{{site.baseurl}}/v2.0.0/cuda
)
-
[
使用X86预测库
](
{{site.baseurl}}/v2.0.0/x86
)
## 开发者文档
...
...
_all_pages/v2.0.0/x86.md
0 → 100644
浏览文件 @
9867d6cd
---
layout
:
post
title
:
Lite支持x86编译
---
Paddle-Lite 支持在Docker或Linux环境编译x86预测库。环境搭建参考
[
环境准备
](
../source_compile
)
。
## 编译
一: 下载代码
```
bash
git clone https://github.com/PaddlePaddle/Paddle-Lite.git
#需要切换到 release/v2.0.0之后版本
git checkout <release_tag>
```
二:源码编译
```
bash
cd
Paddle-Lite
./lite/tool/build.sh x86
```
## 编译结果说明
X86编译结果位于
`build.lite.x86/inference_lite_lib`
**具体内容**
说明:
1、
`bin`
文件夹:可执行工具文件
`test_model_bin`
2、
`cxx`
文件夹:包含c++的库文件与相应的头文件
-
`include`
: 头文件
-
`lib`
: 库文件
-
打包的静态库文件:
-
`libpaddle_api_full_bundled.a`
:包含 full_api 和 light_api 功能的静态库
-
`libpaddle_api_light_bundled.a`
:只包含 light_api 功能的静态库
-
打包的动态态库文件:
-
`libpaddle_full_api_shared.so`
:包含 full_api 和 light_api 功能的动态库
-
`libpaddle_light_api_shared.so`
:只包含 light_api 功能的动态库
3、
`third_party`
文件夹:第三方库文件
## x86预测API使用示例
```
C++
#include <gflags/gflags.h>
#include <iostream>
#include <vector>
#include "paddle_api.h" // NOLINT
#include "paddle_use_kernels.h" // NOLINT
#include "paddle_use_ops.h" // NOLINT
#include "paddle_use_passes.h" // NOLINT
using namespace paddle::lite_api; // NOLINT
DEFINE_string(model_dir, "", "Model dir path.");
DEFINE_string(optimized_model_dir, "", "Optimized model dir.");
DEFINE_bool(prefer_int8_kernel, false, "Prefer to run model with int8 kernels");
int64_t ShapeProduction(const shape_t& shape) {
int64_t res = 1;
for (auto i : shape) res *= i;
return res;
}
void RunModel() {
// 1. Set CxxConfig
CxxConfig config;
config.set_model_file(FLAGS_model_dir + "model");
config.set_param_file(FLAGS_model_dir + "params");
config.set_valid_places({
lite_api::Place{TARGET(kX86), PRECISION(kFloat)},
lite_api::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(shape_t({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 dim: " << 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) {
google::ParseCommandLineFlags(&argc, &argv, true);
RunModel();
return 0;
}
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录