Browse Source

!7545 GPU reshape add type

Merge pull request !7545 from VectorSL/int64
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
fd8ebde400
5 changed files with 103 additions and 10 deletions
  1. +6
    -0
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.cc
  2. +9
    -0
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.cc
  3. +51
    -10
      mindspore/ccsrc/backend/kernel_compiler/gpu/nn/flatten_gpu_kernel.cc
  4. +3
    -0
      mindspore/ops/_op_impl/akg/gpu/cast.py
  5. +34
    -0
      tests/st/ops/gpu/test_cast_op.py

+ 6
- 0
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.cc View File

@@ -24,5 +24,11 @@ MS_REG_GPU_KERNEL_ONE(Slice, KernelAttr().AddInputAttr(kNumberTypeInt32).AddOutp
SliceGpuFwdKernel, int)
MS_REG_GPU_KERNEL_ONE(Slice, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
SliceGpuFwdKernel, half)
MS_REG_GPU_KERNEL_ONE(Slice, KernelAttr().AddInputAttr(kNumberTypeInt16).AddOutputAttr(kNumberTypeInt16),
SliceGpuFwdKernel, int16_t)
MS_REG_GPU_KERNEL_ONE(Slice, KernelAttr().AddInputAttr(kNumberTypeUInt8).AddOutputAttr(kNumberTypeUInt8),
SliceGpuFwdKernel, uchar)
MS_REG_GPU_KERNEL_ONE(Slice, KernelAttr().AddInputAttr(kNumberTypeBool).AddOutputAttr(kNumberTypeBool),
SliceGpuFwdKernel, bool)
} // namespace kernel
} // namespace mindspore

+ 9
- 0
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.cc View File

@@ -29,5 +29,14 @@ MS_REG_GPU_KERNEL_ONE(
SliceGrad,
KernelAttr().AddInputAttr(kNumberTypeFloat16).AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
SliceGradGpuKernel, half)
MS_REG_GPU_KERNEL_ONE(
SliceGrad, KernelAttr().AddInputAttr(kNumberTypeInt16).AddInputAttr(kNumberTypeInt16).AddOutputAttr(kNumberTypeInt16),
SliceGradGpuKernel, int16_t)
MS_REG_GPU_KERNEL_ONE(
SliceGrad, KernelAttr().AddInputAttr(kNumberTypeUInt8).AddInputAttr(kNumberTypeUInt8).AddOutputAttr(kNumberTypeUInt8),
SliceGradGpuKernel, uchar)
MS_REG_GPU_KERNEL_ONE(
SliceGrad, KernelAttr().AddInputAttr(kNumberTypeBool).AddInputAttr(kNumberTypeBool).AddOutputAttr(kNumberTypeBool),
SliceGradGpuKernel, bool)
} // namespace kernel
} // namespace mindspore

+ 51
- 10
mindspore/ccsrc/backend/kernel_compiler/gpu/nn/flatten_gpu_kernel.cc View File

@@ -18,27 +18,68 @@

namespace mindspore {
namespace kernel {
// float64
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeFloat64).AddOutputAttr(kNumberTypeFloat64),
FlattenGpuFwdKernel, double)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeFloat64).AddOutputAttr(kNumberTypeFloat64),
FlattenGpuFwdKernel, double)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeFloat64).AddOutputAttr(kNumberTypeFloat64),
FlattenGpuFwdKernel, double)
// float32
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32),
FlattenGpuFwdKernel, float)
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32),
FlattenGpuFwdKernel, int)
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
FlattenGpuFwdKernel, half)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32),
FlattenGpuFwdKernel, float)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32),
FlattenGpuFwdKernel, float)
// float16
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
FlattenGpuFwdKernel, half)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
FlattenGpuFwdKernel, half)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
FlattenGpuFwdKernel, half)
// int64
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeInt64).AddOutputAttr(kNumberTypeInt64),
FlattenGpuFwdKernel, int64_t)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeInt64).AddOutputAttr(kNumberTypeInt64),
FlattenGpuFwdKernel, int64_t)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeInt64).AddOutputAttr(kNumberTypeInt64),
FlattenGpuFwdKernel, int64_t)
// int32
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32),
FlattenGpuFwdKernel, int)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32),
FlattenGpuFwdKernel, int)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32),
FlattenGpuFwdKernel, int)
// int16
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeInt16).AddOutputAttr(kNumberTypeInt16),
FlattenGpuFwdKernel, int16_t)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeInt16).AddOutputAttr(kNumberTypeInt16),
FlattenGpuFwdKernel, int16_t)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeInt16).AddOutputAttr(kNumberTypeInt16),
FlattenGpuFwdKernel, int16_t)
// uint8
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeUInt8).AddOutputAttr(kNumberTypeUInt8),
FlattenGpuFwdKernel, uchar)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeUInt8).AddOutputAttr(kNumberTypeUInt8),
FlattenGpuFwdKernel, uchar)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeUInt8).AddOutputAttr(kNumberTypeUInt8),
FlattenGpuFwdKernel, uchar)
// int8
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeInt8).AddOutputAttr(kNumberTypeInt8),
FlattenGpuFwdKernel, char)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeInt8).AddOutputAttr(kNumberTypeInt8),
FlattenGpuFwdKernel, char)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeInt8).AddOutputAttr(kNumberTypeInt8),
FlattenGpuFwdKernel, char)
// bool
MS_REG_GPU_KERNEL_ONE(Flatten, KernelAttr().AddInputAttr(kNumberTypeBool).AddOutputAttr(kNumberTypeBool),
FlattenGpuFwdKernel, bool)
MS_REG_GPU_KERNEL_ONE(Reshape, KernelAttr().AddInputAttr(kNumberTypeBool).AddOutputAttr(kNumberTypeBool),
FlattenGpuFwdKernel, bool)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32),
FlattenGpuFwdKernel, float)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
FlattenGpuFwdKernel, half)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32),
FlattenGpuFwdKernel, int)
MS_REG_GPU_KERNEL_ONE(ExpandDims, KernelAttr().AddInputAttr(kNumberTypeBool).AddOutputAttr(kNumberTypeBool),
FlattenGpuFwdKernel, bool)
} // namespace kernel
} // namespace mindspore

+ 3
- 0
mindspore/ops/_op_impl/akg/gpu/cast.py View File

@@ -26,6 +26,8 @@ cast_op_info = AkgGpuRegOp("Cast") \
.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.F64_Default) \
.dtype_format(DataType.I32_Default, DataType.I64_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) \
@@ -61,6 +63,7 @@ cast_op_info = AkgGpuRegOp("Cast") \
.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.F64_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) \


+ 34
- 0
tests/st/ops/gpu/test_cast_op.py View File

@@ -478,3 +478,37 @@ def test_cast25():
assert type0 == 'int16'
type1 = output[1].asnumpy().dtype
assert type1 == 'int8'

@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_cast26():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
t0 = mstype.int64
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
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 == 'int64'
type1 = output[1].asnumpy().dtype
assert type1 == 'float64'

@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_cast27():
x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
t0 = mstype.float64
x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
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'

Loading…
Cancel
Save