Coverage Report

Created: 2021-09-30 20:21

/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 "3rdparty/khash/khash.h"
17
#include "3rdparty/jemalloc/rb.h"
18
19
39.1k
#define CCV_NNC_IS_EXTERN_TENSOR_VIEW(tv) ((uintptr_t)(tv) & 1)
20
68.6k
#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
  struct {
32
    ccv_nnc_tensor_variable_destructor_f func;
33
    void* context;
34
  } destructor_hook;
35
  ccv_nnc_tensor_param_t info;
36
  ccv_nnc_tensor_symbol_t symbol;
37
  ccv_nnc_tensor_view_t* tensor_view;
38
  int ofs[CCV_NNC_MAX_DIM_ALLOC];
39
  int inc[CCV_NNC_MAX_DIM_ALLOC];
40
};
41
42
enum {
43
  CCV_NNC_TENSOR_NO_VARIABLE = -1,
44
  CCV_NNC_TENSOR_NO_VARIABLE_BUT_USED = -2,
45
};
46
47
typedef struct {
48
  ccv_nnc_cmd_vtab_t super;
49
  void(*apply_gradients)(const ccv_nnc_cmd_t cmd, ccv_nnc_stream_context_t* const stream_context);
50
} ccv_nnc_stateful_cmd_vtab_t;
51
52
typedef struct { // Extra information kept per tensor symbol along with symbolic graph.
53
  int type;
54
  int index; // The index back into the tensor variable. -1 meant no associated tensor vairable.
55
  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.
56
  struct {
57
    ccv_nnc_tensor_variable_destructor_f func;
58
    void* context;
59
  } destructor_hook;
60
  ccv_array_t* sources; // array of graph_exec_symbol, use this tensor symbol as output.
61
  ccv_array_t* destinations; // array of graph_exec_symbol, use this tensor symbol as input.
62
  ccv_nnc_tensor_view_t* tensor_view; // Transfer ownership of the tensor view to here.
63
} ccv_nnc_tensor_variable_graph_bind_t;
64
65
typedef struct {
66
  ccv_nnc_dynamic_graph_t* graph;
67
  ccv_nnc_stream_context_t* stream;
68
} ccv_nnc_dy_xpu_alloc_t;
69
70
typedef struct {
71
  int8_t requires_grad;
72
  int8_t is_test;
73
  int8_t did_backward_but_not_apply_gradients;
74
  int8_t should_free;
75
  int index;
76
  uint64_t disable_outgrad;
77
  ccv_nnc_tensor_tape_t* tensor_tape;
78
  void* data;
79
  ccv_nnc_cmd_t cmd;
80
} ccv_nnc_stateful_exec_t;
81
82
KHASH_MAP_INIT_INT(stateful_exec, ccv_nnc_stateful_exec_t*)
83
84
typedef struct dy_alloc_metadata_s dy_alloc_metadata_t;
85
struct dy_alloc_metadata_s {
86
  int device;
87
  size_t size;
88
  intptr_t str;
89
  rb_node(dy_alloc_metadata_t) link;
90
  dy_alloc_metadata_t* next; // So I can chain them together.
91
  void* ptr;
92
};
93
typedef rb_tree(dy_alloc_metadata_t) dy_alloc_tree_t;
94
KHASH_MAP_INIT_INT(dy_dev, dy_alloc_tree_t);
95
typedef struct {
96
  int hook_id;
97
  khash_t(dy_dev)* dev;
98
} dy_str_t;
99
KHASH_MAP_INIT_INT64(dy_str, dy_str_t);
100
KHASH_MAP_INIT_INT64(dy_alloc, dy_alloc_metadata_t*);
101
102
struct ccv_nnc_dynamic_graph_s {
103
  int no_grad; // 1 if gradient computation is disabled.
104
  int reuse_var; // -1 if no var can be reused. Otherwise first locate the reuse var without increase array size.
105
  int mp_hdr; // Memory pressure handler.
106
  int reuse_stateful_exec; // -1 if no stateful exec can be reused. Otherwise first locate the reuse without increase array size.
107
  ccv_array_t* vars; // Array keeps track of all allocated tensor variable.
108
  ccv_array_t* binds; // Array keeps track of extra information for a tensor symbol.
109
  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.
110
  khash_t(dy_str)* freed; // The freed memory allocations.
111
  khash_t(dy_alloc)* allocd; // The allocated memory.
112
  ccv_nnc_symbolic_graph_t* tape; // Symbolic graph to keep track of computation.
113
  khash_t(stream_map)* stream_map; // Keeps track of streams on both GPU / CPU and devices so it can be used properly during execution.
114
  ccv_array_t* ws; // array of integers as workspace
115
};
116
117
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);
118
119
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)
120
4.47k
{
121
4.47k
  if (visited[(d >> 5)] & (1u << (d & 31)))
122
7
    return;
123
4.46k
  visited[(d >> 5)] |= (1u << (d & 31));
124
4.46k
  buf0[0] = d;
125
4.46k
  int* buf[2] = {
126
4.46k
    buf0, buf1
127
4.46k
  };
128
4.46k
  int buf_size[2] = {
129
4.46k
    1, 0
130
4.46k
  };
131
4.46k
  int p = 0, q = 1;
132
4.46k
  int i, j, k;
133
4.46k
  int flag = 0;
134
19.7k
  while (buf_size[p] > 0)
135
15.2k
  {
136
15.2k
    buf_size[q] = 0;
137
30.5k
    for (i = 0; i < buf_size[p]; 
i++15.3k
)
138
15.3k
    {
139
15.3k
      const int* outgoings; int outgoing_size;
140
15.3k
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
141
15.3k
        .d = buf[p][i],
142
15.3k
        .graph = graph
143
15.3k
      }, &outgoings, &outgoing_size);
144
26.1k
      for (j = 0; j < outgoing_size; 
j++10.8k
)
145
10.8k
      {
146
10.8k
        const int outgoing_idx = outgoings[j];
147
10.9k
        for (k = 0; k < sources->rnum; 
k++85
)
148
85
        {
149
85
          ccv_nnc_graph_exec_symbol_t* const source_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, k);
150
85
          // If this outgoing idx is one of the source, replace it with d, or delete it.
151
85
          if (source_symbol->d == outgoing_idx)
152
0
          {
153
0
            if (!flag)
154
0
            {
155
0
              source_symbol->d = d;
156
0
              flag = 1;
157
0
            } else {
158
0
              // Delete this from the list.
159
0
              if (k < sources->rnum - 1)
160
0
                source_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, sources->rnum - 1))->d;
161
0
              --sources->rnum;
162
0
            }
163
0
            break;
164
0
          }
