Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[luci/import] Add importModule with raw data/size #13762

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/luci/import/include/luci/Importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ class Importer final
}

public:
// TODO move to private
std::unique_ptr<Module> importModule(const circle::Model *model) const;
std::unique_ptr<Module> importModule(const uint8_t *data, size_t size);

private:
const GraphBuilderSource *_source = nullptr;
const uint8_t *_file_data = nullptr;
size_t _file_size = 0;
};

} // namespace luci
Expand Down
28 changes: 26 additions & 2 deletions compiler/luci/import/src/Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,17 @@ std::unique_ptr<Module> Importer::importModule(const circle::Model *model) const
}

CircleReader reader;
if (!reader.parse(model))
return nullptr;
if (_file_data && _file_size)
{
if (!reader.parse(model, _file_data, _file_size))
return nullptr;
}
else
{
// TODO remove this
if (!reader.parse(model))
return nullptr;
}

for (uint32_t g = 0; g < reader.num_subgraph(); ++g)
{
Expand Down Expand Up @@ -361,4 +370,19 @@ std::unique_ptr<Module> Importer::importModule(const circle::Model *model) const
return module;
}

std::unique_ptr<Module> Importer::importModule(const uint8_t *data, size_t size)
{
if (data == nullptr || size == 0)
return nullptr;

_file_data = data;
_file_size = size;

const circle::Model *circle_model = circle::GetModel(_file_data);
if (circle_model == nullptr)
return nullptr;

return importModule(circle_model);
}

} // namespace luci