Coverage Report

Created: 2022-07-27 23:53

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/_ccv_nnc_dynamic_graph.h
Line
Count
Source (jump to first uncovered line)
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_dynamic_graph_internal_h
11
#define GUARD_ccv_nnc_dynamic_graph_internal_h
12
13
#include "ccv_nnc.h"
14
#include "ccv_nnc_internal.h"
15
#include "_ccv_nnc_stream.h"
16
#include "_ccv_nnc_xpu_alloc.h"
17
#include "3rdparty/khash/khash.h"
18
19
39.1k
#define CCV_NNC_IS_EXTERN_TENSOR_VIEW(tv) ((uintptr_t)(tv) & 1)
20
68.7k
#define CCV_NNC_TENSOR_VIEW(tv) ((ccv_nnc_tensor_view_t*)((uintptr_t)(tv) & ~(uintptr_t)1))
21
22
enum {
23
  CCV_NNC_TENSOR_VARIABLE,
24
  CCV_NNC_TENSOR_CONSTANT,
25
};
26
27
struct ccv_nnc_tensor_variable_s {
28
  int type;
29
  int index;
30
  int alias_index_ref; // The index back into the original tensor variable. 0 means no alias.
31
  off_t alias_off; // If it is an alias, what's the off on the tensor before ofs applied.
32
  struct {
33
    ccv_nnc_tensor_variable_destructor_f func;
34
    void* context;
35
  } destructor_hook;
36
  ccv_nnc_tensor_param_t info;
37
  ccv_nnc_tensor_symbol_t symbol;
38
  ccv_nnc_tensor_view_t* tensor_view;
39
  int ofs[CCV_NNC_MAX_DIM_ALLOC];
40
  int inc[CCV_NNC_MAX_DIM_ALLOC];
41
};
42
43
enum {
44
  CCV_NNC_TENSOR_NO_VARIABLE = -1,
45
  CCV_NNC_TENSOR_NO_VARIABLE_BUT_USED = -2,
46
};
47
48
typedef struct {
49
  ccv_nnc_cmd_vtab_t super;
50
  void(*apply_gradients)(const ccv_nnc_cmd_t cmd, ccv_nnc_stream_context_t* const stream_context);
51
} ccv_nnc_stateful_cmd_vtab_t;
52
53
typedef struct { // Extra information kept per tensor symbol along with symbolic graph.
54
  int type;
55
  int index; // The index back into the tensor variable. -1 meant no associated tensor vairable.
56
  int alias_ref; // If this is an alias tensor view to a tensor. 0 means no alias, otherwise the index + 1 of the original symbol on the tape.
57
  struct {
58
    ccv_nnc_tensor_variable_destructor_f func;
59
    void* context;
60
  } destructor_hook;
61
  ccv_array_t* sources; // array of graph_exec_symbol, use this tensor symbol as output.
62
  ccv_array_t* destinations; // array of graph_exec_symbol, use this tensor symbol as input.
63
  ccv_nnc_tensor_view_t* tensor_view; // Transfer ownership of the tensor view to here.
64
} ccv_nnc_tensor_variable_graph_bind_t;
65
66
typedef struct {
67
  ccv_nnc_xpu_alloc_t* xpu_alloc;
68
  ccv_nnc_stream_context_t* stream;
69
} ccv_nnc_dy_xpu_alloc_t;
70
71
typedef struct {
72
  int8_t requires_grad;
73
  int8_t is_test;
74
  int8_t did_backward_but_not_apply_gradients;
75
  int8_t should_free;
76
  int index;
77
  uint64_t disable_outgrad;
78
  ccv_nnc_tensor_tape_t* tensor_tape;
79
  void* data;
80
  ccv_nnc_cmd_t cmd;
81
} ccv_nnc_stateful_exec_t;
82
83
KHASH_MAP_INIT_INT(stateful_exec, ccv_nnc_stateful_exec_t*)
84
85
struct ccv_nnc_dynamic_graph_s {
86
  int no_grad; // 1 if gradient computation is disabled.
87
  int reuse_var; // -1 if no var can be reused. Otherwise first locate the reuse var without increase array size.
88
  int reuse_stateful_exec; // -1 if no stateful exec can be reused. Otherwise first locate the reuse without increase array size.
89
  ccv_nnc_xpu_alloc_t xpu_alloc; // Allocate memory dynamically.
90
  ccv_array_t* vars; // Array keeps track of all allocated tensor variable.
91
  ccv_array_t* binds; // Array keeps track of extra information for a tensor symbol.
92
  ccv_array_t* stateful_execs; // Array keeps track of the stateful execs. The stateful execs type can have additional apply_gradients calls to update its internal states.
93
  ccv_nnc_symbolic_graph_t* tape; // Symbolic graph to keep track of computation.
94
  khash_t(stream_map)* stream_map; // Keeps track of streams on both GPU / CPU and devices so it can be used properly during execution.
95
  ccv_array_t* ws; // array of integers as workspace
96
};
97
98
ccv_nnc_tensor_variable_t ccv_nnc_tensor_variable_exchange_new(ccv_nnc_dynamic_graph_t* const graph, ccv_nnc_tensor_variable_t tensor_variable);
99
100
static inline void ccv_nnc_insert_if_prior_to_any(const ccv_nnc_symbolic_graph_t* const graph, const int d, ccv_array_t* const sources, uint32_t* const visited, int* const buf0, int* const buf1)
101
4.47k
{
102
4.47k
  if (visited[(d >> 5)] & (1u << (d & 31)))
103
7
    return;
104
4.47k
  visited[(d >> 5)] |= (1u << (d & 31));
105
4.47k
  buf0[0] = d;
106
4.47k
  int* buf[2] = {
107
4.47k
    buf0, buf1
108
4.47k
  };
109
4.47k
  int buf_size[2] = {
110
4.47k
    1, 0
111
4.47k
  };
112
4.47k
  int p = 0, q = 1;
113
4.47k
  int i, j, k;
114
4.47k
  int flag = 0;
115
19.7k
  while (buf_size[p] > 0)
116
15.3k
  {
117
15.3k
    buf_size[q] = 0;
118
30.6k
    for (i = 0; i < buf_size[p]; 
i++15.3k
)
119
15.3k
    {
120
15.3k
      const int* outgoings; int outgoing_size;
121
15.3k
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
122
15.3k
        .d = buf[p][i],
123
15.3k
        .graph = graph
124
15.3k
      }, &outgoings, &outgoing_size);
125
26.1k
      for (j = 0; j < outgoing_size; 
j++10.8k
)
126
10.8k
      {
127
10.8k
        const int outgoing_idx = outgoings[j];
128
10.9k
        for (k = 0; k < sources->rnum; 
k++85
)
129
85
        {
130
85
          ccv_nnc_graph_exec_symbol_t* const source_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, k);
131
          // If this outgoing idx is one of the source, replace it with d, or delete it.
132
85
          if (source_symbol->d == outgoing_idx)
133
0
          {
134
0
            if (!flag)
135
0
            {
136
0
              source_symbol->d = d;
137
0
              flag = 1;
138
0
            } else {
139
              // Delete this from the list.
140
0
              if (k < sources->rnum - 1)
141
0
                source_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, sources->rnum - 1))->d;
142
0
              --sources->rnum;
143
0
            }
144
0
            break;
145
0
          }
