Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
7c5fd231
P
Paddle
项目概览
wzpei9
/
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,发现更多精彩内容 >>
提交
7c5fd231
编写于
2月 17, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update MultiGradientMachine::getLayerOutput
上级
393d8354
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
22 addition
and
29 deletion
+22
-29
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
+17
-24
paddle/gserver/layers/CosSimLayer.cpp
paddle/gserver/layers/CosSimLayer.cpp
+1
-1
paddle/math/tests/test_RowBuffer.cpp
paddle/math/tests/test_RowBuffer.cpp
+4
-4
未找到文件。
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
浏览文件 @
7c5fd231
...
@@ -283,41 +283,34 @@ void MultiGradientMachine::forwardBackward(const std::vector<Argument>& inArgs,
...
@@ -283,41 +283,34 @@ void MultiGradientMachine::forwardBackward(const std::vector<Argument>& inArgs,
}
}
MatrixPtr
MultiGradientMachine
::
getLayerOutput
(
const
std
::
string
&
layerName
)
{
MatrixPtr
MultiGradientMachine
::
getLayerOutput
(
const
std
::
string
&
layerName
)
{
// neural networks are same in each trainer thread
// each thread has the same neuro network
// layer output height = height of layer output * thread nums
auto
nn
=
threads_
[
0
]
->
getGradientMachine
();
auto
nn
=
dynamic_cast
<
NeuralNetwork
*>
(
threads_
[
0
]
->
getGradientMachine
());
auto
height
=
nn
->
getLayerOutput
(
layerName
)
->
getHeight
()
*
threads_
.
size
();
auto
stream
=
HPPL_STREAM_DEFAULT
;
auto
copyLayerOutput
=
[
height
,
stream
](
MatrixPtr
&
dst
,
MatrixPtr
src
,
int
startRow
,
bool
useGpu
)
{
size_t
width
=
src
->
getWidth
();
if
(
!
dst
)
{
dst
=
src
->
clone
(
height
,
width
,
useGpu
);
}
else
{
dst
->
resize
(
height
,
width
);
}
MatrixPtr
tmpMatrix
=
dst
->
subMatrix
(
startRow
,
src
->
getHeight
());
size_t
height
=
0
;
tmpMatrix
->
copyFrom
(
*
src
,
stream
);
size_t
width
=
nn
->
getLayerOutput
(
layerName
)
->
getWidth
();
};
for
(
auto
&
thread
:
threads_
)
{
auto
out
=
thread
->
getGradientMachine
()
->
getLayerOutput
(
layerName
);
height
+=
out
->
getHeight
();
CHECK_EQ
(
width
,
out
->
getWidth
());
}
MatrixPtr
mats
;
MatrixPtr
dst
;
size_t
startRow
=
0
;
Matrix
::
resizeOrCreate
(
dst
,
height
,
width
,
false
,
useGpu_
)
;
// copy one layer output from one trainer thread at each time
// copy one layer output from one trainer thread at each time
size_t
startRow
=
0
;
for
(
auto
&
thread
:
threads_
)
{
for
(
auto
&
thread
:
threads_
)
{
auto
nn
=
dynamic_cast
<
NeuralNetwork
*>
(
thread
->
getGradientMachine
()
);
auto
src
=
thread
->
getGradientMachine
()
->
getLayerOutput
(
layerName
);
auto
mat
=
nn
->
getLayerOutput
(
layerName
);
auto
tmpMatrix
=
dst
->
subMatrix
(
startRow
,
src
->
getHeight
()
);
copyLayerOutput
(
mats
,
mat
,
startRow
,
useGpu_
);
tmpMatrix
->
copyFrom
(
*
src
,
HPPL_STREAM_DEFAULT
);
startRow
+=
mat
->
getHeight
();
startRow
+=
src
->
getHeight
();
}
}
if
(
useGpu_
)
{
if
(
useGpu_
)
{
hl_stream_synchronize
(
HPPL_STREAM_DEFAULT
);
hl_stream_synchronize
(
HPPL_STREAM_DEFAULT
);
}
}
return
mats
;
return
dst
;
}
}
void
MultiGradientMachine
::
backwardImp
(
const
UpdateCallback
&
callback
)
{
void
MultiGradientMachine
::
backwardImp
(
const
UpdateCallback
&
callback
)
{
...
...
paddle/gserver/layers/CosSimLayer.cpp
浏览文件 @
7c5fd231
...
@@ -42,7 +42,7 @@ void CosSimLayer::forward(PassType passType) {
...
@@ -42,7 +42,7 @@ void CosSimLayer::forward(PassType passType) {
/* malloc memory for the output_ if necessary */
/* malloc memory for the output_ if necessary */
int
batchSize
=
getInputValue
(
0
)
->
getHeight
();
int
batchSize
=
getInputValue
(
0
)
->
getHeight
();
int
size
=
getSize
();
int
size
=
getSize
();
CHECK_EQ
(
forward_
.
size
(),
1
)
<<
"Only one forward function needed"
;
CHECK_EQ
(
forward_
.
size
(),
1
UL
)
<<
"Only one forward function needed"
;
{
{
REGISTER_TIMER_INFO
(
"CosFwResetTimer"
,
getName
().
c_str
());
REGISTER_TIMER_INFO
(
"CosFwResetTimer"
,
getName
().
c_str
());
...
...
paddle/math/tests/test_RowBuffer.cpp
浏览文件 @
7c5fd231
...
@@ -17,10 +17,10 @@ limitations under the License. */
...
@@ -17,10 +17,10 @@ limitations under the License. */
TEST
(
RowBuffer
,
testAutoGrow
)
{
TEST
(
RowBuffer
,
testAutoGrow
)
{
paddle
::
RowBuffer
buf
(
128
);
paddle
::
RowBuffer
buf
(
128
);
ASSERT_EQ
(
128
,
buf
.
getWidth
());
ASSERT_EQ
(
128
UL
,
buf
.
getWidth
());
ASSERT_TRUE
(
buf
.
isAutoGrowth
());
ASSERT_TRUE
(
buf
.
isAutoGrowth
());
buf
.
resize
(
2
);
buf
.
resize
(
2
);
ASSERT_EQ
(
2
,
buf
.
getRowCount
());
ASSERT_EQ
(
2
UL
,
buf
.
getRowCount
());
for
(
size_t
i
=
0
;
i
<
buf
.
getWidth
()
*
2
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
buf
.
getWidth
()
*
2
;
++
i
)
{
buf
.
data
()[
i
]
=
i
;
buf
.
data
()[
i
]
=
i
;
}
}
...
@@ -35,7 +35,7 @@ TEST(RowBuffer, testAutoGrow) {
...
@@ -35,7 +35,7 @@ TEST(RowBuffer, testAutoGrow) {
data
[
i
]
=
i
;
data
[
i
]
=
i
;
}
}
ASSERT_EQ
(
3
,
buf
.
getRowCount
());
ASSERT_EQ
(
3
UL
,
buf
.
getRowCount
());
for
(
size_t
i
=
0
;
i
<
buf
.
getRowCount
()
-
1
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
buf
.
getRowCount
()
-
1
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
buf
.
getWidth
();
++
j
)
{
for
(
size_t
j
=
0
;
j
<
buf
.
getWidth
();
++
j
)
{
ASSERT_NEAR
(
i
*
buf
.
getWidth
()
+
j
,
buf
.
get
(
i
)[
j
],
1e-5
);
ASSERT_NEAR
(
i
*
buf
.
getWidth
()
+
j
,
buf
.
get
(
i
)[
j
],
1e-5
);
...
@@ -51,7 +51,7 @@ TEST(RowBuffer, testWithMemBuf) {
...
@@ -51,7 +51,7 @@ TEST(RowBuffer, testWithMemBuf) {
std
::
make_shared
<
paddle
::
CpuMemoryHandle
>
(
128
*
2
*
sizeof
(
real
));
std
::
make_shared
<
paddle
::
CpuMemoryHandle
>
(
128
*
2
*
sizeof
(
real
));
paddle
::
RowBuffer
buf
(
mem
,
128
);
paddle
::
RowBuffer
buf
(
mem
,
128
);
ASSERT_TRUE
(
!
buf
.
isAutoGrowth
());
ASSERT_TRUE
(
!
buf
.
isAutoGrowth
());
ASSERT_EQ
(
2
,
buf
.
getRowCount
());
ASSERT_EQ
(
2
UL
,
buf
.
getRowCount
());
for
(
size_t
i
=
0
;
i
<
buf
.
getWidth
()
*
2
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
buf
.
getWidth
()
*
2
;
++
i
)
{
buf
.
data
()[
i
]
=
i
;
buf
.
data
()[
i
]
=
i
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录