MCPcopy Create free account
hub / github.com/MegEngine/MegCC / is_likely_multi_device_model

Function is_likely_multi_device_model

runtime/src/init.c:244–297  ·  view source on GitHub ↗

! likely device model condition: * 1. same number of instruction * 2. same instruction type of every instruction * 3. same init function id * 4. same weights id * 5. same processed weights layout */

Source from the content-addressed store, hash-verified

242 * 5. same processed weights layout
243 */
244static int is_likely_multi_device_model(CombineModel* combo_model) {
245 //! compute the tensor memory ptr
246 for (int model_idx = 1; model_idx < combo_model->nr_device_model; ++model_idx) {
247 DeviceModel* model = combo_model->device_models[model_idx];
248 DeviceModel* model0 = combo_model->device_models[0];
249 //! if instruction is not equal, return 0
250 if (model->nr_instruction != model0->nr_instruction) {
251 return 0;
252 }
253 int nr_instruction = model->nr_instruction;
254 for (int ins_idx = 0; ins_idx < nr_instruction; ins_idx++) {
255 Instruction* ins0 = model0->instructions + ins_idx;
256 Instruction* ins = model->instructions + ins_idx;
257 //! if each instruction type is not equal, return 0
258 if (ins0->tag != ins->tag) {
259 return 0;
260 }
261 if (ins0->tag == TinyNN_INST_OPR) {
262 Opr* opr0 = &ins0->workload.opr;
263 Opr* opr = &ins->workload.opr;
264 if (opr0->init_func >= 0 && opr0->init_func < NR_INIT) {
265 //! if each instruction init function is not equal,
266 //! return 0
267 if (opr0->init_func != opr->init_func) {
268 return 0;
269 }
270 InitFunc init = init_kernels[opr0->init_func];
271
272 Tensor tmp_weights0, tmp_weights;
273 init(opr0->inputs, opr0->nr_input, &tmp_weights0, NULL,
274 &model->opt);
275 init(opr->inputs, opr->nr_input, &tmp_weights, NULL, &model->opt);
276 if (!is_equal_tensor_layout(&tmp_weights, &tmp_weights0)) {
277 return 0;
278 }
279 }
280 if (opr0->nr_input != opr->nr_input) {
281 return 0;
282 }
283 for (int input_idx = 0; input_idx < opr0->nr_input; input_idx++) {
284 if (!opr0->inputs[input_idx]->is_weight) {
285 continue;
286 } else {
287 //! each opr weight is the same
288 if (opr->inputs[input_idx] != opr0->inputs[input_idx]) {
289 return 0;
290 }
291 }
292 }
293 }
294 }
295 }
296 return 1;
297}
298
299static TinyNNStatus init_multi_likely_device_model(CombineModel* combo_model) {
300 DeviceModel* model = combo_model->device_models[0];

Callers 1

init_model_weightsFunction · 0.85

Calls 1

is_equal_tensor_layoutFunction · 0.85

Tested by

no test coverage detected