146
85
        }
147
10.8k
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
148
19
          continue;
149
10.8k
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
150
10.8k
        buf[q][buf_size[q]] = outgoing_idx;
151
10.8k
        ++buf_size[q];
152
10.8k
      }
153
15.3k
    }
154
15.3k
    CCV_SWAP(p, q, i);
155
15.3k
  }
156
  // If this node is not visited, and we cannot find anything in the sources to replace, this is a new top node.
157
4.47k
  if (!flag)
158
4.47k
  {
159
4.47k
    const ccv_nnc_graph_exec_symbol_t source_symbol = {
160
4.47k
      .d = d,
161
4.47k
      .graph = graph
162
4.47k
    };
163
4.47k
    ccv_array_push(sources, &source_symbol);
164
4.47k
  }
165
4.47k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph.c:ccv_nnc_insert_if_prior_to_any
Unexecuted instantiation: ccv_nnc_dynamic_graph_alloc.c:ccv_nnc_insert_if_prior_to_any
ccv_nnc_dynamic_graph_backward.c:ccv_nnc_insert_if_prior_to_any
Line
Count
Source
101
3.47k
{
102
3.47k
  if (visited[(d >> 5)] & (1u << (d & 31)))
103
7
    return;
104
3.46k
  visited[(d >> 5)] |= (1u << (d & 31));
105
3.46k
  buf0[0] = d;
106
3.46k
  int* buf[2] = {
107
3.46k
    buf0, buf1
108
3.46k
  };
109
3.46k
  int buf_size[2] = {
110
3.46k
    1, 0
111
3.46k
  };
112
3.46k
  int p = 0, q = 1;
113
3.46k
  int i, j, k;
114
3.46k
  int flag = 0;
115
15.7k
  while (buf_size[p] > 0)
116
12.2k
  {
117
12.2k
    buf_size[q] = 0;
118
24.5k
    for (i = 0; i < buf_size[p]; 
i++12.3k
)
119
12.3k
    {
120
12.3k
      const int* outgoings; int outgoing_size;
121
12.3k
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
122
12.3k
        .d = buf[p][i],
123
12.3k
        .graph = graph
124
12.3k
      }, &outgoings, &outgoing_size);
125
21.1k
      for (j = 0; j < outgoing_size; 
j++8.85k
)
126
8.85k
      {
127
8.85k
        const int outgoing_idx = outgoings[j];
128
8.93k
        for (k = 0; k < sources->rnum; 
k++85
)
129
85
        {
130
85
          ccv_nnc_graph_exec_symbol_t* const source_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, k);
131
          // If this outgoing idx is one of the source, replace it with d, or delete it.
132
85
          if (source_symbol->d == outgoing_idx)
133
0
          {
134
0
            if (!flag)
135
0
            {
136
0
              source_symbol->d = d;
137
0
              flag = 1;
138
0
            } else {
139
              // Delete this from the list.
140
0
              if (k < sources->rnum - 1)
141
0
                source_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, sources->rnum - 1))->d;
142
0
              --sources->rnum;
143
0
            }
144
0
            break;
145
0
          }