165
85
        }
166
10.8k
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
167
19
          continue;
168
10.8k
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
169
10.8k
        buf[q][buf_size[q]] = outgoing_idx;
170
10.8k
        ++buf_size[q];
171
10.8k
      }
172
15.3k
    }
173
15.2k
    CCV_SWAP(p, q, i);
174
15.2k
  }
175
4.46k
  // If this node is not visited, and we cannot find anything in the sources to replace, this is a new top node.
176
4.46k
  if (!flag)
177
4.46k
  {
178
4.46k
    const ccv_nnc_graph_exec_symbol_t source_symbol = {
179
4.46k
      .d = d,
180
4.46k
      .graph = graph
181
4.46k
    };
182
4.46k
    ccv_array_push(sources, &source_symbol);
183
4.46k
  }
184
4.46k
}
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
120
3.47k
{
121
3.47k
  if (visited[(d >> 5)] & (1u << (d & 31)))
122
7
    return;
123
3.46k
  visited[(d >> 5)] |= (1u << (d & 31));
124
3.46k
  buf0[0] = d;
125
3.46k
  int* buf[2] = {
126
3.46k
    buf0, buf1
127
3.46k
  };
128
3.46k
  int buf_size[2] = {
129
3.46k
    1, 0
130
3.46k
  };
131
3.46k
  int p = 0, q = 1;
132
3.46k
  int i, j, k;
133
3.46k
  int flag = 0;
134
15.7k
  while (buf_size[p] > 0)
135
12.2k
  {
136
12.2k
    buf_size[q] = 0;
137
24.5k
    for (i = 0; i < buf_size[p]; 
i++12.2k
)
138
12.2k
    {
139
12.2k
      const int* outgoings; int outgoing_size;
140
12.2k
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
141
12.2k
        .d = buf[p][i],
142
12.2k
        .graph = graph
143
12.2k
      }, &outgoings, &outgoing_size);
144
21.1k
      for (j = 0; j < outgoing_size; 
j++8.85k
)
145
8.85k
      {
146
8.85k
        const int outgoing_idx = outgoings[j];
147
8.93k
        for (k = 0; k < sources->rnum; 
k++85
)
148
85
        {
149
85
          ccv_nnc_graph_exec_symbol_t* const source_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, k);
150
85
          // If this outgoing idx is one of the source, replace it with d, or delete it.
151
85
          if (source_symbol->d == outgoing_idx)
152
0
          {
153
0
            if (!flag)
154
0
            {
155
0
              source_symbol->d = d;
156
0
              flag = 1;
157
0
            } else {
158
0
              // Delete this from the list.
159
0
              if (k < sources->rnum - 1)
160
0
                source_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, sources->rnum - 1))->d;
161
0
              --sources->rnum;
162
0
            }
163
0
            break;
164
0
          }
