const auto &model_obj = _graph.operands().at(index);
// For only CONSTANTS
- if (model_obj.getUsage() != neurun::model::operand::OperandUsage::CONSTANT)
+ if (model_obj.usage() != neurun::model::operand::Usage::CONSTANT)
return;
auto type = model_obj.typeInfo().type();
auto axis_index = node.param().axis_index;
// To prepare concat elimination, axis should be constant
- if (_ctx.at(axis_index).getUsage() != model::operand::OperandUsage::CONSTANT)
+ if (_ctx.at(axis_index).usage() != model::operand::Usage::CONSTANT)
{
VERBOSE(SUBTENSOR) << "Cannot handle non-constant axis" << std::endl;
return;
operands.iterate([&](const model::operand::Index &index, const model::operand::Object &object) {
bool showing_cond = false;
- auto usage = object.getUsage();
+ auto usage = object.usage();
if (_option == OPTIONS::SHOW_CONSTANTS)
{
showing_cond = object.usageIsDefined();
}
else
{
- showing_cond = (usage == model::operand::OperandUsage::MODEL_INPUT) ||
- (usage == model::operand::OperandUsage::OPERATION_OUTPUT);
+ showing_cond = (usage == model::operand::Usage::MODEL_INPUT) ||
+ (usage == model::operand::Usage::OPERATION_OUTPUT);
}
- if (usage != model::operand::OperandUsage::OPERATION_OUTPUT)
+ if (usage != model::operand::Usage::OPERATION_OUTPUT)
{
showing_cond = showing_cond && (object.getUses().size() > 0);
}
{
return ANEURALNETWORKS_BAD_DATA;
}
- if (!obj.setAsConstant())
+ if (!obj.usage(neurun::model::operand::Usage::CONSTANT))
{
return ANEURALNETWORKS_BAD_DATA;
}
{
return ANEURALNETWORKS_BAD_DATA;
}
- if (!obj.setAsConstant())
+ if (!obj.usage(neurun::model::operand::Usage::CONSTANT))
{
return ANEURALNETWORKS_BAD_DATA;
}
const ::neurun::model::operand::Index ind{outputs[i]};
auto &obj = model->deref().operands().at(ind);
- if (!obj.setAsOperationOutput())
+ if (!obj.usage(neurun::model::operand::Usage::OPERATION_OUTPUT))
{
return ANEURALNETWORKS_BAD_DATA;
}
const ::neurun::model::operand::Index ind{outputs[i]};
auto &obj = model->deref().operands().at(ind);
- if (!obj.setAsOperationOutput())
+ if (!obj.usage(neurun::model::operand::Usage::OPERATION_OUTPUT))
{
return ANEURALNETWORKS_BAD_DATA;
}
model->deref().addInput(ind);
auto &obj = model->deref().operands().at(ind);
- if (!obj.setAsModelInput())
+ if (!obj.usage(neurun::model::operand::Usage::MODEL_INPUT))
{
return ANEURALNETWORKS_BAD_DATA;
}
// Generate output operand and permute operation
auto out_operand_index = _graph.addOperand(operand.shape(), operand.typeInfo());
auto &out_operand = _graph.operands().at(out_operand_index);
- out_operand.setAsOperationOutput();
+ out_operand.usage(model::operand::Usage::OPERATION_OUTPUT);
// change model output if operand_index is model output index
auto &model_outputs = _graph.getOutputs();
if (model_outputs.contains(operand_index))
{
model_outputs.replace(operand_index, out_operand_index);
}
- out_operand.setAsOperationOutput();
+ out_operand.usage(model::operand::Usage::OPERATION_OUTPUT);
auto out_operand_li =
nnfw::cpp14::make_unique<operand::LowerInfo>(operand::asShape4D(operand.shape()));
out_operand_li->addDefBackend(backend);
// If a tensor is a constant, increase the use of the tensor.
// It makes the tensor not be dealloced.
- if (obj.getUsage() == model::operand::OperandUsage::CONSTANT)
+ if (obj.usage() == model::operand::Usage::CONSTANT)
{
constants.push_back(ind);
uses_map[ind]++;
return element_size * elements;
}
-bool Object::setUsage(const OperandUsage usage)
+bool Object::usage(const Usage usage)
{
if (usageIsDefined() && (_usage != usage))
{
void Object::appendUse(const ::neurun::model::operation::Index &idx)
{
- assert(_usage != OperandUsage::NOT_DEFINED);
+ assert(_usage != Usage::NOT_DEFINED);
assert(!_uses.contains(idx));
_uses.append(idx);
void Object::removeUse(const ::neurun::model::operation::Index &idx)
{
- assert(_usage != OperandUsage::NOT_DEFINED);
+ assert(_usage != Usage::NOT_DEFINED);
assert(_uses.contains(idx));
_uses.remove(idx);
void Object::appendDef(const ::neurun::model::operation::Index &idx)
{
- assert(_usage != OperandUsage::NOT_DEFINED && _usage != OperandUsage::CONSTANT);
+ assert(_usage != Usage::NOT_DEFINED && _usage != Usage::CONSTANT);
assert(_def.size() == 0);
_def.append(idx);
void Object::removeDef(const ::neurun::model::operation::Index &idx)
{
- assert(_usage != OperandUsage::NOT_DEFINED);
+ assert(_usage != Usage::NOT_DEFINED);
assert(_def.contains(idx));
_def.remove(idx);
{
// Operand usage should be exact one of these
-enum class OperandUsage
+enum class Usage
{
NOT_DEFINED,
MODEL_INPUT,
{
public:
explicit Object(const Shape &shape, const TypeInfo &type)
- : _shape{shape}, _type{type}, _usage{OperandUsage::NOT_DEFINED}
+ : _shape{shape}, _type{type}, _usage{Usage::NOT_DEFINED}
{
// DO NOTHING
}
const Shape &shape(void) const { return _shape; }
const TypeInfo &typeInfo(void) const { return _type; }
size_t operandSize(void) const;
- bool setAsConstant() { return setUsage(OperandUsage::CONSTANT); }
- bool setAsModelInput() { return setUsage(OperandUsage::MODEL_INPUT); }
- bool setAsOperationOutput() { return setUsage(OperandUsage::OPERATION_OUTPUT); }
- bool usageIsDefined(void) const { return _usage != OperandUsage::NOT_DEFINED; }
- bool isModelInput(void) const { return _usage == OperandUsage::MODEL_INPUT; }
- OperandUsage getUsage() const { return _usage; }
+ bool usageIsDefined(void) const { return _usage != Usage::NOT_DEFINED; }
+ bool isModelInput(void) const { return _usage == Usage::MODEL_INPUT; }
+ Usage usage() const { return _usage; }
+ bool usage(Usage usage);
const operation::IndexList &getUses() const { return _uses; }
const operation::IndexList &getDef() const { return _def; }
void appendDef(const operation::Index &idx);
void removeDef(const operation::Index &idx);
-private:
- bool setUsage(OperandUsage usage);
-
public:
void data(std::unique_ptr<Data> &&data) { _data = std::move(data); }
const Data &data(void) const { return *_data; }
const Shape _shape;
const TypeInfo _type;
std::unique_ptr<Data> _data;
- OperandUsage _usage;
+ Usage _usage;
operation::IndexList _uses;
operation::IndexList _def; // size is 0 (constant) or 1 (from def operation)
auto output_operand = graph.addOperand(shape, type);
graph.addInput(input_operand);
- graph.operands().at(input_operand).setAsModelInput();
+ graph.operands().at(input_operand).usage(neurun::model::operand::Usage::MODEL_INPUT);
graph.addOutput(output_operand);
- graph.operands().at(output_operand).setAsOperationOutput();
+ graph.operands().at(output_operand).usage(neurun::model::operand::Usage::OPERATION_OUTPUT);
// MockNode1
auto operand_index1 = graph.addOperand(shape, type);
- graph.operands().at(operand_index1).setAsOperationOutput();
+ graph.operands().at(operand_index1).usage(neurun::model::operand::Usage::OPERATION_OUTPUT);
auto mocknode_index1 = graph.addOperation(
nnfw::cpp14::make_unique<MockNode>(IndexSet{input_operand}, IndexSet{operand_index1}));
// MockNode2
auto operand_index2 = graph.addOperand(shape, type);
- graph.operands().at(operand_index2).setAsOperationOutput();
+ graph.operands().at(operand_index2).usage(neurun::model::operand::Usage::OPERATION_OUTPUT);
auto mocknode_index2 = graph.addOperation(
nnfw::cpp14::make_unique<MockNode>(IndexSet{input_operand}, IndexSet{operand_index2}));
auto operand2 = graph.addOperand(shape, type);
graph.addInput(operand1);
- graph.operands().at(operand1).setAsModelInput();
+ graph.operands().at(operand1).usage(neurun::model::operand::Usage::MODEL_INPUT);
graph.addOutput(operand2);
- graph.operands().at(operand2).setAsOperationOutput();
+ graph.operands().at(operand2).usage(neurun::model::operand::Usage::OPERATION_OUTPUT);
graph.addOperation(nnfw::cpp14::make_unique<MockNode>(IndexSet{operand1}, IndexSet{operand2}));