146
85
        }
147
8.85k
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
148
19
          continue;
149
8.83k
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
150
8.83k
        buf[q][buf_size[q]] = outgoing_idx;
151
8.83k
        ++buf_size[q];
152
8.83k
      }
153
12.3k
    }
154
12.2k
    CCV_SWAP(p, q, i);
155
12.2k
  }
156
  // If this node is not visited, and we cannot find anything in the sources to replace, this is a new top node.
157
3.46k
  if (!flag)
158
3.46k
  {
159
3.46k
    const ccv_nnc_graph_exec_symbol_t source_symbol = {
160
3.46k
      .d = d,
161
3.46k
      .graph = graph
162
3.46k
    };
163
3.46k
    ccv_array_push(sources, &source_symbol);
164
3.46k
  }
165
3.46k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_insert_if_prior_to_any
ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_insert_if_prior_to_any
Line
Count
Source
101
1.00k
{
102
1.00k
  if (visited[(d >> 5)] & (1u << (d & 31)))
103
0
    return;
104
1.00k
  visited[(d >> 5)] |= (1u << (d & 31));
105
1.00k
  buf0[0] = d;
106
1.00k
  int* buf[2] = {
107
1.00k
    buf0, buf1
108
1.00k
  };
109
1.00k
  int buf_size[2] = {
110
1.00k
    1, 0
111
1.00k
  };
112
1.00k
  int p = 0, q = 1;
113
1.00k
  int i, j, k;
114
1.00k
  int flag = 0;
115
4.00k
  while (buf_size[p] > 0)
116
3.00k
  {
117
3.00k
    buf_size[q] = 0;
118
6.00k
    for (i = 0; i < buf_size[p]; 
i++3.00k
)
119
3.00k
    {
120
3.00k
      const int* outgoings; int outgoing_size;
121
3.00k
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
122
3.00k
        .d = buf[p][i],
123
3.00k
        .graph = graph
124
3.00k
      }, &outgoings, &outgoing_size);
125
5.00k
      for (j = 0; j < outgoing_size; 
j++2.00k
)
126
2.00k
      {
127
2.00k
        const int outgoing_idx = outgoings[j];
128
2.00k
        for (k = 0; k < sources->rnum; 
k++0
)
129
0
        {
130
0
          ccv_nnc_graph_exec_symbol_t* const source_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, k);
131
          // If this outgoing idx is one of the source, replace it with d, or delete it.
132
0
          if (source_symbol->d == outgoing_idx)
133
0
          {
134
0
            if (!flag)
135
0
            {
136
0
              source_symbol->d = d;
137
0
              flag = 1;
138
0
            } else {
139
              // Delete this from the list.
140
0
              if (k < sources->rnum - 1)
141
0
                source_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, sources->rnum - 1))->d;
142
0
              --sources->rnum;
143
0
            }
144
0
            break;
145
0
          }
