Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
384d6ee8
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
384d6ee8
编写于
4月 13, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
02842cfc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
40 deletion
+12
-40
paddle/fluid/framework/details/broadcast_op_handle.cc
paddle/fluid/framework/details/broadcast_op_handle.cc
+6
-31
paddle/fluid/framework/details/gather_op_handle.cc
paddle/fluid/framework/details/gather_op_handle.cc
+3
-6
paddle/fluid/framework/tensor_util.cc
paddle/fluid/framework/tensor_util.cc
+3
-3
未找到文件。
paddle/fluid/framework/details/broadcast_op_handle.cc
浏览文件 @
384d6ee8
...
...
@@ -61,33 +61,24 @@ void BroadcastOpHandle::RunImpl() {
// Wait input done, this Wait is asynchronous operation
auto
&
in_place
=
in_var_handle
[
0
]
->
place_
;
if
(
in_var_handle
[
0
]
->
generated_op_
)
{
in_var_handle
[
0
]
->
generated_op_
->
Wait
(
dev_ctxes_
[
in_place
]);
for
(
auto
*
out
:
out_var_handles
)
{
auto
&
out_p
=
out
->
place_
;
if
(
platform
::
is_same_place
(
in_place
,
out_p
))
continue
;
in_var_handle
[
0
]
->
generated_op_
->
Wait
(
dev_ctxes_
[
out_p
]);
}
}
//
auto
in_scope_idx
=
in_var_handle
[
0
]
->
scope_idx_
;
PADDLE_ENFORCE_LT
(
in_scope_idx
,
local_scopes_
.
size
(),
"The input(%s) is not in the local_scopes."
,
in_var_handle
[
0
]
->
name_
);
auto
in_var
=
local_scopes_
[
in_scope_idx
]
->
FindVar
(
in_var_handle
[
0
]
->
name_
);
auto
in_var
=
local_scopes_
.
at
(
in_scope_idx
)
->
FindVar
(
in_var_handle
[
0
]
->
name_
);
Tensor
*
in_tensor
=
GetTensorFromVar
(
in_var
);
for
(
auto
*
out
:
out_var_handles
)
{
auto
&
out_p
=
out
->
place_
;
auto
out_var
=
local_scopes_
.
at
(
out
->
scope_idx_
)
->
FindVar
(
out
->
name_
);
auto
out_scope_idx
=
out
->
scope_idx_
;
PADDLE_ENFORCE_LT
(
out_scope_idx
,
local_scopes_
.
size
(),
"%s is not in the local_scopes "
,
out
->
name_
);
auto
*
s
=
local_scopes_
[
out_scope_idx
];
auto
out_var
=
s
->
FindVar
(
out
->
name_
);
PADDLE_ENFORCE_EQ
(
out_p
.
which
(),
in_place
.
which
(),
"
The place of input and output should be the same
."
);
"
Places must be all on CPU or all on CUDA
."
);
if
(
in_var
->
IsType
<
framework
::
SelectedRows
>
())
{
auto
&
in_sr
=
in_var
->
Get
<
framework
::
SelectedRows
>
();
...
...
@@ -109,24 +100,8 @@ void BroadcastOpHandle::RunImpl() {
}
Tensor
*
out_tensor
=
GetTensorFromVar
(
out_var
);
if
(
platform
::
is_cpu_place
(
in_place
))
{
paddle
::
framework
::
TensorCopy
(
*
in_tensor
,
out_p
,
*
(
dev_ctxes_
[
in_place
]),
out_tensor
);
}
else
if
(
platform
::
is_gpu_place
(
in_place
))
{
#ifdef PADDLE_WITH_CUDA
auto
src_gpu_place
=
boost
::
get
<
platform
::
CUDAPlace
>
(
in_place
);
auto
dst_gpu_place
=
boost
::
get
<
platform
::
CUDAPlace
>
(
out_p
);
void
*
dst_ptr
=
out_tensor
->
mutable_data
(
out_p
);
void
*
src_ptr
=
in_tensor
->
data
<
void
>
();
int64_t
size
=
in_tensor
->
numel
()
*
SizeOfType
(
in_tensor
->
type
());
memory
::
Copy
(
dst_gpu_place
,
dst_ptr
,
src_gpu_place
,
src_ptr
,
size
,
reinterpret_cast
<
platform
::
CUDADeviceContext
*>
(
dev_ctxes_
[
out_p
])
->
stream
());
#else
PADDLE_THROW
(
"CUDAPlace is not supported in CPU device."
);
#endif
}
paddle
::
framework
::
TensorCopy
(
*
in_tensor
,
out_p
,
*
(
dev_ctxes_
[
in_place
]),
out_tensor
);
}
}
...
...
paddle/fluid/framework/details/gather_op_handle.cc
浏览文件 @
384d6ee8
...
...
@@ -74,13 +74,10 @@ void GatherOpHandle::RunImpl() {
auto
in_handle
=
static_cast
<
VarHandle
*>
(
in
);
auto
in_p
=
in_handle
->
place_
;
in_places
.
push_back
(
in_p
);
PADDLE_ENFORCE_LT
(
in_handle
->
scope_idx_
,
local_scopes_
.
size
(),
"%s is not the the local_scopes "
,
in_handle
->
name_
);
PADDLE_ENFORCE_EQ
(
in_p
.
which
(),
pre_place
.
which
(),
"The place of input should be the same."
);
auto
*
s
=
local_scopes_
[
in_handle
->
scope_idx_
];
auto
in_var
=
s
->
FindVar
(
in_handle
->
name_
);
"Places must be all on CPU or all on CUDA."
);
auto
in_var
=
local_scopes_
.
at
(
in_handle
->
scope_idx_
)
->
FindVar
(
in_handle
->
name_
);
auto
&
in_sr
=
in_var
->
Get
<
framework
::
SelectedRows
>
();
PADDLE_ENFORCE_EQ
(
in_sr
.
value
().
type
(),
pre_in
.
value
().
type
(),
...
...
paddle/fluid/framework/tensor_util.cc
浏览文件 @
384d6ee8
...
...
@@ -11,8 +11,10 @@
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 "paddle/fluid/framework/tensor_util.h"
#include <algorithm>
#include <limits>
#include <vector>
namespace
paddle
{
namespace
framework
{
...
...
@@ -65,8 +67,6 @@ void TensorCopy(const Tensor& src, const platform::Place& dst_place,
auto
dst_gpu_place
=
boost
::
get
<
platform
::
CUDAPlace
>
(
dst_place
);
auto
ctx_place
=
ctx
.
GetPlace
();
PADDLE_ENFORCE
(
platform
::
is_gpu_place
(
ctx_place
));
auto
ctx_gpu_place
=
boost
::
get
<
platform
::
CUDAPlace
>
(
ctx_place
);
PADDLE_ENFORCE_EQ
(
src_gpu_place
,
ctx_gpu_place
);
memory
::
Copy
(
dst_gpu_place
,
dst_ptr
,
src_gpu_place
,
src_ptr
,
size
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
ctx
).
stream
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录