gelu.cu 2.35 KB
Newer Older
Przemek Tredak's avatar
Przemek Tredak committed
1
/*************************************************************************
2
 * Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Przemek Tredak's avatar
Przemek Tredak committed
3
4
5
 *
 * See LICENSE for license information.
 ************************************************************************/
6

7
#include "../util/math.h"
8
#include "./activation_template.h"
Przemek Tredak's avatar
Przemek Tredak committed
9

10
void nvte_gelu(const NVTETensor input, NVTETensor output, cudaStream_t stream) {
11
  NVTE_API_CALL(nvte_gelu);
Przemek Tredak's avatar
Przemek Tredak committed
12
  using namespace transformer_engine;
13
  act_fn<fp32, Empty, gelu<fp32, fp32>>(input, output, stream);
14
15
}

16
void nvte_dgelu(const NVTETensor grad, const NVTETensor input, NVTETensor output,
17
18
19
                cudaStream_t stream) {
  NVTE_API_CALL(nvte_dgelu);
  using namespace transformer_engine;
20
  dact_fn<fp32, Empty, dgelu<fp32, fp32>>(grad, input, output, stream);
Przemek Tredak's avatar
Przemek Tredak committed
21
}
22

23
void nvte_geglu(const NVTETensor input, NVTETensor output, cudaStream_t stream) {
24
  NVTE_API_CALL(nvte_geglu);
25
  using namespace transformer_engine;
26
27
  Empty e = {};
  gated_act_fn<fp32, Empty, gelu<fp32, fp32>>(input, output, e, stream);
28
29
}

30
void nvte_dgeglu(const NVTETensor grad, const NVTETensor input, NVTETensor output,
31
                 cudaStream_t stream) {
32
  NVTE_API_CALL(nvte_dgeglu);
33
  using namespace transformer_engine;
34
35
  Empty e = {};
  dgated_act_fn<fp32, Empty, gelu<fp32, fp32>, dgelu<fp32, fp32>>(grad, input, output, e, stream);
36
}
37

38
void nvte_qgelu(const NVTETensor input, NVTETensor output, cudaStream_t stream) {
39
40
  NVTE_API_CALL(nvte_qgelu);
  using namespace transformer_engine;
41
  act_fn<fp32, Empty, qgelu<fp32, fp32>>(input, output, stream);
42
43
}

44
45
void nvte_dqgelu(const NVTETensor grad, const NVTETensor input, NVTETensor output,
                 cudaStream_t stream) {
46
47
  NVTE_API_CALL(nvte_dqgelu);
  using namespace transformer_engine;
48
  dact_fn<fp32, Empty, dqgelu<fp32, fp32>>(grad, input, output, stream);
49
}
50

51
void nvte_qgeglu(const NVTETensor input, NVTETensor output, cudaStream_t stream) {
52
53
  NVTE_API_CALL(nvte_qgeglu);
  using namespace transformer_engine;
54
55
  Empty e = {};
  gated_act_fn<fp32, Empty, qgelu<fp32, fp32>>(input, output, e, stream);
56
57
}

58
59
void nvte_dqgeglu(const NVTETensor grad, const NVTETensor input, NVTETensor output,
                  cudaStream_t stream) {
60
61
  NVTE_API_CALL(nvte_dqgeglu);
  using namespace transformer_engine;
62
63
  Empty e = {};
  dgated_act_fn<fp32, Empty, qgelu<fp32, fp32>, dqgelu<fp32, fp32>>(grad, input, output, e, stream);
64
}