Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b5288289
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看板
提交
b5288289
编写于
3月 21, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename some API to C-Style
上级
08113b20
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
366 addition
and
270 deletion
+366
-270
paddle/capi/Arguments.cpp
paddle/capi/Arguments.cpp
+19
-19
paddle/capi/CMakeLists.txt
paddle/capi/CMakeLists.txt
+4
-4
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
+16
-6
paddle/capi/PaddleCAPI.h
paddle/capi/PaddleCAPI.h
+60
-179
paddle/capi/Vector.cpp
paddle/capi/Vector.cpp
+11
-6
paddle/capi/config.h.in
paddle/capi/config.h.in
+4
-0
paddle/capi/error.h
paddle/capi/error.h
+15
-0
paddle/capi/matrix.h
paddle/capi/matrix.h
+91
-0
paddle/capi/tests/test_Arguments.cpp
paddle/capi/tests/test_Arguments.cpp
+21
-21
paddle/capi/tests/test_GradientMachine.cpp
paddle/capi/tests/test_GradientMachine.cpp
+5
-5
paddle/capi/tests/test_Matrix.cpp
paddle/capi/tests/test_Matrix.cpp
+9
-8
paddle/capi/tests/test_Vector.cpp
paddle/capi/tests/test_Vector.cpp
+7
-7
paddle/capi/vector.h
paddle/capi/vector.h
+89
-0
未找到文件。
paddle/capi/Arguments.cpp
浏览文件 @
b5288289
...
@@ -23,25 +23,25 @@ using paddle::capi::cast;
...
@@ -23,25 +23,25 @@ using paddle::capi::cast;
extern
"C"
{
extern
"C"
{
PD_Arguments
PDArgsCreateNone
()
{
return
new
paddle
::
capi
::
CArguments
();
}
PD_Arguments
PDArgsCreateNone
()
{
return
new
paddle
::
capi
::
CArguments
();
}
PD_E
rror
PDArgsDestroy
(
PD_Arguments
args
)
{
paddle_e
rror
PDArgsDestroy
(
PD_Arguments
args
)
{
if
(
args
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
)
return
kPD_NULLPTR
;
delete
castArg
(
args
);
delete
castArg
(
args
);
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
)
{
paddle_e
rror
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
)
{
if
(
args
==
nullptr
||
size
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
size
==
nullptr
)
return
kPD_NULLPTR
;
*
size
=
castArg
(
args
)
->
args
.
size
();
*
size
=
castArg
(
args
)
->
args
.
size
();
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
)
{
paddle_e
rror
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
)
{
if
(
args
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
)
return
kPD_NULLPTR
;
castArg
(
args
)
->
args
.
resize
(
size
);
castArg
(
args
)
->
args
.
resize
(
size
);
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_M
atrix
mat
)
{
paddle_error
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_m
atrix
mat
)
{
if
(
args
==
nullptr
||
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
m
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CMatrix
>
(
mat
);
auto
m
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CMatrix
>
(
mat
);
if
(
m
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
m
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
...
@@ -51,7 +51,7 @@ PD_Error PDArgsSetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat) {
...
@@ -51,7 +51,7 @@ PD_Error PDArgsSetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_M
atrix
mat
)
{
paddle_error
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_m
atrix
mat
)
{
if
(
args
==
nullptr
||
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
m
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CMatrix
>
(
mat
);
auto
m
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CMatrix
>
(
mat
);
auto
a
=
castArg
(
args
);
auto
a
=
castArg
(
args
);
...
@@ -60,7 +60,7 @@ PD_Error PDArgsGetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat) {
...
@@ -60,7 +60,7 @@ PD_Error PDArgsGetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IV
ector
ids
)
{
paddle_error
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_iv
ector
ids
)
{
if
(
args
==
nullptr
||
ids
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
ids
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
ids
);
auto
iv
=
castIVec
(
ids
);
auto
a
=
castArg
(
args
);
auto
a
=
castArg
(
args
);
...
@@ -69,7 +69,7 @@ PD_Error PDArgsGetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
...
@@ -69,7 +69,7 @@ PD_Error PDArgsGetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IV
ector
ids
)
{
paddle_error
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_iv
ector
ids
)
{
//! TODO(lizhao): Complete this method.
//! TODO(lizhao): Complete this method.
if
(
args
==
nullptr
||
ids
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
ids
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
ids
);
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
ids
);
...
@@ -80,9 +80,9 @@ PD_Error PDArgsSetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
...
@@ -80,9 +80,9 @@ PD_Error PDArgsSetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
paddle_e
rror
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
seqPos
)
{
paddle_iv
ector
seqPos
)
{
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
seqPos
);
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
seqPos
);
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
@@ -93,9 +93,9 @@ PD_Error PDArgsSetSequenceStartPos(PD_Arguments args,
...
@@ -93,9 +93,9 @@ PD_Error PDArgsSetSequenceStartPos(PD_Arguments args,
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
paddle_e
rror
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
subSeqPos
)
{
paddle_iv
ector
subSeqPos
)
{
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
subSeqPos
);
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
subSeqPos
);
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
@@ -106,9 +106,9 @@ PD_Error PDArgsSetSubSequenceStartPos(PD_Arguments args,
...
@@ -106,9 +106,9 @@ PD_Error PDArgsSetSubSequenceStartPos(PD_Arguments args,
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
paddle_e
rror
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
seqPos
)
{
paddle_iv
ector
seqPos
)
{
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
seqPos
);
auto
iv
=
castIVec
(
seqPos
);
auto
a
=
castArg
(
args
);
auto
a
=
castArg
(
args
);
...
@@ -118,9 +118,9 @@ PD_Error PDArgsGetSequenceStartPos(PD_Arguments args,
...
@@ -118,9 +118,9 @@ PD_Error PDArgsGetSequenceStartPos(PD_Arguments args,
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
paddle_e
rror
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
subSeqPos
)
{
paddle_iv
ector
subSeqPos
)
{
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
subSeqPos
);
auto
iv
=
castIVec
(
subSeqPos
);
auto
a
=
castArg
(
args
);
auto
a
=
castArg
(
args
);
...
...
paddle/capi/CMakeLists.txt
浏览文件 @
b5288289
...
@@ -12,14 +12,14 @@ configure_file(config.h.in config.h @ONLY)
...
@@ -12,14 +12,14 @@ configure_file(config.h.in config.h @ONLY)
# PaddleCAPI.h is the only header we exposed. It currently only used for model
# PaddleCAPI.h is the only header we exposed. It currently only used for model
# inference.
# inference.
set
(
CAPI_HEADER PaddleCAPI.h
)
file
(
GLOB CAPI_HEADERS *.h
)
set
(
CAPI_PRIVATE_HEADER PaddleCAPIPrivate.h
)
set
(
CAPI_PRIVATE_HEADER PaddleCAPIPrivate.h
)
list
(
REMOVE_ITEM CAPI_HEADERS
${
CAPI_PRIVATE_HEADER
}
)
file
(
GLOB CAPI_SOURCES *.cpp
)
file
(
GLOB CAPI_SOURCES *.cpp
)
# building paddle_capi
# building paddle_capi
add_library
(
paddle_capi STATIC
${
CAPI_SOURCES
}
)
add_library
(
paddle_capi STATIC
${
CAPI_HEADERS
}
${
CAPI_PRIVATE_HEADER
}
${
CAPI_SOURCES
}
)
target_include_directories
(
paddle_capi PUBLIC
${
CMAKE_CURRENT_BINARY_DIR
}
)
target_include_directories
(
paddle_capi PUBLIC
${
CMAKE_CURRENT_BINARY_DIR
}
)
...
...
paddle/capi/GradientMachine.cpp
浏览文件 @
b5288289
...
@@ -38,9 +38,9 @@ NeuralNetwork* newCustomNerualNetwork(const std::string& name,
...
@@ -38,9 +38,9 @@ NeuralNetwork* newCustomNerualNetwork(const std::string& name,
}
// namespace paddle
}
// namespace paddle
extern
"C"
{
extern
"C"
{
PD_E
rror
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
paddle_e
rror
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
void
*
modelConfigProtobuf
,
int
size
)
{
int
size
)
{
if
(
modelConfigProtobuf
==
nullptr
)
return
kPD_NULLPTR
;
if
(
modelConfigProtobuf
==
nullptr
)
return
kPD_NULLPTR
;
paddle
::
ModelConfig
config
;
paddle
::
ModelConfig
config
;
if
(
!
config
.
ParseFromArray
(
modelConfigProtobuf
,
size
)
||
if
(
!
config
.
ParseFromArray
(
modelConfigProtobuf
,
size
)
||
...
@@ -55,13 +55,13 @@ PD_Error PDGradientMachineCreateForPredict(PD_GradientMachine* machine,
...
@@ -55,13 +55,13 @@ PD_Error PDGradientMachineCreateForPredict(PD_GradientMachine* machine,
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDGradientMachineDestroy
(
PD_GradientMachine
machine
)
{
paddle_e
rror
PDGradientMachineDestroy
(
PD_GradientMachine
machine
)
{
delete
cast
(
machine
);
delete
cast
(
machine
);
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
paddle_e
rror
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
)
{
const
char
*
path
)
{
auto
m
=
cast
(
machine
);
auto
m
=
cast
(
machine
);
if
(
m
==
nullptr
||
path
==
nullptr
||
m
->
machine
==
nullptr
)
if
(
m
==
nullptr
||
path
==
nullptr
||
m
->
machine
==
nullptr
)
return
kPD_NULLPTR
;
return
kPD_NULLPTR
;
...
@@ -69,10 +69,10 @@ PD_Error PDGradientMachineLoadParameterFromDisk(PD_GradientMachine machine,
...
@@ -69,10 +69,10 @@ PD_Error PDGradientMachineLoadParameterFromDisk(PD_GradientMachine machine,
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDGradientMachineForward
(
PD_GradientMachine
machine
,
paddle_e
rror
PDGradientMachineForward
(
PD_GradientMachine
machine
,
PD_Arguments
inArgs
,
PD_Arguments
inArgs
,
PD_Arguments
outArgs
,
PD_Arguments
outArgs
,
bool
isTrain
)
{
bool
isTrain
)
{
auto
m
=
cast
(
machine
);
auto
m
=
cast
(
machine
);
auto
in
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CArguments
>
(
inArgs
);
auto
in
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CArguments
>
(
inArgs
);
auto
out
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CArguments
>
(
outArgs
);
auto
out
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CArguments
>
(
outArgs
);
...
@@ -83,10 +83,10 @@ PD_Error PDGradientMachineForward(PD_GradientMachine machine,
...
@@ -83,10 +83,10 @@ PD_Error PDGradientMachineForward(PD_GradientMachine machine,
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_E
rror
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
paddle_e
rror
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
void
*
modelConfigProtobuf
,
void
*
modelConfigProtobuf
,
int
size
,
int
size
,
PD_GradientMachine
*
slave
)
{
PD_GradientMachine
*
slave
)
{
auto
o
=
cast
(
origin
);
auto
o
=
cast
(
origin
);
if
(
origin
==
nullptr
||
slave
==
nullptr
||
o
->
machine
==
nullptr
)
{
if
(
origin
==
nullptr
||
slave
==
nullptr
||
o
->
machine
==
nullptr
)
{
return
kPD_NULLPTR
;
return
kPD_NULLPTR
;
...
...
paddle/capi/Main.cpp
浏览文件 @
b5288289
...
@@ -29,7 +29,7 @@ static void initPaddle(int argc, char** argv) {
...
@@ -29,7 +29,7 @@ static void initPaddle(int argc, char** argv) {
}
}
extern
"C"
{
extern
"C"
{
PD_E
rror
PDInit
(
int
argc
,
char
**
argv
)
{
paddle_e
rror
PDInit
(
int
argc
,
char
**
argv
)
{
std
::
vector
<
char
*>
realArgv
;
std
::
vector
<
char
*>
realArgv
;
realArgv
.
reserve
(
argc
+
1
);
realArgv
.
reserve
(
argc
+
1
);
realArgv
.
push_back
(
strdup
(
""
));
realArgv
.
push_back
(
strdup
(
""
));
...
...
paddle/capi/Matrix.cpp
浏览文件 @
b5288289
...
@@ -18,22 +18,28 @@ limitations under the License. */
...
@@ -18,22 +18,28 @@ limitations under the License. */
#define cast(v) paddle::capi::cast<paddle::capi::CMatrix>(v)
#define cast(v) paddle::capi::cast<paddle::capi::CMatrix>(v)
extern
"C"
{
extern
"C"
{
PD_Matrix
PDMatCreate
(
uint64_t
height
,
uint64_t
width
,
bool
useGpu
)
{
paddle_matrix
paddle_matrix_create
(
uint64_t
height
,
uint64_t
width
,
bool
useGpu
)
{
auto
ptr
=
new
paddle
::
capi
::
CMatrix
();
auto
ptr
=
new
paddle
::
capi
::
CMatrix
();
ptr
->
mat
=
paddle
::
Matrix
::
create
(
height
,
width
,
false
,
useGpu
);
ptr
->
mat
=
paddle
::
Matrix
::
create
(
height
,
width
,
false
,
useGpu
);
return
ptr
;
return
ptr
;
}
}
PD_Matrix
PDMatCreateNone
()
{
return
new
paddle
::
capi
::
CMatrix
();
}
paddle_matrix
paddle_matrix_create_none
()
{
return
new
paddle
::
capi
::
CMatrix
();
}
PD_Error
PDMatDestroy
(
PD_M
atrix
mat
)
{
paddle_error
paddle_matrix_destroy
(
paddle_m
atrix
mat
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
cast
(
mat
);
auto
ptr
=
cast
(
mat
);
delete
ptr
;
delete
ptr
;
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDMatCopyToRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
*
rowArray
)
{
paddle_error
paddle_matrix_set_row
(
paddle_matrix
mat
,
uint64_t
rowID
,
pd_real
*
rowArray
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
cast
(
mat
);
auto
ptr
=
cast
(
mat
);
if
(
ptr
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
ptr
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
...
@@ -48,7 +54,9 @@ PD_Error PDMatCopyToRow(PD_Matrix mat, uint64_t rowID, pd_real* rowArray) {
...
@@ -48,7 +54,9 @@ PD_Error PDMatCopyToRow(PD_Matrix mat, uint64_t rowID, pd_real* rowArray) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDMatGetRow
(
PD_Matrix
mat
,
uint64_t
rowID
,
pd_real
**
rawRowBuffer
)
{
paddle_error
paddle_matrix_get_row
(
paddle_matrix
mat
,
uint64_t
rowID
,
pd_real
**
rawRowBuffer
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
cast
(
mat
);
auto
ptr
=
cast
(
mat
);
if
(
ptr
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
ptr
->
mat
==
nullptr
)
return
kPD_NULLPTR
;
...
@@ -57,7 +65,9 @@ PD_Error PDMatGetRow(PD_Matrix mat, uint64_t rowID, pd_real** rawRowBuffer) {
...
@@ -57,7 +65,9 @@ PD_Error PDMatGetRow(PD_Matrix mat, uint64_t rowID, pd_real** rawRowBuffer) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDMatGetShape
(
PD_Matrix
mat
,
uint64_t
*
height
,
uint64_t
*
width
)
{
paddle_error
paddle_matrix_get_shape
(
paddle_matrix
mat
,
uint64_t
*
height
,
uint64_t
*
width
)
{
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
if
(
height
!=
nullptr
)
{
if
(
height
!=
nullptr
)
{
*
height
=
cast
(
mat
)
->
mat
->
getHeight
();
*
height
=
cast
(
mat
)
->
mat
->
getHeight
();
...
...
paddle/capi/PaddleCAPI.h
浏览文件 @
b5288289
...
@@ -17,10 +17,9 @@ limitations under the License. */
...
@@ -17,10 +17,9 @@ limitations under the License. */
#include <stdbool.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdint.h>
#include "config.h"
#include "config.h"
#include "error.h"
// Since we only support linux and macos in compile, always use clang or
#include "matrix.h"
// gcc 4.8+. DLL_IMPORT/DLL_EXPORT is as simple as below.
#include "vector.h"
#define PD_API __attribute__((visibility("default")))
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -33,132 +32,6 @@ extern "C" {
...
@@ -33,132 +32,6 @@ extern "C" {
* NOTE: This is an experimental API, it could be changed.
* NOTE: This is an experimental API, it could be changed.
*/
*/
/**
* Error Type for Paddle API.
*/
typedef
enum
{
kPD_NO_ERROR
=
0
,
kPD_NULLPTR
=
1
,
kPD_OUT_OF_RANGE
=
2
,
kPD_PROTOBUF_ERROR
=
3
,
kPD_UNDEFINED_ERROR
=
-
1
,
}
PD_Error
;
/**
* Int Vector Functions. Return will be a PD_Error type.
*/
typedef
void
*
PD_IVector
;
/**
* @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 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
PD_IVector
PDIVectorCreate
(
int
*
array
,
uint64_t
size
,
bool
copy
,
bool
useGPU
);
/**
* @brief PDIVecDestroy destory an int vector.
* @param ivec vector to be destoried.
* @return PD_Error
*/
PD_API
PD_Error
PDIVecDestroy
(
PD_IVector
ivec
);
/**
* @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
);
/**
* @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
);
/**
* @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
;
/**
* @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
);
/**
* @brief PDMatDestroy Destroy a matrix.
* @param mat
* @return PD_Error
*/
PD_API
PD_Error
PDMatDestroy
(
PD_Matrix
mat
);
/**
* @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
);
/**
* @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
);
/**
* @brief PDMatCreateNone Create None Matrix
* @return
*/
PD_API
PD_Matrix
PDMatCreateNone
();
/**
* @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
* Arguments functions. Each argument means layer output. Arguments means a
* array of arguemnt.
* array of arguemnt.
...
@@ -174,25 +47,25 @@ PD_API PD_Arguments PDArgsCreateNone();
...
@@ -174,25 +47,25 @@ PD_API PD_Arguments PDArgsCreateNone();
/**
/**
* @brief PDArgsDestroy Destroy the arguments
* @brief PDArgsDestroy Destroy the arguments
* @param args arguments to destroy
* @param args arguments to destroy
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDArgsDestroy
(
PD_Arguments
args
);
PD_API
paddle_e
rror
PDArgsDestroy
(
PD_Arguments
args
);
/**
/**
* @brief PDArgsGetSize Get size of arguments array
* @brief PDArgsGetSize Get size of arguments array
* @param [in] args arguments array
* @param [in] args arguments array
* @param [out] size array size
* @param [out] size array size
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
);
PD_API
paddle_e
rror
PDArgsGetSize
(
PD_Arguments
args
,
uint64_t
*
size
);
/**
/**
* @brief PDArgsResize Resize a arguments array.
* @brief PDArgsResize Resize a arguments array.
* @param args arguments array.
* @param args arguments array.
* @param size target size of array
* @param size target size of array
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
);
PD_API
paddle_e
rror
PDArgsResize
(
PD_Arguments
args
,
uint64_t
size
);
/**
/**
* @brief PDArgsSetValue Set value matrix of one argument in array, which index
* @brief PDArgsSetValue Set value matrix of one argument in array, which index
...
@@ -200,9 +73,11 @@ PD_API PD_Error PDArgsResize(PD_Arguments args, uint64_t size);
...
@@ -200,9 +73,11 @@ PD_API PD_Error PDArgsResize(PD_Arguments args, uint64_t size);
* @param args arguments array
* @param args arguments array
* @param ID array index
* @param ID array index
* @param mat matrix pointer
* @param mat matrix pointer
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_Error
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
);
PD_API
paddle_error
PDArgsSetValue
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_matrix
mat
);
/**
/**
* @brief PDArgsGetValue Get value matrix of one argument in array, which index
* @brief PDArgsGetValue Get value matrix of one argument in array, which index
...
@@ -210,9 +85,11 @@ PD_API PD_Error PDArgsSetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat);
...
@@ -210,9 +85,11 @@ PD_API PD_Error PDArgsSetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat);
* @param [in] args arguments array
* @param [in] args arguments array
* @param [in] ID array index
* @param [in] ID array index
* @param [out] mat matrix pointer
* @param [out] mat matrix pointer
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_Error
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
PD_Matrix
mat
);
PD_API
paddle_error
PDArgsGetValue
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_matrix
mat
);
/**
/**
* @brief PDArgsGetIds Get the integer vector of one argument in array, which
* @brief PDArgsGetIds Get the integer vector of one argument in array, which
...
@@ -220,9 +97,11 @@ PD_API PD_Error PDArgsGetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat);
...
@@ -220,9 +97,11 @@ PD_API PD_Error PDArgsGetValue(PD_Arguments args, uint64_t ID, PD_Matrix mat);
* @param args arguments array
* @param args arguments array
* @param ID array index
* @param ID array index
* @param ids integer vector pointer
* @param ids integer vector pointer
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_Error
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
);
PD_API
paddle_error
PDArgsGetIds
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_ivector
ids
);
/**
/**
* @brief PDArgsSetIds Set the integer vector of one argument in array, which
* @brief PDArgsSetIds Set the integer vector of one argument in array, which
...
@@ -230,9 +109,11 @@ PD_API PD_Error PDArgsGetIds(PD_Arguments args, uint64_t ID, PD_IVector ids);
...
@@ -230,9 +109,11 @@ PD_API PD_Error PDArgsGetIds(PD_Arguments args, uint64_t ID, PD_IVector ids);
* @param [in] args arguments array
* @param [in] args arguments array
* @param [in] ID array index
* @param [in] ID array index
* @param [out] ids integer vector pointer
* @param [out] ids integer vector pointer
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_Error
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
);
PD_API
paddle_error
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
paddle_ivector
ids
);
/**
/**
* @brief PDArgsSetSequenceStartPos Set sequence start position vector of one
* @brief PDArgsSetSequenceStartPos Set sequence start position vector of one
...
@@ -240,22 +121,22 @@ PD_API PD_Error PDArgsSetIds(PD_Arguments args, uint64_t ID, PD_IVector ids);
...
@@ -240,22 +121,22 @@ PD_API PD_Error PDArgsSetIds(PD_Arguments args, uint64_t ID, PD_IVector ids);
* @param args arguments array
* @param args arguments array
* @param ID array index
* @param ID array index
* @param seqPos sequence position array.
* @param seqPos sequence position array.
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
PD_API
paddle_e
rror
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
seqPos
);
paddle_iv
ector
seqPos
);
/**
/**
* @brief PDArgsGetSequenceStartPos Get sequence start position vector of one
* @brief PDArgsGetSequenceStartPos Get sequence start position vector of one
* argument in array, which index is `ID`.
* argument in array, which index is `ID`.
* @param [in] args arguments array
* @param [in] args arguments array
* @param [in] ID array index
* @param [in] ID array index
* @param [out] seqPos sequence position array
* @param [out] seqPos sequence position array
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
PD_API
paddle_e
rror
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
seqPos
);
paddle_iv
ector
seqPos
);
/**
/**
* @brief PDArgsSetSubSequenceStartPos Set sub-sequence start position vector of
* @brief PDArgsSetSubSequenceStartPos Set sub-sequence start position vector of
...
@@ -263,11 +144,11 @@ PD_API PD_Error PDArgsGetSequenceStartPos(PD_Arguments args,
...
@@ -263,11 +144,11 @@ PD_API PD_Error PDArgsGetSequenceStartPos(PD_Arguments args,
* @param args arguments array
* @param args arguments array
* @param ID array index
* @param ID array index
* @param subSeqPos sub-sequence start position array.
* @param subSeqPos sub-sequence start position array.
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
PD_API
paddle_e
rror
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
subSeqPos
);
paddle_iv
ector
subSeqPos
);
/**
/**
* @brief PDArgsGetSubSequenceStartPos Get sub-sequence start position vector of
* @brief PDArgsGetSubSequenceStartPos Get sub-sequence start position vector of
...
@@ -275,11 +156,11 @@ PD_API PD_Error PDArgsSetSubSequenceStartPos(PD_Arguments args,
...
@@ -275,11 +156,11 @@ PD_API PD_Error PDArgsSetSubSequenceStartPos(PD_Arguments args,
* @param args arguments array
* @param args arguments array
* @param ID array index
* @param ID array index
* @param subSeqPos sub-sequence start position array
* @param subSeqPos sub-sequence start position array
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
PD_API
paddle_e
rror
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
uint64_t
ID
,
PD_IV
ector
subSeqPos
);
paddle_iv
ector
subSeqPos
);
/**
/**
* @brief GradientMachine means a neural network.
* @brief GradientMachine means a neural network.
*/
*/
...
@@ -291,19 +172,18 @@ typedef void* PD_GradientMachine;
...
@@ -291,19 +172,18 @@ typedef void* PD_GradientMachine;
* @param [out] machine that used for model inference.
* @param [out] machine that used for model inference.
* @param [in] modelConfigProtobuf
* @param [in] modelConfigProtobuf
* @param [in] size
* @param [in] size
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_Error
PDGradientMachineCreateForPredict
(
PD_GradientMachine
*
machine
,
PD_API
paddle_error
PDGradientMachineCreateForPredict
(
void
*
modelConfigProtobuf
,
PD_GradientMachine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
);
int
size
);
/**
/**
* @brief PDGradientMachineLoadParameterFromDisk Load parameter from disk.
* @brief PDGradientMachineLoadParameterFromDisk Load parameter from disk.
* @param machine Gradient Machine.
* @param machine Gradient Machine.
* @param path local directory path.
* @param path local directory path.
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDGradientMachineLoadParameterFromDisk
(
PD_API
paddle_e
rror
PDGradientMachineLoadParameterFromDisk
(
PD_GradientMachine
machine
,
const
char
*
path
);
PD_GradientMachine
machine
,
const
char
*
path
);
/**
/**
...
@@ -312,12 +192,12 @@ PD_API PD_Error PDGradientMachineLoadParameterFromDisk(
...
@@ -312,12 +192,12 @@ PD_API PD_Error PDGradientMachineLoadParameterFromDisk(
* @param inArgs input arguments
* @param inArgs input arguments
* @param outArgs output arguments
* @param outArgs output arguments
* @param isTrain is train or not
* @param isTrain is train or not
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDGradientMachineForward
(
PD_GradientMachine
machine
,
PD_API
paddle_e
rror
PDGradientMachineForward
(
PD_GradientMachine
machine
,
PD_Arguments
inArgs
,
PD_Arguments
inArgs
,
PD_Arguments
outArgs
,
PD_Arguments
outArgs
,
bool
isTrain
);
bool
isTrain
);
/**
/**
* @brief PDGradientMachineCreateSharedParam Create a gradient machine, which
* @brief PDGradientMachineCreateSharedParam Create a gradient machine, which
...
@@ -326,24 +206,25 @@ PD_API PD_Error PDGradientMachineForward(PD_GradientMachine machine,
...
@@ -326,24 +206,25 @@ PD_API PD_Error PDGradientMachineForward(PD_GradientMachine machine,
* @param [in] modelConfigProtobuf model config protobuf
* @param [in] modelConfigProtobuf model config protobuf
* @param [in] size of model config buffer.
* @param [in] size of model config buffer.
* @param [out] slave gradient machine, the output value.
* @param [out] slave gradient machine, the output value.
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_Error
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
PD_API
paddle_error
void
*
modelConfigProtobuf
,
PDGradientMachineCreateSharedParam
(
PD_GradientMachine
origin
,
int
size
,
void
*
modelConfigProtobuf
,
PD_GradientMachine
*
slave
);
int
size
,
PD_GradientMachine
*
slave
);
/**
/**
* @brief PDGradientMachineDestroy Destroy a gradient machine
* @brief PDGradientMachineDestroy Destroy a gradient machine
* @param machine that need to destroy
* @param machine that need to destroy
* @return
PD_E
rror
* @return
paddle_e
rror
*/
*/
PD_API
PD_E
rror
PDGradientMachineDestroy
(
PD_GradientMachine
machine
);
PD_API
paddle_e
rror
PDGradientMachineDestroy
(
PD_GradientMachine
machine
);
/**
/**
* Initialize Paddle.
* Initialize Paddle.
*/
*/
PD_API
PD_E
rror
PDInit
(
int
argc
,
char
**
argv
);
PD_API
paddle_e
rror
PDInit
(
int
argc
,
char
**
argv
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
paddle/capi/Vector.cpp
浏览文件 @
b5288289
...
@@ -19,9 +19,14 @@ using paddle::capi::cast;
...
@@ -19,9 +19,14 @@ using paddle::capi::cast;
extern
"C"
{
extern
"C"
{
PD_IVector
PDIVecCreateNone
()
{
return
new
paddle
::
capi
::
CIVector
();
}
paddle_ivector
paddle_ivector_create_none
()
{
return
new
paddle
::
capi
::
CIVector
();
}
PD_IVector
PDIVectorCreate
(
int
*
array
,
uint64_t
size
,
bool
copy
,
bool
useGPU
)
{
paddle_ivector
paddle_ivector_create
(
int
*
array
,
uint64_t
size
,
bool
copy
,
bool
useGPU
)
{
auto
ptr
=
new
paddle
::
capi
::
CIVector
();
auto
ptr
=
new
paddle
::
capi
::
CIVector
();
if
(
copy
)
{
if
(
copy
)
{
ptr
->
vec
=
paddle
::
IVector
::
create
(
size
,
useGPU
);
ptr
->
vec
=
paddle
::
IVector
::
create
(
size
,
useGPU
);
...
@@ -32,13 +37,13 @@ PD_IVector PDIVectorCreate(int* array, uint64_t size, bool copy, bool useGPU) {
...
@@ -32,13 +37,13 @@ PD_IVector PDIVectorCreate(int* array, uint64_t size, bool copy, bool useGPU) {
return
ptr
;
return
ptr
;
}
}
PD_Error
PDIVecDestroy
(
PD_IV
ector
ivec
)
{
paddle_error
paddle_ivector_destroy
(
paddle_iv
ector
ivec
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
delete
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
delete
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDIVectorGet
(
PD_IV
ector
ivec
,
int
**
buffer
)
{
paddle_error
paddle_ivector_get
(
paddle_iv
ector
ivec
,
int
**
buffer
)
{
if
(
ivec
==
nullptr
||
buffer
==
nullptr
)
return
kPD_NULLPTR
;
if
(
ivec
==
nullptr
||
buffer
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
@@ -46,7 +51,7 @@ PD_Error PDIVectorGet(PD_IVector ivec, int** buffer) {
...
@@ -46,7 +51,7 @@ PD_Error PDIVectorGet(PD_IVector ivec, int** buffer) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDIVectorResize
(
PD_IV
ector
ivec
,
uint64_t
size
)
{
paddle_error
paddle_ivector_resize
(
paddle_iv
ector
ivec
,
uint64_t
size
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
@@ -54,7 +59,7 @@ PD_Error PDIVectorResize(PD_IVector ivec, uint64_t size) {
...
@@ -54,7 +59,7 @@ PD_Error PDIVectorResize(PD_IVector ivec, uint64_t size) {
return
kPD_NO_ERROR
;
return
kPD_NO_ERROR
;
}
}
PD_Error
PDIVectorGetSize
(
PD_IV
ector
ivec
,
uint64_t
*
size
)
{
paddle_error
paddle_ivector_get_size
(
paddle_iv
ector
ivec
,
uint64_t
*
size
)
{
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
...
...
paddle/capi/config.h.in
浏览文件 @
b5288289
...
@@ -3,4 +3,8 @@
...
@@ -3,4 +3,8 @@
typedef @PADDLE_FLOAT_TYPE@ pd_real;
typedef @PADDLE_FLOAT_TYPE@ pd_real;
// Since we only support linux and macos in compile, always use clang or
// gcc 4.8+. DLL_IMPORT/DLL_EXPORT is as simple as below.
#define PD_API __attribute__((visibility("default")))
#endif
#endif
paddle/capi/error.h
0 → 100644
浏览文件 @
b5288289
#ifndef __PADDLE_CAPI_ERROR_H__
#define __PADDLE_CAPI_ERROR_H__
/**
* Error Type for Paddle API.
*/
typedef
enum
{
kPD_NO_ERROR
=
0
,
kPD_NULLPTR
=
1
,
kPD_OUT_OF_RANGE
=
2
,
kPD_PROTOBUF_ERROR
=
3
,
kPD_UNDEFINED_ERROR
=
-
1
,
}
paddle_error
;
#endif
paddle/capi/matrix.h
0 → 100644
浏览文件 @
b5288289
/* 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_MATRIX_H__
#define __PADDLE_CAPI_MATRIX_H__
#include <stdint.h>
#include "config.h"
#include "error.h"
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* Matrix functions. Return will be a paddle_error type.
*/
typedef
void
*
paddle_matrix
;
/**
* @brief paddle_matrix_create Create a dense matrix
* @param height matrix height.
* @param width matrix width
* @param useGpu use GPU of not
* @return Matrix handler
*/
PD_API
paddle_matrix
paddle_matrix_create
(
uint64_t
height
,
uint64_t
width
,
bool
useGpu
);
/**
* @brief paddle_matrix_destroy Destroy a matrix.
* @param mat
* @return paddle_error
*/
PD_API
paddle_error
paddle_matrix_destroy
(
paddle_matrix
mat
);
/**
* @brief paddle_matrix_set_row Set a row to matrix.
* @param mat Target Matrix
* @param rowID Index of row
* @param rowArray Row data.
* @return paddle_error
*/
PD_API
paddle_error
paddle_matrix_set_row
(
paddle_matrix
mat
,
uint64_t
rowID
,
pd_real
*
rowArray
);
/**
* @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 paddle_error
*/
PD_API
paddle_error
paddle_matrix_get_row
(
paddle_matrix
mat
,
uint64_t
rowID
,
pd_real
**
rawRowBuffer
);
/**
* @brief PDMatCreateNone Create None Matrix
* @return
*/
PD_API
paddle_matrix
paddle_matrix_create_none
();
/**
* @brief PDMatGetShape get the shape of matrix
* @param mat target matrix
* @param height The height of matrix
* @param width The width of matrix
* @return paddle_error
*/
PD_API
paddle_error
paddle_matrix_get_shape
(
paddle_matrix
mat
,
uint64_t
*
height
,
uint64_t
*
width
);
#ifdef __cplusplus
}
#endif
#endif
paddle/capi/tests/test_Arguments.cpp
浏览文件 @
b5288289
...
@@ -39,14 +39,14 @@ TEST(CAPIArguments, value) {
...
@@ -39,14 +39,14 @@ TEST(CAPIArguments, value) {
PD_Arguments
args
=
PDArgsCreateNone
();
PD_Arguments
args
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_Matrix
mat
=
PDMatC
reate
(
128
,
64
,
false
);
paddle_matrix
mat
=
paddle_matrix_c
reate
(
128
,
64
,
false
);
for
(
size_t
i
=
0
;
i
<
128
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
128
;
++
i
)
{
std
::
vector
<
pd_real
>
sampleBuf
=
randomBuffer
(
64
);
std
::
vector
<
pd_real
>
sampleBuf
=
randomBuffer
(
64
);
PDMatCopyToR
ow
(
mat
,
i
,
sampleBuf
.
data
());
paddle_matrix_set_r
ow
(
mat
,
i
,
sampleBuf
.
data
());
}
}
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetValue
(
args
,
0
,
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetValue
(
args
,
0
,
mat
));
PD_Matrix
val
=
PDMatCreateN
one
();
paddle_matrix
val
=
paddle_matrix_create_n
one
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetValue
(
args
,
0
,
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetValue
(
args
,
0
,
val
));
...
@@ -54,15 +54,15 @@ TEST(CAPIArguments, value) {
...
@@ -54,15 +54,15 @@ TEST(CAPIArguments, value) {
pd_real
*
row1
;
pd_real
*
row1
;
pd_real
*
row2
;
pd_real
*
row2
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatGetR
ow
(
mat
,
i
,
&
row1
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_get_r
ow
(
mat
,
i
,
&
row1
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatGetR
ow
(
val
,
i
,
&
row2
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_get_r
ow
(
val
,
i
,
&
row2
));
ASSERT_EQ
(
row1
,
row2
);
ASSERT_EQ
(
row1
,
row2
);
}
}
PD_IVector
ivec
=
PDIVecCreateN
one
();
paddle_ivector
ivec
=
paddle_ivector_create_n
one
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecD
estroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_d
estroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatD
estroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_d
estroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatD
estroy
(
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_d
estroy
(
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
}
}
...
@@ -70,15 +70,15 @@ TEST(CAPIArguments, ids) {
...
@@ -70,15 +70,15 @@ TEST(CAPIArguments, ids) {
PD_Arguments
args
=
PDArgsCreateNone
();
PD_Arguments
args
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_IV
ector
ivec
;
paddle_iv
ector
ivec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
int
array
[
3
]
=
{
1
,
2
,
3
};
ivec
=
PDIVectorC
reate
(
array
,
3
,
true
,
false
);
ivec
=
paddle_ivector_c
reate
(
array
,
3
,
true
,
false
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetIds
(
args
,
0
,
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetIds
(
args
,
0
,
ivec
));
PD_IVector
val
=
PDIVecCreateN
one
();
paddle_ivector
val
=
paddle_ivector_create_n
one
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetIds
(
args
,
0
,
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetIds
(
args
,
0
,
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecD
estroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_d
estroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecD
estroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_d
estroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
}
}
...
@@ -87,24 +87,24 @@ void testSequenceHelper(T1 setter, T2 getter) {
...
@@ -87,24 +87,24 @@ void testSequenceHelper(T1 setter, T2 getter) {
PD_Arguments
args
=
PDArgsCreateNone
();
PD_Arguments
args
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_IV
ector
ivec
;
paddle_iv
ector
ivec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
int
array
[
3
]
=
{
1
,
2
,
3
};
ivec
=
PDIVectorC
reate
(
array
,
3
,
true
,
false
);
ivec
=
paddle_ivector_c
reate
(
array
,
3
,
true
,
false
);
ASSERT_EQ
(
kPD_NO_ERROR
,
setter
(
args
,
0
,
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
setter
(
args
,
0
,
ivec
));
PD_IVector
val
=
PDIVecCreateN
one
();
paddle_ivector
val
=
paddle_ivector_create_n
one
();
ASSERT_EQ
(
kPD_NO_ERROR
,
getter
(
args
,
0
,
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
getter
(
args
,
0
,
val
));
uint64_t
size
;
uint64_t
size
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorGetS
ize
(
val
,
&
size
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_get_s
ize
(
val
,
&
size
));
int
*
rawBuf
;
int
*
rawBuf
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorG
et
(
val
,
&
rawBuf
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_g
et
(
val
,
&
rawBuf
));
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
ASSERT_EQ
(
array
[
i
],
rawBuf
[
i
]);
ASSERT_EQ
(
array
[
i
],
rawBuf
[
i
]);
}
}
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecD
estroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_d
estroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecD
estroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_d
estroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
}
}
...
...
paddle/capi/tests/test_GradientMachine.cpp
浏览文件 @
b5288289
...
@@ -59,12 +59,12 @@ TEST(GradientMachine, testPredict) {
...
@@ -59,12 +59,12 @@ TEST(GradientMachine, testPredict) {
PD_Arguments
inArgs
=
PDArgsCreateNone
();
PD_Arguments
inArgs
=
PDArgsCreateNone
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
inArgs
,
1
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
inArgs
,
1
));
PD_Matrix
mat
=
PDMatC
reate
(
1
,
100
,
false
);
paddle_matrix
mat
=
paddle_matrix_c
reate
(
1
,
100
,
false
);
static_assert
(
std
::
is_same
<
pd_real
,
paddle
::
real
>::
value
,
""
);
static_assert
(
std
::
is_same
<
pd_real
,
paddle
::
real
>::
value
,
""
);
auto
data
=
randomBuffer
(
100
);
auto
data
=
randomBuffer
(
100
);
pd_real
*
rowPtr
;
pd_real
*
rowPtr
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatGetR
ow
(
mat
,
0
,
&
rowPtr
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_get_r
ow
(
mat
,
0
,
&
rowPtr
));
memcpy
(
rowPtr
,
data
.
data
(),
data
.
size
()
*
sizeof
(
pd_real
));
memcpy
(
rowPtr
,
data
.
data
(),
data
.
size
()
*
sizeof
(
pd_real
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetValue
(
inArgs
,
0
,
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetValue
(
inArgs
,
0
,
mat
));
...
@@ -87,16 +87,16 @@ TEST(GradientMachine, testPredict) {
...
@@ -87,16 +87,16 @@ TEST(GradientMachine, testPredict) {
auto
matPaddle
=
paddleOutArgs
[
0
].
value
;
auto
matPaddle
=
paddleOutArgs
[
0
].
value
;
uint64_t
height
,
width
;
uint64_t
height
,
width
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatGetS
hape
(
mat
,
&
height
,
&
width
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_get_s
hape
(
mat
,
&
height
,
&
width
));
ASSERT_EQ
(
matPaddle
->
getHeight
(),
height
);
ASSERT_EQ
(
matPaddle
->
getHeight
(),
height
);
ASSERT_EQ
(
matPaddle
->
getWidth
(),
width
);
ASSERT_EQ
(
matPaddle
->
getWidth
(),
width
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatGetR
ow
(
mat
,
0
,
&
rowPtr
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_get_r
ow
(
mat
,
0
,
&
rowPtr
));
for
(
size_t
i
=
0
;
i
<
width
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
width
;
++
i
)
{
ASSERT_NEAR
(
matPaddle
->
getData
()[
i
],
rowPtr
[
i
],
1e-5
);
ASSERT_NEAR
(
matPaddle
->
getData
()[
i
],
rowPtr
[
i
],
1e-5
);
}
}
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatD
estroy
(
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_d
estroy
(
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
inArgs
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
inArgs
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
outArgs
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
outArgs
));
std
::
swap
(
machineSlave
,
machine
);
std
::
swap
(
machineSlave
,
machine
);
...
...
paddle/capi/tests/test_Matrix.cpp
浏览文件 @
b5288289
...
@@ -16,30 +16,31 @@ limitations under the License. */
...
@@ -16,30 +16,31 @@ limitations under the License. */
#include "gtest/gtest.h"
#include "gtest/gtest.h"
TEST
(
CAPIMatrix
,
create
)
{
TEST
(
CAPIMatrix
,
create
)
{
PD_Matrix
mat
=
PDMatC
reate
(
128
,
32
,
false
);
paddle_matrix
mat
=
paddle_matrix_c
reate
(
128
,
32
,
false
);
std
::
vector
<
pd_real
>
sampleRow
;
std
::
vector
<
pd_real
>
sampleRow
;
sampleRow
.
resize
(
32
);
sampleRow
.
resize
(
32
);
for
(
size_t
i
=
0
;
i
<
sampleRow
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
sampleRow
.
size
();
++
i
)
{
sampleRow
[
i
]
=
1.0
/
(
i
+
1.0
);
sampleRow
[
i
]
=
1.0
/
(
i
+
1.0
);
}
}
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatCopyToRow
(
mat
,
0
,
sampleRow
.
data
()));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_set_row
(
mat
,
0
,
sampleRow
.
data
()));
ASSERT_EQ
(
kPD_OUT_OF_RANGE
,
PDMatCopyToRow
(
mat
,
128
,
sampleRow
.
data
()));
ASSERT_EQ
(
kPD_OUT_OF_RANGE
,
paddle_matrix_set_row
(
mat
,
128
,
sampleRow
.
data
()));
pd_real
*
arrayPtr
;
pd_real
*
arrayPtr
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatGetR
ow
(
mat
,
0
,
&
arrayPtr
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_get_r
ow
(
mat
,
0
,
&
arrayPtr
));
for
(
size_t
i
=
0
;
i
<
sampleRow
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
sampleRow
.
size
();
++
i
)
{
ASSERT_NEAR
(
sampleRow
[
i
],
arrayPtr
[
i
],
1e-5
);
ASSERT_NEAR
(
sampleRow
[
i
],
arrayPtr
[
i
],
1e-5
);
}
}
uint64_t
height
,
width
;
uint64_t
height
,
width
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatGetS
hape
(
mat
,
&
height
,
&
width
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_get_s
hape
(
mat
,
&
height
,
&
width
));
ASSERT_EQ
(
128UL
,
height
);
ASSERT_EQ
(
128UL
,
height
);
ASSERT_EQ
(
32UL
,
width
);
ASSERT_EQ
(
32UL
,
width
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatD
estroy
(
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_d
estroy
(
mat
));
}
}
TEST
(
CAPIMatrix
,
createNone
)
{
TEST
(
CAPIMatrix
,
createNone
)
{
PD_Matrix
mat
=
PDMatCreateN
one
();
paddle_matrix
mat
=
paddle_matrix_create_n
one
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatD
estroy
(
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_matrix_d
estroy
(
mat
));
}
}
paddle/capi/tests/test_Vector.cpp
浏览文件 @
b5288289
...
@@ -16,16 +16,16 @@ limitations under the License. */
...
@@ -16,16 +16,16 @@ limitations under the License. */
#include "gtest/gtest.h"
#include "gtest/gtest.h"
TEST
(
CAPIVector
,
create
)
{
TEST
(
CAPIVector
,
create
)
{
PD_IV
ector
vec
;
paddle_iv
ector
vec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
int
array
[
3
]
=
{
1
,
2
,
3
};
vec
=
PDIVectorC
reate
(
array
,
3
,
true
,
false
);
vec
=
paddle_ivector_c
reate
(
array
,
3
,
true
,
false
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorR
esize
(
vec
,
1000
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_r
esize
(
vec
,
1000
));
uint64_t
size
;
uint64_t
size
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorGetS
ize
(
vec
,
&
size
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_get_s
ize
(
vec
,
&
size
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecD
estroy
(
vec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_d
estroy
(
vec
));
}
}
TEST
(
CAPIVector
,
createNone
)
{
TEST
(
CAPIVector
,
createNone
)
{
PD_IVector
vec
=
PDIVecCreateN
one
();
paddle_ivector
vec
=
paddle_ivector_create_n
one
();
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecD
estroy
(
vec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
paddle_ivector_d
estroy
(
vec
));
}
}
paddle/capi/vector.h
0 → 100644
浏览文件 @
b5288289
/* 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_VECTOR_H__
#define __PADDLE_CAPI_VECTOR_H__
#include <stdbool.h>
#include <stdint.h>
#include "config.h"
#include "error.h"
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* Int Vector Functions. Return will be a paddle_error type.
*/
typedef
void
*
paddle_ivector
;
/**
* @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
paddle_ivector
paddle_ivector_create_none
();
/**
* @brief paddle_ivector_create create a paddle int vector
* @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 paddle_error
*/
PD_API
paddle_ivector
paddle_ivector_create
(
int
*
array
,
uint64_t
size
,
bool
copy
,
bool
useGPU
);
/**
* @brief paddle_ivector_destroy destory an int vector.
* @param ivec vector to be destoried.
* @return paddle_error
*/
PD_API
paddle_error
paddle_ivector_destroy
(
paddle_ivector
ivec
);
/**
* @brief paddle_ivector_get 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 paddle_error
*/
PD_API
paddle_error
paddle_ivector_get
(
paddle_ivector
ivec
,
int
**
buffer
);
/**
* @brief paddle_ivector_resize resize the int vector.
* @param [in] ivec: int vector
* @param [in] size: size to change
* @return paddle_error
*/
PD_API
paddle_error
paddle_ivector_resize
(
paddle_ivector
ivec
,
uint64_t
size
);
/**
* @brief paddle_ivector_get_size get the size of int vector.
* @param [in] ivec: int vector
* @param [out] size: return size of this int vector.
* @return paddle_error
*/
PD_API
paddle_error
paddle_ivector_get_size
(
paddle_ivector
ivec
,
uint64_t
*
size
);
#ifdef __cplusplus
}
#endif
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录