/home/liu/actions-runner/_work/ccv/ccv/lib/nnc/cmd/gelu/ccv_nnc_gelu.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "ccv.h" |
2 | | #include "nnc/ccv_nnc.h" |
3 | | #include "nnc/ccv_nnc_internal.h" |
4 | | |
5 | | static int _ccv_nnc_gelu_allow_first_replace(const ccv_nnc_cmd_param_t cmd, const int input_idx, const int input_size, const int output_idx, const int output_size) |
6 | 19 | { |
7 | 19 | return input_idx == 0 && output_idx == 013 ; |
8 | 19 | } |
9 | | |
10 | | static int _ccv_nnc_gelu_forw_bitmask(const ccv_nnc_cmd_param_t cmd, const int input_size, const int output_size, const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size) |
11 | 1 | { |
12 | 1 | if ((input_bitmasks[0] & 1u) == 1u && output_bitmasks[0] == 1u) |
13 | 1 | return 1; |
14 | 0 | return 0; |
15 | 1 | } |
16 | | |
17 | | static int _ccv_nnc_gelu_back_bitmask(const ccv_nnc_cmd_param_t cmd, const int input_size, const int output_size, const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size) |
18 | 26 | { |
19 | 26 | if ((input_bitmasks[0] & 3u) == ((1u << 0) | (1u << 1)) && output_bitmasks[0] == 1u12 ) |
20 | 12 | return 1; |
21 | 14 | return 0; |
22 | 26 | } |
23 | | |
24 | | REGISTER_COMMAND(CCV_NNC_GELU_FORWARD)(ccv_nnc_cmd_registry_t* const registry) |
25 | | FIND_BACKEND(ccv_nnc_gelu_cpu_ref.c, gpu/ccv_nnc_gelu_gpu_ref.cu, mps/ccv_nnc_gelu_mps.m) |
26 | 1 | { |
27 | 1 | registry->bitmask = _ccv_nnc_gelu_forw_bitmask; |
28 | 1 | registry->tensor_auto = ccv_nnc_hint_tensor_auto_forward_from_inputs; |
29 | 1 | registry->allow_inplace = _ccv_nnc_gelu_allow_first_replace; |
30 | 1 | } |
31 | | |
32 | | REGISTER_COMMAND(CCV_NNC_GELU_BACKWARD)(ccv_nnc_cmd_registry_t* const registry) |
33 | | FIND_BACKEND(ccv_nnc_gelu_cpu_ref.c, gpu/ccv_nnc_gelu_gpu_ref.cu, mps/ccv_nnc_gelu_mps.m) |
34 | 1 | { |
35 | 1 | registry->bitmask = _ccv_nnc_gelu_back_bitmask; |
36 | 1 | registry->tensor_auto = ccv_nnc_hint_tensor_auto_backward_from_gradient; |
37 | 1 | registry->allow_inplace = _ccv_nnc_gelu_allow_first_replace; |
38 | 1 | } |
39 | | |
40 | | //@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_GELU_FORWARD) |
41 | | #define CMD_GELU_FORWARD(_tanh) ccv_nnc_cmd(CCV_NNC_GELU_FORWARD, 0, (ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.gelu={.tanh=_tanh}}, 0) |
42 | | //@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_GELU_BACKWARD) |
43 | | #define CMD_GELU_BACKWARD(_tanh) ccv_nnc_cmd(CCV_NNC_GELU_BACKWARD, 0, (ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.gelu={.tanh=_tanh}}, 0) |