165
85
        }
166
8.85k
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
167
19
          continue;
168
8.83k
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
169
8.83k
        buf[q][buf_size[q]] = outgoing_idx;
170
8.83k
        ++buf_size[q];
171
8.83k
      }
172
12.2k
    }
173
12.2k
    CCV_SWAP(p, q, i);
174
12.2k
  }
175
3.46k
  // If this node is not visited, and we cannot find anything in the sources to replace, this is a new top node.
176
3.46k
  if (!flag)
177
3.46k
  {
178
3.46k
    const ccv_nnc_graph_exec_symbol_t source_symbol = {
179
3.46k
      .d = d,
180
3.46k
      .graph = graph
181
3.46k
    };
182
3.46k
    ccv_array_push(sources, &source_symbol);
183
3.46k
  }
184
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
120
1.00k
{
121
1.00k
  if (visited[(d >> 5)] & (1u << (d & 31)))
122
0
    return;
123
1.00k
  visited[(d >> 5)] |= (1u << (d & 31));
124
1.00k
  buf0[0] = d;
125
1.00k
  int* buf[2] = {
126
1.00k
    buf0, buf1
127
1.00k
  };
128
1.00k
  int buf_size[2] = {
129
1.00k
    1, 0
130
1.00k
  };
131
1.00k
  int p = 0, q = 1;
132
1.00k
  int i, j, k;
133
1.00k
  int flag = 0;
134
4.00k
  while (buf_size[p] > 0)
135
3.00k
  {
136
3.00k
    buf_size[q] = 0;
137
6.00k
    for (i = 0; i < buf_size[p]; 
i++3.00k
)
138
3.00k
    {
139
3.00k
      const int* outgoings; int outgoing_size;
140
3.00k
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
141
3.00k
        .d = buf[p][i],
142
3.00k
        .graph = graph
143
3.00k
      }, &outgoings, &outgoing_size);
144
5.00k
      for (j = 0; j < outgoing_size; 
j++2.00k
)
145
2.00k
      {
146
2.00k
        const int outgoing_idx = outgoings[j];
147
2.00k
        for (k = 0; k < sources->rnum; 
k++0
)
148
0
        {
149
0
          ccv_nnc_graph_exec_symbol_t* const source_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, k);
150
0
          // If this outgoing idx is one of the source, replace it with d, or delete it.
151
0
          if (source_symbol->d == outgoing_idx)
152
0
          {
153
0
            if (!flag)
154
0
            {
155
0
              source_symbol->d = d;
156
0
              flag = 1;
157
0
            } else {
158
0
              // Delete this from the list.
159
0
              if (k < sources->rnum - 1)
160
0
                source_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(sources, sources->rnum - 1))->d;
161
0
              --sources->rnum;
162
0
            }
163
0
            break;
164
0
          }
165
0
        }
166
2.00k
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
167
0
          continue;
168
2.00k
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
169
2.00k
        buf[q][buf_size[q]] = outgoing_idx;
170
2.00k
        ++buf_size[q];
171
2.00k
      }
172
3.00k
    }
173
3.00k
    CCV_SWAP(p, q, i);
174
3.00k
  }
175
1.00k
  // If this node is not visited, and we cannot find anything in the sources to replace, this is a new top node.
176
1.00k
  if (!flag)
177
1.00k
  {
178
1.00k
    const ccv_nnc_graph_exec_symbol_t source_symbol = {
179
1.00k
      .d = d,
180
1.00k
      .graph = graph
181
1.00k
    };
182
1.00k
    ccv_array_push(sources, &source_symbol);
183
1.00k
  }
