From 930163316e17b198ae44bbf51b775789e3a1672f Mon Sep 17 00:00:00 2001 From: zhangbo9674 <82555433+zhangbo9674@users.noreply.github.com> Date: Mon, 21 Feb 2022 13:36:23 +0800 Subject: [PATCH] [bf16] add bf16 kernel: elementwise_max (#39461) * add elementwise_max & unittest * refine cuda register and unittest * refine unittest * refine uinttest for bf16 * refine optest * refine code * refine unittest * refine unittest --- .../elementwise/elementwise_max_op.cc | 8 +++- .../elementwise/elementwise_max_op.cu | 4 ++ .../paddle/fluid/tests/unittests/op_test.py | 8 ++-- .../unittests/test_elementwise_max_op.py | 37 ++++++++++++++++++- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/operators/elementwise/elementwise_max_op.cc b/paddle/fluid/operators/elementwise/elementwise_max_op.cc index cc27bab720..91da732ef0 100644 --- a/paddle/fluid/operators/elementwise/elementwise_max_op.cc +++ b/paddle/fluid/operators/elementwise/elementwise_max_op.cc @@ -124,13 +124,17 @@ REGISTER_OP_CPU_KERNEL( ops::ElementwiseMaxKernel, ops::ElementwiseMaxKernel, ops::ElementwiseMaxKernel, - ops::ElementwiseMaxKernel); + ops::ElementwiseMaxKernel, + ops::ElementwiseMaxKernel); REGISTER_OP_CPU_KERNEL( elementwise_max_grad, ops::ElementwiseMaxGradKernel, ops::ElementwiseMaxGradKernel, ops::ElementwiseMaxGradKernel, - ops::ElementwiseMaxGradKernel); + ops::ElementwiseMaxGradKernel, + ops::ElementwiseMaxGradKernel); REGISTER_OP_VERSION(elementwise_max) .AddCheckpoint( diff --git a/paddle/fluid/operators/elementwise/elementwise_max_op.cu b/paddle/fluid/operators/elementwise/elementwise_max_op.cu index 7433c505f4..123332a4a2 100644 --- a/paddle/fluid/operators/elementwise/elementwise_max_op.cu +++ b/paddle/fluid/operators/elementwise/elementwise_max_op.cu @@ -69,6 +69,8 @@ REGISTER_OP_CUDA_KERNEL( elementwise_max, ops::ElementwiseMaxKernel, + ops::ElementwiseMaxKernel, ops::ElementwiseMaxKernel, ops::ElementwiseMaxKernel, ops::ElementwiseMaxKernel, @@ -77,6 +79,8 @@ REGISTER_OP_CUDA_KERNEL( elementwise_max_grad, ops::ElementwiseMaxGradKernel, + ops::ElementwiseMaxGradKernel, ops::ElementwiseMaxGradKernel, ops::ElementwiseMaxGradKernel, ops::ElementwiseMaxGradKernel, diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index 85423df3d3..ec3b68086b 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -168,8 +168,10 @@ def get_numeric_gradient(place, elif tensor_to_check._dtype() == core.VarDesc.VarType.BF16: numpy_tensor = np.array(tensor).astype(np.uint16) numpy_tensor = numpy_tensor.flatten() - return struct.unpack('