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

[tfldump] Reivse to support Buffer offset #13712

Merged
merged 1 commit into from
Aug 20, 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
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;
}