Coverage Report

Created: 2017-11-12 13:27

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/cmd/pool/ccv_nnc_pool.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_max_pool_forw_bitmask(const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size)
7
28
{
8
28
  if (
(input_bitmasks[0] & 1u) == 1u && 28
output_bitmasks[0] == 1u28
)
9
28
    return 1;
10
0
  return 0;
11
28
}
12
13
static int _ccv_nnc_max_pool_back_bitmask(const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size)
14
0
{
15
0
  if (
(input_bitmasks[0] & 7u) == ((1u << 0) | (1u << 1) | (1u << 2)) && 0
output_bitmasks[0] == 1u0
)
16
0
    return 1;
17
0
  return 0;
18
0
}
19
20
static void _ccv_nnc_pool_tensor_auto_forw(const ccv_nnc_cmd_param_t cmd, const ccv_nnc_tensor_param_t* inputs, const int input_size, const ccv_nnc_hint_t hint, ccv_nnc_tensor_param_t* outputs, const int output_size)
21
8
{
22
8
  assert(output_size == 1);
23
8
  outputs[0].type = inputs[0].type;
24
8
  outputs[0].format = inputs[0].format;
25
8
  outputs[0].datatype = inputs[0].datatype;
26
8
  // Copy channels / batch size from the original input for now.
27
8
  memcpy(outputs[0].dim, inputs[0].dim, sizeof(inputs[0].dim));
28
8
  ccv_nnc_hint_tensor_forward(cmd, inputs[0], hint, outputs);
29
8
}
30
31
static void _ccv_nnc_pool_tensor_auto_back(const ccv_nnc_cmd_param_t cmd, const ccv_nnc_tensor_param_t* inputs, const int input_size, const ccv_nnc_hint_t hint, ccv_nnc_tensor_param_t* outputs, const int output_size)
32
0
{
33
0
  assert(output_size == 1);
34
0
  outputs[0].type = inputs[0].type;
35
0
  outputs[0].format = inputs[0].format;
36
0
  outputs[0].datatype = inputs[0].datatype;
37
0
  // Copy channels / batch size from the original input for now.
38
0
  memcpy(outputs[0].dim, inputs[0].dim, sizeof(inputs[0].dim));
39
0
  ccv_nnc_hint_tensor_backward(cmd, inputs[0], hint, outputs);
40
0
}
41
42
REGISTER_COMMAND(CCV_NNC_MAX_POOL_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
43
  FIND_BACKEND(ccv_nnc_max_pool_cpu_ref.c)
44
1
{
45
1
  registry->bitmask = _ccv_nnc_max_pool_forw_bitmask;
46
1
  registry->tensor_auto = _ccv_nnc_pool_tensor_auto_forw;
47
1
}
48
49
REGISTER_COMMAND(CCV_NNC_MAX_POOL_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
50
  FIND_BACKEND(ccv_nnc_max_pool_cpu_ref.c)
51
1
{
52
1
  registry->bitmask = _ccv_nnc_max_pool_back_bitmask;
53
1
  registry->tensor_auto = _ccv_nnc_pool_tensor_auto_back;
54
1
}
55
56
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_MAX_POOL_FORWARD)
57
#define CMD_MAX_POOL_FORWARD(rows, cols) ccv_nnc_cmd(CCV_NNC_MAX_POOL_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={rows, cols,1}}}), 0)
58
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_MAX_POOL_BACKWARD)
59
#define CMD_MAX_POOL_BACKWARD(rows, cols) ccv_nnc_cmd(CCV_NNC_MAX_POOL_BACKWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={rows, cols,1}}}), 0)
60
61
static int _ccv_nnc_avg_pool_forw_bitmask(const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size)
62
13
{
63
13
  if (
(input_bitmasks[0] & 1u) == 1u && 13
output_bitmasks[0] == 1u13
)
64
13
    return 1;
65
0
  return 0;
66
13
}
67
68
static int _ccv_nnc_avg_pool_back_bitmask(const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size)
69
6
{
70
6
  if (
(input_bitmasks[0] & 1u) == 1u && 6
output_bitmasks[0] == 1u6
)
71
6
    return 1;
72
0
  return 0;
73
6
}
74
75
REGISTER_COMMAND(CCV_NNC_AVERAGE_POOL_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
76
  FIND_BACKEND(ccv_nnc_avg_pool_cpu_ref.c)
77
1
{
78
1
  registry->bitmask = _ccv_nnc_avg_pool_forw_bitmask;
79
1
  registry->tensor_auto = _ccv_nnc_pool_tensor_auto_forw;
80
1
}
81
82
REGISTER_COMMAND(CCV_NNC_AVERAGE_POOL_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
83
  FIND_BACKEND(ccv_nnc_avg_pool_cpu_ref.c)
84
1
{
85
1
  registry->bitmask = _ccv_nnc_avg_pool_back_bitmask;
86
1
  registry->tensor_auto = _ccv_nnc_pool_tensor_auto_back;
87
1
}
88
89
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_AVERAGE_POOL_FORWARD)
90
#define CMD_AVERAGE_POOL_FORWARD(rows, cols) ccv_nnc_cmd(CCV_NNC_AVERAGE_POOL_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={rows, cols,1}}}), 0)
91
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_AVERAGE_POOL_BACKWARD)
92
#define CMD_AVERAGE_POOL_BACKWARD(rows, cols) ccv_nnc_cmd(CCV_NNC_AVERAGE_POOL_BACKWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={rows, cols,1}}}), 0)