184
1.00k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_insert_if_prior_to_any
185
186
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)
187
22
{
188
22
  int i, j, k;
189
22
  // If it is already visited, this is the later one, we are good.
190
22
  if (visited[(d >> 5)] & (1u << (d & 31)))
191
0
    return;
192
22
  visited[(d >> 5)] |= (1u << (d & 31));
193
22
  buf0[0] = d;
194
22
  int* buf[2] = {
195
22
    buf0, buf1
196
22
  };
197
22
  int buf_size[2] = {
198
22
    1, 0
199
22
  };
200
22
  int p = 0, q = 1;
201
22
  int flag = 0;
202
44
  while (!flag && 
buf_size[p] > 042
)
203
22
  {
204
22
    buf_size[q] = 0;
205
44
    for (i = 0; !flag && 
i < buf_size[p]42
;
i++22
)
206
22
    {
207
22
      const int* outgoings; int outgoing_size;
208
22
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
209
22
        .d = buf[p][i],
210
22
        .graph = graph
211
22
      }, &outgoings, &outgoing_size);
212
25
      for (j = 0; j < outgoing_size; 
j++3
)
213
3
      {
214
3
        const int outgoing_idx = outgoings[j];
215
3
        // If this node happens to be visited, do nothing.
216
3
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
217
0
          continue;
218
6
        
for (k = 0; 3
!flag &&
k < destinations->rnum3
;
k++3
)
219
3
        {
220
3
          ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, k);
221
3
          // If this outgoing idx is one of the destination, delete current node.
222
3
          flag = (destination_symbol->d == outgoing_idx);
223
3
        }
224
3
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
225
3
        buf[q][buf_size[q]] = outgoing_idx;
226
3
        ++buf_size[q];
227
3
      }
228
22
    }
229
22
    CCV_SWAP(p, q, i);
230
22
  }
231
22
  if (flag)
232
3
    
for (i = 0; 2
i < destinations->rnum;
i++1
)
233
3
    {
234
3
      ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, i);
235
3
      // If this outgoing idx is one of the destination, delete current node.
236
3
      if (destination_symbol->d == d)
237
2
      {
238
2
        // Delete this from the list.
239
2
        if (i < destinations->rnum - 1)
240
1
          destination_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, destinations->rnum - 1))->d;
241
2
        --destinations->rnum;
242
2
        break;
243
2
      }
244
3
    }
245
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
187
18
{
188
18
  int i, j, k;
189
18
  // If it is already visited, this is the later one, we are good.
190
18
  if (visited[(d >> 5)] & (1u << (d & 31)))
191
0
    return;
192
18
  visited[(d >> 5)] |= (1u << (d & 31));
193
18
  buf0[0] = d;
194
18
  int* buf[2] = {
195
18
    buf0, buf1
196
18
  };
197
18
  int buf_size[2] = {
198
18
    1, 0
199
18
  };
200
18
  int p = 0, q = 1;
201
18
  int flag = 0;
202
36
  while (!flag && 
buf_size[p] > 034
)
203
18
  {
204
18
    buf_size[q] = 0;
205
36
    for (i = 0; !flag && 
i < buf_size[p]34
;
i++18
)
206
18
    {
207
18
      const int* outgoings; int outgoing_size;
208
18
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
209
18
        .d = buf[p][i],
210
18
        .graph = graph
211
18
      }, &outgoings, &outgoing_size);
212
21
      for (j = 0; j < outgoing_size; 
j++3
)
213
3
      {
214
3
        const int outgoing_idx = outgoings[j];
215
3
        // If this node happens to be visited, do nothing.
216
3
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
217
0
          continue;
218
6
        
for (k = 0; 3
!flag &&
k < destinations->rnum3
;
k++3
)
219
3
        {
220
3
          ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, k);
221
3
          // If this outgoing idx is one of the destination, delete current node.
222
3
          flag = (destination_symbol->d == outgoing_idx);
223
3
        }
224
3
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
225
3
        buf[q][buf_size[q]] = outgoing_idx;
226
3
        ++buf_size[q];
227
3
      }
228
18
    }
229
18
    CCV_SWAP(p, q, i);
230
18
  }
231
18
  if (flag)
232
3
    
for (i = 0; 2
i < destinations->rnum;
i++1
)
233
3
    {
234
3
      ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, i);
235
3
      // If this outgoing idx is one of the destination, delete current node.
236
3
      if (destination_symbol->d == d)
237
2
      {
238
2
        // Delete this from the list.
239
2
        if (i < destinations->rnum - 1)
240
1
          destination_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, destinations->rnum - 1))->d;
241
2
        --destinations->rnum;
242
2
        break;
243
2
      }
244
3
    }