146
0
        }
147
2.00k
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
148
0
          continue;
149
2.00k
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
150
2.00k
        buf[q][buf_size[q]] = outgoing_idx;
151
2.00k
        ++buf_size[q];
152
2.00k
      }
153
3.00k
    }
154
3.00k
    CCV_SWAP(p, q, i);
155
3.00k
  }
156
  // If this node is not visited, and we cannot find anything in the sources to replace, this is a new top node.
157
1.00k
  if (!flag)
158
1.00k
  {
159
1.00k
    const ccv_nnc_graph_exec_symbol_t source_symbol = {
160
1.00k
      .d = d,
161
1.00k
      .graph = graph
162
1.00k
    };
163
1.00k
    ccv_array_push(sources, &source_symbol);
164
1.00k
  }
165
1.00k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_insert_if_prior_to_any
166
167
static inline void ccv_nnc_remove_if_prior_to_any(const ccv_nnc_symbolic_graph_t* const graph, const int d, ccv_array_t* const destinations, uint32_t* const visited, int* const buf0, int* const buf1)
168
22
{
169
22
  int i, j, k;
170
  // If it is already visited, this is the later one, we are good.
171
22
  if (visited[(d >> 5)] & (1u << (d & 31)))
172
0
    return;
173
22
  visited[(d >> 5)] |= (1u << (d & 31));
174
22
  buf0[0] = d;
175
22
  int* buf[2] = {
176
22
    buf0, buf1
177
22
  };
178
22
  int buf_size[2] = {
179
22
    1, 0
180
22
  };
181
22
  int p = 0, q = 1;
182
22
  int flag = 0;
183
44
  while (!flag && 
buf_size[p] > 042
)
184
22
  {
185
22
    buf_size[q] = 0;
186
44
    for (i = 0; !flag && 
i < buf_size[p]42
;
i++22
)
187
22
    {
188
22
      const int* outgoings; int outgoing_size;
189
22
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
190
22
        .d = buf[p][i],
191
22
        .graph = graph
192
22
      }, &outgoings, &outgoing_size);
193
25
      for (j = 0; j < outgoing_size; 
j++3
)
194
3
      {
195
3
        const int outgoing_idx = outgoings[j];
196
        // If this node happens to be visited, do nothing.
197
3
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
198
0
          continue;
199
6
        
for (k = 0; 3
!flag &&
k < destinations->rnum3
;
k++3
)
200
3
        {
201
3
          ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, k);
202
          // If this outgoing idx is one of the destination, delete current node.
203
3
          flag = (destination_symbol->d == outgoing_idx);
204
3
        }
205
3
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
206
3
        buf[q][buf_size[q]] = outgoing_idx;
207
3
        ++buf_size[q];
208
3
      }
209
22
    }
210
22
    CCV_SWAP(p, q, i);
211
22
  }
212
22
  if (flag)
213
3
    
for (i = 0; 2
i < destinations->rnum;
i++1
)
214
3
    {
215
3
      ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, i);
216
      // If this outgoing idx is one of the destination, delete current node.
217
3
      if (destination_symbol->d == d)
218
2
      {
219
        // Delete this from the list.
220
2
        if (i < destinations->rnum - 1)
221
1
          destination_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, destinations->rnum - 1))->d;
222
2
        --destinations->rnum;
223
2
        break;
224
2
      }
225
3
    }
