Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
84b8baf1
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看板
提交
84b8baf1
编写于
10月 02, 2017
作者:
Z
zchen0211
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gather scatter with cuda streams
上级
15941dbd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
14 deletion
+18
-14
paddle/operators/gather.cu.h
paddle/operators/gather.cu.h
+8
-5
paddle/operators/gather_op.cu
paddle/operators/gather_op.cu
+2
-3
paddle/operators/scatter.cu.h
paddle/operators/scatter.cu.h
+6
-4
paddle/operators/scatter_op.cu
paddle/operators/scatter_op.cu
+2
-2
未找到文件。
paddle/operators/gather.cu.h
浏览文件 @
84b8baf1
...
...
@@ -46,9 +46,9 @@ __global__ void GatherCUDAKernel(const T* params, const int* indices, T* output,
* return: output tensor
*/
template
<
typename
T
>
void
GPUGather
(
const
Place
&
place
,
const
Tensor
*
src
,
const
Tensor
*
index
,
Tensor
*
output
)
{
PADDLE_ENFORCE
(
platform
::
is_gpu_place
(
place
));
void
GPUGather
(
const
platform
::
DeviceContext
&
ctx
,
const
Tensor
*
src
,
const
Tensor
*
index
,
Tensor
*
output
)
{
//
PADDLE_ENFORCE(platform::is_gpu_place(place));
// check index of shape 1-D
PADDLE_ENFORCE
(
index
->
dims
().
size
()
==
1
);
int
index_size
=
index
->
dims
()[
0
];
...
...
@@ -68,8 +68,11 @@ void GPUGather(const Place& place, const Tensor* src, const Tensor* index,
int
block
=
512
;
int
n
=
slice_size
*
index_size
;
int
grid
=
(
n
+
block
-
1
)
/
block
;
GatherCUDAKernel
<
T
><<<
grid
,
block
>>>
(
p_src
,
p_index
,
p_output
,
index_size
,
slice_size
);
GatherCUDAKernel
<
T
><<<
grid
,
block
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
ctx
).
stream
()
>>>
(
p_src
,
p_index
,
p_output
,
index_size
,
slice_size
);
}
}
// namespace operators
...
...
paddle/operators/gather_op.cu
浏览文件 @
84b8baf1
...
...
@@ -32,7 +32,7 @@ class GatherOpCUDAKernel : public framework::OpKernel<T> {
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
GPUGather
<
T
>
(
ctx
.
GetPlace
(),
x
,
index
,
output
);
GPUGather
<
T
>
(
ctx
.
device_context
(),
x
,
index
,
output
);
}
};
...
...
@@ -42,7 +42,6 @@ class GatherGradOpCUDAKernel : public framework::OpKernel<T> {
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
PADDLE_ENFORCE
(
platform
::
is_gpu_place
(
ctx
.
GetPlace
()),
"This kernel only runs on GPU device."
);
LOG
(
INFO
)
<<
"Gather grad here"
;
auto
*
Index
=
ctx
.
Input
<
Tensor
>
(
"Index"
);
auto
*
dX
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
dO
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
...
...
@@ -53,7 +52,7 @@ class GatherGradOpCUDAKernel : public framework::OpKernel<T> {
auto
place
=
ctx
.
GetEigenDevice
<
platform
::
GPUPlace
>
();
dxt
.
device
(
place
)
=
dxt
.
constant
(
static_cast
<
T
>
(
0
));
GPUScatterAssign
<
T
>
(
ctx
.
GetPlace
(),
dO
,
Index
,
dX
);
GPUScatterAssign
<
T
>
(
ctx
.
device_context
(),
dO
,
Index
,
dX
);
}
};
...
...
paddle/operators/scatter.cu.h
浏览文件 @
84b8baf1
...
...
@@ -45,11 +45,11 @@ __global__ void ScatterCUDAKernel(const T* params, const int* indices,
* return: output tensor
*/
template
<
typename
T
>
void
GPUScatterAssign
(
const
platform
::
Place
&
place
,
void
GPUScatterAssign
(
const
platform
::
DeviceContext
&
ctx
,
const
paddle
::
framework
::
Tensor
*
src
,
const
paddle
::
framework
::
Tensor
*
index
,
paddle
::
framework
::
Tensor
*
output
)
{
PADDLE_ENFORCE
(
platform
::
is_gpu_place
(
place
));
//
PADDLE_ENFORCE(platform::is_gpu_place(place));
// check index of shape 1-D
PADDLE_ENFORCE
(
index
->
dims
().
size
()
==
1
);
int
index_size
=
index
->
dims
()[
0
];
...
...
@@ -70,8 +70,10 @@ void GPUScatterAssign(const platform::Place& place,
int
n
=
slice_size
*
index_size
;
int
grid
=
(
n
+
block
-
1
)
/
block
;
ScatterCUDAKernel
<
T
><<<
grid
,
block
>>>
(
p_src
,
p_index
,
p_output
,
index_size
,
slice_size
);
ScatterCUDAKernel
<
T
><<<
grid
,
block
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
ctx
).
stream
()
>>>
(
p_src
,
p_index
,
p_output
,
index_size
,
slice_size
);
}
}
// namespace operators
...
...
paddle/operators/scatter_op.cu
浏览文件 @
84b8baf1
...
...
@@ -32,7 +32,7 @@ class ScatterOpCUDAKernel : public framework::OpKernel<T> {
Out
->
ShareDataWith
<
T
>
(
*
Ref
);
GPUScatterAssign
<
T
>
(
ctx
.
GetPlace
(),
Updates
,
Index
,
Out
);
GPUScatterAssign
<
T
>
(
ctx
.
device_context
(),
Updates
,
Index
,
Out
);
}
};
...
...
@@ -51,7 +51,7 @@ class ScatterGradOpCUDAKernel : public framework::OpKernel<T> {
dRef
->
ShareDataWith
<
T
>
(
*
dOut
);
dUpdates
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
// Gradient by Gather: dUpdates = dO[Index]
GPUGather
<
T
>
(
ctx
.
GetPlace
(),
dOut
,
Index
,
dUpdates
);
GPUGather
<
T
>
(
ctx
.
device_context
(),
dOut
,
Index
,
dUpdates
);
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录