Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏有凉风,冬有雪
Paddle
提交
c5eac0ab
P
Paddle
项目概览
夏有凉风,冬有雪
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c5eac0ab
编写于
3月 24, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename API
上级
0afd5c30
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
310 addition
and
270 deletion
+310
-270
paddle/capi/Arguments.cpp
paddle/capi/Arguments.cpp
+10
-34
paddle/capi/Main.cpp
paddle/capi/Main.cpp
+1
-1
paddle/capi/PaddleCAPI.h
paddle/capi/PaddleCAPI.h
+7
-208
paddle/capi/PaddleCAPIPrivate.h
paddle/capi/PaddleCAPIPrivate.h
+16
-0
paddle/capi/arguments.h
paddle/capi/arguments.h
+130
-0
paddle/capi/error.h
paddle/capi/error.h
+14
-0
paddle/capi/gradient_machine.cpp
paddle/capi/gradient_machine.cpp
+14
-14
paddle/capi/gradient_machine.h
paddle/capi/gradient_machine.h
+74
-0
paddle/capi/main.h
paddle/capi/main.h
+19
-0
paddle/capi/tests/test_Arguments.cpp
paddle/capi/tests/test_Arguments.cpp
+16
-4
paddle/capi/tests/test_GradientMachine.cpp
paddle/capi/tests/test_GradientMachine.cpp
+9
-9
未找到文件。
paddle/capi/Arguments.cpp
浏览文件 @
c5eac0ab
...
...
@@ -12,8 +12,8 @@ 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 "PaddleCAPI.h"
#include "PaddleCAPIPrivate.h"
#include "arguments.h"
using
paddle
::
capi
::
cast
;
...
...
@@ -92,50 +92,26 @@ paddle_error paddle_arguments_set_ids(paddle_arguments args,
paddle_error
paddle_arguments_set_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
uint32_t
nestedLevel
,
paddle_ivector
seqPos
)
{
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
seqPos
);
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
a
->
args
[
ID
].
sequenceStartPositions
=
std
::
make_shared
<
paddle
::
ICpuGpuVector
>
(
iv
->
vec
);
return
kPD_NO_ERROR
;
}
paddle_error
paddle_arguments_set_sub_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
subSeqPos
)
{
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
subSeqPos
);
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
a
->
args
[
ID
].
subSequenceStartPositions
=
std
::
make_shared
<
paddle
::
ICpuGpuVector
>
(
iv
->
vec
);
return
kPD_NO_ERROR
;
return
a
->
accessSeqPos
(
ID
,
nestedLevel
,
[
&
iv
](
paddle
::
ICpuGpuVectorPtr
&
ptr
)
{
ptr
=
std
::
make_shared
<
paddle
::
ICpuGpuVector
>
(
iv
->
vec
);
});
}
paddle_error
paddle_arguments_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
uint32_t
nestedLevel
,
paddle_ivector
seqPos
)
{
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
seqPos
);
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
paddle
::
Argument
&
arg
=
a
->
args
[
ID
];
iv
->
vec
=
arg
.
sequenceStartPositions
->
getMutableVector
(
false
);
return
kPD_NO_ERROR
;
}
paddle_error
paddle_arguments_sub_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
subSeqPos
)
{
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
subSeqPos
);
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
seqPos
);
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
paddle
::
Argument
&
arg
=
a
->
args
[
ID
];
iv
->
vec
=
arg
.
subSequenceStartPositions
->
getMutableVector
(
false
);
return
kPD_NO_ERROR
;
return
a
->
accessSeqPos
(
ID
,
nestedLevel
,
[
&
iv
](
paddle
::
ICpuGpuVectorPtr
&
ptr
)
{
iv
->
vec
=
ptr
->
getMutableVector
(
false
);
});
}
}
paddle/capi/Main.cpp
浏览文件 @
c5eac0ab
...
...
@@ -29,7 +29,7 @@ static void initPaddle(int argc, char** argv) {
}
extern
"C"
{
paddle_error
PDI
nit
(
int
argc
,
char
**
argv
)
{
paddle_error
paddle_i
nit
(
int
argc
,
char
**
argv
)
{
std
::
vector
<
char
*>
realArgv
;
realArgv
.
reserve
(
argc
+
1
);
realArgv
.
push_back
(
strdup
(
""
));
...
...
paddle/capi/PaddleCAPI.h
浏览文件 @
c5eac0ab
...
...
@@ -14,16 +14,6 @@ limitations under the License. */
#ifndef PADDLECAPI_H_
#define PADDLECAPI_H_
#include <stdbool.h>
#include <stdint.h>
#include "config.h"
#include "error.h"
#include "matrix.h"
#include "vector.h"
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* Paddle C API. It will replace SWIG as Multiple Language API for model
...
...
@@ -31,203 +21,12 @@ extern "C" {
*
* NOTE: This is an experimental API, it could be changed.
*/
/**
* Arguments functions. Each argument means layer output. Arguments means a
* array of arguemnt.
*/
typedef
void
*
paddle_arguments
;
/**
* @brief paddle_arguments_create_none Create a array of arguments, which size
* is zero.
* @return Arguemnts
*/
PD_API
paddle_arguments
paddle_arguments_create_none
();
/**
* @brief paddle_arguments_destroy Destroy the arguments
* @param args arguments to destroy
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_destroy
(
paddle_arguments
args
);
/**
* @brief PDArgsGetSize Get size of arguments array
* @param [in] args arguments array
* @param [out] size array size
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_size
(
paddle_arguments
args
,
uint64_t
*
size
);
/**
* @brief PDArgsResize Resize a arguments array.
* @param args arguments array.
* @param size target size of array
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_resize
(
paddle_arguments
args
,
uint64_t
size
);
/**
* @brief PDArgsSetValue Set value matrix of one argument in array, which index
* is `ID`.
* @param args arguments array
* @param ID array index
* @param mat matrix pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_value
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_matrix
mat
);
/**
* @brief PDArgsGetValue Get value matrix of one argument in array, which index
* is `ID`.
* @param [in] args arguments array
* @param [in] ID array index
* @param [out] mat matrix pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_value
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_matrix
mat
);
/**
* @brief PDArgsGetIds Get the integer vector of one argument in array, which
* index is `ID`.
* @param args arguments array
* @param ID array index
* @param ids integer vector pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_ids
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
ids
);
/**
* @brief PDArgsSetIds Set the integer vector of one argument in array, which
* index is `ID`.
* @param [in] args arguments array
* @param [in] ID array index
* @param [out] ids integer vector pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_ids
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
ids
);
/**
* @brief PDArgsSetSequenceStartPos Set sequence start position vector of one
* argument in array, which index is `ID`.
* @param args arguments array
* @param ID array index
* @param seqPos sequence position array.
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
seqPos
);
/**
* @brief PDArgsGetSequenceStartPos Get sequence start position vector of one
* argument in array, which index is `ID`.
* @param [in] args arguments array
* @param [in] ID array index
* @param [out] seqPos sequence position array
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
seqPos
);
/**
* @brief PDArgsSetSubSequenceStartPos Set sub-sequence start position vector of
* one argument in array, which index is `ID`.
* @param args arguments array
* @param ID array index
* @param subSeqPos sub-sequence start position array.
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_sub_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
subSeqPos
);
/**
* @brief PDArgsGetSubSequenceStartPos Get sub-sequence start position vector of
* one argument in array, which index is `ID`.
* @param args arguments array
* @param ID array index
* @param subSeqPos sub-sequence start position array
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_sub_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
subSeqPos
);
/**
* @brief GradientMachine means a neural network.
*/
typedef
void
*
PD_GradientMachine
;
/**
* @brief PDGradientMachineCreateForPredict Create a gradient machine used for
* model inference.
* @param [out] machine that used for model inference.
* @param [in] modelConfigProtobuf
* @param [in] size
* @return paddle_error
*/
PD_API
paddle_error
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
);
/**
* @brief PDGradientMachineLoadParameterFromDisk Load parameter from disk.
* @param machine Gradient Machine.
* @param path local directory path.
* @return paddle_error
*/
PD_API
paddle_error
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
);
/**
* @brief PDGradientMachineForward Forward a gradient machine
* @param machine Gradient machine
* @param inArgs input arguments
* @param outArgs output arguments
* @param isTrain is train or not
* @return paddle_error
*/
PD_API
paddle_error
PDGradientMachineForward
(
PD_GradientMachine
machine
,
paddle_arguments
inArgs
,
paddle_arguments
outArgs
,
bool
isTrain
);
/**
* @brief PDGradientMachineCreateSharedParam Create a gradient machine, which
* parameters are shared from another gradient machine.
* @param [in] origin gradient machine
* @param [in] modelConfigProtobuf model config protobuf
* @param [in] size of model config buffer.
* @param [out] slave gradient machine, the output value.
* @return paddle_error
*/
PD_API
paddle_error
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
PD_GradientMachine
*
slave
);
/**
* @brief PDGradientMachineDestroy Destroy a gradient machine
* @param machine that need to destroy
* @return paddle_error
*/
PD_API
paddle_error
PDGradientMachineDestroy
(
PD_GradientMachine
machine
);
/**
* Initialize Paddle.
*/
PD_API
paddle_error
PDInit
(
int
argc
,
char
**
argv
);
#ifdef __cplusplus
}
#endif
#include "arguments.h"
#include "config.h"
#include "error.h"
#include "gradient_machine.h"
#include "main.h"
#include "matrix.h"
#include "vector.h"
#endif // PADDLECAPI_H_
paddle/capi/PaddleCAPIPrivate.h
浏览文件 @
c5eac0ab
...
...
@@ -49,6 +49,22 @@ struct CArguments {
std
::
vector
<
paddle
::
Argument
>
args
;
CArguments
()
:
type
(
kARGUMENTS
)
{}
template
<
typename
T
>
paddle_error
accessSeqPos
(
uint64_t
ID
,
uint32_t
nestedLevel
,
T
callback
)
{
if
(
ID
>=
args
.
size
())
return
kPD_OUT_OF_RANGE
;
switch
(
nestedLevel
)
{
case
0
:
callback
(
args
[
ID
].
sequenceStartPositions
);
break
;
case
1
:
callback
(
args
[
ID
].
subSequenceStartPositions
);
break
;
default:
return
kPD_OUT_OF_RANGE
;
}
return
kPD_NO_ERROR
;
}
};
struct
CGradientMachine
{
...
...
paddle/capi/arguments.h
0 → 100644
浏览文件 @
c5eac0ab
#ifndef __PADDLE_CAPI_ARGUMENTS_H__
#define __PADDLE_CAPI_ARGUMENTS_H__
#include <stdint.h>
#include "config.h"
#include "error.h"
#include "matrix.h"
#include "vector.h"
/**
* Arguments functions. Each argument means layer output. Arguments means a
* array of arguemnt.
*/
typedef
void
*
paddle_arguments
;
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @brief paddle_arguments_create_none Create a array of arguments, which size
* is zero.
* @return Arguemnts
*/
PD_API
paddle_arguments
paddle_arguments_create_none
();
/**
* @brief paddle_arguments_destroy Destroy the arguments
* @param args arguments to destroy
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_destroy
(
paddle_arguments
args
);
/**
* @brief PDArgsGetSize Get size of arguments array
* @param [in] args arguments array
* @param [out] size array size
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_size
(
paddle_arguments
args
,
uint64_t
*
size
);
/**
* @brief PDArgsResize Resize a arguments array.
* @param args arguments array.
* @param size target size of array
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_resize
(
paddle_arguments
args
,
uint64_t
size
);
/**
* @brief PDArgsSetValue Set value matrix of one argument in array, which index
* is `ID`.
* @param args arguments array
* @param ID array index
* @param mat matrix pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_value
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_matrix
mat
);
/**
* @brief PDArgsGetValue Get value matrix of one argument in array, which index
* is `ID`.
* @param [in] args arguments array
* @param [in] ID array index
* @param [out] mat matrix pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_value
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_matrix
mat
);
/**
* @brief PDArgsGetIds Get the integer vector of one argument in array, which
* index is `ID`.
* @param args arguments array
* @param ID array index
* @param ids integer vector pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_ids
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
ids
);
/**
* @brief PDArgsSetIds Set the integer vector of one argument in array, which
* index is `ID`.
* @param [in] args arguments array
* @param [in] ID array index
* @param [out] ids integer vector pointer
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_ids
(
paddle_arguments
args
,
uint64_t
ID
,
paddle_ivector
ids
);
/**
* @brief PDArgsSetSequenceStartPos Set sequence start position vector of one
* argument in array, which index is `ID`.
* @param args arguments array
* @param ID array index
* @param seqPos sequence position array.
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
uint32_t
nestedLevel
,
paddle_ivector
seqPos
);
/**
* @brief PDArgsGetSequenceStartPos Get sequence start position vector of one
* argument in array, which index is `ID`.
* @param [in] args arguments array
* @param [in] ID array index
* @param [out] seqPos sequence position array
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
uint32_t
nestedLevel
,
paddle_ivector
seqPos
);
#ifdef __cplusplus
}
#endif
#endif
paddle/capi/error.h
浏览文件 @
c5eac0ab
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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. */
#ifndef __PADDLE_CAPI_ERROR_H__
#define __PADDLE_CAPI_ERROR_H__
...
...
paddle/capi/
GradientM
achine.cpp
→
paddle/capi/
gradient_m
achine.cpp
浏览文件 @
c5eac0ab
...
...
@@ -38,9 +38,8 @@ NeuralNetwork* newCustomNerualNetwork(const std::string& name,
}
// namespace paddle
extern
"C"
{
paddle_error
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
)
{
paddle_error
paddle_gradient_machine_create_for_inference
(
paddle_gradient_machine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
)
{
if
(
modelConfigProtobuf
==
nullptr
)
return
kPD_NULLPTR
;
paddle
::
ModelConfig
config
;
if
(
!
config
.
ParseFromArray
(
modelConfigProtobuf
,
size
)
||
...
...
@@ -55,13 +54,13 @@ paddle_error PDGradientMachineCreateForPredict(PD_GradientMachine* machine,
return
kPD_NO_ERROR
;
}
paddle_error
PDGradientMachineDestroy
(
PD_GradientM
achine
machine
)
{
paddle_error
paddle_gradient_machine_destroy
(
paddle_gradient_m
achine
machine
)
{
delete
cast
(
machine
);
return
kPD_NO_ERROR
;
}
paddle_error
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
)
{
paddle_error
paddle_gradient_machine_load_parameter_from_disk
(
paddle_gradient_machine
machine
,
const
char
*
path
)
{
auto
m
=
cast
(
machine
);
if
(
m
==
nullptr
||
path
==
nullptr
||
m
->
machine
==
nullptr
)
return
kPD_NULLPTR
;
...
...
@@ -69,10 +68,10 @@ paddle_error PDGradientMachineLoadParameterFromDisk(PD_GradientMachine machine,
return
kPD_NO_ERROR
;
}
paddle_error
PDGradientMachineForward
(
PD_GradientM
achine
machine
,
paddle_arguments
inArgs
,
paddle_arguments
outArgs
,
bool
isTrain
)
{
paddle_error
paddle_gradient_machine_forward
(
paddle_gradient_m
achine
machine
,
paddle_arguments
inArgs
,
paddle_arguments
outArgs
,
bool
isTrain
)
{
auto
m
=
cast
(
machine
);
auto
in
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CArguments
>
(
inArgs
);
auto
out
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CArguments
>
(
outArgs
);
...
...
@@ -83,10 +82,11 @@ paddle_error PDGradientMachineForward(PD_GradientMachine machine,
return
kPD_NO_ERROR
;
}
paddle_error
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
PD_GradientMachine
*
slave
)
{
paddle_error
paddle_gradient_machine_create_shared_param
(
paddle_gradient_machine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
paddle_gradient_machine
*
slave
)
{
auto
o
=
cast
(
origin
);
if
(
origin
==
nullptr
||
slave
==
nullptr
||
o
->
machine
==
nullptr
)
{
return
kPD_NULLPTR
;
...
...
paddle/capi/gradient_machine.h
0 → 100644
浏览文件 @
c5eac0ab
#ifndef __PADDLE_CAPI_GRADIENT_MACHINE_H__
#define __PADDLE_CAPI_GRADIENT_MACHINE_H__
#include "arguments.h"
#include "config.h"
#include "error.h"
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @brief GradientMachine means a neural network.
*/
typedef
void
*
paddle_gradient_machine
;
/**
* @brief Create a gradient machine used for model inference.
* @param [out] machine that used for model inference.
* @param [in] modelConfigProtobuf
* @param [in] size
* @return paddle_error
*/
PD_API
paddle_error
paddle_gradient_machine_create_for_inference
(
paddle_gradient_machine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
);
/**
* @brief Load parameter from disk.
* @param machine Gradient Machine.
* @param path local directory path.
* @return paddle_error
*/
PD_API
paddle_error
paddle_gradient_machine_load_parameter_from_disk
(
paddle_gradient_machine
machine
,
const
char
*
path
);
/**
* @brief Forward a gradient machine
* @param machine Gradient machine
* @param inArgs input arguments
* @param outArgs output arguments
* @param isTrain is train or not
* @return paddle_error
*/
PD_API
paddle_error
paddle_gradient_machine_forward
(
paddle_gradient_machine
machine
,
paddle_arguments
inArgs
,
paddle_arguments
outArgs
,
bool
isTrain
);
/**
* @brief Create a gradient machine, which parameters are shared from another
* gradient machine.
* @param [in] origin gradient machine
* @param [in] modelConfigProtobuf model config protobuf
* @param [in] size of model config buffer.
* @param [out] slave gradient machine, the output value.
* @return paddle_error
*/
PD_API
paddle_error
paddle_gradient_machine_create_shared_param
(
paddle_gradient_machine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
paddle_gradient_machine
*
slave
);
/**
* @brief Destroy a gradient machine
* @param machine that need to destroy
* @return paddle_error
*/
PD_API
paddle_error
paddle_gradient_machine_destroy
(
paddle_gradient_machine
machine
);
#ifdef __cplusplus
}
#endif
#endif
paddle/capi/main.h
0 → 100644
浏览文件 @
c5eac0ab
#ifndef __PADDLE_CAPI_MAIN_H__
#define __PADDLE_CAPI_MAIN_H__
#include "config.h"
#include "error.h"
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* Initialize Paddle.
*/
PD_API
paddle_error
paddle_init
(
int
argc
,
char
**
argv
);
#ifdef __cplusplus
}
#endif
#endif
paddle/capi/tests/test_Arguments.cpp
浏览文件 @
c5eac0ab
...
...
@@ -12,6 +12,7 @@ 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 <functional>
#include "PaddleCAPI.h"
#include "gtest/gtest.h"
#include "paddle/utils/ThreadLocal.h"
...
...
@@ -109,8 +110,19 @@ void testSequenceHelper(T1 setter, T2 getter) {
}
TEST
(
CAPIArguments
,
Sequence
)
{
testSequenceHelper
(
paddle_arguments_set_sequence_start_pos
,
paddle_arguments_sequence_start_pos
);
testSequenceHelper
(
paddle_arguments_set_sub_sequence_start_pos
,
paddle_arguments_sub_sequence_start_pos
);
auto
testSequence
=
[](
uint32_t
nestedLevel
)
{
testSequenceHelper
(
std
::
bind
(
paddle_arguments_set_sequence_start_pos
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
,
nestedLevel
,
std
::
placeholders
::
_3
),
std
::
bind
(
paddle_arguments_sequence_start_pos
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
,
nestedLevel
,
std
::
placeholders
::
_3
));
};
for
(
uint32_t
i
=
0
;
i
<
2
;
++
i
)
{
// test seq and sub-seq.
testSequence
(
i
);
}
}
paddle/capi/tests/test_GradientMachine.cpp
浏览文件 @
c5eac0ab
...
...
@@ -36,10 +36,10 @@ TEST(GradientMachine, testPredict) {
paddle
::
TrainerConfigHelper
config
(
"./test_predict_network.py"
);
std
::
string
buffer
;
ASSERT_TRUE
(
config
.
getModelConfig
().
SerializeToString
(
&
buffer
));
PD_GradientM
achine
machine
;
paddle_gradient_m
achine
machine
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDGradientMachineCreateForPredict
(
paddle_gradient_machine_create_for_inference
(
&
machine
,
&
buffer
[
0
],
(
int
)
buffer
.
size
()));
std
::
unique_ptr
<
paddle
::
GradientMachine
>
gm
(
paddle
::
GradientMachine
::
create
(
config
.
getModelConfig
()));
...
...
@@ -48,11 +48,11 @@ TEST(GradientMachine, testPredict) {
gm
->
saveParameters
(
"./"
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDGradientMachineLoadParameterFromD
isk
(
machine
,
"./"
));
paddle_gradient_machine_load_parameter_from_d
isk
(
machine
,
"./"
));
PD_GradientM
achine
machineSlave
;
paddle_gradient_m
achine
machineSlave
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDGradientMachineCreateSharedP
aram
(
paddle_gradient_machine_create_shared_p
aram
(
machine
,
&
buffer
[
0
],
(
int
)
buffer
.
size
(),
&
machineSlave
));
std
::
swap
(
machineSlave
,
machine
);
paddle_arguments
outArgs
=
paddle_arguments_create_none
();
...
...
@@ -69,7 +69,7 @@ TEST(GradientMachine, testPredict) {
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_arguments_set_value
(
inArgs
,
0
,
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDGradientMachineF
orward
(
machine
,
inArgs
,
outArgs
,
false
));
paddle_gradient_machine_f
orward
(
machine
,
inArgs
,
outArgs
,
false
));
uint64_t
sz
;
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_arguments_size
(
outArgs
,
&
sz
));
...
...
@@ -100,15 +100,15 @@ TEST(GradientMachine, testPredict) {
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_arguments_destroy
(
inArgs
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_arguments_destroy
(
outArgs
));
std
::
swap
(
machineSlave
,
machine
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDGradientMachineD
estroy
(
machineSlave
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDGradientMachineD
estroy
(
machine
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_gradient_machine_d
estroy
(
machineSlave
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_gradient_machine_d
estroy
(
machine
));
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
std
::
vector
<
char
*>
argvs
;
argvs
.
push_back
(
strdup
(
"--use_gpu=false"
));
PDI
nit
((
int
)
argvs
.
size
(),
argvs
.
data
());
paddle_i
nit
((
int
)
argvs
.
size
(),
argvs
.
data
());
for
(
auto
each
:
argvs
)
{
free
(
each
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录