Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,11 @@
"asinh": ["x"],
"atan": ["x"],
"atanh": ["x"],
"ceil": ["x"],
"cos": ["x"],
"cosh": ["x"],
"digamma": ["x"],
"erf": ["x"],
"erfinv": ["x"],
"floor": ["x"],
"i0": ["x"],
"i0e": ["x"],
"i1": ["x"],
Expand All @@ -181,10 +179,7 @@

# ops support casting int tensor into float32 to do forward calculation,
# and it is valid to cast float32 gradient back to int tensor.
type_autocast_valid_grad_op_list = {
"ceil",
"floor",
}
type_autocast_valid_grad_op_list = {}

# dict of special api that forward api's output will affect backward api's output
# backward api's output usually affected by backward api's input
Expand Down
7 changes: 1 addition & 6 deletions paddle/fluid/pir/dialect/op_generator/api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@
"asinh": ["x"],
"atan": ["x"],
"atanh": ["x"],
"ceil": ["x"],
"cos": ["x"],
"cosh": ["x"],
"digamma": ["x"],
"erf": ["x"],
"erfinv": ["x"],
"floor": ["x"],
"i0": ["x"],
"i0e": ["x"],
"i1": ["x"],
Expand All @@ -112,10 +110,7 @@

# ops support casting int tensor into float32 to do forward calculation,
# and it is valid to cast float32 gradient back to int tensor.
type_autocast_valid_grad_op_list = {
"ceil",
"floor",
}
type_autocast_valid_grad_op_list = {}

