Coverage Report

Created: 2017-11-12 13:27

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/cmd/relu/ccv_nnc_relu_cpu_ref.c
Line
Count
Source (jump to first uncovered line)
1
#include <ccv.h>
2
#include <ccv_internal.h>
3
#include <nnc/ccv_nnc.h>
4
#include <nnc/ccv_nnc_easy.h>
5
#include <nnc/ccv_nnc_internal.h>
6
#ifdef USE_OPENMP
7
#include <omp.h>
8
#endif
9
#ifdef USE_DISPATCH
10
#include <dispatch/dispatch.h>
11
#endif
12
13
static int _ccv_nnc_relu_forw(const ccv_nnc_cmd_t cmd, const ccv_nnc_hint_t hint, const int flags, ccv_nnc_tensor_t* const* const inputs, const int input_size, ccv_nnc_tensor_t* const* const outputs, const int output_size, const ccv_nnc_stream_context_t* const stream_context)
14
75
{
15
75
  assert(input_size == 1);
16
75
  const ccv_nnc_tensor_t* a = inputs[0];
17
75
  assert(!CCV_IS_TENSOR_VIEW(a));
18
75
  assert(output_size == 1);
19
75
  ccv_nnc_tensor_t* b = outputs[0];
20
75
  assert(!CCV_IS_TENSOR_VIEW(b));
21
75
  int i, count = ccv_nnc_tensor_count(a->info);
22
280
  for (i = 0; 
i < 280
CCV_NNC_MAX_DIM_ALLOC280
&&
a->info.dim[i] > 0280
;
i++205
)
23
205
  {
24
205
    assert(a->info.dim[i] == b->info.dim[i]);
25
205
  }
26
75
  float* ap = a->data.f32;
27
75
  float* bp = b->data.f32;
28
66.1M
  for (i = 0; 
i < count66.1M
;
i++66.1M
)
29
66.1M
    
bp[i] = 66.1M
ccv_max66.1M
(ap[i], 0);
30
75
  return CCV_NNC_EXEC_SUCCESS;
31
75
}
32
33
static int _ccv_nnc_relu_back(const ccv_nnc_cmd_t cmd, const ccv_nnc_hint_t hint, const int flags, ccv_nnc_tensor_t* const* const inputs, const int input_size, ccv_nnc_tensor_t* const* const outputs, const int output_size, const ccv_nnc_stream_context_t* const stream_context)
34
0
{
35
0
  assert(input_size == 2);
36
0
  const ccv_nnc_tensor_t* g = inputs[0]; // gradient
37
0
  assert(!CCV_IS_TENSOR_VIEW(g));
38
0
  const ccv_nnc_tensor_t* b = inputs[1];
39
0
  assert(!CCV_IS_TENSOR_VIEW(b));
40
0
  assert(output_size == 1);
41
0
  ccv_nnc_tensor_t* h = outputs[0];
42
0
  assert(!CCV_IS_TENSOR_VIEW(h));
43
0
  int i, count = ccv_nnc_tensor_count(g->info);
44
0
  for (i = 0; 
i < 0
CCV_NNC_MAX_DIM_ALLOC0
&&
g->info.dim[i] > 00
;
i++0
)
45
0
  {
46
0
    assert(b->info.dim[i] == g->info.dim[i]);
47
0
    assert(g->info.dim[i] == h->info.dim[i]);
48
0
  }
49
0
  float* bp = b->data.f32;
50
0
  float* gp = g->data.f32;
51
0
  float* hp = h->data.f32;
52
0
  for (i = 0; 
i < count0
;
i++0
)
53
0
    
hp[i] = (bp[i] >= 0) ? 0
gp[i]0
:
00
;
54
0
  return CCV_NNC_EXEC_SUCCESS;
55
0
}
56
57
REGISTER_COMMAND_BACKEND(CCV_NNC_RELU_FORWARD, CCV_NNC_BACKEND_CPU_REF)(ccv_nnc_cmd_backend_registry_t* const registry)
58
1
{
59
1
  registry->tensor_formats = CCV_TENSOR_FORMAT_NHWC;
60
1
  registry->tensor_datatypes = CCV_32F;
61
1
  registry->tensor_memory = CCV_TENSOR_CPU_MEMORY;
62
1
  registry->algorithms = 1;
63
1
  registry->exec = _ccv_nnc_relu_forw;
64
1
}
65
66
REGISTER_COMMAND_BACKEND(CCV_NNC_RELU_BACKWARD, CCV_NNC_BACKEND_CPU_REF)(ccv_nnc_cmd_backend_registry_t* const registry)
67
1
{
68
1
  registry->tensor_formats = CCV_TENSOR_FORMAT_NHWC;
69
1
  registry->tensor_datatypes = CCV_32F;
70
1
  registry->tensor_memory = CCV_TENSOR_CPU_MEMORY;
71
1
  registry->algorithms = 1;
72
1
  registry->exec = _ccv_nnc_relu_back;
73
1
}