Coverage Report

Created: 2019-07-03 22:50

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/cmd/dropout/ccv_nnc_dropout.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_dropout_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)
6
0
{
7
0
  // 1 input (x)
8
0
  // 1 output (y, mask)
9
0
  if (input_bitmasks[0] == 1u && output_bitmasks[0] == 3u)
10
0
    return 1;
11
0
  return 0;
12
0
}
13
14
static int _ccv_nnc_xy_inplace(const int input_idx, const int input_size, const int output_idx, const int output_size)
15
8
{
16
8
  if (input_idx == 0 && output_idx == 0)
17
4
    return 1;
18
4
  return 0;
19
4
}
20
21
static void _ccv_nnc_dropout_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)
22
8
{
23
8
  assert(input_size == 1);
24
8
  assert(output_size == 2);
25
8
  outputs[0] = inputs[0];
26
8
  if (output_size == 1)
27
0
    return;
28
8
  outputs[1] = inputs[0];
29
8
  int i;
30
8
  // Reset to 0.
31
8
  memset(outputs[1].dim, 0, sizeof(outputs[1].dim));
32
8
  const int inc = (int)CCV_GET_DATA_TYPE_SIZE(inputs[0].datatype);
33
8
  // Align to 128-bytes boundary, for each computed result.
34
8
  int line = ((inputs[0].dim[0] + 127) >> 7);
35
10
  for (i = 1; i < CCV_NNC_MAX_DIM_ALLOC && inputs[0].dim[i] > 0; 
i++2
)
36
2
    line *= inputs[0].dim[i];
37
8
  assert((128 % inc) == 0);
38
8
  outputs[1].dim[0] = 128 / inc;
39
8
  outputs[1].dim[1] = line; // Aligned to 128 bytes, reserved space.
40
8
}
41
42
static int _ccv_nnc_dropout_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)
43
12
{
44
12
  // 0b10001
45
12
  // Inputs (dy, 0, 0, 0, mask)
46
12
  // Output the propagated error
47
12
  if ((input_bitmasks[0] & 17u) == 17u && 
(output_bitmasks[0] & 1u) == 1u8
)
48
8
    return 1;
49
4
  return 0;
50
4
}
51
52
REGISTER_COMMAND(CCV_NNC_DROPOUT_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
53
  FIND_BACKEND(ccv_nnc_dropout_cpu_ref.c, gpu/ccv_nnc_dropout_gpu_cudnn.cu)
54
1
{
55
1
  registry->bitmask = _ccv_nnc_dropout_forw_bitmask;
56
1
  registry->tensor_auto = _ccv_nnc_dropout_tensor_auto_forw;
57
1
  registry->enforce_inplace = _ccv_nnc_xy_inplace;
58
1
}
59
60
REGISTER_COMMAND(CCV_NNC_DROPOUT_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
61
  FIND_BACKEND(ccv_nnc_dropout_cpu_ref.c, gpu/ccv_nnc_dropout_gpu_cudnn.cu)
62
1
{
63
1
  registry->bitmask = _ccv_nnc_dropout_back_bitmask;
64
1
  registry->tensor_auto = ccv_nnc_hint_tensor_auto_backward_from_gradient;
65
1
}
66
67
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_DROPOUT_FORWARD)
68
#define CMD_DROPOUT_FORWARD(_p) ccv_nnc_cmd(CCV_NNC_DROPOUT_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.dropout={.p=_p}}), 0)
69
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_DROPOUT_BACKWARD)
70
#define CMD_DROPOUT_BACKWARD(_p) ccv_nnc_cmd(CCV_NNC_DROPOUT_BACKWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.dropout={.p=_p}}), 0)