Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
橘蓝
Paddle
提交
2ccaec4f
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,发现更多精彩内容 >>
提交
2ccaec4f
编写于
10月 02, 2017
作者:
Z
zchen0211
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gather scatter cond
上级
3d09a654
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
16 addition
and
13 deletion
+16
-13
paddle/operators/cond_op.cc
paddle/operators/cond_op.cc
+2
-3
paddle/operators/gather.h
paddle/operators/gather.h
+2
-2
paddle/operators/gather_op.h
paddle/operators/gather_op.h
+2
-2
paddle/operators/gather_test.cc
paddle/operators/gather_test.cc
+3
-1
paddle/operators/scatter.h
paddle/operators/scatter.h
+2
-2
paddle/operators/scatter_op.h
paddle/operators/scatter_op.h
+2
-2
paddle/operators/scatter_test.cc
paddle/operators/scatter_test.cc
+3
-1
未找到文件。
paddle/operators/cond_op.cc
浏览文件 @
2ccaec4f
...
...
@@ -126,8 +126,7 @@ void CondOp::PrepareDataForSubnet(
dim
[
0
]
=
index_tensors
[
i
].
dims
()[
0
];
tensor_child
->
mutable_data
<
float
>
(
dim
,
platform
::
CPUPlace
());
CPUGather
<
float
>
(
dev_ctx
.
GetPlace
(),
tensor_parent
,
&
index_tensors
[
i
],
tensor_child
);
CPUGather
<
float
>
(
dev_ctx
,
tensor_parent
,
&
index_tensors
[
i
],
tensor_child
);
}
}
...
...
@@ -188,7 +187,7 @@ void CondOp::MergeDataFromSubnet(const framework::Scope& scope,
Variable
*
var_child
=
sub_scopes
[
i
]
->
FindVar
(
output
);
PADDLE_ENFORCE_NOT_NULL
(
var_child
);
auto
*
tensor_child
=
&
var_child
->
Get
<
LoDTensor
>
();
ScatterAssign
<
float
>
(
dev_ctx
.
GetPlace
()
,
tensor_child
,
&
index_tensors
[
i
],
ScatterAssign
<
float
>
(
dev_ctx
,
tensor_child
,
&
index_tensors
[
i
],
tensor_parent
);
}
}
...
...
paddle/operators/gather.h
浏览文件 @
2ccaec4f
...
...
@@ -32,11 +32,11 @@ namespace operators {
* return: output tensor
*/
template
<
typename
T
>
void
CPUGather
(
const
platform
::
Place
&
place
,
void
CPUGather
(
const
platform
::
DeviceContext
&
ctx
,
const
paddle
::
framework
::
Tensor
*
src
,
const
paddle
::
framework
::
Tensor
*
index
,
paddle
::
framework
::
Tensor
*
output
)
{
PADDLE_ENFORCE
(
platform
::
is_cpu_place
(
place
));
PADDLE_ENFORCE
(
platform
::
is_cpu_place
(
ctx
.
GetPlace
()
));
// check index of shape 1-D
PADDLE_ENFORCE
(
index
->
dims
().
size
()
==
1
);
int
index_size
=
index
->
dims
()[
0
];
...
...
paddle/operators/gather_op.h
浏览文件 @
2ccaec4f
...
...
@@ -36,7 +36,7 @@ class GatherOpKernel : public framework::OpKernel<T> {
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
CPUGather
<
T
>
(
ctx
.
GetPlace
(),
x
,
index
,
output
);
CPUGather
<
T
>
(
ctx
.
device_context
(),
x
,
index
,
output
);
}
};
...
...
@@ -56,7 +56,7 @@ class GatherGradientOpKernel : public framework::OpKernel<T> {
auto
place
=
ctx
.
GetEigenDevice
<
platform
::
CPUPlace
>
();
dxt
.
device
(
place
)
=
dxt
.
constant
(
static_cast
<
T
>
(
0
));
ScatterAssign
<
T
>
(
ctx
.
GetPlace
(),
dO
,
Index
,
dX
);
ScatterAssign
<
T
>
(
ctx
.
device_context
(),
dO
,
Index
,
dX
);
}
};
...
...
paddle/operators/gather_test.cc
浏览文件 @
2ccaec4f
...
...
@@ -41,7 +41,9 @@ TEST(Gather, GatherData) {
int
*
p_output
=
output
->
mutable_data
<
int
>
(
make_ddim
({
2
,
4
}),
CPUPlace
());
CPUGather
<
int
>
(
CPUPlace
(),
src
,
index
,
output
);
auto
*
cpu_place
=
new
paddle
::
platform
::
CPUPlace
();
paddle
::
platform
::
CPUDeviceContext
ctx
(
*
cpu_place
);
CPUGather
<
int
>
(
ctx
,
src
,
index
,
output
);
for
(
int
i
=
0
;
i
<
4
;
++
i
)
EXPECT_EQ
(
p_output
[
i
],
i
+
4
);
for
(
int
i
=
4
;
i
<
8
;
++
i
)
EXPECT_EQ
(
p_output
[
i
],
i
-
4
);
...
...
paddle/operators/scatter.h
浏览文件 @
2ccaec4f
...
...
@@ -33,11 +33,11 @@ using Tensor = framework::Tensor;
* return: output tensor
*/
template
<
typename
T
>
void
ScatterAssign
(
const
platform
::
Place
&
place
,
void
ScatterAssign
(
const
platform
::
DeviceContext
&
ctx
,
const
paddle
::
framework
::
Tensor
*
src
,
const
paddle
::
framework
::
Tensor
*
index
,
paddle
::
framework
::
Tensor
*
output
)
{
PADDLE_ENFORCE
(
platform
::
is_cpu_place
(
place
));
PADDLE_ENFORCE
(
platform
::
is_cpu_place
(
ctx
.
GetPlace
()
));
// check index of shape 1-D
PADDLE_ENFORCE
(
index
->
dims
().
size
()
==
1
);
int
index_size
=
index
->
dims
()[
0
];
...
...
paddle/operators/scatter_op.h
浏览文件 @
2ccaec4f
...
...
@@ -37,7 +37,7 @@ class ScatterOpKernel : public framework::OpKernel<T> {
// In place output: Out = Ref, Out[Index] += Updates
Out
->
ShareDataWith
<
T
>
(
*
Ref
);
// Apply ScatterUpdate: Out[index] += Updates[:]
ScatterAssign
<
T
>
(
ctx
.
GetPlace
(),
Updates
,
Index
,
Out
);
ScatterAssign
<
T
>
(
ctx
.
device_context
(),
Updates
,
Index
,
Out
);
}
};
...
...
@@ -56,7 +56,7 @@ class ScatterGradientOpKernel : public framework::OpKernel<T> {
dRef
->
ShareDataWith
<
T
>
(
*
dOut
);
dUpdates
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
// Gradient by Gather: dUpdates += dO[Index]
CPUGather
<
T
>
(
ctx
.
GetPlace
(),
dOut
,
Index
,
dUpdates
);
CPUGather
<
T
>
(
ctx
.
device_context
(),
dOut
,
Index
,
dUpdates
);
}
};
...
...
paddle/operators/scatter_test.cc
浏览文件 @
2ccaec4f
...
...
@@ -40,7 +40,9 @@ TEST(scatter, ScatterUpdate) {
float
*
p_output
=
output
->
mutable_data
<
float
>
(
make_ddim
({
4
,
4
}),
CPUPlace
());
ScatterAssign
<
float
>
(
CPUPlace
(),
src
,
index
,
output
);
auto
*
cpu_place
=
new
paddle
::
platform
::
CPUPlace
();
paddle
::
platform
::
CPUDeviceContext
ctx
(
*
cpu_place
);
ScatterAssign
<
float
>
(
ctx
,
src
,
index
,
output
);
for
(
size_t
i
=
0
;
i
<
4
;
++
i
)
EXPECT_EQ
(
p_output
[
i
],
float
(
0
));
for
(
size_t
i
=
0
;
i
<
4
;
++
i
)
EXPECT_EQ
(
output
->
data
<
float
>
()[
i
],
float
(
0
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录