/home/liu/actions-runner/_work/ccv/ccv/lib/nnc/cmd/lamb/ccv_nnc_lamb.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_lamb_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) |
6 | 15 | { |
7 | | // 3 inputs (gradient, x, momentum, velocity) |
8 | | // 2 outputs (y, new momentum, new velocity) |
9 | 15 | if (input_bitmasks[0] == 15u && output_bitmasks[0] == 7u5 ) |
10 | 5 | return 1; |
11 | 10 | return 0; |
12 | 15 | } |
13 | | |
14 | | static int _ccv_nnc_lamb_allow_inplace(const ccv_nnc_cmd_param_t cmd, const int input_idx, const int input_size, const int output_idx, const int output_size) |
15 | 18 | { |
16 | 18 | if (input_idx == output_idx + 1) |
17 | 6 | return 1; |
18 | 12 | return 0; |
19 | 18 | } |
20 | | |
21 | | static int _ccv_nnc_lamb_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) |
22 | 0 | { |
23 | | // Doesn't support. |
24 | 0 | return 0; |
25 | 0 | } |
26 | | |
27 | | static void _ccv_nnc_lamb_tensor_auto_forw(const ccv_nnc_cmd_param_t cmd, const ccv_nnc_tensor_param_t* const inputs, const int input_size, const ccv_nnc_hint_t hint, ccv_nnc_tensor_param_t* const outputs, const int output_size) |
28 | 17 | { |
29 | 17 | int i; |
30 | 68 | for (i = 0; i < output_size; i++51 ) |
31 | 51 | outputs[i] = inputs[0]; |
32 | 17 | } |
33 | | |
34 | | static void _ccv_nnc_lamb_tensor_auto_back(const ccv_nnc_cmd_param_t cmd, const ccv_nnc_tensor_param_t* const inputs, const int input_size, const ccv_nnc_hint_t hint, ccv_nnc_tensor_param_t* const outputs, const int output_size) |
35 | 0 | { |
36 | | // Doesn't support. |
37 | 0 | } |
38 | | |
39 | | REGISTER_COMMAND(CCV_NNC_LAMB_FORWARD)(ccv_nnc_cmd_registry_t* const registry) |
40 | | FIND_BACKEND(ccv_nnc_lamb_cpu_ref.c, gpu/ccv_nnc_lamb_gpu_ref.cu) |
41 | 1 | { |
42 | 1 | registry->bitmask = _ccv_nnc_lamb_forw_bitmask; |
43 | 1 | registry->tensor_auto = _ccv_nnc_lamb_tensor_auto_forw; |
44 | 1 | registry->allow_inplace = _ccv_nnc_lamb_allow_inplace; |
45 | 1 | } |
46 | | |
47 | | REGISTER_COMMAND(CCV_NNC_LAMB_BACKWARD)(ccv_nnc_cmd_registry_t* const registry) |
48 | | FIND_BACKEND(ccv_nnc_lamb_cpu_ref.c, gpu/ccv_nnc_lamb_gpu_ref.cu) |
49 | 1 | { |
50 | 1 | registry->bitmask = _ccv_nnc_lamb_back_bitmask; |
51 | 1 | registry->tensor_auto = _ccv_nnc_lamb_tensor_auto_back; |
52 | 1 | } |
53 | | |
54 | | //@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_LAMB_FORWARD) |
55 | | #define CMD_LAMB_FORWARD(_step, _rate, _beta1, _beta2, _decay, _epsilon) ccv_nnc_cmd(CCV_NNC_LAMB_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.lamb={.step=_step,.rate=_rate,.scale=1,.beta1=_beta1,.beta2=_beta2,.decay=_decay,.epsilon=_epsilon}}), 0) |