Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
7bb12fdb
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7bb12fdb
编写于
3月 10, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor API follow comments.
上级
5a9987a3
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
314 addition
and
159 deletion
+314
-159
paddle/capi/Arguments.cpp
paddle/capi/Arguments.cpp
+20
-24
paddle/capi/GradientMachine.cpp
paddle/capi/GradientMachine.cpp
+14
-14
paddle/capi/Main.cpp
paddle/capi/Main.cpp
+1
-1
paddle/capi/Matrix.cpp
paddle/capi/Matrix.cpp
+7
-12
paddle/capi/PaddleCAPI.h
paddle/capi/PaddleCAPI.h
+245
-58
paddle/capi/Vector.cpp
paddle/capi/Vector.cpp
+9
-16
paddle/capi/tests/test_Arguments.cpp
paddle/capi/tests/test_Arguments.cpp
+11
-20
paddle/capi/tests/test_GradientMachine.cpp
paddle/capi/tests/test_GradientMachine.cpp
+3
-6
paddle/capi/tests/test_Matrix.cpp
paddle/capi/tests/test_Matrix.cpp
+2
-4
paddle/capi/tests/test_Vector.cpp
paddle/capi/tests/test_Vector.cpp
+2
-4
未找到文件。
paddle/capi/Arguments.cpp
浏览文件 @
7bb12fdb
...
...
@@ -21,31 +21,27 @@ using paddle::capi::cast;
#define castIVec(v) cast<paddle::capi::CIVector>(v)
extern
"C"
{
int
PDArgsCreateNone
(
PD_Arguments
*
args
)
{
auto
ptr
=
new
paddle
::
capi
::
CArguments
();
*
args
=
ptr
;
return
kPD_NO_ERROR
;
}
PD_Arguments
PDArgsCreateNone
()
{
return
new
paddle
::
capi
::
CArguments
();
}
int
PDArgsDestroy
(
PD_Arguments
args
)
{
PD_Error
PDArgsDestroy
(
PD_Arguments
args
)
{
if
(
args
==
nullptr
)
return
kPD_NULLPTR
;
delete
castArg
(
args
);
return
kPD_NO_ERROR
;
}
int
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
)
{
PD_Error
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
)
{
if
(
args
==
nullptr
||
size
==
nullptr
)
return
kPD_NULLPTR
;
*
size
=
castArg
(
args
)
->
args
.
size
();
return
kPD_NO_ERROR
;
}
int
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
)
{
PD_Error
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
)
{
if
(
args
==
nullptr
)
return
kPD_NULLPTR
;
castArg
(
args
)
->
args
.
resize
(
size
);
return
kPD_NO_ERROR
;
}
int
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
)
{
PD_Error
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
)
{
if
(
args
==
nullptr
||
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
m
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CMatrix
>
(
mat
);
if
(
m
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
...
...
@@ -55,7 +51,7 @@ int PDArgsSetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat) {
return
kPD_NO_ERROR
;
}
int
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
)
{
PD_Error
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
)
{
if
(
args
==
nullptr
||
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
m
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CMatrix
>
(
mat
);
auto
a
=
castArg
(
args
);
...
...
@@ -64,7 +60,7 @@ int PDArgsGetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat) {
return
kPD_NO_ERROR
;
}
int
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
)
{
PD_Error
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
)
{
if
(
args
==
nullptr
||
ids
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
ids
);
auto
a
=
castArg
(
args
);
...
...
@@ -73,7 +69,7 @@ int PDArgsGetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
return
kPD_NO_ERROR
;
}
int
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
)
{
PD_Error
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
)
{
//! TODO(lizhao): Complete this method.
if
(
args
==
nullptr
||
ids
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
ids
);
...
...
@@ -84,9 +80,9 @@ int PDArgsSetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
return
kPD_NO_ERROR
;
}
int
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
)
{
PD_Error
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_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
;
...
...
@@ -97,9 +93,9 @@ int PDArgsSetSequenceStartPos(PD_Arguments args,
return
kPD_NO_ERROR
;
}
int
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
)
{
PD_Error
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_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
;
...
...
@@ -110,9 +106,9 @@ int PDArgsSetSubSequenceStartPos(PD_Arguments args,
return
kPD_NO_ERROR
;
}
int
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
)
{
PD_Error
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
)
{
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
seqPos
);
auto
a
=
castArg
(
args
);
...
...
@@ -122,9 +118,9 @@ int PDArgsGetSequenceStartPos(PD_Arguments args,
return
kPD_NO_ERROR
;
}
int
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
)
{
PD_Error
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
)
{
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
subSeqPos
);
auto
a
=
castArg
(
args
);
...
...
paddle/capi/GradientMachine.cpp
浏览文件 @
7bb12fdb
...
...
@@ -38,9 +38,9 @@ NeuralNetwork* newCustomNerualNetwork(const std::string& name,
}
// namespace paddle
extern
"C"
{
int
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
)
{
PD_Error
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
)
{
if
(
modelConfigProtobuf
==
nullptr
)
return
kPD_NULLPTR
;
paddle
::
ModelConfig
config
;
if
(
!
config
.
ParseFromArray
(
modelConfigProtobuf
,
size
)
||
...
...
@@ -55,13 +55,13 @@ int PDGradientMachineCreateForPredict(PD_GradientMachine* machine,
return
kPD_NO_ERROR
;
}
int
PDGradientMachineDestroy
(
PD_GradientMachine
machine
)
{
PD_Error
PDGradientMachineDestroy
(
PD_GradientMachine
machine
)
{
delete
cast
(
machine
);
return
kPD_NO_ERROR
;
}
int
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
)
{
PD_Error
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
)
{
auto
m
=
cast
(
machine
);
if
(
m
==
nullptr
||
path
==
nullptr
||
m
->
machine
==
nullptr
)
return
kPD_NULLPTR
;
...
...
@@ -69,10 +69,10 @@ int PDGradientMachineLoadParameterFromDisk(PD_GradientMachine machine,
return
kPD_NO_ERROR
;
}
int
PDGradientMachineForward
(
PD_GradientMachine
machine
,
PD_Arguments
inArgs
,
PD_Arguments
outArgs
,
bool
isTrain
)
{
PD_Error
PDGradientMachineForward
(
PD_GradientMachine
machine
,
PD_Arguments
inArgs
,
PD_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 +83,10 @@ int PDGradientMachineForward(PD_GradientMachine machine,
return
kPD_NO_ERROR
;
}
int
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
PD_GradientMachine
*
slave
)
{
PD_Error
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
PD_GradientMachine
*
slave
)
{
auto
o
=
cast
(
origin
);
if
(
origin
==
nullptr
||
slave
==
nullptr
||
o
->
machine
==
nullptr
)
{
return
kPD_NULLPTR
;
...
...
paddle/capi/Main.cpp
浏览文件 @
7bb12fdb
...
...
@@ -29,7 +29,7 @@ static void initPaddle(int argc, char** argv) {
}
extern
"C"
{
int
PDInit
(
int
argc
,
char
**
argv
)
{
PD_Error
PDInit
(
int
argc
,
char
**
argv
)
{
std
::
vector
<
char
*>
realArgv
;
realArgv
.
reserve
(
argc
+
1
);
realArgv
.
push_back
(
strdup
(
""
));
...
...
paddle/capi/Matrix.cpp
浏览文件 @
7bb12fdb
...
...
@@ -18,27 +18,22 @@ limitations under the License. */
#define cast(v) paddle::capi::cast<paddle::capi::CMatrix>(v)
extern
"C"
{
int
PDMatCreate
(
PD_Matrix
*
mat
,
uint64_t
height
,
uint64_t
width
,
bool
useGpu
)
{
PD_Matrix
PDMatCreate
(
uint64_t
height
,
uint64_t
width
,
bool
useGpu
)
{
auto
ptr
=
new
paddle
::
capi
::
CMatrix
();
ptr
->
mat
=
paddle
::
Matrix
::
create
(
height
,
width
,
false
,
useGpu
);
*
mat
=
ptr
;
return
kPD_NO_ERROR
;
return
ptr
;
}
int
PDMatCreateNone
(
PD_Matrix
*
mat
)
{
auto
ptr
=
new
paddle
::
capi
::
CMatrix
();
*
mat
=
ptr
;
return
kPD_NO_ERROR
;
}
PD_Matrix
PDMatCreateNone
()
{
return
new
paddle
::
capi
::
CMatrix
();
}
int
PDMatDestroy
(
PD_Matrix
mat
)
{
PD_Error
PDMatDestroy
(
PD_Matrix
mat
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
cast
(
mat
);
delete
ptr
;
return
kPD_NO_ERROR
;
}
int
PDMatCopyToRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
*
rowArray
)
{
PD_Error
PDMatCopyToRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
*
rowArray
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
cast
(
mat
);
if
(
ptr
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
...
...
@@ -53,7 +48,7 @@ int PDMatCopyToRow(PD_Matrix mat, uint64_t rowID, pd_real* rowArray) {
return
kPD_NO_ERROR
;
}
int
PDMatGetRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
**
rawRowBuffer
)
{
PD_Error
PDMatGetRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
**
rawRowBuffer
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
cast
(
mat
);
if
(
ptr
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
...
...
@@ -62,7 +57,7 @@ int PDMatGetRow(PD_Matrix mat, uint64_t rowID, pd_real** rawRowBuffer) {
return
kPD_NO_ERROR
;
}
int
PDMatGetShape
(
PD_Matrix
mat
,
uint64_t
*
height
,
uint64_t
*
width
)
{
PD_Error
PDMatGetShape
(
PD_Matrix
mat
,
uint64_t
*
height
,
uint64_t
*
width
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
height
!=
nullptr
)
{
*
height
=
cast
(
mat
)
->
mat
->
getHeight
();
...
...
paddle/capi/PaddleCAPI.h
浏览文件 @
7bb12fdb
...
...
@@ -49,48 +49,115 @@ typedef enum {
*/
typedef
void
*
PD_IVector
;
PD_API
int
PDIVecCreateNone
(
PD_IVector
*
ivec
);
/**
* @brief Create an none int vector. It just a handler and store nothing. Used
* to get output from other api.
* @return None int vector.
*/
PD_API
PD_IVector
PDIVecCreateNone
();
/**
* @brief PDIVectorCreate create a paddle int vector
* @param
[out] ivec: output int vector
.
* @param
[in] array: input array
.
* @param
[in] size: input array size
.
* @param
[in] copy: memory copy or just use same memory. True if copy.
* @param
array: input array
.
* @param
size: input array size
.
* @param
copy: memory copy or just use same memory. True if copy
.
* @param
useGPU: True if use GPU
* @return PD_Error
*/
PD_API
int
PDIVectorCreate
(
PD_IVector
*
ivec
,
int
*
array
,
uint64_t
size
,
bool
copy
);
PD_API
PD_IVector
PDIVectorCreate
(
int
*
array
,
uint64_t
size
,
bool
copy
,
bool
useGPU
);
PD_API
int
PDIVecDestroy
(
PD_IVector
ivec
);
/**
* @brief PDIVecDestroy destory an int vector.
* @param ivec vector to be destoried.
* @return PD_Error
*/
PD_API
PD_Error
PDIVecDestroy
(
PD_IVector
ivec
);
PD_API
int
PDIVectorGet
(
PD_IVector
ivec
,
int
**
buffer
);
/**
* @brief PDIVectorGet get raw buffer stored inside this int vector. It could be
* GPU memory if this int vector is stored in GPU.
* @param [in] ivec int vector
* @param [out] buffer the return buffer pointer.
* @return PD_Error
*/
PD_API
PD_Error
PDIVectorGet
(
PD_IVector
ivec
,
int
**
buffer
);
PD_API
int
PDIVectorResize
(
PD_IVector
ivec
,
uint64_t
size
);
/**
* @brief PDIVectorResize resize the int vector.
* @param [in] ivec: int vector
* @param [in] size: size to change
* @return PD_Error
*/
PD_API
PD_Error
PDIVectorResize
(
PD_IVector
ivec
,
uint64_t
size
);
PD_API
int
PDIVectorGetSize
(
PD_IVector
ivec
,
uint64_t
*
size
);
/**
* @brief PDIVectorGetSize get the size of int vector.
* @param [in] ivec: int vector
* @param [out] size: return size of this int vector.
* @return PD_Error
*/
PD_API
PD_Error
PDIVectorGetSize
(
PD_IVector
ivec
,
uint64_t
*
size
);
/**
* Matrix functions. Return will be a PD_Error type.
*/
typedef
void
*
PD_Matrix
;
PD_API
int
PDMatCreate
(
PD_Matrix
*
mat
,
uint64_t
height
,
uint64_t
width
,
bool
useGpu
);
/**
* @brief PDMatCreate Create a dense matrix
* @param height matrix height.
* @param width matrix width
* @param useGpu use GPU of not
* @return Matrix handler
*/
PD_API
PD_Matrix
PDMatCreate
(
uint64_t
height
,
uint64_t
width
,
bool
useGpu
);
PD_API
int
PDMatDestroy
(
PD_Matrix
mat
);
/**
* @brief PDMatDestroy Destroy a matrix.
* @param mat
* @return PD_Error
*/
PD_API
PD_Error
PDMatDestroy
(
PD_Matrix
mat
);
PD_API
int
PDMatCopyToRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
*
rowArray
);
/**
* @brief PDMatCopyToRow Copy a row to matrix.
* @param mat Target Matrix
* @param rowID Index of row
* @param rowArray Row data.
* @return PD_Error
*/
PD_API
PD_Error
PDMatCopyToRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
*
rowArray
);
PD_API
int
PDMatGetRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
**
rawRowBuffer
);
/**
* @brief PDMatGetRow Get raw row buffer from matrix
* @param [in] mat Target matrix
* @param [in] rowID Index of row.
* @param [out] rawRowBuffer Row Buffer
* @return PD_Error
*/
PD_API
PD_Error
PDMatGetRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
**
rawRowBuffer
);
PD_API
int
PDMatCreateNone
(
PD_Matrix
*
mat
);
/**
* @brief PDMatCreateNone Create None Matrix
* @return
*/
PD_API
PD_Matrix
PDMatCreateNone
();
PD_API
int
PDMatGetShape
(
PD_Matrix
mat
,
uint64_t
*
height
,
uint64_t
*
width
);
/**
* @brief PDMatGetShape get the shape of matrix
* @param mat target matrix
* @param height The height of matrix
* @param width The width of matrix
* @return PD_Error
*/
PD_API
PD_Error
PDMatGetShape
(
PD_Matrix
mat
,
uint64_t
*
height
,
uint64_t
*
width
);
/**
* Arguments functions. Each argument means layer output. Arguments means a
...
...
@@ -98,65 +165,185 @@ PD_API int PDMatGetShape(PD_Matrix mat, uint64_t* height, uint64_t* width);
*/
typedef
void
*
PD_Arguments
;
PD_API
int
PDArgsCreateNone
(
PD_Arguments
*
args
);
PD_API
int
PDArgsDestroy
(
PD_Arguments
args
);
/**
* @brief PDArgsCreateNone Create a array of arguments, which size is zero.
* @return Arguemnts
*/
PD_API
PD_Arguments
PDArgsCreateNone
();
PD_API
int
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
);
/**
* @brief PDArgsDestroy Destroy the arguments
* @param args arguments to destroy
* @return PD_Error
*/
PD_API
PD_Error
PDArgsDestroy
(
PD_Arguments
args
);
PD_API
int
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
);
/**
* @brief PDArgsGetSize Get size of arguments array
* @param [in] args arguments array
* @param [out] size array size
* @return PD_Error
*/
PD_API
PD_Error
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
);
PD_API
int
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
);
/**
* @brief PDArgsResize Resize a arguments array.
* @param args arguments array.
* @param size target size of array
* @return PD_Error
*/
PD_API
PD_Error
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
);
PD_API
int
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
);
PD_API
int
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
);
PD_API
int
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
);
PD_API
int
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
);
PD_API
int
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_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 PD_Error
*/
PD_API
PD_Error
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
);
PD_API
int
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
);
PD_API
int
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_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 PD_Error
*/
PD_API
PD_Error
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
);
/**
* @brief GradientMachine means a neural network.
*/
typedef
void
*
PD_GradientMachine
;
PD_API
int
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
);
PD_API
int
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
);
/**
* @brief PDGradientMachineLoadParameterFromDisk Load parameter from disk.
* @param machine Gradient Machine.
* @param path local directory path.
* @return PD_Error
*/
PD_API
PD_Error
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
);
PD_API
int
PDGradientMachineForward
(
PD_GradientMachine
machine
,
PD_Arguments
inArgs
,
PD_Arguments
outArgs
,
bool
isTrain
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDGradientMachineForward
(
PD_GradientMachine
machine
,
PD_Arguments
inArgs
,
PD_Arguments
outArgs
,
bool
isTrain
);
PD_API
int
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
PD_GradientMachine
*
slave
);
/**
* @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 PD_Error
*/
PD_API
PD_Error
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
void
*
modelConfigProtobuf
,
int
size
,
PD_GradientMachine
*
slave
);
PD_API
int
PDGradientMachineDestroy
(
PD_GradientMachine
machine
);
/**
* @brief PDGradientMachineDestroy Destroy a gradient machine
* @param machine that need to destroy
* @return PD_Error
*/
PD_API
PD_Error
PDGradientMachineDestroy
(
PD_GradientMachine
machine
);
/**
* Initialize Paddle.
*/
PD_API
int
PDInit
(
int
argc
,
char
**
argv
);
PD_API
PD_Error
PDInit
(
int
argc
,
char
**
argv
);
#ifdef __cplusplus
}
...
...
paddle/capi/Vector.cpp
浏览文件 @
7bb12fdb
...
...
@@ -19,33 +19,26 @@ using paddle::capi::cast;
extern
"C"
{
int
PDIVecCreateNone
(
PD_IVector
*
ivec
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
new
paddle
::
capi
::
CIVector
();
*
ivec
=
ptr
;
return
kPD_NO_ERROR
;
}
PD_IVector
PDIVecCreateNone
()
{
return
new
paddle
::
capi
::
CIVector
();
}
int
PDIVectorCreate
(
PD_IVector
*
ivec
,
int
*
array
,
uint64_t
size
,
bool
copy
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
PD_IVector
PDIVectorCreate
(
int
*
array
,
uint64_t
size
,
bool
copy
,
bool
useGPU
)
{
auto
ptr
=
new
paddle
::
capi
::
CIVector
();
if
(
copy
)
{
ptr
->
vec
=
paddle
::
IVector
::
create
(
size
,
false
);
ptr
->
vec
=
paddle
::
IVector
::
create
(
size
,
useGPU
);
ptr
->
vec
->
copyFrom
(
array
,
size
);
}
else
{
ptr
->
vec
=
paddle
::
IVector
::
create
(
array
,
size
,
false
);
ptr
->
vec
=
paddle
::
IVector
::
create
(
array
,
size
,
useGPU
);
}
*
ivec
=
ptr
;
return
kPD_NO_ERROR
;
return
ptr
;
}
int
PDIVecDestroy
(
PD_IVector
ivec
)
{
PD_Error
PDIVecDestroy
(
PD_IVector
ivec
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
delete
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
return
kPD_NO_ERROR
;
}
int
PDIVectorGet
(
PD_IVector
ivec
,
int
**
buffer
)
{
PD_Error
PDIVectorGet
(
PD_IVector
ivec
,
int
**
buffer
)
{
if
(
ivec
==
nullptr
||
buffer
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
...
@@ -53,7 +46,7 @@ int PDIVectorGet(PD_IVector ivec, int** buffer) {
return
kPD_NO_ERROR
;
}
int
PDIVectorResize
(
PD_IVector
ivec
,
uint64_t
size
)
{
PD_Error
PDIVectorResize
(
PD_IVector
ivec
,
uint64_t
size
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
...
@@ -61,7 +54,7 @@ int PDIVectorResize(PD_IVector ivec, uint64_t size) {
return
kPD_NO_ERROR
;
}
int
PDIVectorGetSize
(
PD_IVector
ivec
,
uint64_t
*
size
)
{
PD_Error
PDIVectorGetSize
(
PD_IVector
ivec
,
uint64_t
*
size
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
...
paddle/capi/tests/test_Arguments.cpp
浏览文件 @
7bb12fdb
...
...
@@ -28,8 +28,7 @@ static std::vector<pd_real> randomBuffer(size_t bufSize) {
}
TEST
(
CAPIArguments
,
create
)
{
PD_Arguments
args
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
args
));
PD_Arguments
args
=
PDArgsCreateNone
();
uint64_t
size
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetSize
(
args
,
&
size
));
ASSERT_EQ
(
0UL
,
size
);
...
...
@@ -37,20 +36,17 @@ TEST(CAPIArguments, create) {
}
TEST
(
CAPIArguments
,
value
)
{
PD_Arguments
args
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
args
));
PD_Arguments
args
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_Matrix
mat
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatCreate
(
&
mat
,
128
,
64
,
false
));
PD_Matrix
mat
=
PDMatCreate
(
128
,
64
,
false
);
for
(
size_t
i
=
0
;
i
<
128
;
++
i
)
{
std
::
vector
<
pd_real
>
sampleBuf
=
randomBuffer
(
64
);
PDMatCopyToRow
(
mat
,
i
,
sampleBuf
.
data
());
}
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetValue
(
args
,
0
,
mat
));
PD_Matrix
val
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatCreateNone
(
&
val
));
PD_Matrix
val
=
PDMatCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetValue
(
args
,
0
,
val
));
...
...
@@ -63,8 +59,7 @@ TEST(CAPIArguments, value) {
ASSERT_EQ
(
row1
,
row2
);
}
PD_IVector
ivec
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
ivec
));
PD_IVector
ivec
=
PDIVecCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatDestroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatDestroy
(
mat
));
...
...
@@ -72,17 +67,15 @@ TEST(CAPIArguments, value) {
}
TEST
(
CAPIArguments
,
ids
)
{
PD_Arguments
args
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
args
));
PD_Arguments
args
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_IVector
ivec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
ivec
,
array
,
3
,
true
)
);
ivec
=
PDIVectorCreate
(
array
,
3
,
true
,
false
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetIds
(
args
,
0
,
ivec
));
PD_IVector
val
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
val
));
PD_IVector
val
=
PDIVecCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetIds
(
args
,
0
,
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
val
));
...
...
@@ -91,17 +84,15 @@ TEST(CAPIArguments, ids) {
template
<
typename
T1
,
typename
T2
>
void
testSequenceHelper
(
T1
setter
,
T2
getter
)
{
PD_Arguments
args
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
args
));
PD_Arguments
args
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_IVector
ivec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
ivec
,
array
,
3
,
true
)
);
ivec
=
PDIVectorCreate
(
array
,
3
,
true
,
false
);
ASSERT_EQ
(
kPD_NO_ERROR
,
setter
(
args
,
0
,
ivec
));
PD_IVector
val
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
val
));
PD_IVector
val
=
PDIVecCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
getter
(
args
,
0
,
val
));
uint64_t
size
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorGetSize
(
val
,
&
size
));
...
...
paddle/capi/tests/test_GradientMachine.cpp
浏览文件 @
7bb12fdb
...
...
@@ -55,14 +55,11 @@ TEST(GradientMachine, testPredict) {
PDGradientMachineCreateSharedParam
(
machine
,
&
buffer
[
0
],
(
int
)
buffer
.
size
(),
&
machineSlave
));
std
::
swap
(
machineSlave
,
machine
);
PD_Arguments
outArgs
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
outArgs
));
PD_Arguments
outArgs
=
PDArgsCreateNone
();
PD_Arguments
inArgs
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
inArgs
));
PD_Arguments
inArgs
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
inArgs
,
1
));
PD_Matrix
mat
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatCreate
(
&
mat
,
1
,
100
,
false
));
PD_Matrix
mat
=
PDMatCreate
(
1
,
100
,
false
);
static_assert
(
std
::
is_same
<
pd_real
,
paddle
::
real
>::
value
,
""
);
auto
data
=
randomBuffer
(
100
);
...
...
paddle/capi/tests/test_Matrix.cpp
浏览文件 @
7bb12fdb
...
...
@@ -16,8 +16,7 @@ limitations under the License. */
#include "gtest/gtest.h"
TEST
(
CAPIMatrix
,
create
)
{
PD_Matrix
mat
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatCreate
(
&
mat
,
128
,
32
,
false
));
PD_Matrix
mat
=
PDMatCreate
(
128
,
32
,
false
);
std
::
vector
<
pd_real
>
sampleRow
;
sampleRow
.
resize
(
32
);
for
(
size_t
i
=
0
;
i
<
sampleRow
.
size
();
++
i
)
{
...
...
@@ -41,7 +40,6 @@ TEST(CAPIMatrix, create) {
}
TEST
(
CAPIMatrix
,
createNone
)
{
PD_Matrix
mat
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatCreateNone
(
&
mat
));
PD_Matrix
mat
=
PDMatCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatDestroy
(
mat
));
}
paddle/capi/tests/test_Vector.cpp
浏览文件 @
7bb12fdb
...
...
@@ -18,8 +18,7 @@ limitations under the License. */
TEST
(
CAPIVector
,
create
)
{
PD_IVector
vec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
vec
,
array
,
3
,
true
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
vec
,
array
,
3
,
false
));
vec
=
PDIVectorCreate
(
array
,
3
,
true
,
false
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorResize
(
vec
,
1000
));
uint64_t
size
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorGetSize
(
vec
,
&
size
));
...
...
@@ -27,7 +26,6 @@ TEST(CAPIVector, create) {
}
TEST
(
CAPIVector
,
createNone
)
{
PD_IVector
vec
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
vec
));
PD_IVector
vec
=
PDIVecCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
vec
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录