Skip to content

Commit

Permalink
[tfldump] Revise to support Buffer offset (#13712)
Browse files Browse the repository at this point in the history
This will revise to support Buffer offset;
- pass raw file data to retrieve data outside of flatbuffers area
- get flag if Buffer is from outside of flatbuffers area
- show with '*' for Buffers that are outside of flatbuffers area

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark authored Aug 20, 2024
1 parent f5ea127 commit 5ba6466
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
6 changes: 5 additions & 1 deletion compiler/tfldump/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ int entry(int argc, char **argv)

std::cout << "Dump: " << tflite_path << std::endl << std::endl;

std::cout << tflmodel << std::endl;
tfldump::ModelEx modelex;
modelex.model = tflmodel;
modelex.rawdata = &modelData;

std::cout << modelex << std::endl;

return 0;
}
13 changes: 10 additions & 3 deletions compiler/tfldump/include/tfldump/Dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
namespace tfldump
{

void dump_model(std::ostream &os, const tflite::Model *model);
}
struct ModelEx
{
const tflite::Model *model;
const std::vector<char> *rawdata;
};

void dump_model(std::ostream &os, const ModelEx &model);

} // namespace tfldump

std::ostream &operator<<(std::ostream &os, const tflite::Model *model);
std::ostream &operator<<(std::ostream &os, const tfldump::ModelEx &model);

#endif // __TFLDUMP_DUMP_H__
18 changes: 11 additions & 7 deletions compiler/tfldump/src/Dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ void dump_sub_graph(std::ostream &os, tflread::Reader &reader)
os << std::endl;
}

void dump_model(std::ostream &os, const tflite::Model *model)
void dump_model(std::ostream &os, const tflite::Model *model, const std::vector<char> *rawdata)
{
tflread::Reader reader(model);
tflread::Reader reader(model, rawdata);

uint32_t num_subgraph = reader.num_subgraph();

Expand Down Expand Up @@ -376,13 +376,17 @@ void dump_model(std::ostream &os, const tflite::Model *model)
os << std::endl;

// dump buffer
os << "Buffers: B(index) (length) values, if any" << std::endl;
os << "Buffers: B(index) (length) values, if any; (length *) for ext_offset" << std::endl;
for (uint32_t i = 0; i < buffers->size(); ++i)
{
bool ext_offset = false;
const uint8_t *buff_data;
size_t size = reader.buffer_info(i, &buff_data);
size_t size = reader.buffer_info(i, &buff_data, ext_offset);

os << "B(" << i << ") (" << size << ") ";
os << "B(" << i << ") (" << size;
if (ext_offset)
os << " *";
os << ") ";
if (buff_data != nullptr)
{
dump_buffer(os, buff_data, size, 16);
Expand Down Expand Up @@ -450,8 +454,8 @@ void dump_model(std::ostream &os, const tflite::Model *model)

} // namespace tfldump

std::ostream &operator<<(std::ostream &os, const tflite::Model *model)
std::ostream &operator<<(std::ostream &os, const tfldump::ModelEx &modelex)
{
tfldump::dump_model(os, model);
tfldump::dump_model(os, modelex.model, modelex.rawdata);
return os;
}

0 comments on commit 5ba6466

Please sign in to comment.