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

Function postprocess_weight_memory

runtime/src/init.c:59–92  ·  view source on GitHub ↗

update the opr weights index with the init weight, if origin weights is no need, share it or free it

Source from the content-addressed store, hash-verified

57//! update the opr weights index with the init weight, if
58//! origin weights is no need, share it or free it
59static void postprocess_weight_memory(
60 Opr* opr, DeviceModel* model, Tensor* new_weight) {
61 for (int j = 0; j < opr->nr_input; j++) {
62 Tensor* old_weight = (Tensor*)(*(opr->inputs + j));
63 //! FIXME: maybe name is not suitable
64 if (new_weight->name == old_weight->name) {
65 TINYNN_ASSERT(new_weight->name != NULL);
66 LOG_DEBUG(
67 "opr symbol %s preprocessed weights "
68 ":%s.\n",
69 opr->type, old_weight->name);
70 old_weight->use_count -= 1;
71 if (old_weight->use_count <= 0) {
72 if (!old_weight->is_shared) {
73 model->device.free(old_weight->ptr);
74 old_weight->ptr = NULL;
75 LOG_DEBUG(
76 "opr symbol %s free preprocessed weights: % s.\n ",
77 opr->type, old_weight->name);
78 } else if (old_weight->size >= new_weight->size) {
79 memcpy(old_weight->ptr, new_weight->ptr, new_weight->size);
80 model->device.free(new_weight->ptr);
81 LOG_DEBUG(
82 "processed weights share memory with old "
83 "weights\n");
84 new_weight->ptr = old_weight->ptr;
85 new_weight->is_shared = 1;
86 }
87 }
88 *(opr->inputs + j) = new_weight;
89 break;
90 }
91 }
92}
93
94static size_t get_opr_weights_process_size(
95 Opr* opr, DeviceModel* model, Tensor* weight) {

Callers 1

init_signle_device_modelFunction · 0.85

Calls 1

freeMethod · 0.45

Tested by

no test coverage detected