Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
fd45c6d1
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fd45c6d1
编写于
5月 25, 2018
作者:
Y
Yan Chunwei
提交者:
Qiao Longfei
5月 25, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature/inference api demo impl (#10825)
add inference api demo impl
上级
dd428a01
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
172 addition
and
27 deletion
+172
-27
CMakeLists.txt
CMakeLists.txt
+6
-0
paddle/.gitignore
paddle/.gitignore
+0
-1
paddle/contrib/CMakeLists.txt
paddle/contrib/CMakeLists.txt
+16
-0
paddle/contrib/inference/CMakeLists.txt
paddle/contrib/inference/CMakeLists.txt
+22
-0
paddle/contrib/inference/paddle_inference_api.cc
paddle/contrib/inference/paddle_inference_api.cc
+15
-0
paddle/contrib/inference/paddle_inference_api.h
paddle/contrib/inference/paddle_inference_api.h
+45
-25
paddle/contrib/inference/test_paddle_inference_api.cc
paddle/contrib/inference/test_paddle_inference_api.cc
+64
-0
paddle/scripts/paddle_build.sh
paddle/scripts/paddle_build.sh
+4
-1
未找到文件。
CMakeLists.txt
浏览文件 @
fd45c6d1
...
...
@@ -58,6 +58,8 @@ option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF)
option
(
WITH_DISTRIBUTE
"Compile with grpc distributed support"
OFF
)
option
(
USE_EIGEN_FOR_BLAS
"Use matrix multiplication in Eigen"
OFF
)
option
(
WITH_ARM_FP16
"Use half precision support on armv8.2-a cpu"
OFF
)
option
(
WITH_FAST_BUNDLE_TEST
"Bundle tests that can be run in a single process together to reduce launch overhead"
OFF
)
option
(
WITH_CONTRIB
"Compile the third-party contributation"
OFF
)
# CMAKE_BUILD_TYPE
if
(
NOT CMAKE_BUILD_TYPE
)
...
...
@@ -230,3 +232,7 @@ if(WITH_DOC)
find_python_module
(
recommonmark REQUIRED
)
add_subdirectory
(
doc
)
endif
()
if
(
WITH_CONTRIB
)
add_subdirectory
(
paddle/contrib
)
endif
()
paddle/.gitignore
浏览文件 @
fd45c6d1
...
...
@@ -11,7 +11,6 @@ GTAGS
*.pb.cc
*.pb.h
*_pb2.py
paddle_*
output/
google/
Makefile
...
...
paddle/contrib/CMakeLists.txt
0 → 100644
浏览文件 @
fd45c6d1
# Copyright (c) 2016 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.
#
add_subdirectory
(
inference
)
paddle/contrib/inference/CMakeLists.txt
0 → 100644
浏览文件 @
fd45c6d1
# Copyright (c) 2016 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.
#
cc_library
(
paddle_inference_api
SRCS paddle_inference_api.cc
DEPS
${
FLUID_CORE_MODULES
}
${
GLOB_OP_LIB
}
)
cc_test
(
test_paddle_inference_api
SRCS test_paddle_inference_api.cc
DEPS paddle_inference_api
)
paddle/contrib/inference/paddle_inference_api.cc
0 → 100644
浏览文件 @
fd45c6d1
/* Copyright (c) 2018 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 "paddle/contrib/inference/paddle_inference_api.h"
paddle/contrib/inference/paddle_inference_api.h
浏览文件 @
fd45c6d1
...
...
@@ -12,49 +12,65 @@
See the License for the specific language governing permissions and
limitations under the License. */
/*
* This file contains the definition of a simple Inference API for Paddle.
*
* ATTENTION: It requires some C++ features, for lower version C++ or C, we
* might release another API.
*/
#pragma once
#include <memory>
#include <string>
#include <vector>
namespace
paddle
{
class
Predictor
{
struct
PaddleTensor
{
std
::
string
name
;
// variable name.
std
::
vector
<
int
>
shape
;
std
::
vector
<
unsigned
char
>
data
;
// bytes of data.
size_t
type
{
typeid
(
float
).
hash_code
()};
// hash of type
};
/*
* A simple Inference API for Paddle. Currently this API might just be used by
* non-sequence scenerios.
* TODO(Superjomn) Prepare another API for NLP-related usages.
*/
class
PaddlePredictor
{
public:
struct
Attr
;
Predictor
()
=
default
;
struct
Config
;
PaddlePredictor
()
=
default
;
PaddlePredictor
(
const
PaddlePredictor
&
)
=
delete
;
// Build the network before inference.
bool
Init
(
const
Attr
&
attr
);
// One drived class should has such a constructor
// PaddlePredictor(const XConfig& config);
// The XConfig is a derived class of Config.
// Predict an record.
// Arguments:
// inputs: the name of the input variables.
// outputs: the name of the output varaibles.
// input_shapes: the shape of the input variables.
// output_shapes: the shape of the output variables.
// input_data: the data of the input variables.
// output_data: the data of the output variables.
bool
Run
(
const
std
::
vector
<
std
::
string
>&
inputs
,
const
std
::
vector
<
std
::
string
>&
outputs
,
const
std
::
vector
<
std
::
vector
<
int
>>&
input_shapes
,
const
std
::
vector
<
std
::
vector
<
int
>>&
output_shapes
,
const
std
::
vector
<
std
::
vector
<
float
>>&
input_data
,
std
::
vector
<
std
::
vector
<
float
>>*
output_data
);
// Clone a predictor that share the model weights.
Predictor
*
Clone
();
virtual
bool
Run
(
const
std
::
vector
<
PaddleTensor
>&
inputs
,
std
::
vector
<
PaddleTensor
>*
output_data
)
=
0
;
// Clone a predictor that share the model weights, the Cloned predictor should
// be thread-safe.
virtual
std
::
unique_ptr
<
PaddlePredictor
>
Clone
()
=
0
;
// Destroy the Predictor.
~
Predictor
();
virtual
~
PaddlePredictor
()
{}
friend
std
::
unique_ptr
<
PaddlePredictor
>
CreatePaddlePredictor
(
const
PaddlePredictor
::
Config
&
config
);
struct
Attr
{
// The common configs for all the predictors.
struct
Config
{
enum
class
EngineKind
;
std
::
string
model_dir
;
// path to the model directory.
bool
enable_engine
{
false
};
// Enable to execute (part of) the model on
// third-party engines.
EngineKind
engine_kind
{
Attr
::
EngineKind
::
kNone
};
// third-party engines.
EngineKind
engine_kind
{
Config
::
EngineKind
::
kNone
};
enum
class
EngineKind
{
kNone
=
-
1
,
// Use the native Fluid facility.
...
...
@@ -66,4 +82,8 @@ public:
};
};
// A factory to help create difference predictor.
template
<
typename
ConfigT
>
std
::
unique_ptr
<
PaddlePredictor
>
CreatePaddlePredictor
(
const
ConfigT
&
config
);
}
// namespace paddle
paddle/contrib/inference/test_paddle_inference_api.cc
0 → 100644
浏览文件 @
fd45c6d1
/* Copyright (c) 2018 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 "paddle/contrib/inference/paddle_inference_api.h"
#include <glog/logging.h>
#include <gtest/gtest.h>
namespace
paddle
{
/*
* Do not use this, just a demo indicating how to customize a config for a
* specific predictor.
*/
struct
DemoConfig
:
public
PaddlePredictor
::
Config
{
float
other_config
;
};
/*
* Do not use this, just a demo indicating how to customize a Predictor.
*/
class
DemoPredictor
:
public
PaddlePredictor
{
public:
explicit
DemoPredictor
(
const
DemoConfig
&
config
)
{
LOG
(
INFO
)
<<
"I get other_config "
<<
config
.
other_config
;
}
bool
Run
(
const
std
::
vector
<
PaddleTensor
>
&
inputs
,
std
::
vector
<
PaddleTensor
>
*
output_data
)
override
{
LOG
(
INFO
)
<<
"Run"
;
return
false
;
}
std
::
unique_ptr
<
PaddlePredictor
>
Clone
()
override
{
return
nullptr
;
}
~
DemoPredictor
()
override
{}
};
template
<
>
std
::
unique_ptr
<
PaddlePredictor
>
CreatePaddlePredictor
<
DemoConfig
>
(
const
DemoConfig
&
config
)
{
std
::
unique_ptr
<
PaddlePredictor
>
x
(
new
DemoPredictor
(
config
));
return
x
;
}
TEST
(
paddle_inference_api
,
demo
)
{
DemoConfig
config
;
config
.
other_config
=
1.7
;
auto
predictor
=
CreatePaddlePredictor
(
config
);
std
::
vector
<
PaddleTensor
>
outputs
;
predictor
->
Run
({},
&
outputs
);
}
}
// namespace paddle
paddle/scripts/paddle_build.sh
浏览文件 @
fd45c6d1
...
...
@@ -104,6 +104,8 @@ function cmake_gen() {
-DCMAKE_MODULE_PATH=/opt/rocm/hip/cmake
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DWITH_FLUID_ONLY=
${
WITH_FLUID_ONLY
:-
OFF
}
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DWITH_CONTRIB=ON
========================================
EOF
# Disable UNITTEST_USE_VIRTUALENV in docker because
...
...
@@ -129,7 +131,8 @@ EOF
-DWITH_FAST_BUNDLE_TEST
=
ON
\
-DCMAKE_MODULE_PATH
=
/opt/rocm/hip/cmake
\
-DWITH_FLUID_ONLY
=
${
WITH_FLUID_ONLY
:-
OFF
}
\
-DCMAKE_EXPORT_COMPILE_COMMANDS
=
ON
-DCMAKE_EXPORT_COMPILE_COMMANDS
=
ON
\
-DWITH_CONTRIB
=
ON
}
function
abort
(){
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录