Coverage Report

Created: 2024-08-19 11:27

/home/liu/actions-runner/_work/ccv/ccv/lib/nnc/cmd/sigmoid/ccv_nnc_sigmoid.c
Line
Count
Source (jump to first uncovered line)
1
#include "ccv.h"
2
#include "nnc/ccv_nnc.h"
3
#include "nnc/ccv_nnc_easy.h"
4
#include "nnc/ccv_nnc_internal.h"
5
6
static int _ccv_nnc_sigmoid_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)
7
17
{
8
17
  return input_idx == 0 && 
output_idx == 012
;
9
17
}
10
11
static int _ccv_nnc_sigmoid_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)
12
6
{
13
6
  if ((input_bitmasks[0] & 1u) == 1u && output_bitmasks[0] == 1u)
14
6
    return 1;
15
0
  return 0;
16
6
}
17
18
static int _ccv_nnc_sigmoid_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)
19
26
{
20
  // gradient, [x], y
21
26
  if ((input_bitmasks[0] & 5u) == 5u && 
(output_bitmasks[0] & 1u) == 1u10
)
22
10
    return 1;
23
16
  return 0;
24
26
}
25
26
static void _ccv_nnc_sigmoid_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)
27
34
{
28
34
  assert(input_size == 1);
29
34
  assert(output_size == 1);
30
34
  outputs[0] = inputs[0];
31
34
}
32
33
static void _ccv_nnc_sigmoid_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)
34
5
{
35
5
  assert(input_size >= 3);
36
5
  assert(output_size >= 1);
37
5
  outputs[0] = inputs[2];
38
5
}
39
40
REGISTER_COMMAND(CCV_NNC_SIGMOID_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
41
  FIND_BACKEND(ccv_nnc_sigmoid_cpu_ref.c, gpu/ccv_nnc_sigmoid_gpu_cudnn.cu, mps/ccv_nnc_sigmoid_mps.m)
42
1
{
43
1
  registry->bitmask = _ccv_nnc_sigmoid_forw_bitmask;
44
1
  registry->allow_inplace = _ccv_nnc_sigmoid_allow_first_replace;
45
1
  registry->tensor_auto = _ccv_nnc_sigmoid_tensor_auto_forw;
46
1
}
47
48
REGISTER_COMMAND(CCV_NNC_SIGMOID_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
49
  FIND_BACKEND(ccv_nnc_sigmoid_cpu_ref.c, gpu/ccv_nnc_sigmoid_gpu_cudnn.cu, mps/ccv_nnc_sigmoid_mps.m)
50
1
{
51
1
  registry->flags = CCV_NNC_CMD_ATTR_NULL_IS_ONES;
52
1
  registry->bitmask = _ccv_nnc_sigmoid_back_bitmask;
53
1
  registry->allow_inplace = _ccv_nnc_sigmoid_allow_first_replace;
54
1
  registry->tensor_auto = _ccv_nnc_sigmoid_tensor_auto_back;
55
1
}
56
57
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_SIGMOID_FORWARD)
58
#define CMD_SIGMOID_FORWARD() ccv_nnc_cmd(CCV_NNC_SIGMOID_FORWARD, 0, ccv_nnc_cmd_auto, 0)
59
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_SIGMOID_BACKWARD)
60
#define CMD_SIGMOID_BACKWARD() ccv_nnc_cmd(CCV_NNC_SIGMOID_BACKWARD, 0, ccv_nnc_cmd_auto, 0)