Skip to content

Commit

Permalink
Revert commits (Samsung#7965)
Browse files Browse the repository at this point in the history
This commit reverts some commits to resolve one-cmds test fail.

ONE-DCO-1.0-Signed-off-by: seongwoo <[email protected]>
  • Loading branch information
mhs4670go authored Nov 10, 2021
1 parent 939f42d commit fa8b943
Show file tree
Hide file tree
Showing 35 changed files with 192 additions and 335 deletions.
4 changes: 1 addition & 3 deletions compiler/luci/import/include/luci/Import/CircleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ luci_quantparam(const circle::QuantizationParameters *quantization);
void copy_tensor_attributes(const circle::TensorT &tensor, CircleNode *node);
void copy_tensor_attributes(const circle::Tensor *tensor, CircleNode *node);

std::string fb_string2std_string(const flatbuffers::String *fb_str);

/**
* @brief Wrapper to use flatbuffers::Vector pointer as std::vector entity
*/
Expand Down Expand Up @@ -148,7 +146,7 @@ class CircleReader
CircleOperators native_operators() const { return wrap(_native_subgraph->operators()); }
VectorWrapper<int32_t> native_inputs() const { return wrap(_native_subgraph->inputs()); }
VectorWrapper<int32_t> native_outputs() const { return wrap(_native_subgraph->outputs()); }
std::string native_name() const { return fb_string2std_string(_native_subgraph->name()); }
std::string native_name() const { return _native_subgraph->name()->str(); }
circle::DataFormat native_data_format() const { return _native_subgraph->data_format(); }
CircleMetadataSet native_metadata() const { return wrap(_native_model->metadata()); }

Expand Down
16 changes: 7 additions & 9 deletions compiler/luci/import/src/CircleImportMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,19 @@ namespace luci

CircleImportMetadata::CircleImportMetadata(const luci::CircleReader &reader)
{
const auto metadata = reader.native_metadata();
const auto &metadata = reader.metadata();
for (uint32_t i = 0; i < metadata.size(); ++i)
{
const auto *meta = metadata[i];
assert(meta != nullptr);
const circle::MetadataT &meta = *metadata[i];

assert(meta->buffer() < reader.buffers().size());
const std::vector<uint8_t> &buffer = reader.buffers()[meta->buffer()]->data;
assert(meta.buffer < reader.buffers().size());
const std::vector<uint8_t> &buffer = reader.buffers()[meta.buffer]->data;

assert(meta->name() != nullptr);
if (meta->name()->str().compare("ONE_op_table") == 0)
if (meta.name.compare("ONE_op_table") == 0)
_op_table = decoded_op_table(buffer);
else if (meta->name()->str().compare("ONE_source_table") == 0)
else if (meta.name.compare("ONE_source_table") == 0)
_source_table = decoded_source_table(buffer);
else if (meta->name()->str().compare("ONE_execution_plan_table") == 0)
else if (meta.name.compare("ONE_execution_plan_table") == 0)
_execution_plan_table = decoded_execution_plan(buffer);
}
}
Expand Down
37 changes: 0 additions & 37 deletions compiler/luci/import/src/CircleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,6 @@ void copy_tensor_attributes(const circle::Tensor *tensor, CircleNode *node)
}
}

std::string fb_string2std_string(const flatbuffers::String *fb_str)
{
return fb_str == nullptr ? "" : fb_str->str();
}

circle::BuiltinOperator CircleReader::builtin_code(const circle::OperatorT &op) const
{
const auto &op_codes = opcodes();
Expand All @@ -423,19 +418,6 @@ circle::BuiltinOperator CircleReader::builtin_code(const circle::OperatorT &op)
return opcode.builtin_code;
}

circle::BuiltinOperator CircleReader::builtin_code(const circle::Operator *op) const
{
assert(op != nullptr);

const auto op_codes = native_opcodes();
uint32_t index = op->opcode_index();
assert(index < op_codes.size());
const auto opcode = op_codes[index];
assert(opcode != nullptr);

return opcode->builtin_code();
}

