| 297 | } |
| 298 | |
| 299 | static TinyNNStatus init_multi_likely_device_model(CombineModel* combo_model) { |
| 300 | DeviceModel* model = combo_model->device_models[0]; |
| 301 | int nr_instruction = model->nr_instruction; |
| 302 | int total_processed_weights = count_total_processed_weights_number(combo_model, 0); |
| 303 | LOG_DEBUG("calc total_processed_weights done\n"); |
| 304 | if (total_processed_weights < 1) { |
| 305 | return TinyNN_SUCCESS; |
| 306 | } |
| 307 | //! allocate the processed memory |
| 308 | |
| 309 | for (int model_idx = 0; model_idx < combo_model->nr_device_model; ++model_idx) { |
| 310 | if (model_idx == 0) { |
| 311 | DeviceModel* model = combo_model->device_models[model_idx]; |
| 312 | model->nr_processed_weight = total_processed_weights; |
| 313 | model->processed_weights = |
| 314 | tinynn_malloc(total_processed_weights * sizeof(Tensor)); |
| 315 | memset(model->processed_weights, 0, |
| 316 | total_processed_weights * sizeof(Tensor)); |
| 317 | } else { |
| 318 | DeviceModel* model = combo_model->device_models[model_idx]; |
| 319 | //! this model will share weights from model0 |
| 320 | model->nr_processed_weight = 0; |
| 321 | model->processed_weights = NULL; |
| 322 | } |
| 323 | } |
| 324 | int processed_weights_index = 0; |
| 325 | for (int i = 0; i < nr_instruction; i++) { |
| 326 | Instruction* inst = model->instructions + i; |
| 327 | if (inst->tag == TinyNN_INST_OPR) { |
| 328 | Opr* opr = &inst->workload.opr; |
| 329 | int size = get_ins_nr_processed_weights(opr, model); |
| 330 | if (size == 1) { |
| 331 | Tensor* weight = model->processed_weights + processed_weights_index; |
| 332 | init_ins_weights(opr, model, weight); |
| 333 | broadcast_postprocess_weight_memory(i, combo_model, weight); |
| 334 | processed_weights_index += size; |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | return TinyNN_SUCCESS; |
| 339 | } |
| 340 | |
| 341 | TinyNNStatus init_model_weights(CombineModel* combo_model) { |
| 342 | if (!combo_model) { |
no test coverage detected