Coverage Report

Created: 2019-07-03 22:50

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/cmd/reduce/ccv_nnc_reduce.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 void _ccv_nnc_reduce_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)
6
2.01k
{
7
2.01k
  assert(input_size == 1);
8
2.01k
  assert(output_size == 1);
9
2.01k
  outputs[0] = inputs[0];
10
2.01k
  int i;
11
6.03k
  for (i = 0; i < cmd.reduce.count; 
i++4.02k
)
12
4.02k
    outputs[0].dim[cmd.reduce.axis[i]] = 1; // Reduce the dimension to 1.
13
2.01k
}
14
15
static int _ccv_nnc_reduce_sum_forw_bitmask(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
0
{
17
0
  if (input_bitmasks[0] == 1u && output_bitmasks[0] == 1u)
18
0
    return 1;
19
0
  return 0;
20
0
}
21
22
static int _ccv_nnc_reduce_sum_back_bitmask(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
3.01k
{
24
3.01k
  // Output the propagated error.
25
3.01k
  if ((input_bitmasks[0] & 1u) == 1u && 
output_bitmasks[0] == 1u3.01k
)
26
3.01k
    return 1;
27
6
  return 0;
28
6
}
29
30
REGISTER_COMMAND(CCV_NNC_REDUCE_SUM_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
31
  FIND_BACKEND(ccv_nnc_reduce_sum_cpu_ref.c)
32
1
{
33
1
  registry->bitmask = _ccv_nnc_reduce_sum_forw_bitmask;
34
1
  registry->tensor_auto = _ccv_nnc_reduce_tensor_auto_forw;
35
1
}
36
37
REGISTER_COMMAND(CCV_NNC_REDUCE_SUM_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
38
  FIND_BACKEND(ccv_nnc_reduce_sum_cpu_ref.c)
39
1
{
40
1
  registry->bitmask = _ccv_nnc_reduce_sum_back_bitmask;
41
1
  registry->tensor_auto = ccv_nnc_hint_tensor_auto_backward_from_gradient;
42
1
}
43
44
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_REDUCE_SUM_FORWARD)
45
#define CMD_REDUCE_SUM_FORWARD(...) ccv_nnc_cmd(CCV_NNC_REDUCE_SUM_FORWARD, 0, CMD_REDUCE(__VA_ARGS__), 0)
46
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_REDUCE_SUM_BACKWARD)
47
#define CMD_REDUCE_SUM_BACKWARD(...) ccv_nnc_cmd(CCV_NNC_REDUCE_SUM_BACKWARD, 0, CMD_REDUCE(__VA_ARGS__), 0)
48
49
static int _ccv_nnc_reduce_max_forw_bitmask(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)
50
0
{
51
0
  if (input_bitmasks[0] == 1u && output_bitmasks[0] == 1u)
52
0
    return 1;
53
0
  return 0;
54
0
}
55
56
static int _ccv_nnc_reduce_max_back_bitmask(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)
57
4
{
58
4
  // Output the propagated error.
59
4
  if ((input_bitmasks[0] & 7u) == 7u && 
output_bitmasks[0] == 1u1
)
60
1
    return 1;
61
3
  return 0;
62
3
}
63
64
REGISTER_COMMAND(CCV_NNC_REDUCE_MAX_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
65
  FIND_BACKEND(ccv_nnc_reduce_max_cpu_ref.c)
66
1
{
67
1
  registry->bitmask = _ccv_nnc_reduce_max_forw_bitmask;
68
1
  registry->tensor_auto = _ccv_nnc_reduce_tensor_auto_forw;
69
1
}
70
71
REGISTER_COMMAND(CCV_NNC_REDUCE_MAX_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
72
  FIND_BACKEND(ccv_nnc_reduce_max_cpu_ref.c)
73
1
{
74
1
  registry->bitmask = _ccv_nnc_reduce_max_back_bitmask;
75
1
  registry->tensor_auto = ccv_nnc_hint_tensor_auto_backward_from_gradient;
76
1
}
77
78
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_REDUCE_MAX_FORWARD)
79
#define CMD_REDUCE_MAX_FORWARD(...) ccv_nnc_cmd(CCV_NNC_REDUCE_MAX_FORWARD, 0, CMD_REDUCE(__VA_ARGS__), 0)
80
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_REDUCE_MAX_BACKWARD)
81
#define CMD_REDUCE_MAX_BACKWARD(...) ccv_nnc_cmd(CCV_NNC_REDUCE_MAX_BACKWARD, 0, CMD_REDUCE(__VA_ARGS__), 0)