std::string CircleReader::opcode_name(const circle::OperatorT &op) const
{
const auto &op_codes = opcodes();
Expand All @@ -453,25 +435,6 @@ std::string CircleReader::opcode_name(const circle::OperatorT &op) const
return ::luci::opcode_name(opcode);
}

std::string CircleReader::opcode_name(const circle::Operator *op) const
{
assert(op != nullptr);

const auto op_codes = native_opcodes();
uint32_t index = op->opcode_index();
assert(index < op_codes.size());
const auto opcode = op_codes[index];

if (!is_valid(opcode))
{
std::ostringstream oss;
oss << "(invalid: " << index << ")";
return oss.str();
}

return ::luci::opcode_name(opcode);
}

bool CircleReader::parse(const circle::Model *model)
{
assert(model != nullptr);
Expand Down
15 changes: 7 additions & 8 deletions compiler/luci/import/src/GraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ CircleNode *GraphBuilder::build(const circle::OperatorT &op, GraphBuilderContext

const std::vector<int32_t> &inputs = op.inputs;
const std::vector<int32_t> &outputs = op.outputs;
const auto tensors = context->reader()->native_tensors();
const auto opcodes = context->reader()->native_opcodes();
assert(!tensors.null());
const auto &tensors = context->reader()->tensors();
const auto &opcodes = context->reader()->opcodes();
auto tensors_ptr = context->reader()->tensors_ptr();
assert(tensors_ptr != nullptr);

std::vector<CircleNode *> input_nodes;
for (const int32_t input_tensor_index : inputs)
Expand Down Expand Up @@ -59,18 +60,16 @@ CircleNode *GraphBuilder::build(const circle::OperatorT &op, GraphBuilderContext
// Set up node parameters.
assert(outputs.size() == 1);
{
const auto output_tensor = tensors[outputs[0]];
assert(output_tensor != nullptr);
const circle::TensorT &output_tensor = *tensors[outputs[0]];
copy_tensor_attributes(output_tensor, node);
// mark shape_status
if (output_tensor->shape() == nullptr)
if (tensors_ptr->Get(outputs[0])->shape() == nullptr)
node->shape_status(ShapeStatus::NOSHAPE);
else
node->shape_status(ShapeStatus::VALID);

// mark operator version
assert(opcodes[op.opcode_index] != nullptr);
node->op_version(opcodes[op.opcode_index]->version());
node->op_version(opcodes[op.opcode_index].get()->version);
}

// Register node's only output.
Expand Down
20 changes: 9 additions & 11 deletions compiler/luci/import/src/GraphBuilderMultiOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ CircleNode *GraphBuilderMultiOutput::build(const circle::OperatorT &op,

const std::vector<int32_t> &inputs = op.inputs;
const std::vector<int32_t> &outputs = op.outputs;
const auto tensors = context->reader()->native_tensors();
const auto opcodes = context->reader()->native_opcodes();
assert(!tensors.null());
const auto &tensors = context->reader()->tensors();
const auto &opcodes = context->reader()->opcodes();
auto tensors_ptr = context->reader()->tensors_ptr();
assert(tensors_ptr != nullptr);

std::vector<CircleNode *> input_nodes;
for (const int32_t input_tensor_index : inputs)
Expand Down Expand Up @@ -63,31 +64,28 @@ CircleNode *GraphBuilderMultiOutput::build(const circle::OperatorT &op,
if (output_count > 0)
{
// Let's use attributes from output 0 for this node
const auto output_tensor = tensors[outputs[0]];
assert(output_tensor != nullptr);
const circle::TensorT &output_tensor = *tensors[outputs[0]];
node->name(tensor_name(output_tensor));
node->dtype(luci_datatype(output_tensor->type()));
node->dtype(luci_datatype(output_tensor.type));

// mark operator version
assert(opcodes[op.opcode_index] != nullptr);
node->op_version(opcodes[op.opcode_index]->version());
node->op_version(opcodes[op.opcode_index].get()->version);

// NOTE We don't set quantization for multiple output nodes but to virtual outputs
}

// Create virtual outputs of Virtual Output node(s)
for (uint32_t n = 0; n < output_count; ++n)
{
const auto output_tensor = tensors[outputs[n]];
assert(output_tensor != nullptr);
const circle::TensorT &output_tensor = *tensors[outputs[n]];

BuildOutArgs boa(node, n);
auto *nodeout = build_out(boa);

copy_tensor_attributes(output_tensor, nodeout);
// NOTE name of CxxxOut nodes may have same name
// mark shape_status
if (output_tensor->shape() == nullptr)
if (tensors_ptr->Get(outputs[n])->shape() == nullptr)
nodeout->shape_status(ShapeStatus::NOSHAPE);
else
nodeout->shape_status(ShapeStatus::VALID);
Expand Down
61 changes: 25 additions & 36 deletions compiler/luci/import/src/Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r

luci::GraphBuilderContext gb_context(graph, &reader, nodefinder.get(), tensoroutputs.get());

const auto operators = reader.native_operators();
const auto tensors = reader.native_tensors();
assert(!tensors.null());
const auto &operators = reader.operators();
const auto &tensors = reader.tensors();
auto tensors_ptr = reader.tensors_ptr();
assert(tensors_ptr != nullptr);
auto circle_metadata = std::make_unique<luci::CircleImportMetadata>(reader);

// build a cache to identify if a tensor is output of an operator
// if this is set, we should not create a CircleConst for this tensor
for (uint32_t i = 0; i < operators.size(); ++i)
{
const auto op = operators[i];
assert(op != nullptr);
const auto outputs = luci::wrap(op->outputs());
const circle::OperatorT &op = *operators[i];
const auto &outputs = op.outputs;

for (uint32_t j = 0; j < outputs.size(); ++j)
{
Expand All @@ -73,15 +73,14 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r
// graph inputs; there are no input nodes in TFlite but just Tensors
// creating virtual input nodes will make possible to connect nodes that uses them
// all attributes of tensor should be copied to CircleInput node
for (const auto input : reader.native_inputs())
for (const auto input : reader.inputs())
{
auto input_node = graph->nodes()->create<luci::CircleInput>();
assert(input_node != nullptr);
const auto tensor = tensors[input];
assert(tensor != nullptr);
const circle::TensorT &tensor = *tensors[input];

luci::copy_tensor_attributes(tensor, input_node);
if (tensor->shape() == nullptr)
if (tensors_ptr->Get(input)->shape() == nullptr)
input_node->shape_status(luci::ShapeStatus::NOSHAPE);
else
input_node->shape_status(luci::ShapeStatus::VALID);
Expand All @@ -102,18 +101,16 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r
// Data type
graph_input->dtype(input_node->dtype());

const auto tensor_shape_signature = luci::wrap(tensor->shape_signature());
const auto tensor_shape = luci::wrap(tensor->shape());
assert(tensor_shape_signature.size() == 0 ||
tensor_shape_signature.size() == tensor_shape.size());
assert(tensor.shape_signature.size() == 0 ||
tensor.shape_signature.size() == tensor.shape.size());

// Shape of GraphInput
auto input_shape = std::make_unique<loco::TensorShape>();
const auto &input_dims = tensor_shape; // in NHWC
const std::vector<int32_t> &input_dims = tensor.shape; // in NHWC
input_shape->rank(input_dims.size());
for (uint32_t r = 0; r < input_dims.size(); ++r)
{
if (tensor_shape_signature.size() > 0 && tensor_shape_signature.at(r) == -1)
if (tensor.shape_signature.size() > 0 && tensor.shape_signature.at(r) == -1)
input_shape->dim(r).unset();
else
input_shape->dim(r).set(input_dims[r]);
Expand All @@ -137,23 +134,18 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r
auto origin_table = circle_metadata->origin_table();
for (uint32_t i = 0; i < operators.size(); ++i)
{
const auto op = operators[i];
assert(op != nullptr);
const circle::OperatorT &op = *operators[i];
circle::BuiltinOperator builtincode = reader.builtin_code(op);

if (const auto *builder = source.lookup(builtincode))
{
// create temporary unpack API obj
circle::OperatorT oper_t;
op->UnPackTo(&oper_t);

luci::GraphBuilder::ValidateArgs args(oper_t, reader);
luci::GraphBuilder::ValidateArgs args(op, reader);
if (!builder->validate(args))
{
throw oops::UserExn("Invalid operator", reader.opcode_name(op));
}

auto built_op = builder->build(oper_t, &gb_context);
auto built_op = builder->build(op, &gb_context);
set_node_id(built_op, i);
if (origin_table.find(i) != origin_table.end())
add_origin(built_op, origin_table.at(i));
Expand All @@ -167,10 +159,9 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r
}

// graph outputs
for (auto output : reader.native_outputs())
for (auto output : reader.outputs())
{
const auto tensor = tensors[output];
assert(tensor != nullptr);
const circle::TensorT &tensor = *tensors[output];

auto output_node = graph->nodes()->create<luci::CircleOutput>();
assert(output_node != nullptr);
Expand All @@ -187,7 +178,7 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r
output_node->from(output_dummy);

luci::copy_tensor_attributes(tensor, output_dummy);
if (tensor->shape() == nullptr)
if (tensors_ptr->Get(output)->shape() == nullptr)
output_dummy->shape_status(luci::ShapeStatus::NOSHAPE);
else
output_dummy->shape_status(luci::ShapeStatus::VALID);
Expand All @@ -206,26 +197,24 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r
// Set GraphInputOutputIndex for graph
output_node->index(graph_output->index());

const auto tensor_shape_signature = luci::wrap(tensor->shape_signature());
const auto tensor_shape = luci::wrap(tensor->shape());
assert(tensor_shape_signature.size() == 0 ||
tensor_shape_signature.size() == tensor_shape.size());
assert(tensor.shape_signature.size() == 0 ||
tensor.shape_signature.size() == tensor.shape.size());

// Shape of Output
auto output_shape = std::make_unique<loco::TensorShape>();
const auto &output_dims = tensor_shape; // in NHWC
const std::vector<int32_t> &output_dims = tensor.shape; // in NHWC
output_shape->rank(output_dims.size());
for (uint32_t r = 0; r < output_dims.size(); ++r)
{
if (tensor_shape_signature.size() > 0 && tensor_shape_signature.at(r) == -1)
if (tensor.shape_signature.size() > 0 && tensor.shape_signature.at(r) == -1)
output_shape->dim(r).unset();
else
output_shape->dim(r).set(output_dims[r]);
}
graph_output->shape(std::move(output_shape));

// Data type
auto dtype = luci::luci_datatype(tensor->type());
auto dtype = luci::luci_datatype(tensor.type);
graph_output->dtype(dtype);
}
}
Expand Down Expand Up @@ -310,7 +299,7 @@ std::unique_ptr<Module> Importer::importModule(const circle::Model *model) const
if (!reader.select_subgraph(g))
return nullptr;

graph->name(reader.native_name());
graph->name(reader.name());

// Convert circle::Model to loco::Graph
convert_graph(*source_ptr, reader, graph.get());
Expand Down
12 changes: 5 additions & 7 deletions compiler/luci/import/src/Nodes/CircleCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ bool CircleCastGraphBuilder::validate(const ValidateArgs &args) const
const auto *options = args.op.builtin_options.AsCastOptions();
if (options != nullptr)
{
const auto tensors = args.reader.native_tensors();
const auto output_tensor = tensors[outputs[0]];
assert(output_tensor != nullptr);
const auto &tensors = args.reader.tensors();
const circle::TensorT &output_tensor = *tensors[outputs[0]];
auto name = tensor_name(output_tensor);

const auto tensor_in = tensors.at(inputs.at(0));
assert(tensor_in != nullptr);
if (tensor_in->type() != options->in_data_type)
const auto &tensor_in = tensors.at(inputs.at(0));
if (tensor_in->type != options->in_data_type)
{
if (settings->get(luci::UserSettings::Key::DisableValidation))
{
Expand All @@ -59,7 +57,7 @@ bool CircleCastGraphBuilder::validate(const ValidateArgs &args) const
return false;
}
const auto &tensor_out = tensors.at(outputs[0]);
if (tensor_out->type() != options->out_data_type)
if (tensor_out->type != options->out_data_type)
{
if (settings->get(luci::UserSettings::Key::DisableValidation))
{
Expand Down
Loading

0 comments on commit fa8b943

Please sign in to comment.