Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added round FP32 FWD oneDNN kernel #39653

Merged
merged 1 commit into from
Feb 22, 2022
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
10 changes: 10 additions & 0 deletions paddle/fluid/operators/mkldnn/activation_mkldnn_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ using EluMKLDNNFunctor = MKLDNNActivationFunc<T, dnnl::algorithm::eltwise_elu>;
template <typename T>
using ExpMKLDNNFunctor = MKLDNNActivationFunc<T, dnnl::algorithm::eltwise_exp>;

template <typename T>
using RoundMKLDNNFunctor =
MKLDNNActivationFunc<T, dnnl::algorithm::eltwise_round>;

template <typename T>
using ReluMKLDNNGradFunctor =
MKLDNNActivationGradFunc<T, dnnl::algorithm::eltwise_relu>;
Expand Down Expand Up @@ -330,6 +334,10 @@ namespace ops = paddle::operators;
ops::MKLDNNActivationGradKernel< \
ops::grad_functor<paddle::platform::bfloat16>>);

#define REGISTER_ACTIVATION_MKLDNN_KERNEL_FWD_ONLY(act_type, functor) \
REGISTER_OP_KERNEL(act_type, MKLDNN, ::paddle::platform::CPUPlace, \
ops::MKLDNNActivationKernel<ops::functor<float>>);

#define FOR_EACH_MKLDNN_KERNEL_FUNCTOR(__macro) \
__macro(relu6, Relu6MKLDNNFunctor, Relu6MKLDNNGradFunctor); \
__macro(leaky_relu, ReluMKLDNNFunctor, ReluMKLDNNGradFunctor); \
Expand All @@ -341,6 +349,8 @@ namespace ops = paddle::operators;
__macro(exp, ExpMKLDNNFunctor, ExpMKLDNNGradUseOutFunctor);

FOR_EACH_MKLDNN_KERNEL_FUNCTOR(REGISTER_ACTIVATION_MKLDNN_KERNEL);
REGISTER_ACTIVATION_MKLDNN_KERNEL_FWD_ONLY(round, RoundMKLDNNFunctor);

REGISTER_ACTIVATION_MKLDNN_BF16_KERNEL(relu, ReluMKLDNNFunctor,
ReluMKLDNNGradFunctor);
REGISTER_ACTIVATION_MKLDNN_BF16_KERNEL(gelu, GeluMKLDNNFunctor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,18 @@ def setUp(self):
self.attrs = {"use_mkldnn": True}


class TestMKLDNNRound(TestActivation):
def setUp(self):
self.op_type = "round"

x = np.random.uniform(0.1, 1, [2, 4, 3, 5]).astype(np.float32)
out = np.round(x)

self.inputs = {'X': x}
self.outputs = {'Out': out}
self.attrs = {"use_mkldnn": True}


class TestMKLDNNSigmoidDim4(TestSigmoid):
def setUp(self):
super(TestMKLDNNSigmoidDim4, self).setUp()
Expand Down