Coverage Report

Created: 2021-09-30 20:21

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/cmd/upsample/ccv_nnc_upsample.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
#include "nnc/ccv_nnc_easy.h"
5
6
static void _ccv_nnc_upsample_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)
7
12
{
8
12
  assert(input_size == 1);
9
12
  assert(output_size == 1);
10
12
  outputs[0] = inputs[0];
11
12
  const int nd = ccv_nnc_tensor_nd(inputs[0].dim);
12
12
  if (nd == 2)
13
0
  {
14
0
    outputs[0].dim[0] = (int)(inputs[0].dim[0] * cmd.upsample.height_scale);
15
0
    outputs[0].dim[1] = (int)(inputs[0].dim[1] * cmd.upsample.width_scale);
16
12
  } else if (nd == 3) {
17
0
    if (inputs[0].format == CCV_TENSOR_FORMAT_NCHW || inputs[0].format == CCV_TENSOR_FORMAT_CHWN)
18
0
    {
19
0
      outputs[0].dim[nd - 2] = (int)(inputs[0].dim[nd - 2] * cmd.upsample.height_scale);
20
0
      outputs[0].dim[nd - 1] = (int)(inputs[0].dim[nd - 1] * cmd.upsample.width_scale);
21
0
    } else {
22
0
      outputs[0].dim[0] = (int)(inputs[0].dim[0] * cmd.upsample.height_scale);
23
0
      outputs[0].dim[1] = (int)(inputs[0].dim[1] * cmd.upsample.width_scale);
24
0
    }
25
12
  } else if (nd == 4) {
26
12
    if (inputs[0].format == CCV_TENSOR_FORMAT_NCHW)
27
12
    {
28
12
      outputs[0].dim[nd - 2] = (int)(inputs[0].dim[nd - 2] * cmd.upsample.height_scale);
29
12
      outputs[0].dim[nd - 1] = (int)(inputs[0].dim[nd - 1] * cmd.upsample.width_scale);
30
12
    } else {
31
0
      outputs[0].dim[nd - 3] = (int)(inputs[0].dim[nd - 3] * cmd.upsample.height_scale);
32
0
      outputs[0].dim[nd - 2] = (int)(inputs[0].dim[nd - 2] * cmd.upsample.width_scale);
33
0
    }
34
12
  }
35
12
}
36
37
static int _ccv_nnc_upsample_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)
38
6
{
39
6
  if (input_bitmasks[0] == 1u && 
output_bitmasks[0] == 1u3
)
40
3
    return 1;
41
3
  return 0;
42
3
}
43
44
static int _ccv_nnc_upsample_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)
45
0
{
46
0
  // Output the propagated error.
47
0
  if ((input_bitmasks[0] & 1u) == 1u && output_bitmasks[0] == 1u)
48
0
    return 1;
49
0
  return 0;
50
0
}
51
52
REGISTER_COMMAND(CCV_NNC_UPSAMPLE_BILINEAR_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
53
  FIND_BACKEND(ccv_nnc_upsample_cpu_ref.c, gpu/ccv_nnc_upsample_gpu_ref.cu)
54
1
{
55
1
  registry->bitmask = _ccv_nnc_upsample_forw_bitmask;
56
1
  registry->tensor_auto = _ccv_nnc_upsample_tensor_auto_forw;
57
1
}
58
59
REGISTER_COMMAND(CCV_NNC_UPSAMPLE_BILINEAR_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
60
  FIND_BACKEND(ccv_nnc_upsample_cpu_ref.c, gpu/ccv_nnc_upsample_gpu_ref.cu)
61
1
{
62
1
  registry->bitmask = _ccv_nnc_upsample_back_bitmask;
63
1
  registry->tensor_auto = ccv_nnc_hint_tensor_auto_backward_from_gradient;
64
1
}
65
66
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_UPSAMPLE_BILINEAR_FORWARD)
67
#define CMD_UPSAMPLE_BILINEAR_FORWARD(_width_scale, _height_scale) ccv_nnc_cmd(CCV_NNC_UPSAMPLE_BILINEAR_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.upsample={.width_scale=_width_scale,.height_scale=_height_scale}}), 0)
68
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_UPSAMPLE_BILINEAR_BACKWARD)
69
#define CMD_UPSAMPLE_BILINEAR_BACKWARD(_width_scale, _height_scale) ccv_nnc_cmd(CCV_NNC_UPSAMPLE_BILINEAR_BACKWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.upsample={.width_scale=_width_scale,.height_scale=_height_scale}}), 0)