Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
a14be225
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a14be225
编写于
5月 28, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1594 refine data copy in multi-graph
Merge pull request !1594 from zyli2020/r0.3
上级
1289c3e4
32dbbc1d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
73 addition
and
18 deletion
+73
-18
mindspore/ccsrc/session/gpu_session.cc
mindspore/ccsrc/session/gpu_session.cc
+44
-0
mindspore/ccsrc/session/gpu_session.h
mindspore/ccsrc/session/gpu_session.h
+3
-0
mindspore/ccsrc/session/session_basic.cc
mindspore/ccsrc/session/session_basic.cc
+1
-1
mindspore/ccsrc/utils/convert_utils.cc
mindspore/ccsrc/utils/convert_utils.cc
+1
-1
tests/st/ops/gpu/test_float_status_op.py
tests/st/ops/gpu/test_float_status_op.py
+24
-16
未找到文件。
mindspore/ccsrc/session/gpu_session.cc
浏览文件 @
a14be225
...
...
@@ -25,6 +25,7 @@
#include "device/kernel_runtime_manager.h"
#include "predict/predict.h"
#include "common/utils.h"
#include "common/trans.h"
#include "utils/context/ms_context.h"
namespace
mindspore
{
...
...
@@ -83,6 +84,49 @@ void GPUSession::RunOpAllocateMemory(const std::vector<tensor::TensorPtr> &input
runtime_instance
->
RunOpAssignMemory
(
input_tensors
,
kernel_graph
);
}
void
GPUSession
::
LoadInputData
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
,
const
std
::
vector
<
tensor
::
TensorPtr
>
&
inputs_const
)
const
{
std
::
vector
<
tensor
::
TensorPtr
>
inputs
(
inputs_const
);
MS_EXCEPTION_IF_NULL
(
kernel_graph
);
auto
input_nodes
=
kernel_graph
->
inputs
();
auto
ms_context
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
ms_context
);
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
++
i
)
{
auto
tensor
=
inputs
[
i
];
MS_EXCEPTION_IF_NULL
(
tensor
);
auto
input_node
=
input_nodes
[
i
];
MS_EXCEPTION_IF_NULL
(
input_node
);
if
(
input_node
->
isa
<
Parameter
>
()
&&
AnfAlgo
::
OutputAddrExist
(
input_node
,
0
))
{
auto
pk_node
=
input_node
->
cast
<
ParameterPtr
>
();
auto
device_address
=
AnfAlgo
::
GetMutableOutputAddr
(
pk_node
,
0
);
bool
need_sync
=
false
;
if
(
ms_context
->
enable_pynative_infer
())
{
if
(
tensor
->
device_address
().
get
()
==
nullptr
||
tensor
->
device_address
()
!=
device_address
)
{
need_sync
=
true
;
}
}
else
{
if
(
tensor
->
is_dirty
())
{
need_sync
=
true
;
}
else
if
(
tensor
->
device_address
()
!=
device_address
)
{
AnfAlgo
::
SetOutputAddr
(
tensor
->
device_address
(),
0
,
pk_node
.
get
());
need_sync
=
false
;
}
}
if
(
need_sync
)
{
tensor
->
set_device_address
(
device_address
);
MS_EXCEPTION_IF_NULL
(
device_address
);
if
(
!
device_address
->
SyncHostToDevice
(
trans
::
GetRuntimePaddingShape
(
pk_node
,
0
),
LongToSize
(
tensor
->
data
().
nbytes
()),
tensor
->
data_type
(),
tensor
->
data_c
(
false
)))
{
MS_LOG
(
EXCEPTION
)
<<
"SyncHostToDevice failed."
;
}
}
}
tensor
->
set_dirty
(
false
);
}
}
void
GPUSession
::
Execute
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
)
const
{
auto
runtime_instance
=
device
::
KernelRuntimeManager
::
Instance
().
GetSingleKernelRuntime
(
kGPUDevice
,
device_id_
);
MS_EXCEPTION_IF_NULL
(
runtime_instance
);
...
...
mindspore/ccsrc/session/gpu_session.h
浏览文件 @
a14be225
...
...
@@ -59,6 +59,9 @@ class GPUSession : public SessionBasic {
void
RunOpAllocateMemory
(
const
std
::
vector
<
tensor
::
TensorPtr
>
&
input_tensors
,
KernelGraph
*
kernel_graph
)
const
;
void
LoadInputData
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
,
const
std
::
vector
<
tensor
::
TensorPtr
>
&
inputs_const
)
const
override
;
void
Execute
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
)
const
;
};
using
GPUSessionPtr
=
std
::
shared_ptr
<
GPUSession
>
;
...
...
mindspore/ccsrc/session/session_basic.cc
浏览文件 @
a14be225
...
...
@@ -129,7 +129,7 @@ BaseRef CreateOneTensor(const AnfNodePtr &node, size_t output_index, const Kerne
// if in paynative mode,data only copyed to host when user want to print data
auto
ms_context
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
ms_context
);
if
(
ms_context
->
execution_mode
()
==
kPynativeMode
)
{
if
(
ms_context
->
execution_mode
()
==
kPynativeMode
||
ms_context
->
device_target
()
==
kGPUDevice
)
{
tensor
->
set_device_address
(
AnfAlgo
::
GetMutableOutputAddr
(
node
,
output_index
));
tensor
->
set_dirty
(
false
);
}
else
if
(
!
address
->
SyncDeviceToHost
(
trans
::
GetRuntimePaddingShape
(
node
,
output_index
),
...
...
mindspore/ccsrc/utils/convert_utils.cc
浏览文件 @
a14be225
...
...
@@ -216,7 +216,7 @@ bool ValueToBool(const ValuePtr &v, bool *value) {
}
else
if
(
v
->
isa
<
tensor
::
Tensor
>
())
{
auto
tensor
=
v
->
cast
<
tensor
::
TensorPtr
>
();
MS_EXCEPTION_IF_NULL
(
tensor
);
(
void
)
tensor
->
data_sync
();
bool
*
tensor_data
=
static_cast
<
bool
*>
(
tensor
->
data_c
());
// maybe need to support if tensor is a bool array
auto
vb
=
tensor_data
[
0
];
...
...
tests/st/ops/gpu/test_float_status_op.py
浏览文件 @
a14be225
...
...
@@ -70,13 +70,15 @@ x3 = np.array([[1, 2], [3, 4], [5.0, 88.0]]).astype(np.float32)
def
test_status
():
ms_status
=
Net
();
output1
=
ms_status
(
Tensor
(
x1
))
output2
=
ms_status
(
Tensor
(
x2
))
output3
=
ms_status
(
Tensor
(
x3
))
expect1
=
1
expect2
=
1
expect3
=
0
assert
output1
.
asnumpy
()[
0
]
==
expect1
output2
=
ms_status
(
Tensor
(
x2
))
expect2
=
1
assert
output2
.
asnumpy
()[
0
]
==
expect2
output3
=
ms_status
(
Tensor
(
x3
))
expect3
=
0
assert
output3
.
asnumpy
()[
0
]
==
expect3
...
...
@@ -86,13 +88,15 @@ def test_status():
def
test_nan
():
ms_isnan
=
Netnan
();
output1
=
ms_isnan
(
Tensor
(
x1
))
output2
=
ms_isnan
(
Tensor
(
x2
))
output3
=
ms_isnan
(
Tensor
(
x3
))
expect1
=
[[
False
,
False
,
True
,
False
]]
expect2
=
[[
False
,
False
,
False
,
False
]]
expect3
=
[[
False
,
False
],
[
False
,
False
],
[
False
,
False
]]
assert
(
output1
.
asnumpy
()
==
expect1
).
all
()
output2
=
ms_isnan
(
Tensor
(
x2
))
expect2
=
[[
False
,
False
,
False
,
False
]]
assert
(
output2
.
asnumpy
()
==
expect2
).
all
()
output3
=
ms_isnan
(
Tensor
(
x3
))
expect3
=
[[
False
,
False
],
[
False
,
False
],
[
False
,
False
]]
assert
(
output3
.
asnumpy
()
==
expect3
).
all
()
...
...
@@ -102,13 +106,15 @@ def test_nan():
def
test_inf
():
ms_isinf
=
Netinf
();
output1
=
ms_isinf
(
Tensor
(
x1
))
output2
=
ms_isinf
(
Tensor
(
x2
))
output3
=
ms_isinf
(
Tensor
(
x3
))
expect1
=
[[
False
,
False
,
False
,
False
]]
expect2
=
[[
True
,
False
,
False
,
False
]]
expect3
=
[[
False
,
False
],
[
False
,
False
],
[
False
,
False
]]
assert
(
output1
.
asnumpy
()
==
expect1
).
all
()
output2
=
ms_isinf
(
Tensor
(
x2
))
expect2
=
[[
True
,
False
,
False
,
False
]]
assert
(
output2
.
asnumpy
()
==
expect2
).
all
()
output3
=
ms_isinf
(
Tensor
(
x3
))
expect3
=
[[
False
,
False
],
[
False
,
False
],
[
False
,
False
]]
assert
(
output3
.
asnumpy
()
==
expect3
).
all
()
...
...
@@ -118,11 +124,13 @@ def test_inf():
def
test_finite
():
ms_isfinite
=
Netfinite
();
output1
=
ms_isfinite
(
Tensor
(
x1
))
output2
=
ms_isfinite
(
Tensor
(
x2
))
output3
=
ms_isfinite
(
Tensor
(
x3
))
expect1
=
[[
True
,
True
,
False
,
True
]]
expect2
=
[[
False
,
True
,
True
,
True
]]
expect3
=
[[
True
,
True
],
[
True
,
True
],
[
True
,
True
]]
assert
(
output1
.
asnumpy
()
==
expect1
).
all
()
output2
=
ms_isfinite
(
Tensor
(
x2
))
expect2
=
[[
False
,
True
,
True
,
True
]]
assert
(
output2
.
asnumpy
()
==
expect2
).
all
()
output3
=
ms_isfinite
(
Tensor
(
x3
))
expect3
=
[[
True
,
True
],
[
True
,
True
],
[
True
,
True
]]
assert
(
output3
.
asnumpy
()
==
expect3
).
all
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录