226
22
}
Unexecuted instantiation: ccv_nnc_dynamic_graph.c:ccv_nnc_remove_if_prior_to_any
Unexecuted instantiation: ccv_nnc_dynamic_graph_alloc.c:ccv_nnc_remove_if_prior_to_any
ccv_nnc_dynamic_graph_backward.c:ccv_nnc_remove_if_prior_to_any
Line
Count
Source
168
18
{
169
18
  int i, j, k;
170
  // If it is already visited, this is the later one, we are good.
171
18
  if (visited[(d >> 5)] & (1u << (d & 31)))
172
0
    return;
173
18
  visited[(d >> 5)] |= (1u << (d & 31));
174
18
  buf0[0] = d;
175
18
  int* buf[2] = {
176
18
    buf0, buf1
177
18
  };
178
18
  int buf_size[2] = {
179
18
    1, 0
180
18
  };
181
18
  int p = 0, q = 1;
182
18
  int flag = 0;
183
36
  while (!flag && 
buf_size[p] > 034
)
184
18
  {
185
18
    buf_size[q] = 0;
186
36
    for (i = 0; !flag && 
i < buf_size[p]34
;
i++18
)
187
18
    {
188
18
      const int* outgoings; int outgoing_size;
189
18
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
190
18
        .d = buf[p][i],
191
18
        .graph = graph
192
18
      }, &outgoings, &outgoing_size);
193
21
      for (j = 0; j < outgoing_size; 
j++3
)
194
3
      {
195
3
        const int outgoing_idx = outgoings[j];
196
        // If this node happens to be visited, do nothing.
197
3
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
198
0
          continue;
199
6
        
for (k = 0; 3
!flag &&
k < destinations->rnum3
;
k++3
)
200
3
        {
201
3
          ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, k);
202
          // If this outgoing idx is one of the destination, delete current node.
203
3
          flag = (destination_symbol->d == outgoing_idx);
204
3
        }
205
3
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
206
3
        buf[q][buf_size[q]] = outgoing_idx;
207
3
        ++buf_size[q];
208
3
      }
209
18
    }
210
18
    CCV_SWAP(p, q, i);
211
18
  }
212
18
  if (flag)
213
3
    
for (i = 0; 2
i < destinations->rnum;
i++1
)
214
3
    {
215
3
      ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, i);
216
      // If this outgoing idx is one of the destination, delete current node.
217
3
      if (destination_symbol->d == d)
218
2
      {
219
        // Delete this from the list.
220
2
        if (i < destinations->rnum - 1)
221
1
          destination_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, destinations->rnum - 1))->d;
222
2
        --destinations->rnum;
223
2
        break;
224
2
      }
225
3
    }
226
18
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_remove_if_prior_to_any
ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_remove_if_prior_to_any
Line
Count
Source
168
4
{
169
4
  int i, j, k;
170
  // If it is already visited, this is the later one, we are good.
171
4
  if (visited[(d >> 5)] & (1u << (d & 31)))
172
0
    return;
173
4
  visited[(d >> 5)] |= (1u << (d & 31));
174
4
  buf0[0] = d;
175
4
  int* buf[2] = {
176
4
    buf0, buf1
177
4
  };
178
4
  int buf_size[2] = {
179
4
    1, 0
180
4
  };
181
4
  int p = 0, q = 1;
182
4
  int flag = 0;
183
8
  while (!flag && buf_size[p] > 0)
184
4
  {
185
4
    buf_size[q] = 0;
186
8
    for (i = 0; !flag && i < buf_size[p]; 
i++4
)
187
4
    {
188
4
      const int* outgoings; int outgoing_size;
189
4
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
190
4
        .d = buf[p][i],
191
4
        .graph = graph
192
4
      }, &outgoings, &outgoing_size);
193
4
      for (j = 0; j < outgoing_size; 
j++0
)
194
0
      {
195
0
        const int outgoing_idx = outgoings[j];
196
        // If this node happens to be visited, do nothing.
197
0
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
198
0
          continue;
199
0
        for (k = 0; !flag && k < destinations->rnum; k++)
200
0
        {
201
0
          ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, k);
202
          // If this outgoing idx is one of the destination, delete current node.
203
0
          flag = (destination_symbol->d == outgoing_idx);
204
0
        }
205
0
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
206
0
        buf[q][buf_size[q]] = outgoing_idx;
207
0
        ++buf_size[q];
208
0
      }
209
4
    }
210
4
    CCV_SWAP(p, q, i);
211
4
  }
212
4
  if (flag)
213
0
    for (i = 0; i < destinations->rnum; i++)
214
0
    {
215
0
      ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, i);
216
      // If this outgoing idx is one of the destination, delete current node.
217
0
      if (destination_symbol->d == d)
218
0
      {
219
        // Delete this from the list.
220
0
        if (i < destinations->rnum - 1)
221
0
          destination_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, destinations->rnum - 1))->d;
222
0
        --destinations->rnum;
223
0
        break;
224
0
      }
225
0
    }
