Coverage Report

Created: 2019-07-03 22:50

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/cmd/loss/ccv_nnc_categorical_crossentropy.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_categorical_crossentropy_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)
7
0
{
8
0
  if ((input_bitmasks[0] & 3u) == 3u && output_bitmasks[0] == 1u)
9
0
    return 1;
10
0
  return 0;
11
0
}
12
13
static int _ccv_nnc_categorical_crossentropy_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)
14
18
{
15
18
  if ((input_bitmasks[0] & 7u) == 7u && 
(output_bitmasks[0] & 1u) == 1u7
)
16
7
    return 1;
17
11
  return 0;
18
11
}
19
20
static void _ccv_nnc_categorical_crossentropy_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)
21
8
{
22
8
  assert(input_size == 2);
23
8
  assert(output_size == 1);
24
8
  outputs[0] = inputs[0];
25
8
  // The output should have the same dimentionality of the label data.
26
8
  memcpy(outputs[0].dim, inputs[1].dim, sizeof(outputs[0].dim));
27
8
  const int nd = ccv_nnc_tensor_nd(outputs[0].dim);
28
8
  // Set channel to 1 if it is not..
29
8
  if (nd > 1 && 
ccv_nnc_tensor_get_c(outputs[0]) > 12
)
30
2
    ccv_nnc_tensor_set_c(&outputs[0], nd, 1);
31
8
}
32
33
static void _ccv_nnc_categorical_crossentropy_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
3
{
35
3
  assert(input_size >= 2);
36
3
  assert(output_size >= 1);
37
3
  outputs[0] = inputs[1];
38
3
  if (output_size > 1)
39
3
    outputs[1] = inputs[2];
40
3
}
41
42
REGISTER_COMMAND(CCV_NNC_CATEGORICAL_CROSSENTROPY_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
43
  FIND_BACKEND(ccv_nnc_categorical_crossentropy_cpu_ref.c, gpu/ccv_nnc_categorical_crossentropy_gpu_ref.cu)
44
1
{
45
1
  registry->bitmask = _ccv_nnc_categorical_crossentropy_forw_bitmask;
46
1
  registry->tensor_auto = _ccv_nnc_categorical_crossentropy_tensor_auto_forw;
47
1
}
48
49
REGISTER_COMMAND(CCV_NNC_CATEGORICAL_CROSSENTROPY_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
50
  FIND_BACKEND(ccv_nnc_categorical_crossentropy_cpu_ref.c, gpu/ccv_nnc_categorical_crossentropy_gpu_ref.cu)
51
1
{
52
1
  registry->flags = CCV_NNC_CMD_ATTR_NULL_IS_ONES;
53
1
  registry->bitmask = _ccv_nnc_categorical_crossentropy_back_bitmask;
54
1
  registry->tensor_auto = _ccv_nnc_categorical_crossentropy_tensor_auto_back;
55
1
}
56
57
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_CATEGORICAL_CROSSENTROPY_FORWARD)
58
#define CMD_CATEGORICAL_CROSSENTROPY_FORWARD() ccv_nnc_cmd(CCV_NNC_CATEGORICAL_CROSSENTROPY_FORWARD, 0, ccv_nnc_cmd_auto, 0)
59
//@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_CATEGORICAL_CROSSENTROPY_BACKWARD)
60
#define CMD_CATEGORICAL_CROSSENTROPY_BACKWARD() ccv_nnc_cmd(CCV_NNC_CATEGORICAL_CROSSENTROPY_BACKWARD, 0, ccv_nnc_cmd_auto, 0)