activation_sig.cc 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* Copyright (c) 2022 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. */

#include "paddle/phi/core/compat/op_utils.h"

namespace phi {

Y
YuanRisheng 已提交
19 20 21
#define DEFINE_ACT_GRAD_DEPX_OP_ARGMAP(func_name, op_name, attrs) \
  KernelSignature func_name##GradOpArgumentMapping(               \
      const ArgumentMappingContext& ctx) {                        \
22 23
    return KernelSignature(                                       \
        op_name "_grad", {"X", "Out@GRAD"}, {attrs}, {"X@GRAD"}); \
24 25
  }

Y
YuanRisheng 已提交
26 27 28
#define DEFINE_ACT_GRAD_DEPOUT_OP_ARGMAP(func_name, op_name, attrs) \
  KernelSignature func_name##GradOpArgumentMapping(                 \
      const ArgumentMappingContext& ctx) {                          \
29 30
    return KernelSignature(                                         \
        op_name "_grad", {"Out", "Out@GRAD"}, {attrs}, {"X@GRAD"}); \
31 32
  }

33 34 35 36 37
#define DEFINE_ACT_GRAD_NODEP_OP_ARGMAP(func_name, op_name, attrs) \
  KernelSignature func_name##GradOpArgumentMapping(                \
      const ArgumentMappingContext& ctx) {                         \
    return KernelSignature(                                        \
        op_name "_grad", {"Out@GRAD"}, {attrs}, {"X@GRAD"});       \
Y
YuanRisheng 已提交
38 39
  }

40 41
#define comma ,

Z
zyfncg 已提交
42
DEFINE_ACT_GRAD_DEPX_OP_ARGMAP(HardTanh, "hardtanh", "t_min" comma "t_max");
43
DEFINE_ACT_GRAD_DEPX_OP_ARGMAP(Mish, "mish", "threshold");
44

G
Galaxy1458 已提交
45 46
KernelSignature SwishGradOpArgumentMapping(
    const ArgumentMappingContext& ctx UNUSED) {
47 48 49
  return KernelSignature("swish_grad", {"X", "Out@GRAD"}, {}, {"X@GRAD"});
}

G
Galaxy1458 已提交
50 51
KernelSignature Relu6GradOpArgumentMapping(
    const ArgumentMappingContext& ctx UNUSED) {
52 53
  return KernelSignature("relu6_grad", {"Out", "Out@GRAD"}, {}, {"X@GRAD"});
}
54

55
KernelSignature HardSwishGradOpArgumentMapping(
G
Galaxy1458 已提交
56
    const ArgumentMappingContext& ctx UNUSED) {
57 58 59
  return KernelSignature("hardswish_grad", {"X", "Out@GRAD"}, {}, {"X@GRAD"});
}

G
Galaxy1458 已提交
60 61
KernelSignature HardSwishOpArgumentMapping(
    const ArgumentMappingContext& ctx UNUSED) {
62
  return KernelSignature("hardswish", {"X"}, {}, {"Out"});
63 64
}

G
Galaxy1458 已提交
65 66
KernelSignature SwishOpArgumentMapping(
    const ArgumentMappingContext& ctx UNUSED) {
67 68 69
  return KernelSignature("swish_raw", {"X"}, {"beta"}, {"Out"});
}

G
Galaxy1458 已提交
70 71
KernelSignature Relu6OpArgumentMapping(
    const ArgumentMappingContext& ctx UNUSED) {
72 73 74
  return KernelSignature("relu6_raw", {"X"}, {"threshold"}, {"Out"});
}

75 76
}  // namespace phi

Z
zyfncg 已提交
77 78
PD_REGISTER_BASE_KERNEL_NAME(hard_swish, hardswish);
PD_REGISTER_BASE_KERNEL_NAME(hard_swish_grad, hardswish_grad);
79

80 81
PD_REGISTER_ARG_MAPPING_FN(mish_grad, phi::MishGradOpArgumentMapping);

82
PD_REGISTER_ARG_MAPPING_FN(relu6_grad, phi::Relu6GradOpArgumentMapping);
83
PD_REGISTER_ARG_MAPPING_FN(relu6, phi::Relu6OpArgumentMapping);
Y
YuanRisheng 已提交
84 85
PD_REGISTER_ARG_MAPPING_FN(hard_swish_grad,
                           phi::HardSwishGradOpArgumentMapping);
86
PD_REGISTER_ARG_MAPPING_FN(hard_swish, phi::HardSwishOpArgumentMapping);
Y
YuanRisheng 已提交
87
PD_REGISTER_ARG_MAPPING_FN(swish_grad, phi::SwishGradOpArgumentMapping);
88
PD_REGISTER_ARG_MAPPING_FN(swish, phi::SwishOpArgumentMapping);