Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
aef2c198
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看板
提交
aef2c198
编写于
7月 16, 2020
作者:
V
VectorSL
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cast support more types
上级
ae50c37c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
305 addition
and
11 deletion
+305
-11
mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_attrs_process.cc
...c/backend/kernel_compiler/akg/akg_kernel_attrs_process.cc
+2
-9
mindspore/ops/_op_impl/akg/gpu/cast.py
mindspore/ops/_op_impl/akg/gpu/cast.py
+31
-2
tests/st/ops/gpu/test_cast_op.py
tests/st/ops/gpu/test_cast_op.py
+272
-0
未找到文件。
mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_attrs_process.cc
浏览文件 @
aef2c198
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include <algorithm>
#include <algorithm>
#include "backend/session/anf_runtime_algorithm.h"
#include "backend/session/anf_runtime_algorithm.h"
#include "backend/optimizer/common/helper.h"
#include "backend/optimizer/common/helper.h"
#include "backend/kernel_compiler/common_utils.h"
namespace
mindspore
{
namespace
mindspore
{
namespace
kernel
{
namespace
kernel
{
...
@@ -75,15 +76,7 @@ void SetAkgAttrsForCast(const AnfNodePtr &anf_node) {
...
@@ -75,15 +76,7 @@ void SetAkgAttrsForCast(const AnfNodePtr &anf_node) {
std
::
string
dst_type
;
std
::
string
dst_type
;
TypeId
output_type
=
AnfAlgo
::
GetOutputDeviceDataType
(
anf_node
,
0
);
TypeId
output_type
=
AnfAlgo
::
GetOutputDeviceDataType
(
anf_node
,
0
);
if
(
output_type
==
kFloat32
->
type_id
())
{
dst_type
=
TypeId2String
(
output_type
);
dst_type
=
"float32"
;
}
else
if
(
output_type
==
kFloat16
->
type_id
())
{
dst_type
=
"float16"
;
}
else
if
(
output_type
==
kInt32
->
type_id
())
{
dst_type
=
"int32"
;
}
else
{
MS_LOG
(
WARNING
)
<<
"Unknown cast_to type: "
<<
TypeIdToType
(
output_type
)
->
ToString
();
}
AnfAlgo
::
SetNodeAttr
(
"dst_type"
,
MakeValue
(
dst_type
),
anf_node
);
AnfAlgo
::
SetNodeAttr
(
"dst_type"
,
MakeValue
(
dst_type
),
anf_node
);
}
}
...
...
mindspore/ops/_op_impl/akg/gpu/cast.py
浏览文件 @
aef2c198
...
@@ -21,10 +21,39 @@ cast_op_info = AkgGpuRegOp("Cast") \
...
@@ -21,10 +21,39 @@ cast_op_info = AkgGpuRegOp("Cast") \
.
output
(
0
,
"output"
)
\
.
output
(
0
,
"output"
)
\
.
attr
(
"dst_type"
,
"required"
,
"str"
)
\
.
attr
(
"dst_type"
,
"required"
,
"str"
)
\
.
dtype_format
(
DataType
.
F16_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
F16_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
F32_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
F16_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
F32_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
F16_Default
,
DataType
.
F64_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
I8_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
U8_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
BOOL_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
F64_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
I16_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
I64_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
F64_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
I8_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
I16_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
BOOL_Default
,
DataType
.
I64_Default
)
\
.
dtype_format
(
DataType
.
U8_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
U8_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
U8_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
F64_Default
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
I64_Default
)
\
.
dtype_format
(
DataType
.
I64_Default
,
DataType
.
F64_Default
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
F32_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
F32_Default
,
DataType
.
F16_Default
)
\
.
get_op_info
()
.
get_op_info
()
...
...
tests/st/ops/gpu/test_cast_op.py
浏览文件 @
aef2c198
...
@@ -70,3 +70,275 @@ def test_cast1():
...
@@ -70,3 +70,275 @@ def test_cast1():
assert
type0
==
'float32'
assert
type0
==
'float32'
type1
=
output
[
1
].
asnumpy
().
dtype
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float32'
assert
type1
==
'float32'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast2
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
float16
))
t0
=
mstype
.
int32
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
float16
))
t1
=
mstype
.
float64
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int32'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float64'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast3
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
float16
))
t0
=
mstype
.
int32
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
float32
))
t1
=
mstype
.
int32
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int32'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'int32'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast4
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int32
))
t0
=
mstype
.
float16
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int32
))
t1
=
mstype
.
int8
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'float16'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'int8'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast5
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int32
))
t0
=
mstype
.
uint8
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int32
))
t1
=
mstype
.
bool_
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'uint8'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'bool'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast6
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int8
))
t0
=
mstype
.
float64
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int8
))
t1
=
mstype
.
float32
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'float64'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float32'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast7
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int8
))
t0
=
mstype
.
float32
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int8
))
t1
=
mstype
.
float16
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'float32'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float16'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast8
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int8
))
t0
=
mstype
.
int32
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int8
))
t1
=
mstype
.
int16
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int32'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'int16'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast9
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int8
))
t0
=
mstype
.
int64
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
bool
))
t1
=
mstype
.
float16
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int64'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float16'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast10
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
bool
))
t0
=
mstype
.
int8
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
bool
))
t1
=
mstype
.
float64
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int8'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float64'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast11
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
bool
))
t0
=
mstype
.
int16
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
bool
))
t1
=
mstype
.
int32
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int16'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'int32'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast12
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
bool
))
t0
=
mstype
.
int64
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
uint8
))
t1
=
mstype
.
float32
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int64'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float32'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast13
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
uint8
))
t0
=
mstype
.
int32
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
uint8
))
t1
=
mstype
.
float16
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'int32'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float16'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast14
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int16
))
t0
=
mstype
.
float64
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int16
))
t1
=
mstype
.
float32
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'float64'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float32'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast15
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int16
))
t0
=
mstype
.
float16
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int16
))
t1
=
mstype
.
int32
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'float16'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'int32'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast16
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int16
))
t0
=
mstype
.
float16
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int64
))
t1
=
mstype
.
float64
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'float16'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float64'
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
env_onecard
def
test_cast17
():
x0
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int16
))
t0
=
mstype
.
float32
x1
=
Tensor
(
np
.
arange
(
24
).
reshape
((
4
,
3
,
2
)).
astype
(
np
.
int16
))
t1
=
mstype
.
float16
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
'GPU'
)
net
=
Net
(
t0
,
t1
)
output
=
net
(
x0
,
x1
)
type0
=
output
[
0
].
asnumpy
().
dtype
assert
type0
==
'float32'
type1
=
output
[
1
].
asnumpy
().
dtype
assert
type1
==
'float16'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录