Coverage Report

Created: 2021-04-11 20:23

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