Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
1039c1e3
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看板
提交
1039c1e3
编写于
12月 29, 2017
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
scatter optimizers
上级
641b4c0f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
30 deletion
+32
-30
paddle/operators/adagrad_op.cu
paddle/operators/adagrad_op.cu
+6
-4
paddle/operators/math/selected_rows_functor.cc
paddle/operators/math/selected_rows_functor.cc
+3
-4
paddle/operators/math/selected_rows_functor.cu
paddle/operators/math/selected_rows_functor.cu
+20
-18
paddle/operators/math/selected_rows_functor.h
paddle/operators/math/selected_rows_functor.h
+3
-4
未找到文件。
paddle/operators/adagrad_op.cu
浏览文件 @
1039c1e3
...
...
@@ -79,12 +79,12 @@ struct SparseAdagradFunctor<platform::CUDADeviceContext, T> {
framework
::
Tensor
*
moment
,
framework
::
Tensor
*
param
)
{
// 1. g_m.rows = set(g.rows)
auto
grad_width
=
grad
.
value
().
dims
()[
1
];
math
::
scatter
::
MergeAdd
<
platform
::
C
PU
DeviceContext
,
T
>
merge_func
;
math
::
scatter
::
MergeAdd
<
platform
::
C
UDA
DeviceContext
,
T
>
merge_func
;
auto
grad_merge
=
merge_func
(
context
,
grad
);
auto
*
grad_merge_data
=
grad_merge
.
mutable_value
()
->
template
data
<
T
>();
auto
&
merge_rows
=
grad_merge
.
rows
;
auto
&
merge_rows
=
grad_merge
.
rows
()
;
// 2. m += g_m * g_m
math
::
scatter
::
Mul
<
platform
::
C
PU
DeviceContext
,
T
>
sqare_func
;
math
::
scatter
::
Mul
<
platform
::
C
UDA
DeviceContext
,
T
>
sqare_func
;
auto
grad_square
=
sqare_func
(
context
,
grad_merge
,
grad_merge
);
math
::
SelectedRowsAddToTensor
<
platform
::
CUDADeviceContext
,
T
>
functor
;
...
...
@@ -95,11 +95,13 @@ struct SparseAdagradFunctor<platform::CUDADeviceContext, T> {
auto
*
param_data
=
param
->
data
<
T
>
();
auto
*
moment_data
=
moment
->
data
<
T
>
();
const
int
block_size
=
256
;
dim3
threads
(
block_size
,
1
);
dim3
grid2
(
1
,
merge_rows
.
size
());
SparseAdagradFunctorKernel
<
T
,
256
><<<
grid2
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
grad_merge_data
,
grad_merge
->
rows
().
data
(),
.
stream
()
>>>
(
grad_merge_data
,
grad_merge
.
rows
().
data
(),
lr
,
param_data
,
moment_data
,
grad_width
,
epsilon
);
}
...
...
paddle/operators/math/selected_rows_functor.cc
浏览文件 @
1039c1e3
...
...
@@ -233,10 +233,9 @@ template struct MergeAdd<platform::CPUDeviceContext, int64_t>;
template
<
typename
T
>
struct
UpdateToTensor
<
platform
::
CPUDeviceContext
,
T
>
{
framework
::
Tensor
operator
()(
const
platform
::
CPUDeviceContext
&
context
,
const
ScatterOps
&
op
,
const
framework
::
SelectedRows
&
input1
,
framework
::
Tensor
*
input2
)
{
void
operator
()(
const
platform
::
CPUDeviceContext
&
context
,
const
ScatterOps
&
op
,
const
framework
::
SelectedRows
&
input1
,
framework
::
Tensor
*
input2
)
{
auto
in1_height
=
input1
.
height
();
auto
in2_dims
=
input2
->
dims
();
PADDLE_ENFORCE_EQ
(
in1_height
,
in2_dims
[
0
]);
...
...
paddle/operators/math/selected_rows_functor.cu
浏览文件 @
1039c1e3
...
...
@@ -12,6 +12,8 @@ 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. */
#include <set>
#include "paddle/operators/math/math_function.h"
#include "paddle/operators/math/selected_rows_functor.h"
#include "paddle/platform/cuda_helper.h"
...
...
@@ -251,8 +253,8 @@ __global__ void MergeAddKernel(const T* input, const int64_t* input_rows,
}
template
<
typename
T
>
struct
MergeAdd
<
platform
::
GPU
DeviceContext
,
T
>
{
framework
::
SelectedRows
operator
()(
const
platform
::
GPU
DeviceContext
&
context
,
struct
MergeAdd
<
platform
::
CUDA
DeviceContext
,
T
>
{
framework
::
SelectedRows
operator
()(
const
platform
::
CUDA
DeviceContext
&
context
,
const
framework
::
SelectedRows
&
input
)
{
framework
::
SelectedRows
out
;
auto
input_rows
=
input
.
rows
();
...
...
@@ -288,10 +290,10 @@ struct MergeAdd<platform::GPUDeviceContext, T> {
}
};
template
struct
MergeAdd
<
platform
::
GPU
DeviceContext
,
float
>;
template
struct
MergeAdd
<
platform
::
GPU
DeviceContext
,
double
>;
template
struct
MergeAdd
<
platform
::
GPU
DeviceContext
,
int
>;
template
struct
MergeAdd
<
platform
::
GPU
DeviceContext
,
int64_t
>;
template
struct
MergeAdd
<
platform
::
CUDA
DeviceContext
,
float
>;
template
struct
MergeAdd
<
platform
::
CUDA
DeviceContext
,
double
>;
template
struct
MergeAdd
<
platform
::
CUDA
DeviceContext
,
int
>;
template
struct
MergeAdd
<
platform
::
CUDA
DeviceContext
,
int64_t
>;
template
<
typename
T
,
int
block_size
>
__global__
void
UpdateToTensorKernel
(
const
T
*
selected_rows
,
...
...
@@ -343,14 +345,14 @@ __global__ void UpdateToTensorKernel(const T* selected_rows,
}
template
<
typename
T
>
struct
UpdateToTensor
<
platform
::
GPUDeviceContext
,
T
>
{
framework
::
Tensor
operator
()(
const
platform
::
GPUDeviceContext
&
context
,
const
ScatterOps
&
op
,
const
framework
::
SelectedRows
&
input1
,
framework
::
Tensor
*
input2
)
{
struct
UpdateToTensor
<
platform
::
CUDADeviceContext
,
T
>
{
void
operator
()(
const
platform
::
CUDADeviceContext
&
context
,
const
ScatterOps
&
op
,
const
framework
::
SelectedRows
&
input1
,
framework
::
Tensor
*
input2
)
{
// NOTE: Use SelectedRowsAddToTensor for better performance
// no additional MergeAdd called.
auto
merged_in1
=
MergeAdd
()(
context
,
input1
);
MergeAdd
<
platform
::
CUDADeviceContext
,
T
>
merge_func
;
auto
merged_in1
=
merge_func
(
context
,
input1
);
auto
in1_height
=
merged_in1
.
height
();
auto
in2_dims
=
input2
->
dims
();
...
...
@@ -362,14 +364,14 @@ struct UpdateToTensor<platform::GPUDeviceContext, T> {
int64_t
in1_row_numel
=
in1_value
.
numel
()
/
in1_rows
.
size
();
PADDLE_ENFORCE_EQ
(
in1_row_numel
,
input2
->
numel
()
/
in1_height
);
auto
*
in1_data
=
in1_value
.
data
<
T
>
();
auto
*
in
put
2_data
=
input2
->
data
<
T
>
();
auto
*
in1_data
=
in1_value
.
template
data
<
T
>();
auto
*
in2_data
=
input2
->
data
<
T
>
();
dim3
threads
(
PADDLE_CUDA_NUM_THREADS
,
1
);
dim3
threads
(
platform
::
PADDLE_CUDA_NUM_THREADS
,
1
);
dim3
grid
(
1
,
in1_rows
.
size
());
UpdateToTensorKernel
<
T
,
PADDLE_CUDA_NUM_THREADS
><<<
grid
,
threads
,
0
,
context
.
stream
()
>>>
(
in1_data
,
in1_rows
.
data
(),
op
,
in2_data
,
in1_row_numel
);
UpdateToTensorKernel
<
T
,
platform
::
PADDLE_CUDA_NUM_THREADS
><<<
grid
,
threads
,
0
,
context
.
stream
()
>>>
(
in1_data
,
in1_rows
.
data
(),
op
,
in2_data
,
in1_row_numel
);
}
};
}
// namespace scatter
...
...
paddle/operators/math/selected_rows_functor.h
浏览文件 @
1039c1e3
...
...
@@ -123,10 +123,9 @@ enum class ScatterOps { ASSIGN, ADD, SUB, SUBBY, MUL, DIV, DIVBY };
// out = seleted_rows_in / tensor
template
<
typename
DeviceContext
,
typename
T
>
struct
UpdateToTensor
{
framework
::
Tensor
operator
()(
const
DeviceContext
&
context
,
const
ScatterOps
&
op
,
const
framework
::
SelectedRows
&
input1
,
framework
::
Tensor
*
input2
);
void
operator
()(
const
DeviceContext
&
context
,
const
ScatterOps
&
op
,
const
framework
::
SelectedRows
&
input1
,
framework
::
Tensor
*
input2
);
};
}
// namespace scatter
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录