Coverage Report

Created: 2024-08-19 11:27

/home/liu/actions-runner/_work/ccv/ccv/lib/nnc/cmd/softmax/ccv_nnc_softmax.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_arbitary_inplace(const ccv_nnc_cmd_param_t cmd, const int input_idx, const int input_size, const int output_idx, const int output_size)
6
24
{
7
24
  return 1;
8
24
}
9
10
static int _ccv_nnc_allow_gradient_inplace(const ccv_nnc_cmd_param_t cmd, const int input_idx, const int input_size, const int output_idx, const int output_size)
11
40
{
12
40
  return (input_idx == 0 && 
output_idx == 019
);
13
40
}
14
15
static int _ccv_nnc_softmax_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)
16
12
{
17
12
  if ((input_bitmasks[0] & 1u) == 1u && output_bitmasks[0] == 1u)
18
12
    return 1;
19
0
  return 0;
20
12
}
21
22
static int _ccv_nnc_softmax_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)
23
56
{
24
56
  if ((input_bitmasks[0] & 5u) == 5u && 
output_bitmasks[0] == 1u20
)
25
20
    return 1;
26
36
  return 0;
27
56
}
28
29
REGISTER_COMMAND(CCV_NNC_SOFTMAX_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
30
  FIND_BACKEND(ccv_nnc_softmax_cpu_ref.c, gpu/ccv_nnc_softmax_gpu_cudnn.cu, mps/ccv_nnc_softmax_mps.m)
31
1
{
32
1
  registry->bitmask = _ccv_nnc_softmax_forw_bitmask;
33
1
  registry->tensor_auto = ccv_nnc_hint_tensor_auto_forward_from_inputs;
34
1
  registry->allow_inplace = _ccv_nnc_arbitary_inplace;
35
1
}
36
37
REGISTER_COMMAND(CCV_NNC_SOFTMAX_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
38
  FIND_BACKEND(ccv_nnc_softmax_cpu_ref.c, gpu/ccv_nnc_softmax_gpu_cudnn.cu, mps/ccv_nnc_softmax_mps.m)
39
1
{
40
1
  registry->flags = CCV_NNC_CMD_ATTR_NULL_IS_ONES;
41
1
  registry->bitmask = _ccv_nnc_softmax_back_bitmask;
42
1
  registry->tensor_auto = ccv_nnc_hint_tensor_auto_backward_from_gradient;
43
1
  registry->allow_inplace = _ccv_nnc_allow_gradient_inplace;
44
1
}
45
46
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_SOFTMAX_FORWARD)
47
#define CMD_SOFTMAX_FORWARD() ccv_nnc_cmd(CCV_NNC_SOFTMAX_FORWARD, 0, ccv_nnc_cmd_auto, 0)
48
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_SOFTMAX_BACKWARD)
49
#define CMD_SOFTMAX_BACKWARD() ccv_nnc_cmd(CCV_NNC_SOFTMAX_BACKWARD, 0, ccv_nnc_cmd_auto, 0)