Coverage Report

Created: 2022-07-27 23:53

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/_ccv_cnnp_model.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_cnnp_model_internal_h
11
#define GUARD_ccv_cnnp_model_internal_h
12
13
#include "ccv_nnc.h"
14
#include "_ccv_nnc_stream.h"
15
#include "_ccv_nnc_xpu_alloc.h"
16
#include "3rdparty/khash/khash.h"
17
18
typedef void(*ccv_cnnp_cmd_updater_f)(void* const context, const ccv_nnc_graph_exec_symbol_t symbol, const ccv_nnc_cmd_t cmd, const ccv_nnc_hint_t hint);
19
typedef void(*ccv_cnnp_add_to_array_f)(void* const context, const ccv_nnc_tensor_symbol_t symbol);
20
/**
21
 * This is the virtual table of the model.
22
 */
23
typedef struct {
24
  void (*deinit)(ccv_cnnp_model_t* const self); /**< It can be nil. */
25
  void (*build)(ccv_cnnp_model_t* const self, ccv_nnc_symbolic_graph_t* const graph, const ccv_nnc_tensor_symbol_t* const inputs, const int input_size, ccv_nnc_tensor_symbol_t* const outputs, const int output_size); /**< Call this graph to build computation. No need to specify input size or output size, as it is defined along in the model already. */
26
  void (*init_states)(ccv_cnnp_model_t* const self, ccv_nnc_symbolic_graph_t* const graph, const ccv_cnnp_state_initializer_f initializer, void* const context); /**< This is called to init ccv_nnc_tensor_symbol_t with a exec. */
27
  void (*add_to_parameter)(ccv_cnnp_model_t* const self, const ccv_cnnp_add_to_array_f add_to_array, void* const parameters); /**< This is called to add ccv_nnc_tensor_symbol_t to as list of parameters. */
28
  void (*add_to_output)(ccv_cnnp_model_t* const self, const ccv_cnnp_add_to_array_f add_to_array, void* const outputs); /**< This is called to add ccv_nnc_tensor_symbol_t to as list of outputs for retention. The final outputs are already added. This method is optional for any additional values we want to retain. */
29
  ccv_cnnp_model_t* (*copy)(const ccv_cnnp_model_t* const self, void* const context); /**< This is called to make a deep copy of itself. */
30
  void (*set_is_test)(ccv_cnnp_model_t* const self, const int is_test, const ccv_cnnp_cmd_updater_f updater, void* const context); /**< This is called when it is switched between test or training. */
31
  void (*add_to_parameter_indices)(ccv_cnnp_model_t* const self, const int index, ccv_array_t* const parameter_indices); /**< This is called when we try to get parameter indices out of a given model */
32
  void (*notify)(const ccv_cnnp_model_t* const self, const int tag, void* const payload); /**< This is called when we want to notify something to this model. */
33
} ccv_cnnp_model_vtab_t;
34
35
struct ccv_cnnp_model_io_s {
36
  int param_ref; // Reference to parameter in the model, starts with 1. 0 means no such thing.
37
  int param_sel; // Selector to parameter in the model, starts with 1. 0 means no selector.
38
  int visit; // Temporary bits stored in the ccv_cnnp_model_io_t object, whoever uses it should clean it up.
39
  ccv_cnnp_model_t* model; // Reference back to the model who holds it. This is required because the model is the one whole holds the io.
40
  ccv_array_t* incomings; // Array of ccv_cnnp_model_io_t. The order is important because it impacts the order of symbols.
41
  ccv_array_t* outgoings; // Array of ccv_cnnp_model_io_t.
42
  ccv_nnc_tensor_symbol_t* outputs; // This is different from the outputs from a model. A model could be reused, causing the outputs on that model to be the most recent one. This keeps the outputs of each.
43
};
44
45
enum {
46
  CCV_CNNP_MODEL_GRAPH_FIT_MODE, // This mode computes loss, backprop, and then apply gradients.
47
  CCV_CNNP_MODEL_GRAPH_MULTISTAGE_MODE_NO_GRAD, // This mode allows you to only use ccv_cnnp_model_evaluate (others require gradient).
48
  CCV_CNNP_MODEL_GRAPH_MULTISTAGE_MODE, // This mode allows you to use ccv_cnnp_model_evaluate, ccv_cnnp_model_backward, ccv_cnnp_model_apply_gradients separately.
49
};
50
51
enum {
52
  CCV_CNNP_COMPILED_DATA_GRADIENT_NONE,
53
  CCV_CNNP_COMPILED_DATA_GRADIENT_TRAINABLES,
54
  CCV_CNNP_COMPILED_DATA_GRADIENT_TRAINABLES_AND_INPUTS,
55
};
56
57
enum {
58
  CCV_CNNP_REWIND_GRAPH_EXEC,
59
  CCV_CNNP_REWIND_TENSOR,
60
};
61
62
typedef struct {
63
  int type;
64
  union {
65
    ccv_nnc_tensor_symbol_t tensor;
66
    ccv_nnc_graph_exec_symbol_t graph_exec;
67
  };
68
} ccv_cnnp_rewind_symbol_t;
69
70
// This contains relevant information after model compilation.
71
typedef struct {
72
  int graph_mode;
73
  int gradient_mode; // Have init gradient graph.
74
  int is_test;
75
  int stream_type;
76
  int outgrad_size;
77
  uint64_t disable_outgrad;
78
  ccv_nnc_symbolic_graph_compile_param_t compile_params;
79
  ccv_nnc_xpu_alloc_t xpu_alloc;
80
  ccv_nnc_graph_t* graph;
81
  ccv_nnc_tensor_arena_t* tensor_arena;
82
  ccv_nnc_graph_exec_arena_t* graph_exec_arena;
83
  khash_t(stream_map)* stream_map; // Keeps track of streams on both GPU / CPU and devices so it can be used properly during execution.
84
  ccv_array_t* parameters;
85
  ccv_array_t* internals; // Additional symbols need to retain.
86
  ccv_nnc_tensor_symbol_t* gradients;
87
  ccv_nnc_tensor_symbol_t* outgrads;
88
  ccv_nnc_tensor_symbol_t* updated_parameters;
89
  ccv_nnc_graph_exec_symbol_t* update_nodes;
90
  ccv_nnc_tensor_symbol_map_t* saved_aux;
91
  ccv_array_t* rewindables;
92
  struct {
93
    int size;
94
    uint32_t* v;
95
  } tensors_init;
96
  struct {
97
    ccv_nnc_tensor_t** internals; // Additional need to retained tensors.
98
    ccv_nnc_tensor_t** parameters;
99
    ccv_nnc_tensor_t** gradients;
100
    ccv_nnc_tensor_t** accum_gradients;
101
  } tensors;
102
  struct {
103
    ccv_array_t* parameters;
104
    ccv_array_t* internals;
105
  } ids;
106
  struct {
107
    int to_op_size;
108
    int to_size;
109
    ccv_nnc_graph_exec_t* to_ops;
110
    ccv_nnc_graph_exec_symbol_t* tos;
111
    ccv_nnc_graph_static_schedule_t* schedule; // The partial schedule for running evaluate step.
112
  } evaluate; // Data related to ccv_cnnp_model_evaluate
113
  struct {
114
    int count; // Called backward how many times. Starting with 0.
115
    int from_op_size;
116
    ccv_nnc_graph_exec_t* from_ops; // These are the ops in the main graph.
117
    int to_size;
118
    ccv_nnc_graph_exec_symbol_t* tos;
119
    ccv_nnc_graph_t* accum; // The graph to accumulate gradients.
120
    ccv_nnc_tensor_arena_t* tensor_arena;
121
    ccv_nnc_graph_exec_arena_t* graph_exec_arena;
122
    ccv_nnc_tensor_symbol_t* gradients; // The new gradients.
123
    ccv_nnc_tensor_symbol_t* accum_gradients; // The old accumulate gradients.
124
    ccv_nnc_tensor_symbol_t* updated_accum_gradients; // The new accumulate gradients.
125
    ccv_nnc_graph_static_schedule_t* schedule; // The partial schedule for running backward step.
126
  } backward;
127
  struct {
128
    ccv_nnc_graph_t* graph;
129
    ccv_nnc_tensor_arena_t* tensor_arena;
130
    ccv_nnc_graph_exec_arena_t* graph_exec_arena;
131
  } apply_gradients;
132
  struct {
133
    ccv_nnc_cmd_t minimizer;
134
    ccv_array_t* parameters;
135
    int max_saved_aux_size;
136
  } minimize;
137
  ccv_nnc_cmd_t loss;
138
  ccv_nnc_tensor_symbol_t* f;
139
  ccv_nnc_tensor_symbol_t fits[1];
140
} ccv_cnnp_compiled_data_t;
141
142
struct ccv_cnnp_model_s {
143
  const ccv_cnnp_model_vtab_t* isa;
144
  int input_size; // This is the best effort number, mostly just for subclass to use.
145
  int output_size;
146
  ccv_array_t* io; // The opaque io that can be nil.
147
  ccv_array_t* parameter_indices; // The indexes for parameters in the final model.
148
  ccv_nnc_symbolic_graph_t* graph;
149
  ccv_nnc_tensor_symbol_t* inputs; // Unlike outputs, which is not dynamically allocated, inputs is dynamically allocated, and may be 0.
150
  ccv_nnc_tensor_symbol_t* outputs;
151
  char* name;
152
  struct {
153
    ccv_cnnp_model_notify_f func;
154
    void* context;
155
  } notify_hook;
156
  ccv_cnnp_compiled_data_t* compiled_data;
157
  int parallel_count; // How many parallel devices.
158
  int memory_compression; // Whether to enable memory compression for training phase.
159
  size_t workspace_size; // Set the default workspace size.
160
  void* data; // Temporary storage for some internal functions.
161
};
162
163
KHASH_MAP_INIT_STR(ccv_cnnp_model_name_bank, int)
164
165
typedef struct {
166
  int sequence;
167
  khash_t(ccv_cnnp_model_name_bank)* bank;
168
  const char* name;
169
} ccv_cnnp_model_name_t;
170
171
typedef struct {
172
  int it;
173
  ccv_cnnp_model_t* model;
174
  khash_t(ccv_cnnp_model_name_bank)* bank;
175
  ccv_array_t* sequences;
176
} ccv_cnnp_model_sequence_t;
177
178
static inline void ccv_cnnp_model_push(ccv_cnnp_model_t* const self, ccv_cnnp_model_sequence_t* const model_sequence)
179
5.15k
{
180
  // Reset to 0.
181
5.15k
  if (!model_sequence->sequences)
182
2.26k
    model_sequence->sequences = ccv_array_new(sizeof(ccv_cnnp_model_name_t), 1, 0);
183
5.15k
  khash_t(ccv_cnnp_model_name_bank)* bank = model_sequence->sequences->rnum > 0 ? 
((ccv_cnnp_model_name_t*)0
ccv_array_get0
(model_sequence->sequences, model_sequence->sequences->rnum - 1))->bank : model_sequence->bank;
184
5.15k
  int ret;
185
5.15k
  khiter_t k = kh_put(ccv_cnnp_model_name_bank, bank, self->name ? self->name : "", &ret);
186
5.15k
  int sequence;
187
5.15k
  if (ret != 0)
188
2.34k
    sequence = kh_val(bank, k) = 0;
189
2.81k
  else
190
2.81k
    sequence = ++kh_val(bank, k);
191
5.15k
  ccv_cnnp_model_name_t name = {
192
5.15k
    .bank = kh_init(ccv_cnnp_model_name_bank),
193
5.15k
    .name = self->name,
194
5.15k
    .sequence = sequence,
195
5.15k
  };
196
5.15k
  ccv_array_push(model_sequence->sequences, &name);
197
5.15k
  model_sequence->model = self;
198
5.15k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_push
ccv_cnnp_model.c:ccv_cnnp_model_push
Line
Count
Source
179
2.26k
{
180
  // Reset to 0.
181
2.26k
  if (!model_sequence->sequences)
182
1.21k
    model_sequence->sequences = ccv_array_new(sizeof(ccv_cnnp_model_name_t), 1, 0);
183
2.26k
  khash_t(ccv_cnnp_model_name_bank)* bank = model_sequence->sequences->rnum > 0 ? 
((ccv_cnnp_model_name_t*)0
ccv_array_get0
(model_sequence->sequences, model_sequence->sequences->rnum - 1))->bank : model_sequence->bank;
184
2.26k
  int ret;
185
2.26k
  khiter_t k = kh_put(ccv_cnnp_model_name_bank, bank, self->name ? self->name : "", &ret);
186
2.26k
  int sequence;
187
2.26k
  if (ret != 0)
188
1.22k
    sequence = kh_val(bank, k) = 0;
189
1.04k
  else
190
1.04k
    sequence = ++kh_val(bank, k);
191
2.26k
  ccv_cnnp_model_name_t name = {
192
2.26k
    .bank = kh_init(ccv_cnnp_model_name_bank),
193
2.26k
    .name = self->name,
194
2.26k
    .sequence = sequence,
195
2.26k
  };
196
2.26k
  ccv_array_push(model_sequence->sequences, &name);
197
2.26k
  model_sequence->model = self;
198
2.26k
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_push
ccv_cnnp_model_core.c:ccv_cnnp_model_push
Line
Count
Source
179
2.89k
{
180
  // Reset to 0.
181
2.89k
  if (!model_sequence->sequences)
182
1.05k
    model_sequence->sequences = ccv_array_new(sizeof(ccv_cnnp_model_name_t), 1, 0);
183
2.89k
  khash_t(ccv_cnnp_model_name_bank)* bank = model_sequence->sequences->rnum > 0 ? 
((ccv_cnnp_model_name_t*)0
ccv_array_get0
(model_sequence->sequences, model_sequence->sequences->rnum - 1))->bank : model_sequence->bank;
184
2.89k
  int ret;
185
2.89k
  khiter_t k = kh_put(ccv_cnnp_model_name_bank, bank, self->name ? self->name : "", &ret);
186
2.89k
  int sequence;
187
2.89k
  if (ret != 0)
188
1.12k
    sequence = kh_val(bank, k) = 0;
189
1.77k
  else
190
1.77k
    sequence = ++kh_val(bank, k);
191
2.89k
  ccv_cnnp_model_name_t name = {
192
2.89k
    .bank = kh_init(ccv_cnnp_model_name_bank),
193
2.89k
    .name = self->name,
194
2.89k
    .sequence = sequence,
195
2.89k
  };
196
2.89k
  ccv_array_push(model_sequence->sequences, &name);
197
2.89k
  model_sequence->model = self;
198
2.89k
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_push
199
200
static inline void ccv_cnnp_model_pop(const ccv_cnnp_model_t* const self, ccv_cnnp_model_sequence_t* const model_sequence)
201
5.15k
{
202
5.15k
  khash_t(ccv_cnnp_model_name_bank)* const bank = ((ccv_cnnp_model_name_t*)ccv_array_get(model_sequence->sequences, model_sequence->sequences->rnum - 1))->bank;
203
5.15k
  kh_destroy(ccv_cnnp_model_name_bank, bank);
204
5.15k
  --model_sequence->sequences->rnum;
205
5.15k
  assert(model_sequence->sequences->rnum >= 0);
206
5.15k
  model_sequence->model = 0;
207
5.15k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_pop
ccv_cnnp_model.c:ccv_cnnp_model_pop
Line
Count
Source
201
2.26k
{
202
2.26k
  khash_t(ccv_cnnp_model_name_bank)* const bank = ((ccv_cnnp_model_name_t*)ccv_array_get(model_sequence->sequences, model_sequence->sequences->rnum - 1))->bank;
203
2.26k
  kh_destroy(ccv_cnnp_model_name_bank, bank);
204
2.26k
  --model_sequence->sequences->rnum;
205
2.26k
  assert(model_sequence->sequences->rnum >= 0);
206
2.26k
  model_sequence->model = 0;
207
2.26k
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_pop
ccv_cnnp_model_core.c:ccv_cnnp_model_pop
Line
Count
Source
201
2.89k
{
202
2.89k
  khash_t(ccv_cnnp_model_name_bank)* const bank = ((ccv_cnnp_model_name_t*)ccv_array_get(model_sequence->sequences, model_sequence->sequences->rnum - 1))->bank;
203
2.89k
  kh_destroy(ccv_cnnp_model_name_bank, bank);
204
2.89k
  --model_sequence->sequences->rnum;
205
2.89k
  assert(model_sequence->sequences->rnum >= 0);
206
2.89k
  model_sequence->model = 0;
207
2.89k
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_pop
208
209
static inline ccv_cnnp_model_t* _ccv_cnnp_model_copy(const ccv_cnnp_model_t* const model, void* const context)
210
4.30k
{
211
4.30k
  assert(model->isa->copy);
212
4.30k
  return model->isa->copy(model, context);
213
4.30k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:_ccv_cnnp_model_copy
ccv_cnnp_model.c:_ccv_cnnp_model_copy
Line
Count
Source
210
2.21k
{
211
2.21k
  assert(model->isa->copy);
212
2.21k
  return model->isa->copy(model, context);
213
2.21k
}
Unexecuted instantiation: ccv_cnnp_model_io.c:_ccv_cnnp_model_copy
ccv_cnnp_model_core.c:_ccv_cnnp_model_copy
Line
Count
Source
210
2.09k
{
211
2.09k
  assert(model->isa->copy);
212
2.09k
  return model->isa->copy(model, context);
213
2.09k
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:_ccv_cnnp_model_copy
214
215
static inline void ccv_cnnp_model_copy_name(ccv_cnnp_model_t* const self, const char* const name)
216
5.21k
{
217
5.21k
  if (name)
218
109
  {
219
109
    const size_t len = strnlen(name, 63);
220
109
    const size_t n = len + 1;
221
109
    self->name = (char*)ccmalloc(n);
222
    // Don't use strndup because this way I can have custom allocator (for ccmalloc).
223
109
    memcpy(self->name, name, n);
224
109
    self->name[len] = 0;
225
109
  }
226
5.21k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_copy_name
Unexecuted instantiation: ccv_cnnp_model.c:ccv_cnnp_model_copy_name
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_copy_name
ccv_cnnp_model_core.c:ccv_cnnp_model_copy_name
Line
Count
Source
216
1.27k
{
217
1.27k
  if (name)
218
61
  {
219
61
    const size_t len = strnlen(name, 63);
220
61
    const size_t n = len + 1;
221
61
    self->name = (char*)ccmalloc(n);
222
    // Don't use strndup because this way I can have custom allocator (for ccmalloc).
223
61
    memcpy(self->name, name, n);
224
61
    self->name[len] = 0;
225
61
  }
226
1.27k
}
ccv_cnnp_model_addons.c:ccv_cnnp_model_copy_name
Line
Count
Source
216
3.94k
{
217
3.94k
  if (name)
218
48
  {
219
48
    const size_t len = strnlen(name, 63);
220
48
    const size_t n = len + 1;
221
48
    self->name = (char*)ccmalloc(n);
222
    // Don't use strndup because this way I can have custom allocator (for ccmalloc).
223
48
    memcpy(self->name, name, n);
224
48
    self->name[len] = 0;
225
48
  }
226
3.94k
}
227
228
static inline void ccv_cnnp_model_add_to_parameter(ccv_cnnp_model_t* const self, const ccv_cnnp_add_to_array_f add_to_array, void* const parameters)
229
5.16k
{
230
5.16k
  if (self->isa->add_to_parameter)
231
2.58k
    self->isa->add_to_parameter(self, add_to_array, parameters);
232
5.16k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_add_to_parameter
ccv_cnnp_model.c:ccv_cnnp_model_add_to_parameter
Line
Count
Source
229
2.26k
{
230
2.26k
  if (self->isa->add_to_parameter)
231
1.21k
    self->isa->add_to_parameter(self, add_to_array, parameters);
232
2.26k
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_add_to_parameter
ccv_cnnp_model_core.c:ccv_cnnp_model_add_to_parameter
Line
Count
Source
229
2.90k
{
230
2.90k
  if (self->isa->add_to_parameter)
231
1.37k
    self->isa->add_to_parameter(self, add_to_array, parameters);
232
2.90k
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_add_to_parameter
233
234
static inline void ccv_cnnp_model_add_to_output(ccv_cnnp_model_t* const self, const ccv_cnnp_add_to_array_f add_to_array, void* const outputs)
235
5.16k
{
236
5.16k
  if (self->isa->add_to_output)
237
164
    self->isa->add_to_output(self, add_to_array, outputs);
238
5.16k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_add_to_output
ccv_cnnp_model.c:ccv_cnnp_model_add_to_output
Line
Count
Source
235
2.26k
{
236
2.26k
  if (self->isa->add_to_output)
237
8
    self->isa->add_to_output(self, add_to_array, outputs);
238
2.26k
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_add_to_output
ccv_cnnp_model_core.c:ccv_cnnp_model_add_to_output
Line
Count
Source
235
2.90k
{
236
2.90k
  if (self->isa->add_to_output)
237
156
    self->isa->add_to_output(self, add_to_array, outputs);
238
2.90k
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_add_to_output
239
240
typedef struct {
241
  ccv_cnnp_model_sequence_t* model_sequence;
242
  ccv_cnnp_add_to_array_f add_to_array;
243
  ccv_array_t* parameters;
244
  struct {
245
    void* add_to_parameter;
246
    void* add_to_output;
247
  } context;
248
} ccv_cnnp_model_build_data_t; // Host temporary data for building models.
249
250
static inline ccv_nnc_tensor_symbol_t ccv_cnnp_parameter_from_indice(ccv_cnnp_model_t* const self, const int indice)
251
2
{
252
2
  assert(self->data);
253
2
  ccv_cnnp_model_build_data_t* const build_data = (ccv_cnnp_model_build_data_t*)self->data;
254
2
  assert(indice < build_data->parameters->rnum);
255
2
  return *(ccv_nnc_tensor_symbol_t*)ccv_array_get(build_data->parameters, indice);
256
2
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_parameter_from_indice
Unexecuted instantiation: ccv_cnnp_model.c:ccv_cnnp_parameter_from_indice
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_parameter_from_indice
ccv_cnnp_model_core.c:ccv_cnnp_parameter_from_indice
Line
Count
Source
251
2
{
252
2
  assert(self->data);
253
2
  ccv_cnnp_model_build_data_t* const build_data = (ccv_cnnp_model_build_data_t*)self->data;
254
2
  assert(indice < build_data->parameters->rnum);
255
2
  return *(ccv_nnc_tensor_symbol_t*)ccv_array_get(build_data->parameters, indice);
256
2
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_parameter_from_indice
257
258
static inline void ccv_cnnp_model_build(ccv_cnnp_model_t* const self, ccv_nnc_symbolic_graph_t* const graph, const ccv_nnc_tensor_symbol_t* const inputs, const int input_size, ccv_nnc_tensor_symbol_t* const outputs, const int output_size)
259
5.15k
{
260
5.15k
  if (outputs && 
output_size2.88k
)
261
2.88k
  {
262
2.88k
    assert(output_size == self->output_size);
263
2.88k
    self->isa->build(self, graph, inputs, input_size, outputs, output_size);
264
2.88k
    memcpy(self->outputs, outputs, sizeof(ccv_nnc_tensor_symbol_t) * output_size);
265
2.88k
  } else
266
2.27k
    self->isa->build(self, graph, inputs, input_size, self->outputs, self->output_size);
267
5.15k
  assert(self->data);
268
5.15k
  ccv_cnnp_model_build_data_t* const build_data = (ccv_cnnp_model_build_data_t*)self->data;
269
5.15k
  ccv_cnnp_model_push(self, build_data->model_sequence);
270
5.15k
  build_data->model_sequence->it = 0;
271
5.15k
  ccv_cnnp_model_add_to_parameter(self, build_data->add_to_array, build_data->context.add_to_parameter);
272
5.15k
  build_data->model_sequence->it = 0;
273
5.15k
  ccv_cnnp_model_add_to_output(self, build_data->add_to_array, build_data->context.add_to_output);
274
5.15k
  ccv_cnnp_model_pop(self, build_data->model_sequence);
275
5.15k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_build
ccv_cnnp_model.c:ccv_cnnp_model_build
Line
Count
Source
259
2.26k
{
260
2.26k
  if (outputs && 
output_size0
)
261
0
  {
262
0
    assert(output_size == self->output_size);
263
0
    self->isa->build(self, graph, inputs, input_size, outputs, output_size);
264
0
    memcpy(self->outputs, outputs, sizeof(ccv_nnc_tensor_symbol_t) * output_size);
265
0
  } else
266
2.26k
    self->isa->build(self, graph, inputs, input_size, self->outputs, self->output_size);
267
2.26k
  assert(self->data);
268
2.26k
  ccv_cnnp_model_build_data_t* const build_data = (ccv_cnnp_model_build_data_t*)self->data;
269
2.26k
  ccv_cnnp_model_push(self, build_data->model_sequence);
270
2.26k
  build_data->model_sequence->it = 0;
271
2.26k
  ccv_cnnp_model_add_to_parameter(self, build_data->add_to_array, build_data->context.add_to_parameter);
272
2.26k
  build_data->model_sequence->it = 0;
273
2.26k
  ccv_cnnp_model_add_to_output(self, build_data->add_to_array, build_data->context.add_to_output);
274
2.26k
  ccv_cnnp_model_pop(self, build_data->model_sequence);
275
2.26k
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_build
ccv_cnnp_model_core.c:ccv_cnnp_model_build
Line
Count
Source
259
2.89k
{
260
2.89k
  if (outputs && 
output_size2.88k
)
261
2.88k
  {
262
2.88k
    assert(output_size == self->output_size);
263
2.88k
    self->isa->build(self, graph, inputs, input_size, outputs, output_size);
264
2.88k
    memcpy(self->outputs, outputs, sizeof(ccv_nnc_tensor_symbol_t) * output_size);
265
2.88k
  } else
266
8
    self->isa->build(self, graph, inputs, input_size, self->outputs, self->output_size);
267
2.89k
  assert(self->data);
268
2.89k
  ccv_cnnp_model_build_data_t* const build_data = (ccv_cnnp_model_build_data_t*)self->data;
269
2.89k
  ccv_cnnp_model_push(self, build_data->model_sequence);
270
2.89k
  build_data->model_sequence->it = 0;
271
2.89k
  ccv_cnnp_model_add_to_parameter(self, build_data->add_to_array, build_data->context.add_to_parameter);
272
2.89k
  build_data->model_sequence->it = 0;
273
2.89k
  ccv_cnnp_model_add_to_output(self, build_data->add_to_array, build_data->context.add_to_output);
274
2.89k
  ccv_cnnp_model_pop(self, build_data->model_sequence);
275
2.89k
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_build
276
277
static inline void ccv_cnnp_model_init_states(ccv_cnnp_model_t* const self, ccv_nnc_symbolic_graph_t* const graph, const ccv_cnnp_state_initializer_f initializer, void* const context)
278
482
{
279
482
  if (self->isa->init_states)
280
273
    self->isa->init_states(self, graph, initializer, context);
281
482
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_init_states
ccv_cnnp_model.c:ccv_cnnp_model_init_states
Line
Count
Source
278
34
{
279
34
  if (self->isa->init_states)
280
34
    self->isa->init_states(self, graph, initializer, context);
281
34
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_init_states
ccv_cnnp_model_core.c:ccv_cnnp_model_init_states
Line
Count
Source
278
448
{
279
448
  if (self->isa->init_states)
280
239
    self->isa->init_states(self, graph, initializer, context);
281
448
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_init_states
282
283
static inline void ccv_cnnp_model_set_is_test(ccv_cnnp_model_t* const self, const int is_test, const ccv_cnnp_cmd_updater_f updater, void* const context)
284
945
{
285
945
  if (self->isa->set_is_test)
286
211
    self->isa->set_is_test(self, is_test, updater, context);
287
945
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_set_is_test
ccv_cnnp_model.c:ccv_cnnp_model_set_is_test
Line
Count
Source
284
91
{
285
91
  if (self->isa->set_is_test)
286
69
    self->isa->set_is_test(self, is_test, updater, context);
287
91
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_set_is_test
ccv_cnnp_model_core.c:ccv_cnnp_model_set_is_test
Line
Count
Source
284
854
{
285
854
  if (self->isa->set_is_test)
286
142
    self->isa->set_is_test(self, is_test, updater, context);
287
854
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_set_is_test
288
289
static inline void ccv_cnnp_model_add_to_parameter_indices(ccv_cnnp_model_t* const self, const int index, ccv_array_t* const parameter_indices)
290
13.2k
{
291
13.2k
  if (self->isa->add_to_parameter_indices)
292
3.59k
    self->isa->add_to_parameter_indices(self, index, parameter_indices);
293
9.69k
  else {
294
9.69k
    int i;
295
9.69k
    if (!self->parameter_indices)
296
4.59k
      return;
297
5.10k
    if (index == -1)
298
150
      
for (i = 0; 93
i < self->parameter_indices->rnum;
i++57
)
299
57
        ccv_array_push(parameter_indices, ccv_array_get(self->parameter_indices, i));
300
5.00k
    else if (index < self->parameter_indices->rnum)
301
5.00k
      ccv_array_push(parameter_indices, ccv_array_get(self->parameter_indices, index));
302
5.10k
  }
303
13.2k
}
Unexecuted instantiation: ccv_nnc_dynamic_graph_evaluate.c:ccv_cnnp_model_add_to_parameter_indices
ccv_cnnp_model.c:ccv_cnnp_model_add_to_parameter_indices
Line
Count
Source
290
360
{
291
360
  if (self->isa->add_to_parameter_indices)
292
339
    self->isa->add_to_parameter_indices(self, index, parameter_indices);
293
21
  else {
294
21
    int i;
295
21
    if (!self->parameter_indices)
296
0
      return;
297
21
    if (index == -1)
298
30
      
for (i = 0; 15
i < self->parameter_indices->rnum;
i++15
)
299
15
        ccv_array_push(parameter_indices, ccv_array_get(self->parameter_indices, i));
300
6
    else if (index < self->parameter_indices->rnum)
301
6
      ccv_array_push(parameter_indices, ccv_array_get(self->parameter_indices, index));
302
21
  }
303
360
}
Unexecuted instantiation: ccv_cnnp_model_io.c:ccv_cnnp_model_add_to_parameter_indices
ccv_cnnp_model_core.c:ccv_cnnp_model_add_to_parameter_indices
Line
Count
Source
290
12.9k
{
291
12.9k
  if (self->isa->add_to_parameter_indices)
292
3.25k
    self->isa->add_to_parameter_indices(self, index, parameter_indices);
293
9.67k
  else {
294
9.67k
    int i;
295
9.67k
    if (!self->parameter_indices)
296
4.59k
      return;
297
5.08k
    if (index == -1)
298
120
      
for (i = 0; 78
i < self->parameter_indices->rnum;
i++42
)
299
42
        ccv_array_push(parameter_indices, ccv_array_get(self->parameter_indices, i));
300
5.00k
    else if (index < self->parameter_indices->rnum)
301
5.00k
      ccv_array_push(parameter_indices, ccv_array_get(self->parameter_indices, index));
302
5.08k
  }
303
12.9k
}
Unexecuted instantiation: ccv_cnnp_model_addons.c:ccv_cnnp_model_add_to_parameter_indices
304
305
void ccv_cnnp_model_tensors_init(const ccv_cnnp_model_t* const model, ccv_cnnp_compiled_data_t* const compiled_data);
306
ccv_nnc_stream_context_t* ccv_cnnp_compiled_data_get_stream(ccv_cnnp_compiled_data_t* const compiled_data, const int type);
307
308
#endif