Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
7c5fd231
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
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,
}
MatrixPtr
MultiGradientMachine
::
getLayerOutput
(
const
std
::
string
&
layerName
)
{
// neural networks are same in each trainer thread
// layer output height = height of layer output * thread nums
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
);
}
// each thread has the same neuro network
auto
nn
=
threads_
[
0
]
->
getGradientMachine
();
MatrixPtr
tmpMatrix
=
dst
->
subMatrix
(
startRow
,
src
->
getHeight
());
tmpMatrix
->
copyFrom
(
*
src
,
stream
);
};
size_t
height
=
0
;
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
;
size_t
startRow
=
0
;
MatrixPtr
dst
;
Matrix
::
resizeOrCreate
(
dst
,
height
,
width
,
false
,
useGpu_
)
;
// copy one layer output from one trainer thread at each time
size_t
startRow
=
0
;
for
(
auto
&
thread
:
threads_
)
{
auto
nn
=
dynamic_cast
<
NeuralNetwork
*>
(
thread
->
getGradientMachine
()
);
auto
mat
=
nn
->
getLayerOutput
(
layerName
);
copyLayerOutput
(
mats
,
mat
,
startRow
,
useGpu_
);
startRow
+=
mat
->
getHeight
();
auto
src
=
thread
->
getGradientMachine
()
->
getLayerOutput
(
layerName
);
auto
tmpMatrix
=
dst
->
subMatrix
(
startRow
,
src
->
getHeight
()
);
tmpMatrix
->
copyFrom
(
*
src
,
HPPL_STREAM_DEFAULT
);
startRow
+=
src
->
getHeight
();
}
if
(
useGpu_
)
{
hl_stream_synchronize
(
HPPL_STREAM_DEFAULT
);
}
return
mats
;
return
dst
;
}
void
MultiGradientMachine
::
backwardImp
(
const
UpdateCallback
&
callback
)
{
...
...
paddle/gserver/layers/CosSimLayer.cpp
浏览文件 @
7c5fd231
...
...
@@ -42,7 +42,7 @@ void CosSimLayer::forward(PassType passType) {
/* malloc memory for the output_ if necessary */
int
batchSize
=
getInputValue
(
0
)
->
getHeight
();
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
());
...
...
paddle/math/tests/test_RowBuffer.cpp
浏览文件 @
7c5fd231
...
...
@@ -17,10 +17,10 @@ limitations under the License. */
TEST
(
RowBuffer
,
testAutoGrow
)
{
paddle
::
RowBuffer
buf
(
128
);
ASSERT_EQ
(
128
,
buf
.
getWidth
());
ASSERT_EQ
(
128
UL
,
buf
.
getWidth
());
ASSERT_TRUE
(
buf
.
isAutoGrowth
());
buf
.
resize
(
2
);
ASSERT_EQ
(
2
,
buf
.
getRowCount
());
ASSERT_EQ
(
2
UL
,
buf
.
getRowCount
());
for
(
size_t
i
=
0
;
i
<
buf
.
getWidth
()
*
2
;
++
i
)
{
buf
.
data
()[
i
]
=
i
;
}
...
...
@@ -35,7 +35,7 @@ TEST(RowBuffer, testAutoGrow) {
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
j
=
0
;
j
<
buf
.
getWidth
();
++
j
)
{
ASSERT_NEAR
(
i
*
buf
.
getWidth
()
+
j
,
buf
.
get
(
i
)[
j
],
1e-5
);
...
...
@@ -51,7 +51,7 @@ TEST(RowBuffer, testWithMemBuf) {
std
::
make_shared
<
paddle
::
CpuMemoryHandle
>
(
128
*
2
*
sizeof
(
real
));
paddle
::
RowBuffer
buf
(
mem
,
128
);
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
)
{
buf
.
data
()[
i
]
=
i
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录