| @@ -1,5 +1,5 @@ | |||||
| /** | /** | ||||
| * Copyright 2019 Huawei Technologies Co., Ltd | |||||
| * Copyright 2019-2021 Huawei Technologies Co., Ltd | |||||
| * | * | ||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
| @@ -18,6 +18,8 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| namespace kernel { | namespace kernel { | ||||
| MS_REG_GPU_KERNEL_ONE(ReduceMax, KernelAttr().AddInputAttr(kNumberTypeFloat64).AddOutputAttr(kNumberTypeFloat64), | |||||
| ArrayReduceGpuKernel, double) | |||||
| MS_REG_GPU_KERNEL_ONE(ReduceMax, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), | MS_REG_GPU_KERNEL_ONE(ReduceMax, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), | ||||
| ArrayReduceGpuKernel, float) | ArrayReduceGpuKernel, float) | ||||
| MS_REG_GPU_KERNEL_ONE(ReduceMax, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), | MS_REG_GPU_KERNEL_ONE(ReduceMax, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), | ||||
| @@ -26,6 +28,8 @@ MS_REG_GPU_KERNEL_ONE(ReduceMean, KernelAttr().AddInputAttr(kNumberTypeFloat32). | |||||
| ArrayReduceGpuKernel, float) | ArrayReduceGpuKernel, float) | ||||
| MS_REG_GPU_KERNEL_ONE(ReduceMean, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), | MS_REG_GPU_KERNEL_ONE(ReduceMean, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), | ||||
| ArrayReduceGpuKernel, half) | ArrayReduceGpuKernel, half) | ||||
| MS_REG_GPU_KERNEL_ONE(ReduceSum, KernelAttr().AddInputAttr(kNumberTypeFloat64).AddOutputAttr(kNumberTypeFloat64), | |||||
| ArrayReduceGpuKernel, double) | |||||
| MS_REG_GPU_KERNEL_ONE(ReduceSum, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), | MS_REG_GPU_KERNEL_ONE(ReduceSum, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), | ||||
| ArrayReduceGpuKernel, float) | ArrayReduceGpuKernel, float) | ||||
| MS_REG_GPU_KERNEL_ONE(ReduceSum, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), | MS_REG_GPU_KERNEL_ONE(ReduceSum, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), | ||||
| @@ -1,5 +1,5 @@ | |||||
| /** | /** | ||||
| * Copyright 2019-2020 Huawei Technologies Co., Ltd | |||||
| * Copyright 2019-2021 Huawei Technologies Co., Ltd | |||||
| * | * | ||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
| @@ -14,8 +14,8 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_ARRAYREDUCE_GPU_KERNEL_H_ | |||||
| #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_ARRAYREDUCE_GPU_KERNEL_H_ | |||||
| #ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_ARRAYS_ARRAY_REDUCE_GPU_KERNEL_H_ | |||||
| #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_ARRAYS_ARRAY_REDUCE_GPU_KERNEL_H_ | |||||
| #include <map> | #include <map> | ||||
| #include <string> | #include <string> | ||||
| @@ -291,4 +291,4 @@ class ArrayReduceGpuKernel : public GpuKernel { | |||||
| } // namespace kernel | } // namespace kernel | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_ARRAYREDUCE_GPU_KERNEL_H_ | |||||
| #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_ARRAYS_ARRAY_REDUCE_GPU_KERNEL_H_ | |||||
| @@ -1,4 +1,4 @@ | |||||
| # Copyright 2019 Huawei Technologies Co., Ltd | |||||
| # Copyright 2019-2021 Huawei Technologies Co., Ltd | |||||
| # | # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | # you may not use this file except in compliance with the License. | ||||
| @@ -209,3 +209,26 @@ def test_reduce_max_dynamic(): | |||||
| np.testing.assert_almost_equal(output_1.asnumpy(), expect_1) | np.testing.assert_almost_equal(output_1.asnumpy(), expect_1) | ||||
| np.testing.assert_almost_equal(output_2.asnumpy(), expect_2) | np.testing.assert_almost_equal(output_2.asnumpy(), expect_2) | ||||
| class ReduceMaxTypeNet(nn.Cell): | |||||
| def __init__(self, nptype): | |||||
| super(ReduceMaxTypeNet, self).__init__() | |||||
| self.x0 = Tensor(x0.astype(nptype)) | |||||
| self.axis0 = axis0 | |||||
| self.keep_dims0 = keep_dims0 | |||||
| def construct(self): | |||||
| return P.ReduceMax(self.keep_dims0)(self.x0, self.axis0) | |||||
| @pytest.mark.level0 | |||||
| @pytest.mark.platform_x86_gpu_training | |||||
| @pytest.mark.env_onecard | |||||
| def test_reduce_max_float64(): | |||||
| context.set_context(mode=context.GRAPH_MODE, device_target="GPU") | |||||
| net = ReduceMaxTypeNet(np.float64) | |||||
| output = net() | |||||
| expect = np.max(x0, axis=axis0, keepdims=keep_dims0).astype(np.float64) | |||||
| diff = abs(output.asnumpy() - expect) | |||||
| error = np.ones(shape=expect.shape) * 1.0e-5 | |||||
| assert np.all(diff < error) | |||||
| assert output.shape == expect.shape | |||||
| @@ -1,4 +1,4 @@ | |||||
| # Copyright 2019 Huawei Technologies Co., Ltd | |||||
| # Copyright 2019-2021 Huawei Technologies Co., Ltd | |||||
| # | # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | # you may not use this file except in compliance with the License. | ||||
| @@ -301,3 +301,26 @@ def test_reduce_sum_dynamic(): | |||||
| np.testing.assert_almost_equal(output_1.asnumpy(), expect_1) | np.testing.assert_almost_equal(output_1.asnumpy(), expect_1) | ||||
| np.testing.assert_almost_equal(output_2.asnumpy(), expect_2) | np.testing.assert_almost_equal(output_2.asnumpy(), expect_2) | ||||
| class ReduceSumTypeNet(nn.Cell): | |||||
| def __init__(self, nptype): | |||||
| super(ReduceSumTypeNet, self).__init__() | |||||
| self.x0 = Tensor(x0.astype(nptype)) | |||||
| self.axis0 = axis0 | |||||
| self.keep_dims0 = keep_dims0 | |||||
| def construct(self): | |||||
| return P.ReduceSum(self.keep_dims0)(self.x0, self.axis0) | |||||
| @pytest.mark.level0 | |||||
| @pytest.mark.platform_x86_gpu_training | |||||
| @pytest.mark.env_onecard | |||||
| def test_reduce_sum_float64(): | |||||
| context.set_context(mode=context.GRAPH_MODE, device_target="GPU") | |||||
| net = ReduceSumTypeNet(np.float64) | |||||
| output = net() | |||||
| expect = np.sum(x0, axis=axis0, keepdims=keep_dims0).astype(np.float64) | |||||
| diff = abs(output.asnumpy() - expect) | |||||
| error = np.ones(shape=expect.shape) * 1.0e-5 | |||||
| assert np.all(diff < error) | |||||
| assert output.shape == expect.shape | |||||