未验证 提交 df5d55bb 编写于 作者: Z Zhang Ting 提交者: GitHub

[part 1]change type of function args (#38885)

上级 f5166284
...@@ -24,14 +24,14 @@ struct CudaAbsFunctor; ...@@ -24,14 +24,14 @@ struct CudaAbsFunctor;
template <typename T> template <typename T>
struct CudaAbsFunctor<T, math::Complex<T, math::Real<T>>> { struct CudaAbsFunctor<T, math::Complex<T, math::Real<T>>> {
__device__ __forceinline__ math::Real<T> operator()(const T& x) const { __device__ __forceinline__ math::Real<T> operator()(const T x) const {
return abs(x); return abs(x);
} }
}; };
template <typename T> template <typename T>
struct CudaAbsFunctor<T, math::NoComplex<T, math::Real<T>>> { struct CudaAbsFunctor<T, math::NoComplex<T, math::Real<T>>> {
__device__ __forceinline__ T operator()(const T& x) const { __device__ __forceinline__ T operator()(const T x) const {
return std::abs(x); return std::abs(x);
} }
}; };
......
...@@ -28,8 +28,8 @@ template <typename T> ...@@ -28,8 +28,8 @@ template <typename T>
struct BCELossGradFunctor { struct BCELossGradFunctor {
T one = static_cast<T>(1.0f); T one = static_cast<T>(1.0f);
T eps = static_cast<T>(1e-12); T eps = static_cast<T>(1e-12);
__device__ __forceinline__ T operator()(const T& x, const T& label, __device__ __forceinline__ T operator()(const T x, const T label,
const T& dout) const { const T dout) const {
T term1 = max((one - x) * x, eps); T term1 = max((one - x) * x, eps);
return (dout * (x - label) / term1); return (dout * (x - label) / term1);
} }
......
...@@ -32,7 +32,7 @@ template <typename T> ...@@ -32,7 +32,7 @@ template <typename T>
class ClipFunctor { class ClipFunctor {
public: public:
explicit ClipFunctor(const T min, const T max) : min_(min), max_(max) {} explicit ClipFunctor(const T min, const T max) : min_(min), max_(max) {}
HOSTDEVICE T operator()(const T& x) const { HOSTDEVICE T operator()(const T x) const {
return x < min_ ? min_ : x > max_ ? max_ : x; return x < min_ ? min_ : x > max_ ? max_ : x;
} }
......
...@@ -63,7 +63,7 @@ __device__ __forceinline__ double inline_pow(double base, double exponent) { ...@@ -63,7 +63,7 @@ __device__ __forceinline__ double inline_pow(double base, double exponent) {
template <typename T> template <typename T>
struct NonzeroFunctor { struct NonzeroFunctor {
HOSTDEVICE explicit inline NonzeroFunctor() {} HOSTDEVICE explicit inline NonzeroFunctor() {}
HOSTDEVICE inline T operator()(const T& x) const { HOSTDEVICE inline T operator()(const T x) const {
return static_cast<T>(static_cast<double>(x) != 0); return static_cast<T>(static_cast<double>(x) != 0);
} }
}; };
...@@ -71,7 +71,7 @@ struct NonzeroFunctor { ...@@ -71,7 +71,7 @@ struct NonzeroFunctor {
template <typename T> template <typename T>
struct AbsFunctor { struct AbsFunctor {
HOSTDEVICE explicit inline AbsFunctor() {} HOSTDEVICE explicit inline AbsFunctor() {}
HOSTDEVICE inline T operator()(const T& x) const { HOSTDEVICE inline T operator()(const T x) const {
return static_cast<T>(inline_abs(x)); return static_cast<T>(inline_abs(x));
} }
}; };
...@@ -81,7 +81,7 @@ struct UnsignedPowFunctor { ...@@ -81,7 +81,7 @@ struct UnsignedPowFunctor {
HOSTDEVICE explicit inline UnsignedPowFunctor(float porder) { HOSTDEVICE explicit inline UnsignedPowFunctor(float porder) {
this->porder = porder; this->porder = porder;
} }
HOSTDEVICE inline Ty operator()(const Tx& x) const { HOSTDEVICE inline Ty operator()(const Tx x) const {
return static_cast<Ty>(inline_pow(inline_abs(x), static_cast<Tx>(porder))); return static_cast<Ty>(inline_pow(inline_abs(x), static_cast<Tx>(porder)));
} }
float porder; float porder;
...@@ -90,7 +90,7 @@ struct UnsignedPowFunctor { ...@@ -90,7 +90,7 @@ struct UnsignedPowFunctor {
template <typename Tx, typename Ty = Tx> template <typename Tx, typename Ty = Tx>
struct PowFunctor { struct PowFunctor {
HOSTDEVICE explicit inline PowFunctor(float porder) { this->porder = porder; } HOSTDEVICE explicit inline PowFunctor(float porder) { this->porder = porder; }
HOSTDEVICE inline Ty operator()(const Tx& x) const { HOSTDEVICE inline Ty operator()(const Tx x) const {
return static_cast<Ty>(inline_pow(x, static_cast<Tx>(porder))); return static_cast<Ty>(inline_pow(x, static_cast<Tx>(porder)));
} }
float porder; float porder;
......
...@@ -42,7 +42,7 @@ struct UnsignedPowFunctor { ...@@ -42,7 +42,7 @@ struct UnsignedPowFunctor {
HOSTDEVICE explicit inline UnsignedPowFunctor(float porder) { HOSTDEVICE explicit inline UnsignedPowFunctor(float porder) {
this->porder = porder; this->porder = porder;
} }
HOSTDEVICE inline Ty operator()(const Tx& x) const { HOSTDEVICE inline Ty operator()(const Tx x) const {
return static_cast<Ty>(inline_pow(inline_abs(x), static_cast<Tx>(porder))); return static_cast<Ty>(inline_pow(inline_abs(x), static_cast<Tx>(porder)));
} }
float porder; float porder;
......
...@@ -30,7 +30,7 @@ namespace pten { ...@@ -30,7 +30,7 @@ namespace pten {
template <typename InT, typename OutT> template <typename InT, typename OutT>
struct CastFuctor { struct CastFuctor {
__device__ __forceinline__ OutT operator()(const InT& x) const { __device__ __forceinline__ OutT operator()(const InT x) const {
return static_cast<OutT>(x); return static_cast<OutT>(x);
} }
}; };
......
...@@ -34,7 +34,7 @@ struct ScaleFunctor { ...@@ -34,7 +34,7 @@ struct ScaleFunctor {
bias_after_scale = is_bias_after_sacle; bias_after_scale = is_bias_after_sacle;
} }
__device__ __forceinline__ InT operator()(const InT& x) const { __device__ __forceinline__ InT operator()(const InT x) const {
if (bias_after_scale) { if (bias_after_scale) {
return scale * x + bias; return scale * x + bias;
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册