Skip to content

Commit

Permalink
[luci/import] Revise CircleReader
Browse files Browse the repository at this point in the history
This will revise CircleReader to provide direct file data access.

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark committed Aug 26, 2024
1 parent 6ffbc44 commit af248b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/luci/import/include/luci/Import/CircleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,19 @@ class CircleReader

public:
bool parse(const circle::Model *model);
bool parse(const circle::Model *model, const uint8_t *data, const size_t size);
bool select_subgraph(uint32_t subgraph);

public:
// to access raw file data for Buffer outside of flatbuffer range
const uint8_t *file_data(uint64_t offset) const;
size_t file_size(void) const { return _file_size; }

private:
const circle::Model *_model{nullptr};
const circle::SubGraph *_current_subgraph{nullptr};
const uint8_t *_file_data{nullptr};
size_t _file_size{0};
};

} // namespace luci
Expand Down
24 changes: 24 additions & 0 deletions compiler/luci/import/src/CircleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ bool CircleReader::parse(const circle::Model *model)
return true;
}

bool CircleReader::parse(const circle::Model *model, const uint8_t *data, const size_t size)
{
assert(model != nullptr);
assert(data != nullptr);
assert(size > 0);

// for direct pointer access
_model = model;

_file_data = data;
_file_size = size;

return true;
}

bool CircleReader::select_subgraph(uint32_t sgindex)
{
if (num_subgraph() <= sgindex)
Expand All @@ -349,6 +364,15 @@ bool CircleReader::select_subgraph(uint32_t sgindex)
return true;
}

// NOTE need caution not to access beyond _file_data + _file_size.
// current method doesn't have this guard.
const uint8_t *CircleReader::file_data(uint64_t offset) const
{
assert(_file_data);
assert(offset < _file_size);
return (_file_data == nullptr) ? nullptr : _file_data + offset;
}

template <typename T>
VectorWrapper<T>::VectorWrapper(const flatbuffers::Vector<T> *ptr) : _vector(ptr)
{
Expand Down

0 comments on commit af248b5

Please sign in to comment.