PD_MANUAL_API_LIST = {
'embedding_grad',
Expand Down
30 changes: 28 additions & 2 deletions paddle/phi/kernels/cpu/activation_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,6 @@ PD_REGISTER_ACTIVATION_DOUBLE_GRAD_KERNEL_WITH_COMPLEX(log_double_grad,
PD_REGISTER_ACTIVATION_GRAD_KERNEL_WITH_COMPLEX(hardswish_grad,
HardSwishGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(swish_grad, SwishGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(floor_grad, FloorGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(ceil_grad, CeilGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(celu_grad, CeluGradKernel)
PD_REGISTER_ACTIVATION_DOUBLE_GRAD_KERNEL(celu_double_grad,
CeluDoubleGradKernel)
Expand Down Expand Up @@ -541,3 +539,31 @@ PD_REGISTER_KERNEL(pow_triple_grad,
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(ceil_grad,
CPU,
ALL_LAYOUT,
phi::CeilGradKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}

PD_REGISTER_KERNEL(floor_grad,
CPU,
ALL_LAYOUT,
phi::FloorGradKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
30 changes: 28 additions & 2 deletions paddle/phi/kernels/cpu/activation_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ PD_REGISTER_ACTIVATION_KERNEL(hardsigmoid, HardSigmoidKernel)
PD_REGISTER_ACTIVATION_KERNEL(swish, SwishKernel)
PD_REGISTER_ACTIVATION_KERNEL(relu6, Relu6Kernel)
PD_REGISTER_ACTIVATION_KERNEL_WITH_COMPLEX(hardswish, HardSwishKernel)
PD_REGISTER_ACTIVATION_KERNEL(floor, FloorKernel)
PD_REGISTER_ACTIVATION_KERNEL(ceil, CeilKernel)
PD_REGISTER_ACTIVATION_KERNEL(celu, CeluKernel)

PD_REGISTER_KERNEL(
Expand Down Expand Up @@ -381,3 +379,31 @@ PD_REGISTER_KERNEL(pow,
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(ceil,
CPU,
ALL_LAYOUT,
phi::CeilKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}

PD_REGISTER_KERNEL(floor,
CPU,
ALL_LAYOUT,
phi::FloorKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
1 change: 1 addition & 0 deletions paddle/phi/kernels/cpu/full_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ PD_REGISTER_KERNEL(full_like,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
Expand Down
44 changes: 40 additions & 4 deletions paddle/phi/kernels/funcs/activation_functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,16 @@ template <typename T>
struct FloorFunctor : public BaseActivationFunctor<T> {
template <typename Device, typename X, typename Out>
void operator()(Device d, X x, Out out) const {
out.device(d) = x.floor();
if constexpr ((std::is_same<T, uint8_t>::value) ||
(std::is_same<T, int8_t>::value) ||
(std::is_same<T, uint16_t>::value) ||
(std::is_same<T, int16_t>::value) ||
(std::is_same<T, int>::value) ||
(std::is_same<T, int64_t>::value)) {
out.device(d) = x;
} else {
out.device(d) = x.floor();
}
}
};

Expand Down Expand Up @@ -3160,7 +3169,16 @@ template <typename T>
struct CeilFunctor : public BaseActivationFunctor<T> {
template <typename Device, typename X, typename Out>
void operator()(Device d, X x, Out out) const {
out.device(d) = x.ceil();
if constexpr ((std::is_same<T, uint8_t>::value) ||
(std::is_same<T, int8_t>::value) ||
(std::is_same<T, uint16_t>::value) ||
(std::is_same<T, int16_t>::value) ||
(std::is_same<T, int>::value) ||
(std::is_same<T, int64_t>::value)) {
out.device(d) = x;
} else {
out.device(d) = x.ceil();
}
}
};

Expand Down Expand Up @@ -5403,7 +5421,16 @@ struct CudaCeilFunctor : public BaseActivationFunctor<T> {
// ceil(x) = ceil(x)
__device__ __forceinline__ T operator()(const T arg_x) const {
MPType x = static_cast<MPType>(arg_x);
return static_cast<T>(ceil(x));
if constexpr ((std::is_same<T, uint8_t>::value) ||
(std::is_same<T, int8_t>::value) ||
(std::is_same<T, uint16_t>::value) ||
(std::is_same<T, int16_t>::value) ||
(std::is_same<T, int>::value) ||
(std::is_same<T, int64_t>::value)) {
return static_cast<T>(x);
} else {
return static_cast<T>(ceil(x));
}
}
};

Expand Down Expand Up @@ -5492,7 +5519,16 @@ struct CudaFloorFunctor : public BaseActivationFunctor<T> {
// floor(x) = floor(x)
__device__ __forceinline__ T operator()(const T arg_x) const {
MPType x = static_cast<MPType>(arg_x);
return static_cast<T>(floor(x));
if constexpr ((std::is_same<T, uint8_t>::value) ||
(std::is_same<T, int8_t>::value) ||
(std::is_same<T, uint16_t>::value) ||
(std::is_same<T, int16_t>::value) ||
(std::is_same<T, int>::value) ||
(std::is_same<T, int64_t>::value)) {
return static_cast<T>(x);
} else {
return static_cast<T>(floor(x));
}
}
};

Expand Down
28 changes: 26 additions & 2 deletions paddle/phi/kernels/gpu/activation_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,6 @@ PD_REGISTER_KERNEL(log_double_grad,
PD_REGISTER_ACTIVATION_GRAD_KERNEL_WITH_COMPLEX(hardswish_grad,
HardSwishGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(swish_grad, SwishGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(floor_grad, FloorGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(ceil_grad, CeilGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(celu_grad, CeluGradKernel)
PD_REGISTER_ACTIVATION_GRAD_KERNEL(celu_double_grad, CeluDoubleGradKernel)

Expand Down Expand Up @@ -617,3 +615,29 @@ PD_REGISTER_KERNEL(pow_triple_grad,
phi::dtype::bfloat16,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
PD_REGISTER_KERNEL(ceil_grad,
GPU,
ALL_LAYOUT,
phi::CeilGradKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
PD_REGISTER_KERNEL(floor_grad,
GPU,
ALL_LAYOUT,
phi::FloorGradKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
28 changes: 26 additions & 2 deletions paddle/phi/kernels/gpu/activation_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ PD_REGISTER_ACTIVATION_KERNEL_WITH_COMPLEX(logsigmoid, LogSigmoidKernel)
PD_REGISTER_ACTIVATION_KERNEL(hardsigmoid, HardSigmoidKernel)
PD_REGISTER_ACTIVATION_KERNEL_WITH_COMPLEX(hardswish, HardSwishKernel)
PD_REGISTER_ACTIVATION_KERNEL(swish, SwishKernel)
PD_REGISTER_ACTIVATION_KERNEL(floor, FloorKernel)
PD_REGISTER_ACTIVATION_KERNEL(ceil, CeilKernel)
PD_REGISTER_ACTIVATION_KERNEL(celu, CeluKernel)
PD_REGISTER_ACTIVATION_KERNEL(selu, SeluKernel)
PD_REGISTER_ACTIVATION_KERNEL(logit, LogitCUDAKernel)
Expand Down Expand Up @@ -435,3 +433,29 @@ PD_REGISTER_KERNEL(pow,
phi::dtype::bfloat16,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
PD_REGISTER_KERNEL(ceil,
GPU,
ALL_LAYOUT,
phi::CeilKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
PD_REGISTER_KERNEL(floor,
GPU,
ALL_LAYOUT,
phi::FloorKernel,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
11 changes: 10 additions & 1 deletion paddle/phi/kernels/xpu/activation_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,16 @@ PD_REGISTER_KERNEL(acos,
#define PD_REGISTER_ACTIVATION_KERNEL(name, func) \
PD_REGISTER_KERNEL(name, XPU, ALL_LAYOUT, phi::func, float) {}

PD_REGISTER_ACTIVATION_KERNEL(floor, FloorKernel)
PD_REGISTER_ACTIVATION_KERNEL(mish, MishKernel)
PD_REGISTER_ACTIVATION_KERNEL(reciprocal, ReciprocalKernel)
PD_REGISTER_ACTIVATION_KERNEL(softplus, SoftplusKernel)

PD_REGISTER_KERNEL(floor,
XPU,
ALL_LAYOUT,
phi::FloorKernel,
float,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
1 change: 1 addition & 0 deletions paddle/phi/kernels/xpu/full_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ PD_REGISTER_KERNEL(full_like,
float,
double,
uint8_t,
int8_t,
int16_t,
int,
int64_t,
Expand Down
1 change: 0 additions & 1 deletion python/paddle/tensor/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ def floor(x: Tensor, name: str | None = None) -> Tensor:

Returns:
Tensor. Output of Floor operator, a Tensor with shape same as input
(integer types are autocasted into float32).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

记得修改中文文档的这里。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Examples:
.. code-block:: python
Expand Down
50 changes: 50 additions & 0 deletions test/legacy_test/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,31 @@ def init_shape(self):
self.shape = []


class TestCeil_UInt8(TestCeil):
def init_dtype(self):
self.dtype = np.uint8


class TestCeil_Int8(TestCeil):
def init_dtype(self):
self.dtype = np.int8


class TestCeil_Int16(TestCeil):
def init_dtype(self):
self.dtype = np.int16


class TestCeil_Int32(TestCeil):
def init_dtype(self):
self.dtype = np.int32


class TestCeil_Int64(TestCeil):
def init_dtype(self):
self.dtype = np.int64


class TestFloor(TestActivation):
def setUp(self):
self.op_type = "floor"
Expand Down Expand Up @@ -2138,6 +2163,31 @@ def init_shape(self):
self.shape = []


class TestFloor_UInt8(TestFloor):
def init_dtype(self):
self.dtype = np.uint8


class TestFloor_Int8(TestFloor):
def init_dtype(self):
self.dtype = np.int8


class TestFloor_Int16(TestFloor):
def init_dtype(self):
self.dtype = np.int16


class TestFloor_Int32(TestFloor):
def init_dtype(self):
self.dtype = np.int32


class TestFloor_Int64(TestFloor):
def init_dtype(self):
self.dtype = np.int64


class TestCos(TestActivation):
def setUp(self):
self.op_type = "cos"
Expand Down