diff --git a/paddle/fluid/operators/activation_op.cu.h b/paddle/fluid/operators/activation_op.cu.h index 08a8d9a08960936bcd2d660cc368d4fda0a61184..d9b1545abce4ce32f1756b0991a4954c05901ffe 100644 --- a/paddle/fluid/operators/activation_op.cu.h +++ b/paddle/fluid/operators/activation_op.cu.h @@ -12,10 +12,10 @@ limitations under the License. */ #pragma once #include "paddle/fluid/operators/activation_op.h" -#include "paddle/fluid/operators/amp/fp16_type_traits.h" #include "paddle/fluid/operators/elementwise/elementwise_op_impl.cu.h" #include "paddle/fluid/platform/bfloat16.h" #include "paddle/phi/backends/gpu/gpu_device_function.h" +#include "paddle/phi/common/amp_type_traits.h" #include "paddle/phi/kernels/funcs/activation_functor.h" namespace paddle { @@ -23,7 +23,7 @@ namespace operators { template struct CudaSoftReluFunctor : public BaseActivationFunctor { - using MPType = typename details::MPTypeTrait::Type; + using MPType = typename phi::dtype::MPTypeTrait::Type; MPType one = static_cast(1.0f); float threshold; @@ -44,7 +44,7 @@ struct CudaSoftReluFunctor : public BaseActivationFunctor { template struct CudaSoftReluGradFunctor : public BaseActivationFunctor { - using MPType = typename details::MPTypeTrait::Type; + using MPType = typename phi::dtype::MPTypeTrait::Type; MPType one = static_cast(1.0f); float threshold; diff --git a/paddle/fluid/operators/amp/fp16_type_traits.h b/paddle/fluid/operators/amp/fp16_type_traits.h deleted file mode 100644 index 56aebe90788fbaa6c300ee9ac620c3d7613ff141..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/amp/fp16_type_traits.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#pragma once - -#include "paddle/fluid/platform/bfloat16.h" -#include "paddle/fluid/platform/float16.h" - -namespace paddle { -namespace operators { -namespace details { - -template -class MPTypeTrait { - public: - using Type = T; -}; - -template <> -class MPTypeTrait { - public: - using Type = float; -}; - -template <> -class MPTypeTrait { - public: - using Type = float; -}; - -} // namespace details -} // namespace operators -} // namespace paddle diff --git a/paddle/fluid/operators/fused/fused_dropout_common.h b/paddle/fluid/operators/fused/fused_dropout_common.h index 06606f4a1adadc72b047e4ce6bed288db9c5d88f..ccd099109487c9eb4a6ee04bc454930c2e03e17b 100644 --- a/paddle/fluid/operators/fused/fused_dropout_common.h +++ b/paddle/fluid/operators/fused/fused_dropout_common.h @@ -19,12 +19,12 @@ limitations under the License. */ #include #include "paddle/fluid/memory/memory.h" -#include "paddle/fluid/operators/amp/fp16_type_traits.h" #include "paddle/fluid/operators/fused/quant_dequant_kernel.h" #include "paddle/fluid/platform/device/gpu/gpu_launch_config.h" #include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/float16.h" #include "paddle/phi/backends/gpu/gpu_device_function.h" +#include "paddle/phi/common/amp_type_traits.h" #include "paddle/phi/kernels/funcs/aligned_vector.h" #include "paddle/phi/kernels/funcs/functors.h" #include "paddle/phi/kernels/funcs/layer_norm_impl.cu.h" diff --git a/paddle/fluid/operators/fused/fused_residual_dropout_bias.h b/paddle/fluid/operators/fused/fused_residual_dropout_bias.h index 43c25bcaf10cb1b3ae566fead5294921572c178a..ea6c771656c86e5a6ad953c3528094567241f2a7 100644 --- a/paddle/fluid/operators/fused/fused_residual_dropout_bias.h +++ b/paddle/fluid/operators/fused/fused_residual_dropout_bias.h @@ -15,6 +15,7 @@ limitations under the License. */ #pragma once #include "paddle/fluid/operators/fused/fused_dropout_common.h" +#include "paddle/phi/common/amp_type_traits.h" namespace paddle { namespace operators { @@ -45,8 +46,8 @@ __forceinline__ __device__ void FusedResidualDropoutBiasOneThread( OutType *dst, MaskType *mask, const bool is_test, - typename details::MPTypeTrait::Type *mean_val, - typename details::MPTypeTrait::Type *var_val, + typename phi::dtype::MPTypeTrait::Type *mean_val, + typename phi::dtype::MPTypeTrait::Type *var_val, Functor act_func, const float quant_last_in_scale = 1.0, const float *dequant_out_scale_data = nullptr, @@ -61,7 +62,7 @@ __forceinline__ __device__ void FusedResidualDropoutBiasOneThread( using StoreOutType = phi::AlignedVector; using MaskStoreT = phi::AlignedVector; - using U = typename details::MPTypeTrait::Type; + using U = typename phi::dtype::MPTypeTrait::Type; LoadInType src_vec; LoadT residual_vec; diff --git a/paddle/fluid/operators/gaussian_random_batch_size_like_op.cu b/paddle/fluid/operators/gaussian_random_batch_size_like_op.cu index 7546c3c350db092f5c1973eec3e9f2774cdeb5c9..9c5244976fc9d0d78e47b8457d4b7c6ca18476a3 100644 --- a/paddle/fluid/operators/gaussian_random_batch_size_like_op.cu +++ b/paddle/fluid/operators/gaussian_random_batch_size_like_op.cu @@ -11,11 +11,12 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ + #include #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/operator.h" -#include "paddle/fluid/operators/amp/fp16_type_traits.h" +#include "paddle/phi/common/amp_type_traits.h" #include "paddle/phi/core/generator.h" #include "paddle/phi/kernels/funcs/index_impl.cu.h" @@ -37,7 +38,7 @@ struct GaussianGenerator { __host__ __device__ T operator()(const unsigned int n) const { thrust::minstd_rand rng; rng.seed(seed_); - using MT = typename details::MPTypeTrait::Type; + using MT = typename phi::dtype::MPTypeTrait::Type; thrust::normal_distribution dist(static_cast(mean_), static_cast(std_)); unsigned int new_n = n + offset_; diff --git a/paddle/fluid/operators/index_impl.cu.h b/paddle/fluid/operators/index_impl.cu.h index 9d8f22661e7c4f7c99997af9cf98f114a59f2c05..7d2cdae87950bc995e7702ee30084892e5804e20 100644 --- a/paddle/fluid/operators/index_impl.cu.h +++ b/paddle/fluid/operators/index_impl.cu.h @@ -11,15 +11,17 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ + #pragma once + #include #include #include #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/operator.h" -#include "paddle/fluid/operators/amp/fp16_type_traits.h" #include "paddle/phi/backends/gpu/gpu_launch_config.h" +#include "paddle/phi/common/amp_type_traits.h" #include "paddle/phi/core/generator.h" #include "paddle/phi/core/hostdevice.h" #include "paddle/phi/kernels/funcs/aligned_vector.h" diff --git a/paddle/fluid/operators/optimizers/lars_momentum_op.cu b/paddle/fluid/operators/optimizers/lars_momentum_op.cu index 83293c991e94d18774725935c827a44cb76cd48a..20769747a4aa9195a8d6b38e23ab55fbbaeed395 100644 --- a/paddle/fluid/operators/optimizers/lars_momentum_op.cu +++ b/paddle/fluid/operators/optimizers/lars_momentum_op.cu @@ -14,7 +14,7 @@ limitations under the License. */ #include "paddle/fluid/operators/optimizers/lars_momentum_op.h" #include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/operators/amp/fp16_type_traits.h" +#include "paddle/phi/common/amp_type_traits.h" #include "paddle/phi/kernels/funcs/aligned_vector.h" #include "paddle/phi/kernels/funcs/math_cuda_utils.h" @@ -34,7 +34,7 @@ namespace paddle { namespace operators { template -using MultiPrecisionType = typename details::MPTypeTrait::Type; +using MultiPrecisionType = typename phi::dtype::MPTypeTrait::Type; __device__ __forceinline__ float Sqrt(float x) { return sqrtf(x); } __device__ __forceinline__ double Sqrt(double x) { return sqrt(x); } diff --git a/paddle/fluid/operators/optimizers/sgd_op.cu b/paddle/fluid/operators/optimizers/sgd_op.cu index ee7b0f4c7e46ed8a85fbc17ce692ba051f0e3339..f6d2435590f9e4329b0cb082e5db09dab49402fb 100644 --- a/paddle/fluid/operators/optimizers/sgd_op.cu +++ b/paddle/fluid/operators/optimizers/sgd_op.cu @@ -14,9 +14,9 @@ limitations under the License. */ #include -#include "paddle/fluid/operators/amp/fp16_type_traits.h" #include "paddle/fluid/operators/optimizers/sgd_op.h" #include "paddle/phi/backends/gpu/gpu_primitives.h" +#include "paddle/phi/common/amp_type_traits.h" namespace paddle { namespace operators { @@ -77,7 +77,7 @@ class SGDOpKernel : public framework::OpKernel { ctx.InputNames("Param").front(), paddle::framework::ToTypeName(param_var->Type()))); - using MPDType = typename details::MPTypeTrait::Type; + using MPDType = typename phi::dtype::MPTypeTrait::Type; auto* param = ctx.Input("Param"); auto* param_out = ctx.Output("ParamOut"); diff --git a/paddle/fluid/operators/optimizers/sparse_momentum_op.h b/paddle/fluid/operators/optimizers/sparse_momentum_op.h index 38de9c439034f7be641e3b306f752dc4cab808a7..f1b162be4661015bb7c17736c43ff4dd15ed13b4 100644 --- a/paddle/fluid/operators/optimizers/sparse_momentum_op.h +++ b/paddle/fluid/operators/optimizers/sparse_momentum_op.h @@ -21,9 +21,9 @@ #include "paddle/fluid/framework/convert_utils.h" #include "paddle/fluid/framework/eigen.h" #include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/operators/amp/fp16_type_traits.h" #include "paddle/fluid/platform/float16.h" #include "paddle/fluid/platform/for_range.h" +#include "paddle/phi/common/amp_type_traits.h" #ifdef __NVCC__ #include "cub/cub.cuh" @@ -37,7 +37,7 @@ namespace paddle { namespace operators { template -using MultiPrecisionType = typename details::MPTypeTrait::Type; +using MultiPrecisionType = typename phi::dtype::MPTypeTrait::Type; enum class RegularizationType { kNONE = 0, diff --git a/paddle/fluid/operators/reduce_ops/reduce_op.h b/paddle/fluid/operators/reduce_ops/reduce_op.h index 40c82619db4a3cd63dc78d4671c36bafb958b805..ab1c48a08f06a24b8b497c9f65a0f47ba64aad74 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_op.h +++ b/paddle/fluid/operators/reduce_ops/reduce_op.h @@ -832,7 +832,7 @@ class ReduceCudaGradKernel : public framework::OpKernel { pt_out_dtype = d_out->dtype(); } - using MPType = typename kps::details::MPTypeTrait::Type; + using MPType = typename phi::dtype::MPTypeTrait::Type; phi::ReduceGrad>(dev_ctx, pt_d_out.get(), pt_d_x.get(), diff --git a/paddle/phi/kernels/funcs/check_numerics_utils.h b/paddle/phi/kernels/funcs/check_numerics_utils.h index c9ca80294e4f3df150a831247aa4f4867a6b6d2f..473d7994058a8dce8ff9fe349ca05856c57cd5c4 100644 --- a/paddle/phi/kernels/funcs/check_numerics_utils.h +++ b/paddle/phi/kernels/funcs/check_numerics_utils.h @@ -265,7 +265,7 @@ static void CheckNumericsCpuImpl(const T* value_ptr, } else if (std::isinf(value)) { thread_num_inf[tid] += 1; } - if (value == 0) { + if (value == static_cast(0)) { thread_num_zero[tid] += 1; } } diff --git a/paddle/phi/kernels/primitive/compute_primitives_xpu2.h b/paddle/phi/kernels/primitive/compute_primitives_xpu2.h index 2fecebaf3d2687243d759037d6381f694f0be55c..07a3ad4ed94909bc5c143387cee12156f81d8567 100644 --- a/paddle/phi/kernels/primitive/compute_primitives_xpu2.h +++ b/paddle/phi/kernels/primitive/compute_primitives_xpu2.h @@ -13,7 +13,8 @@ // limitations under the License. #pragma once -#include "paddle/phi/common/float16.h" + +#include "paddle/phi/common/amp_type_traits.h" #include "xpu/kernel/cluster_header.h" #include "xpu/kernel/debug.h" #include "xpu/kernel/math.h" @@ -27,18 +28,6 @@ namespace details { // kLocalMode: thread reduce, each thread gets an output; enum ReduceMode { kGlobalMode, kLocalMode }; -template -class MPTypeTrait { - public: - using Type = T; -}; - -template <> -class MPTypeTrait { - public: - using Type = float; -}; - static inline __device__ void sync_all() { __asm__ __volatile__( "sync_local\t\n" diff --git a/test/cpp/fluid/fused/fused_dropout_act_bias_test.cu b/test/cpp/fluid/fused/fused_dropout_act_bias_test.cu index ddcc3f513d510e8523bbc7aff610aea5c9c67910..29fb7701d0c6a3473c4192e4a9c1070d774f1111 100644 --- a/test/cpp/fluid/fused/fused_dropout_act_bias_test.cu +++ b/test/cpp/fluid/fused/fused_dropout_act_bias_test.cu @@ -17,8 +17,8 @@ limitations under the License. */ #include #include -#include "paddle/fluid/operators/amp/fp16_type_traits.h" #include "paddle/fluid/operators/fused/fused_dropout_act_bias.h" +#include "paddle/phi/common/amp_type_traits.h" #include "paddle/phi/core/kernel_registry.h" #include "paddle/phi/kernels/funcs/functors.h" #include "test/cpp/fluid/fused/fused_dropout_test.h" @@ -30,7 +30,6 @@ PD_DECLARE_KERNEL(dropout_grad, GPU, ALL_LAYOUT); namespace framework = paddle::framework; namespace platform = paddle::platform; -namespace details = paddle::operators::details; /** * @brief the unittest of fused_dropout_act_bias