Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
57e25211
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
57e25211
编写于
1月 09, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BufferArg add ArgType and Function remove inouts
上级
d35ef9de
变更
4
展开全部
显示空白变更内容
内联
并排
Showing
4 changed file
with
59 addition
and
1886 deletion
+59
-1886
paddle/function/BufferArg.h
paddle/function/BufferArg.h
+37
-8
paddle/function/Function.h
paddle/function/Function.h
+21
-7
paddle/function/FunctionTest.cpp
paddle/function/FunctionTest.cpp
+1
-1
paddle/math/Matrix.h~RFbb8b484f.TMP
paddle/math/Matrix.h~RFbb8b484f.TMP
+0
-1870
未找到文件。
paddle/function/BufferArg.h
浏览文件 @
57e25211
...
...
@@ -38,16 +38,40 @@ enum SparseDataType {
enum
SparseDataFormat
{
SPARSE_CSR_FORMAT
=
0
,
SPARSE_CSC_FORMAT
=
1
};
/**
* BufferArg used as the argument type for Function.
*/
class
BufferArg
;
class
SequenceArg
;
class
SparseMatrixArg
;
typedef
std
::
shared_ptr
<
BufferArg
>
BufferArgPtr
;
// an array of arbitrary dimensions
/**
* \brief BufferArg used as the argument type of Function.
*
* The arguments of the Paddle Function have four Buffer types.
* 1. BufferArg for a dense Buffer of any dimension.
* 2. SequenceIdArg for a Buffer of sequence start positions.
* 3. SequenceArg for a Buffer of sequence data.
* 4. SparseMatrixArg for a Buffer of sparse matrix.
*
* There is an ArgType property for the BufferArg used as Function Output.
* Whether the result of the Function calculation is assigned to the
* output Buffer or added to the output Buffer is determined by the
* argType_ property of the output BufferArg.
*/
class
BufferArg
{
public:
// ArgType is only used by output BufferArg.
// For input argument, argType_ is ignored.
// For output argument, need to set the argType_ of the BufferArg.
enum
ArgType
{
UNSPECIFIED
=
0
,
ASSIGN_TO
=
1
,
ADD_TO
=
2
,
};
void
setArgType
(
ArgType
argType
)
{
argType_
=
argType
;
}
ArgType
getArgType
()
const
{
return
argType_
;
}
public:
BufferArg
(
void
*
buf
,
ValueType
valueType
,
const
TensorShape
&
shape
)
:
buf_
(
buf
),
valueType_
(
valueType
),
shape_
(
shape
)
{}
...
...
@@ -56,7 +80,8 @@ public:
:
buf_
(
buf
),
valueType_
(
valueType
)
{}
BufferArg
(
const
Matrix
&
matrix
)
:
buf_
(
reinterpret_cast
<
void
*>
(
matrix
.
getData
())),
:
buf_
(
const_cast
<
void
*>
(
reinterpret_cast
<
const
void
*>
(
matrix
.
getData
()))),
valueType_
(
DataType
<
real
>::
value
),
shape_
(
2
)
{
shape_
.
setDim
(
0
,
matrix
.
getHeight
());
...
...
@@ -64,21 +89,24 @@ public:
}
BufferArg
(
const
Matrix
&
matrix
,
const
TensorShape
&
shape
)
:
buf_
(
reinterpret_cast
<
void
*>
(
matrix
.
getData
())),
:
buf_
(
const_cast
<
void
*>
(
reinterpret_cast
<
const
void
*>
(
matrix
.
getData
()))),
valueType_
(
DataType
<
real
>::
value
),
shape_
(
shape
)
{
CHECK_EQ
(
matrix
.
getElementCnt
(),
shape
.
getElements
());
}
BufferArg
(
const
Vector
&
vector
)
:
buf_
(
reinterpret_cast
<
void
*>
(
vector
.
getData
())),
:
buf_
(
const_cast
<
void
*>
(
reinterpret_cast
<
const
void
*>
(
vector
.
getData
()))),
valueType_
(
DataType
<
real
>::
value
),
shape_
(
1
)
{
shape_
.
setDim
(
0
,
vector
.
getSize
());
}
BufferArg
(
const
IVector
&
vector
)
:
buf_
(
reinterpret_cast
<
void
*>
(
vector
.
getData
())),
:
buf_
(
const_cast
<
void
*>
(
reinterpret_cast
<
const
void
*>
(
vector
.
getData
()))),
valueType_
(
VALUE_TYPE_INT32
),
shape_
(
1
)
{
shape_
.
setDim
(
0
,
vector
.
getSize
());
...
...
@@ -124,6 +152,7 @@ protected:
ValueType
valueType_
;
TensorShape
shape_
;
BufferType
bufferType_
;
ArgType
argType_
=
UNSPECIFIED
;
// leading dimensions. The size is dims_.size()
// Dims lds_;
};
...
...
paddle/function/Function.h
浏览文件 @
57e25211
...
...
@@ -56,12 +56,18 @@ public:
BufferArgs
()
{}
size_t
size
()
const
{
return
args_
.
size
();
}
// add argument into BufferArgss
// add argument into BufferArgs
// Tensor can be Matrix, Vector, IVector.
template
<
typename
Tensor
>
void
addArg
(
const
Tensor
&
arg
)
{
args_
.
push_back
(
std
::
make_shared
<
BufferArg
>
(
arg
));
}
// Add arg into BufferArgs and reshape the arg.
//
// For example, arg represents an image buffer,
// but Matrix can only represent a two-dimensional Tensor.
// So need an extra argument to describe the shape of the image buffer.
void
addArg
(
const
Matrix
&
arg
,
const
TensorShape
&
shape
);
void
addArg
(
const
CpuSparseMatrix
&
arg
);
...
...
@@ -78,10 +84,20 @@ private:
};
/**
* Base class for Function.
*
\brief
Base class for Function.
* The basic Function implementation requires override init and calc interfaces.
* Need to pay attention to the inouts argument. For the input argument
* that will be modified, it needs to be passed through inouts.
*
* Function inputs are readonly, Function outputs have two modes: ASSIGN_TO
* and ADD_TO.
* If output.getArgType() == ASSIGN_TO, this is assign mode, and the calculation
* result of Function assigned to the output BufferArg.
* If output.getArgType() == ADD_TO, this is add mode, and the calculation
* result of Function need added to the output BufferArg.
*
* For example:
* ASSIGN_TO: output = Function(inputs)
* ADD_TO: output += Function(inputs)
* If Function has more than one output, each output can have different modes.
*/
class
FunctionBase
{
public:
...
...
@@ -89,9 +105,7 @@ public:
virtual
void
init
(
const
FuncConfig
&
config
)
{}
virtual
void
calc
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
,
const
BufferArgs
&
inouts
)
{}
virtual
void
calc
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
{}
static
ClassRegistrar
<
FunctionBase
>
funcRegistrar_
;
};
...
...
paddle/function/FunctionTest.cpp
浏览文件 @
57e25211
...
...
@@ -35,7 +35,7 @@ void FunctionApi<DEVICE_TYPE_GPU>(GpuMatrix& output, const GpuMatrix& input) {
template
<
DeviceType
DType
>
void
Function
(
const
BufferArgs
&
arguments
)
{
auto
input
=
arguments
[
0
].
matrix
<
DType
>
();
const
auto
input
=
arguments
[
0
].
matrix
<
DType
>
();
auto
output
=
arguments
[
1
].
matrix
<
DType
>
();
FunctionApi
<
DType
>
(
output
,
input
);
}
...
...
paddle/math/Matrix.h~RFbb8b484f.TMP
已删除
100644 → 0
浏览文件 @
d35ef9de
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录