245
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
187
4
{
188
4
  int i, j, k;
189
4
  // If it is already visited, this is the later one, we are good.
190
4
  if (visited[(d >> 5)] & (1u << (d & 31)))
191
0
    return;
192
4
  visited[(d >> 5)] |= (1u << (d & 31));
193
4
  buf0[0] = d;
194
4
  int* buf[2] = {
195
4
    buf0, buf1
196
4
  };
197
4
  int buf_size[2] = {
198
4
    1, 0
199
4
  };
200
4
  int p = 0, q = 1;
201
4
  int flag = 0;
202
8
  while (!flag && buf_size[p] > 0)
203
4
  {
204
4
    buf_size[q] = 0;
205
8
    for (i = 0; !flag && i < buf_size[p]; 
i++4
)
206
4
    {
207
4
      const int* outgoings; int outgoing_size;
208
4
      ccv_nnc_graph_exec_symbol_to(graph, (ccv_nnc_graph_exec_symbol_t){
209
4
        .d = buf[p][i],
210
4
        .graph = graph
211
4
      }, &outgoings, &outgoing_size);
212
4
      for (j = 0; j < outgoing_size; 
j++0
)
213
0
      {
214
0
        const int outgoing_idx = outgoings[j];
215
0
        // If this node happens to be visited, do nothing.
216
0
        if (visited[(outgoing_idx >> 5)] & (1u << (outgoing_idx & 31)))
217
0
          continue;
218
0
        for (k = 0; !flag && k < destinations->rnum; k++)
219
0
        {
220
0
          ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, k);
221
0
          // If this outgoing idx is one of the destination, delete current node.
222
0
          flag = (destination_symbol->d == outgoing_idx);
223
0
        }
224
0
        visited[(outgoing_idx >> 5)] |= (1u << (outgoing_idx & 31));
225
0
        buf[q][buf_size[q]] = outgoing_idx;
226
0
        ++buf_size[q];
227
0
      }
228
4
    }
229
4
    CCV_SWAP(p, q, i);
230
4
  }
231
4
  if (flag)
232
0
    for (i = 0; i < destinations->rnum; i++)
233
0
    {
234
0
      ccv_nnc_graph_exec_symbol_t* const destination_symbol = (ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, i);
235
0
      // If this outgoing idx is one of the destination, delete current node.
236
0
      if (destination_symbol->d == d)
237
0
      {
238
0
        // Delete this from the list.
239
0
        if (i < destinations->rnum - 1)
240
0
          destination_symbol->d = ((ccv_nnc_graph_exec_symbol_t*)ccv_array_get(destinations, destinations->rnum - 1))->d;
241
0
        --destinations->rnum;
242
0
        break;
243
0
      }
244
0
    }
