backend::TensorBuilderSet tensor_builders;
model::OperandIndexMap<std::shared_ptr<backend::ITensorBuilder>> tensor_builder_map;
- // TODO Add maps which support for subtensors
+ // NOTE
+ // While current ITensorBuilder exposes registerSubTensorInfo for subtensor,
+ // this stage uses registerSubTensorInfo() and notify{First|Last}Use()
+ // but handling subtensor should be processed on each backend. See #5726.
model::OperandIndexMap<uint32_t> uses_map;
model::OperandIndexMap<uint32_t> def_map;
model::OperandIndexSequence constants;
uses_map[ind] = obj.getUses().size();
def_map[ind] = obj.getDef().size(); // should be 1 or 0
- // If a tensor is a constant, increase the use of the tensor.
- // It makes the tensor not be dealloced.
if (obj.isConstant())
{
constants.append(ind);
- uses_map[ind]++;
}
for (auto factor : lower_info->def_factors())
// This aim is same to above one.
for (const auto &ind : _model->outputs)
{
- assert(uses_map.find(ind) != uses_map.end());
uses_map[ind]++;
}
- // Start scanning
- // Allocate constant operands first
+ // Start scanning to do notify{First|Last}Use for each tensor
+
+ // If a tensor is a constant, increase the use of the tensor.
+ // It makes the tensor not be dealloced. It means these will be deallocated last.
+ // And allocate constant operands first
VERBOSE(LINEAR) << "TENSORS as CONSTANT" << std::endl;
for (const auto &ind : constants)
{
+ uses_map[ind]++;
tensor_builder_map[ind]->notifyFirstUse(ind);
}
}
// At each operation,
- // 1. Scan USE of inputs. Decrease the USE and deallocate if the USE is 0
- // 2. Scan DEF of outputs. If the DEF, allocate it
+ // 1. Scan DEF of outputs. If the DEF, allocate it
+ // 2. Scan USE of inputs. Decrease the USE and deallocate if the USE is 0
VERBOSE(LINEAR) << "TENSORS" << std::endl;
for (const auto &e : *_elements)
{
for (const auto &ind : _model->outputs)
{
--uses_map[ind];
+ assert(uses_map[ind] == 0);
tensor_builder_map[ind]->notifyLastUse(ind);
}
for (const auto &ind : constants)
+ {
--uses_map[ind];
+ assert(uses_map[ind] == 0);
+ tensor_builder_map[ind]->notifyLastUse(ind);
+ }
assert(std::all_of(
uses_map.begin(), uses_map.end(),