gpu update cast type

This commit is contained in:
VectorSL 2020-08-08 12:25:32 +08:00
parent 57b3052c1e
commit b0a6346b54
2 changed files with 133 additions and 2 deletions

View File

@ -23,6 +23,7 @@ cast_op_info = AkgGpuRegOp("Cast") \
.dtype_format(DataType.F16_Default, DataType.F32_Default) \
.dtype_format(DataType.F16_Default, DataType.I32_Default) \
.dtype_format(DataType.F16_Default, DataType.F64_Default) \
.dtype_format(DataType.F16_Default, DataType.BOOL_Default) \
.dtype_format(DataType.I32_Default, DataType.F16_Default) \
.dtype_format(DataType.I32_Default, DataType.F32_Default) \
.dtype_format(DataType.I32_Default, DataType.I8_Default) \
@ -34,6 +35,7 @@ cast_op_info = AkgGpuRegOp("Cast") \
.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.I8_Default, DataType.BOOL_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) \
@ -44,19 +46,29 @@ cast_op_info = AkgGpuRegOp("Cast") \
.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.U8_Default, DataType.BOOL_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.I16_Default, DataType.F32_Default) \
.dtype_format(DataType.I16_Default, DataType.BOOL_Default) \
.dtype_format(DataType.I64_Default, DataType.F64_Default) \
.dtype_format(DataType.I64_Default, DataType.F32_Default) \
.dtype_format(DataType.I64_Default, DataType.F16_Default) \
.dtype_format(DataType.I64_Default, DataType.I32_Default) \
.dtype_format(DataType.I16_Default, DataType.F32_Default) \
.dtype_format(DataType.I16_Default, DataType.F16_Default) \
.dtype_format(DataType.I64_Default, DataType.BOOL_Default) \
.dtype_format(DataType.F32_Default, DataType.I32_Default) \
.dtype_format(DataType.F32_Default, DataType.F16_Default) \
.dtype_format(DataType.F32_Default, DataType.BOOL_Default) \
.dtype_format(DataType.F64_Default, DataType.BOOL_Default) \
.dtype_format(DataType.F64_Default, DataType.F32_Default) \
.dtype_format(DataType.F64_Default, DataType.F16_Default) \
.dtype_format(DataType.F64_Default, DataType.I64_Default) \
.dtype_format(DataType.F64_Default, DataType.I32_Default) \
.dtype_format(DataType.F64_Default, DataType.I16_Default) \
.dtype_format(DataType.F64_Default, DataType.I8_Default) \
.get_op_info()

View File

@ -359,3 +359,122 @@ def test_cast18():
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_cast19():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
t0 = mstype.bool_
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
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 == 'bool'
type1 = output[1].asnumpy().dtype
assert type1 == 'bool'
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_cast20():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int64))
t0 = mstype.bool_
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float16))
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 == 'bool'
type1 = output[1].asnumpy().dtype
assert type1 == 'bool'
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_cast21():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
t0 = mstype.bool_
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
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 == 'bool'
type1 = output[1].asnumpy().dtype
assert type1 == 'bool'
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_cast22():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.uint8))
t0 = mstype.bool_
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 == 'bool'
type1 = output[1].asnumpy().dtype
assert type1 == 'bool'
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_cast23():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
t0 = mstype.float32
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
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_cast24():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
t0 = mstype.int64
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
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 == 'int64'
type1 = output[1].asnumpy().dtype
assert type1 == 'int32'
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_cast25():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
t0 = mstype.int16
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
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 == 'int16'
type1 = output[1].asnumpy().dtype
assert type1 == 'int8'