245
4
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_remove_if_prior_to_any
246
247
typedef struct {
248
  int type;
249
  int d;
250
} ccv_nnc_tape_symbol_t;
251
252
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)
253
42.9k
{
254
42.9k
  ccv_array_t* const stack = (ccv_array_t*)context;
255
42.9k
  ccv_nnc_tape_symbol_t tape_symbol = {
256
42.9k
    .d = symbol.d,
257
42.9k
    .type = CCV_NNC_SYMBOL_TENSOR,
258
42.9k
  };
259
42.9k
  ccv_array_push(stack, &tape_symbol);
260
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
253
27.1k
{
254
27.1k
  ccv_array_t* const stack = (ccv_array_t*)context;
255
27.1k
  ccv_nnc_tape_symbol_t tape_symbol = {
256
27.1k
    .d = symbol.d,
257
27.1k
    .type = CCV_NNC_SYMBOL_TENSOR,
258
27.1k
  };
259
27.1k
  ccv_array_push(stack, &tape_symbol);
260
27.1k
}
ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
Line
Count
Source
253
5.72k
{
254
5.72k
  ccv_array_t* const stack = (ccv_array_t*)context;
255
5.72k
  ccv_nnc_tape_symbol_t tape_symbol = {
256
5.72k
    .d = symbol.d,
257
5.72k
    .type = CCV_NNC_SYMBOL_TENSOR,
258
5.72k
  };
259
5.72k
  ccv_array_push(stack, &tape_symbol);
260
5.72k
}
ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
Line
Count
Source
253
10.0k
{
254
10.0k
  ccv_array_t* const stack = (ccv_array_t*)context;
255
10.0k
  ccv_nnc_tape_symbol_t tape_symbol = {
256
10.0k
    .d = symbol.d,
257
10.0k
    .type = CCV_NNC_SYMBOL_TENSOR,
258
10.0k
  };
259
10.0k
  ccv_array_push(stack, &tape_symbol);
260
10.0k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_dynamic_graph_push_backward_tensor_symbol
261
262
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)
263
1.01k
{
264
1.01k
  ccv_array_t* const stack = (ccv_array_t*)context;
265
1.01k
  ccv_nnc_tape_symbol_t tape_symbol = {
266
1.01k
    .d = symbol.d,
267
1.01k
    .type = CCV_NNC_SYMBOL_TENSOR_ALIAS,
268
1.01k
  };
269
1.01k
  ccv_array_push(stack, &tape_symbol);
270
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
263
1.01k
{
264
1.01k
  ccv_array_t* const stack = (ccv_array_t*)context;
265
1.01k
  ccv_nnc_tape_symbol_t tape_symbol = {
266
1.01k
    .d = symbol.d,
267
1.01k
    .type = CCV_NNC_SYMBOL_TENSOR_ALIAS,
268
1.01k
  };
269
1.01k
  ccv_array_push(stack, &tape_symbol);
270
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
271
272
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)
273
23.9k
{
274
23.9k
  ccv_array_t* const stack = (ccv_array_t*)context;
275
23.9k
  ccv_nnc_tape_symbol_t tape_symbol = {
276
23.9k
    .d = symbol.d,
277
23.9k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
278
23.9k
  };
279
23.9k
  ccv_array_push(stack, &tape_symbol);
280
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
273
17.4k
{
274
17.4k
  ccv_array_t* const stack = (ccv_array_t*)context;
275
17.4k
  ccv_nnc_tape_symbol_t tape_symbol = {
276
17.4k
    .d = symbol.d,
277
17.4k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
278
17.4k
  };
279
17.4k
  ccv_array_push(stack, &tape_symbol);
280
17.4k
}
ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
Line
Count
Source
273
1.44k
{
274
1.44k
  ccv_array_t* const stack = (ccv_array_t*)context;
275
1.44k
  ccv_nnc_tape_symbol_t tape_symbol = {
276
1.44k
    .d = symbol.d,
277
1.44k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
278
1.44k
  };
279
1.44k
  ccv_array_push(stack, &tape_symbol);
280
1.44k
}
ccv_nnc_dynamic_graph_minimize.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
Line
Count
Source
273
5.01k
{
274
5.01k
  ccv_array_t* const stack = (ccv_array_t*)context;
275
5.01k
  ccv_nnc_tape_symbol_t tape_symbol = {
276
5.01k
    .d = symbol.d,
277
5.01k
    .type = CCV_NNC_SYMBOL_GRAPH_EXEC,
278
5.01k
  };
279
5.01k
  ccv_array_push(stack, &tape_symbol);
280
5.01k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_nnc_dynamic_graph_push_backward_graph_exec_symbol
281
282
static inline int ccv_nnc_tensor_variable_contains_value(ccv_nnc_tensor_variable_t const tensor_variable)
283
4.67k
{
284
4.67k
  // 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).
285
4.67k
  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
);
286
4.67k
}
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
283
3.24k
{
284
3.24k
  // 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).
285
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
);
286
3.24k
}
ccv_nnc_dynamic_graph_apply_gradients.c:ccv_nnc_tensor_variable_contains_value
Line
Count
Source
283
1.43k
{
284
1.43k
  // 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).
285
1.43k
  return tensor_variable->tensor_view && 
(1.39k
!1.39k
CCV_NNC_IS_EXTERN_TENSOR_VIEW1.39k
(tensor_variable->tensor_view) ||
tensor_variable->symbol.d >= 00
);
286
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
287
288
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);
289
void* ccv_nnc_dynamic_graph_xpu_alloc(ccv_nnc_dynamic_graph_t* const graph, const int device, ccv_nnc_stream_context_t* const stream, const size_t size);
290
void ccv_nnc_dynamic_graph_xpu_free(ccv_nnc_dynamic_graph_t* const graph, void* const ptr);
291
void ccv_nnc_dynamic_graph_xpu_alloc_destroy(ccv_nnc_dynamic_graph_t* const graph);
292
293
extern const ccv_nnc_symbolic_graph_compile_allocator_vtab_t ccv_nnc_dy_allocator_isa;
294
295
typedef struct {
296
  ccv_nnc_graph_t* graph;
297
  ccv_nnc_tensor_arena_t* tensor_arena;
298
  ccv_nnc_graph_exec_arena_t* exec_arena;
299
} ccv_nnc_compilation_artifact_t;
300
301
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);
302
void ccv_nnc_compilation_artifact_free(ccv_nnc_compilation_artifact_t* const artifact);
303
304
#endif