226
4
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_remove_if_prior_to_any
227
228
typedef struct {
229
  int type;
230
  int d;
231
} ccv_nnc_tape_symbol_t;
232
233
static inline void ccv_nnc_dynamic_graph_push_backward_tensor_symbol(void* context, const ccv_nnc_tensor_symbol_t symbol, const ccv_nnc_tensor_param_t info, const char* const name)
234
42.9k
{
235
42.9k
  ccv_array_t* const stack = (ccv_array_t*)context;
236
42.9k
  ccv_nnc_tape_symbol_t tape_symbol = {
237
42.9k
    .d = symbol.d,
238
42.9k
    .type = CCV_NNC_SYMBOL_TENSOR,
239
42.9k
  };
240
42.9k
  ccv_array_push(stack, &tape_symbol);
241
42.9k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
Unexecuted instantiation: ccv_nnc_dynamic_graph_alloc.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
ccv_nnc_dynamic_graph_backward.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
Line
Count
Source
234
27.1k
{
235
27.1k
  ccv_array_t* const stack = (ccv_array_t*)context;
236
27.1k
  ccv_nnc_tape_symbol_t tape_symbol = {
237
27.1k
    .d = symbol.d,
238
27.1k
    .type = CCV_NNC_SYMBOL_TENSOR,
239
27.1k
  };
240
27.1k
  ccv_array_push(stack, &tape_symbol);
241
27.1k
}
ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
Line
Count
Source
234
5.73k
{
235
5.73k
  ccv_array_t* const stack = (ccv_array_t*)context;
236
5.73k
  ccv_nnc_tape_symbol_t tape_symbol = {
237
5.73k
    .d = symbol.d,
238
5.73k
    .type = CCV_NNC_SYMBOL_TENSOR,
239
5.73k
  };
240
5.73k
  ccv_array_push(stack, &tape_symbol);
241
5.73k
}
ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
Line
Count
Source
234
10.0k
{
235
10.0k
  ccv_array_t* const stack = (ccv_array_t*)context;
236
10.0k
  ccv_nnc_tape_symbol_t tape_symbol = {
237
10.0k
    .d = symbol.d,
238
10.0k
    .type = CCV_NNC_SYMBOL_TENSOR,
239
10.0k
  };
240
10.0k
  ccv_array_push(stack, &tape_symbol);
241
10.0k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
242
243
static inline void ccv_nnc_dynamic_graph_push_backward_tensor_symbol_alias(void* context, const ccv_nnc_tensor_symbol_t symbol, const ccv_nnc_tensor_symbol_t from_symbol, const int ofs[CCV_NNC_MAX_DIM_ALLOC], const int inc[CCV_NNC_MAX_DIM_ALLOC], const ccv_nnc_tensor_param_t info, const char* const name)
244
1.01k
{
245
1.01k
  ccv_array_t* const stack = (ccv_array_t*)context;
246
1.01k
  ccv_nnc_tape_symbol_t tape_symbol = {
247
1.01k
    .d = symbol.d,
248
1.01k
    .type = CCV_NNC_SYMBOL_TENSOR_ALIAS,
249
1.01k
  };
250
1.01k
  ccv_array_push(stack, &tape_symbol);
251
1.01k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol_alias
Unexecuted instantiation: ccv_nnc_dynamic_graph_alloc.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol_alias
ccv_nnc_dynamic_graph_backward.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol_alias
Line
Count
Source
244
1.01k
{
245
1.01k
  ccv_array_t* const stack = (ccv_array_t*)context;
246
1.01k
  ccv_nnc_tape_symbol_t tape_symbol = {
247
1.01k
    .d = symbol.d,
248
1.01k
    .type = CCV_NNC_SYMBOL_TENSOR_ALIAS,
249
1.01k
  };
250
1.01k
  ccv_array_push(stack, &tape_symbol);
251
1.01k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol_alias
Unexecuted instantiation: ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol_alias
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol_alias
252
253
static inline void ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol(void* context, const ccv_nnc_graph_exec_symbol_t symbol, const ccv_nnc_cmd_t cmd, const ccv_nnc_tensor_symbol_t* const inputs, const int input_size, const ccv_nnc_tensor_symbol_t* const outputs, const int output_size, const char* const name)
254
23.9k
{
255
23.9k
  ccv_array_t* const stack = (ccv_array_t*)context;
256
23.9k
  ccv_nnc_tape_symbol_t tape_symbol = {
257
23.9k
    .d = symbol.d,
258
23.9k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
259
23.9k
  };
260
23.9k
  ccv_array_push(stack, &tape_symbol);
261
23.9k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
Unexecuted instantiation: ccv_nnc_dynamic_graph_alloc.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
ccv_nnc_dynamic_graph_backward.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
Line
Count
Source
254
17.4k
{
255
17.4k
  ccv_array_t* const stack = (ccv_array_t*)context;
256
17.4k
  ccv_nnc_tape_symbol_t tape_symbol = {
257
17.4k
    .d = symbol.d,
258
17.4k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
259
17.4k
  };
260
17.4k
  ccv_array_push(stack, &tape_symbol);
261
17.4k
}
ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
Line
Count
Source
254
1.44k
{
255
1.44k
  ccv_array_t* const stack = (ccv_array_t*)context;
256
1.44k
  ccv_nnc_tape_symbol_t tape_symbol = {
257
1.44k
    .d = symbol.d,
258
1.44k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
259
1.44k
  };
260
1.44k
  ccv_array_push(stack, &tape_symbol);
261
1.44k
}
ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
Line
Count
Source
254
5.01k
{
255
5.01k
  ccv_array_t* const stack = (ccv_array_t*)context;
256
5.01k
  ccv_nnc_tape_symbol_t tape_symbol = {
257
5.01k
    .d = symbol.d,
258
5.01k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
259
5.01k
  };
260
5.01k
  ccv_array_push(stack, &tape_symbol);
261
5.01k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
262
263
static inline int ccv_nnc_tensor_variable_contains_value(ccv_nnc_tensor_variable_t const tensor_variable)
264
4.68k
{
265
  // A tensor variable contains value only if it has a tensor view, and these tensor view is not external bind without a symbol (thus, freshly external bind).
266
4.68k
  return tensor_variable->tensor_view && 
(3.40k
!3.40k
CCV_NNC_IS_EXTERN_TENSOR_VIEW3.40k
(tensor_variable->tensor_view) ||
tensor_variable->symbol.d >= 01
);
267
4.68k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph.c:ccv_nnc_tensor_variable_contains_value
Unexecuted instantiation: ccv_nnc_dynamic_graph_alloc.c:ccv_nnc_tensor_variable_contains_value
ccv_nnc_dynamic_graph_backward.c:ccv_nnc_tensor_variable_contains_value
Line
Count
Source
264
3.24k
{
265
  // A tensor variable contains value only if it has a tensor view, and these tensor view is not external bind without a symbol (thus, freshly external bind).
266
3.24k
  return tensor_variable->tensor_view && 
(2.00k
!2.00k
CCV_NNC_IS_EXTERN_TENSOR_VIEW2.00k
(tensor_variable->tensor_view) ||
tensor_variable->symbol.d >= 01
);
267
3.24k
}
ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_tensor_variable_contains_value
Line
Count
Source
264
1.43k
{
265
  // A tensor variable contains value only if it has a tensor view, and these tensor view is not external bind without a symbol (thus, freshly external bind).
266
1.43k
  return tensor_variable->tensor_view && 
(1.40k
!1.40k
CCV_NNC_IS_EXTERN_TENSOR_VIEW1.40k
(tensor_variable->tensor_view) ||
tensor_variable->symbol.d >= 00
);
267
1.43k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_tensor_variable_contains_value
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_tensor_variable_contains_value
268
269
void ccv_nnc_dynamic_graph_exec_ret(ccv_nnc_dynamic_graph_t* const graph, const ccv_nnc_cmd_t cmd, const ccv_nnc_hint_t hint, const int flags, const ccv_nnc_tensor_variable_t* const inputs, const int input_size, ccv_nnc_tensor_variable_t* const outputs, const int output_size, const int parallel, ccv_nnc_stream_context_t* const stream_context, ccv_nnc_graph_exec_symbol_t* const graph_execs);
270
271
extern const ccv_nnc_symbolic_graph_compile_allocator_vtab_t ccv_nnc_dy_allocator_isa;
272
273
typedef struct {
274
  ccv_nnc_graph_t* graph;
275
  ccv_nnc_tensor_arena_t* tensor_arena;
276
  ccv_nnc_graph_exec_arena_t* exec_arena;
277
} ccv_nnc_compilation_artifact_t;
278
279
ccv_nnc_compilation_artifact_t* ccv_nnc_compilation_artifact_new(ccv_nnc_graph_t* const graph, ccv_nnc_tensor_arena_t* const tensor_arena, ccv_nnc_graph_exec_arena_t* const exec_arena);
280
void ccv_nnc_compilation_artifact_free(ccv_nnc_compilation_artifact_t* const artifact);
281
282
#endif