Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
橘蓝
Paddle
提交
f9681459
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,发现更多精彩内容 >>
提交
f9681459
编写于
10月 17, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix gpu build error
上级
ab8cc401
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
23 addition
and
8 deletion
+23
-8
paddle/operators/sgd_op.cc
paddle/operators/sgd_op.cc
+1
-1
paddle/operators/sgd_op.cu
paddle/operators/sgd_op.cu
+3
-3
paddle/operators/sgd_op.h
paddle/operators/sgd_op.h
+1
-1
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+9
-1
python/paddle/v2/framework/tests/test_sgd_op.py
python/paddle/v2/framework/tests/test_sgd_op.py
+9
-2
未找到文件。
paddle/operators/sgd_op.cc
浏览文件 @
f9681459
...
...
@@ -61,7 +61,7 @@ param_out = param - learning_rate * grad;
template
<
typename
T
>
struct
SparseSGDFunctor
<
platform
::
CPUPlace
,
T
>
{
void
operator
()(
const
platform
::
DeviceContext
&
c
tx
,
void
operator
()(
const
platform
::
DeviceContext
&
c
ontext
,
const
framework
::
SelectedRows
&
input
,
const
framework
::
Tensor
&
learning_rate
,
framework
::
Tensor
*
output
)
{
...
...
paddle/operators/sgd_op.cu
浏览文件 @
f9681459
...
...
@@ -34,15 +34,15 @@ __global__ void SparseSGDFunctorKernel(const T* selected_rows,
for
(
int
index
=
tid
;
index
<
row_numel
;
index
+=
block_size
)
{
// Since index in rows of SelectedRows can be duplicate, we have to use
// Atomic Operation to avoid concurrent write error.
paddle
::
platform
::
CudaAtomic
Sub
(
tensor_out
+
index
,
learning_rate
[
0
]
*
selected_rows
[
index
]);
paddle
::
platform
::
CudaAtomic
Add
(
tensor_out
+
index
,
-
1.0
*
learning_rate
[
0
]
*
selected_rows
[
index
]);
}
}
}
// namespace
template
<
typename
T
>
struct
SparseSGDFunctor
<
platform
::
GPUPlace
,
T
>
{
void
operator
()(
const
platform
::
DeviceContext
&
c
tx
,
void
operator
()(
const
platform
::
DeviceContext
&
c
ontext
,
const
framework
::
SelectedRows
&
input
,
const
framework
::
Tensor
&
learning_rate
,
framework
::
Tensor
*
output
)
{
...
...
paddle/operators/sgd_op.h
浏览文件 @
f9681459
...
...
@@ -22,7 +22,7 @@ namespace operators {
template
<
typename
Place
,
typename
T
>
struct
SparseSGDFunctor
{
void
operator
()(
const
platform
::
DeviceContext
&
c
tx
,
void
operator
()(
const
platform
::
DeviceContext
&
c
ontext
,
const
framework
::
SelectedRows
&
input
,
const
framework
::
Tensor
&
learning_rate
,
framework
::
Tensor
*
output
);
...
...
paddle/pybind/pybind.cc
浏览文件 @
f9681459
...
...
@@ -153,7 +153,15 @@ PYBIND11_PLUGIN(core) {
py
::
return_value_policy
::
reference
)
.
def
(
"set_height"
,
&
SelectedRows
::
set_height
)
.
def
(
"height"
,
&
SelectedRows
::
height
)
.
def
(
"set_rows"
,
&
SelectedRows
::
set_rows
)
.
def
(
"set_rows"
,
[](
SelectedRows
&
self
,
std
::
vector
<
int64_t
>
rows
)
{
#ifndef PADDLE_WITH_CUDA
self
.
set_rows
(
rows
);
#else
Vector
<
int64_t
>
new_rows
(
rows
);
self
.
set_rows
(
new_rows
);
#endif
})
.
def
(
"rows"
,
[](
SelectedRows
&
self
)
{
#ifndef PADDLE_WITH_CUDA
return
self
.
rows
();
...
...
python/paddle/v2/framework/tests/test_sgd_op.py
浏览文件 @
f9681459
...
...
@@ -20,11 +20,10 @@ class TestSGDOp(OpTest):
class
TestSparseSGDOp
(
unittest
.
TestCase
):
def
test_sparse_sgd
(
self
):
def
check_with_place
(
self
,
place
):
scope
=
core
.
Scope
()
# create and initialize Grad Variable
place
=
core
.
CPUPlace
()
height
=
10
rows
=
[
0
,
4
,
7
]
row_numel
=
12
...
...
@@ -35,6 +34,7 @@ class TestSparseSGDOp(unittest.TestCase):
np_array
=
np
.
ones
((
len
(
rows
),
row_numel
)).
astype
(
"float32"
)
np_array
[
0
,
0
]
=
2.0
np_array
[
2
,
8
]
=
4.0
grad_tensor
=
grad_selected_rows
.
get_tensor
()
grad_tensor
.
set
(
np_array
,
place
)
...
...
@@ -76,6 +76,13 @@ class TestSparseSGDOp(unittest.TestCase):
# rows[2] = 7, 5.0 - 2.0 * 4.0
self
.
assertAlmostEqual
(
-
3.0
,
result_array
[
rows
[
2
],
8
])
def
test_sparse_sgd
(
self
):
places
=
[
core
.
CPUPlace
()]
if
core
.
is_compile_gpu
():
places
.
append
(
core
.
GPUPlace
(
0
))
for
place
in
places
:
self
.
check_with_place
(
place
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录