Coverage Report

Created: 2017-11-12 13:27

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/_ccv_nnc_symbolic_graph.h
Line
Count
Source
1
/**********************************************************
2
 * C-based/Cached/Core Computer Vision Library
3
 * Liu Liu, 2010-02-01
4
 **********************************************************/
5
6
/**********************************************************
7
 * CCV - Neural Network Collection
8
 **********************************************************/
9
10
#ifndef GUARD_ccv_nnc_symbolic_graph_internal_h
11
#define GUARD_ccv_nnc_symbolic_graph_internal_h
12
13
#include "ccv_nnc.h"
14
#include "ccv_nnc_internal.h"
15
16
typedef struct {
17
  // Start for while loop handling
18
  int assign_ref; // Reference to the tensor that the value will be copied from (for parameter passing). Starts at 1.
19
  int p_ref; // Reference to the tensor number in its parent graph. Starts at 1.
20
  // End of while loop handling.
21
  int alias_ref; // Reference to the tensor. Starts at 1.
22
  int peer_ref; // Reference to its peer. Starts at 1.
23
  int flags;
24
  int ofs[CCV_NNC_MAX_DIM_ALLOC];
25
  int inc[CCV_NNC_MAX_DIM_ALLOC];
26
  ccv_array_t* s_ref; // Reference to the tensor number in its sub graphs, Starts at 1.
27
  char* name;
28
  ccv_nnc_tensor_param_t info;
29
} ccv_nnc_tensor_symbol_info_t;
30
31
typedef struct {
32
  int input_size;
33
  int output_size;
34
  int graph_ref; // Reference to the sub-graph. Starts at 1.
35
  int dead; // Mark this node as dead.
36
  int* inputs;
37
  int* outputs;
38
  ccv_array_t* outgoings; // Outgoing nodes
39
  char* name;
40
  ccv_nnc_cmd_t cmd;
41
  ccv_nnc_hint_t hint;
42
} ccv_nnc_graph_exec_symbol_info_t;
43
44
struct ccv_nnc_symbolic_graph_s {
45
  ccv_array_t* tensor_symbol_info; // A lit of info for tensor symbols.
46
  ccv_array_t* exec_symbol_info; // A list of info for exec symbols.
47
  // I think that I can be more explicit about which are sources and which are destinations.
48
  ccv_array_t* sources;
49
  ccv_array_t* destinations;
50
  // Some extra information piggy-back on symbolic graph struct.
51
  // Start for while loop handling
52
  ccv_array_t* sub_graphs; // A list of its sub-graphs (for while loop).
53
  struct ccv_nnc_symbolic_graph_s* peer; // The peer graph (only useful for backward prop graph).
54
  struct ccv_nnc_symbolic_graph_s* p; // The parent graph (if current one is a sub-graph).
55
  int p_idx; // Reference to the index in its parent graph's sub-graph array, Starts at 1.
56
  int exec_idx; // Reference to the index in its parent graph's exec (the graph exec), Starts at 1.
57
  // Why some of these I choose to be flat int* array, some of these I choose to be ccv_array_t?
58
  // for flat int* array, these are not going to be modified until next time call ccv_nnc_symbolic_graph_backward
59
  // for ccv_array_t, we can continue to modify what's inside.
60
  int breakpoint_size;
61
  ccv_nnc_graph_exec_symbol_t* breakpoints;
62
  ccv_nnc_graph_while_f while_expr;
63
  const void* while_data;
64
  // Map between parent / sub-graph's tensor symbols.
65
  // End of while loop handling.
66
  // Start for backward (automatic differentiation) handling
67
  int forward_symbol_size;
68
  int* backward_tensor_symbols;
69
  int backward_symbol_size;
70
  int* backward_exec_symbols;
71
  ccv_array_t* tape_variables; // The tensor symbols that will be backed by tape. If this is a backward graph, these tensor symbols won't be allocated on the tensor arena.
72
  // End of backward (automatic differentiation) handling.
73
};
74
75
struct ccv_nnc_tensor_arena_s {
76
  int memory_type;
77
  int device_id;
78
  intptr_t graph_ref; // A value contains the pointer name of the graph.
79
  int sub_arena_size;
80
  struct ccv_nnc_tensor_arena_s** sub_arenas; // Corresponding to sub graphs.
81
  // This is a table of tensor references to real allocated tensors.
82
  int vt_tensor_size;
83
  ccv_nnc_tensor_t** vt_tensors;
84
  int m_tensor_size;
85
  ccv_nnc_tensor_t** m_tensors;
86
  // This is the allocated non-continuous buffers.
87
  int buffer_size;
88
  struct {
89
    uint64_t size;
90
    uint8_t* ptr;
91
  }* buffers;
92
  // Real allocated tensor header metadata (this is a mixed pool of ccv_tensor_t, ccv_tensor_view_t,
93
  // ccv_tensor_multiview_t, thus, it is aligned to a 16-byte boundary).
94
  ccv_array_t* tensor_metadata;
95
};
96
97
struct ccv_nnc_graph_exec_arena_s {
98
  intptr_t graph_ref; // A value contains the pointer name of the graph.
99
  int sub_arena_size;
100
  struct ccv_nnc_graph_exec_arena_s** sub_arenas; // Corresponding to sub graphs.
101
  ccv_nnc_graph_exec_t source;
102
  ccv_nnc_graph_exec_t destination;
103
  int graph_exec_size;
104
  ccv_nnc_graph_exec_t graph_execs[1];
105
};
106
107
inline static void ccv_array_replace_int(ccv_array_t* ints, const int idx, const int outgoing)
108
187
{
109
187
  int i;
110
317
  for (i = 0; 
i < ints->rnum317
;
i++130
)
111
137
    
if (137
*(int*)137
ccv_array_get137
(ints, i) == idx)
112
7
    {
113
7
      *(int*)ccv_array_get(ints, i) = outgoing;
114
7
      return;
115
7
    }
116
180
  ccv_array_push(ints, &outgoing);
117
180
}
Unexecuted instantiation: ccv_nnc_symbolic_graph.c:ccv_array_replace_int
ccv_nnc_symbolic_graph_compile.c:ccv_array_replace_int
Line
Count
Source
108
168
{
109
168
  int i;
110
293
  for (i = 0; 
i < ints->rnum293
;
i++125
)
111
125
    
if (125
*(int*)125
ccv_array_get125
(ints, i) == idx)
112
0
    {
113
0
      *(int*)ccv_array_get(ints, i) = outgoing;
114
0
      return;
115
0
    }
116
168
  ccv_array_push(ints, &outgoing);
117
168
}
ccv_nnc_symbolic_graph_backward.c:ccv_array_replace_int
Line
Count
Source
108
19
{
109
19
  int i;
110
24
  for (i = 0; 
i < ints->rnum24
;
i++5
)
111
12
    
if (12
*(int*)12
ccv_array_get12
(ints, i) == idx)
112
7
    {
113
7
      *(int*)ccv_array_get(ints, i) = outgoing;
114
7
      return;
115
7
    }
116
12
  ccv_array_push(ints, &outgoing);
117
12
}
Unexecuted instantiation: ccv_nnc_symbolic_graph_while.c:ccv_array_replace_int
118
119
void ccv_nnc_symbolic_graph_symbol_infer(const ccv_nnc_symbolic_graph_t* const symbolic_graph, const ccv_nnc_graph_visit_t* const visit, const ccv_nnc_graph_exec_symbol_t* const sources, const int source_size, const ccv_nnc_graph_exec_symbol_t* const destinations, const int destination_size, const ccv_nnc_tensor_symbol_info_t* const p_tensor_symbol_info, const int p_tensor_symbol_info_size, ccv_nnc_tensor_symbol_info_t* const tensor_symbol_info, ccv_nnc_graph_exec_symbol_info_t* const exec_symbol_info);
120
121
void ccv_nnc_symbolic_graph_add_source(ccv_nnc_symbolic_graph_t* const graph, const ccv_nnc_graph_exec_symbol_t source);
122
void ccv_nnc_symbolic_graph_add_destination(ccv_nnc_symbolic_graph_t* const graph, const ccv_nnc_graph_exec_symbol_t destination);
123
124
#endif
125