| 53 | } |
| 54 | |
| 55 | ITensor *IWeightsManager::run(const ITensor *weights, ITransformWeights *weights_transform) |
| 56 | { |
| 57 | ARM_COMPUTE_ERROR_ON_MSG(!are_weights_managed(weights), "Cannot run function. Weights are not managed"); |
| 58 | |
| 59 | // Find if I have the same weights with weights transform. If I do, don't run the reshape |
| 60 | auto item = _managed_weights.find(weights); |
| 61 | bool perform_run{true}; |
| 62 | ITensor *weights_tensor{nullptr}; |
| 63 | |
| 64 | // Check if I already have the requested transform and I have run the reshape function |
| 65 | for (auto it : item->second) |
| 66 | { |
| 67 | if (it->is_reshape_run() && (it->uid() == weights_transform->uid())) |
| 68 | { |
| 69 | weights_tensor = it->get_weights(); |
| 70 | perform_run = false; |
| 71 | break; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if (perform_run) |
| 76 | { |
| 77 | weights_transform->run(); |
| 78 | weights_tensor = weights_transform->get_weights(); |
| 79 | } |
| 80 | |
| 81 | // Check if we can release memory from parent |
| 82 | auto parent_item = _managed_weights_parents.find(weights); |
| 83 | if (parent_item != _managed_weights_parents.end()) |
| 84 | { |
| 85 | int32_t refcount = parent_item->second->decrease_refcount(); |
| 86 | if (refcount == 0) |
| 87 | { |
| 88 | parent_item->second->release(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Check top level weights. If all the transformations are done |
| 93 | // mark the weights as unused |
| 94 | if (_managed_weights_parents.find(weights) == _managed_weights_parents.end()) |
| 95 | { |
| 96 | auto item = _managed_weights.find(weights); |
| 97 | bool mark_as_unused = true; |
| 98 | for (auto it : item->second) |
| 99 | { |
| 100 | if (!it->is_reshape_run()) |
| 101 | { |
| 102 | mark_as_unused = false; |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (mark_as_unused) |
| 108 | { |
| 109 | weights->mark_as_unused(); |
| 110 | } |
| 111 | } |
| 112 |
nothing calls this directly
no test coverage detected