未验证 提交 9d4b4be3 编写于 作者: H haosicheng 提交者: GitHub

add floor fp32 op *test=kunlun (#48458)

上级 a66bb67a
......@@ -282,6 +282,7 @@ XPUOpMap& get_kl2_ops() {
pOpKernelType(vartype::INT32, XPUPlace()),
pOpKernelType(vartype::INT8, XPUPlace()),
pOpKernelType(vartype::FP32, XPUPlace())})},
{"floor", XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace())})},
{"gather_grad",
XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace()),
pOpKernelType(vartype::FP16, XPUPlace())})},
......
......@@ -426,7 +426,21 @@ struct XPUTanhFunctor : public funcs::BaseActivationFunctor<T> {
}
};
template <typename T>
struct XPUFloorFunctor : public funcs::BaseActivationFunctor<T> {
using XPUType = typename XPUTypeTrait<T>::Type;
template <typename Context>
void operator()(const Context& dev_ctx,
const DenseTensor& x,
DenseTensor* out) const {
int r = xpu_activation_func<Context, T, XPUType>(
dev_ctx, x, out, xpu::floor<XPUType>);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "floor");
}
};
DEFINE_XPU_ACTIVATION_KERNEL(Exp, XPUExpFunctor)
DEFINE_XPU_ACTIVATION_KERNEL(Floor, XPUFloorFunctor)
DEFINE_XPU_ACTIVATION_KERNEL(Log, XPULogFunctor)
DEFINE_XPU_ACTIVATION_KERNEL(Reciprocal, XPUReciprocalFunctor)
DEFINE_XPU_ACTIVATION_KERNEL(Relu, XPUReluFunctor)
......@@ -483,6 +497,7 @@ PD_REGISTER_KERNEL(
square, XPU, ALL_LAYOUT, phi::SquareKernel, float, phi::dtype::float16) {}
PD_REGISTER_ACTIVATION_KERNEL(exp, ExpKernel) // no grad
PD_REGISTER_ACTIVATION_KERNEL(floor, FloorKernel)
PD_REGISTER_ACTIVATION_KERNEL(log, LogKernel)
PD_REGISTER_ACTIVATION_KERNEL(leaky_relu, LeakyReluKernel)
PD_REGISTER_ACTIVATION_KERNEL(hard_sigmoid, HardSigmoidKernel)
......
......@@ -177,6 +177,32 @@ for stype in support_types:
create_test_class(globals(), XPUTestSqrtOP, stype)
class XPUTestFloorOP(XPUOpTestWrapper):
def __init__(self):
self.op_name = 'floor'
self.use_dynamic_create_class = False
class XPUTestSqrt(TestActivationOPBase):
def set_case(self):
self.op_type = "floor"
self.dtype = self.in_type
x = np.random.uniform(0.1, 1, [11, 17]).astype(self.dtype)
out = np.floor(x)
self.attrs = {'use_xpu': True}
self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
self.outputs = {'Out': out}
def test_check_grad(self):
self.check_output_with_place(self.place)
support_types = get_xpu_op_support_types('floor')
for stype in support_types:
create_test_class(globals(), XPUTestFloorOP, stype)
class XPUTestAbsOP(XPUOpTestWrapper):
def __init__(self):
self.op_name = 'abs'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册