Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4db23bba
P
Paddle
项目概览
PaddlePaddle
/
Paddle
11 个月 前同步成功
通知
2292
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4db23bba
编写于
6月 27, 2017
作者:
H
hedaoyuan
提交者:
GitHub
6月 27, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2618 from hedaoyuan/fix_copyFrom
Change the CpuMatrix::copyFrom and CpuVector::copyFrom with the strea…
上级
7978f05d
49e87ee3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
29 addition
and
5 deletion
+29
-5
paddle/gserver/layers/Layer.cpp
paddle/gserver/layers/Layer.cpp
+5
-0
paddle/math/Matrix.cpp
paddle/math/Matrix.cpp
+2
-0
paddle/math/Matrix.h
paddle/math/Matrix.h
+2
-1
paddle/math/Vector.cpp
paddle/math/Vector.cpp
+2
-0
paddle/math/Vector.h
paddle/math/Vector.h
+4
-4
paddle/math/tests/test_matrixCompare.cpp
paddle/math/tests/test_matrixCompare.cpp
+14
-0
未找到文件。
paddle/gserver/layers/Layer.cpp
浏览文件 @
4db23bba
...
...
@@ -191,6 +191,11 @@ void Layer::addOutputArgument(int deviceId) {
void
Layer
::
copyOutputToOtherDevice
()
{
for
(
size_t
i
=
0
;
i
!=
outputOtherDevice_
.
size
();
i
++
)
{
SetDevice
device
(
outputOtherDevice_
[
i
].
deviceId
);
// If outputOtherDevice_[i].value is a CpuMatrix,
// the copyFrom is a synchronous interface.
// If outputOtherDevice_[i].value is a GpuMatrix, since subsequent
// calculations are all on HPPL_STREAM_DEFAULT,
// copyFrom can be an asynchronous interface.
outputOtherDevice_
[
i
].
value
->
copyFrom
(
*
getOutputValue
(),
HPPL_STREAM_DEFAULT
);
outputOtherDevice_
[
i
].
sequenceStartPositions
=
...
...
paddle/math/Matrix.cpp
浏览文件 @
4db23bba
...
...
@@ -1565,6 +1565,8 @@ void CpuMatrix::copyFrom(const Matrix& src, hl_stream_t stream) {
const_cast
<
real
*>
(
src
.
getData
()),
sizeof
(
real
)
*
elementCnt_
,
stream
);
// There is a need to add synchronization to ensure that the data is copied.
hl_stream_synchronize
(
stream
);
}
else
if
(
typeid
(
src
)
==
typeid
(
CpuMatrix
))
{
memcpy
(
data_
,
src
.
getData
(),
sizeof
(
real
)
*
elementCnt_
);
}
else
{
...
...
paddle/math/Matrix.h
浏览文件 @
4db23bba
...
...
@@ -239,7 +239,8 @@ public:
LOG
(
FATAL
)
<<
"Not implemented"
;
}
// asynchronous copy
// For GpuMatrix this is an asynchronous copy interface
// For CpuMatrix this is an synchronous copy interface
virtual
void
copyFrom
(
const
Matrix
&
src
,
hl_stream_t
stream
)
{
LOG
(
FATAL
)
<<
"Not implemented"
;
}
...
...
paddle/math/Vector.cpp
浏览文件 @
4db23bba
...
...
@@ -657,6 +657,8 @@ void CpuVectorT<T>::copyFrom(const VectorT<T>& src, hl_stream_t stream) {
(
void
*
)
src
.
getData
(),
sizeof
(
T
)
*
this
->
getSize
(),
stream
);
// There is a need to add synchronization to ensure that the data is copied.
hl_stream_synchronize
(
stream
);
}
else
{
src
.
copyTo
(
this
);
}
...
...
paddle/math/Vector.h
浏览文件 @
4db23bba
...
...
@@ -168,11 +168,11 @@ public:
virtual
void
copyFrom
(
const
VectorT
<
T
>&
src
)
=
0
;
/**
* If
use_gpu, this function will push the copy-task to the specifed-stream
* and return immediately.
* If
GpuVector, this function is an asynchronous interface,
*
will push the copy-task to the specifed-stream
and return immediately.
*
* If
not use GPU, this function is same as
*
the copyFrom(const VectorT<T>& src), which use stream HPPL_STREAM_DEFAULT
.
* If
CpuVector, this function is an synchronous interface,
*
same as the copyFrom(const VectorT<T>& src)
.
*/
virtual
void
copyFrom
(
const
VectorT
<
T
>&
src
,
hl_stream_t
stream
)
=
0
;
...
...
paddle/math/tests/test_matrixCompare.cpp
浏览文件 @
4db23bba
...
...
@@ -1127,4 +1127,18 @@ TEST(Matrix, MaxOutFwdBwd) {
}
}
TEST
(
CpuMatrix
,
copyFrom
)
{
const
size_t
height
=
1000
;
const
size_t
width
=
1000
;
CpuMatrix
cpu
(
height
,
width
);
GpuMatrix
gpu
(
height
,
width
);
CpuMatrix
copy
(
height
,
width
);
cpu
.
randomizeUniform
();
gpu
.
copyFrom
(
cpu
);
copy
.
copyFrom
(
gpu
,
HPPL_STREAM_DEFAULT
);
TensorCheckEqual
(
cpu
,
copy
);
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录