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

[tflchef] Revise with Buffer generation with ext_offset flag #13703

Merged
Merged
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
82 changes: 57 additions & 25 deletions compiler/tflchef/core/src/ModelChef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,26 @@ template <typename T> void ModelChef::cook_operands(const T &graph)
sparse_uint8.emplace_back(arr[b]);
}
}
auto data = _flatbuffer_builder->CreateVector(sparse_uint8);

// Create Buffer
tflite::BufferBuilder buffer_builder{*_flatbuffer_builder};
buffer_builder.add_data(data);
auto buffer = buffer_builder.Finish();
if (_ext_offset)
{
buffer_index = _buffer_vec.size();
_buffer_data_map[buffer_index] = sparse_uint8;

// Update Buffer Index & Vector
buffer_index = _buffer_vec.size();
_buffer_vec.emplace_back(buffer);
auto buffer = tflite::CreateBuffer(*_flatbuffer_builder, 0, 1, 1);
_buffer_vec.emplace_back(buffer);
}
else
{
auto data = _flatbuffer_builder->CreateVector(sparse_uint8);
// Create Buffer
tflite::BufferBuilder buffer_builder{*_flatbuffer_builder};
buffer_builder.add_data(data);
auto buffer = buffer_builder.Finish();

// Update Buffer Index & Vector
buffer_index = _buffer_vec.size();
_buffer_vec.emplace_back(buffer);
}

// save SparsityParameters
auto traversal_order = _flatbuffer_builder->CreateVector(traversal_order_vec);
Expand Down Expand Up @@ -405,16 +415,27 @@ template <typename T> void ModelChef::cook_operands(const T &graph)
sparse_uint8.emplace_back(arr[b]);
}
}
auto data = _flatbuffer_builder->CreateVector(sparse_uint8);
if (_ext_offset)
{
buffer_index = _buffer_vec.size();
_buffer_data_map[buffer_index] = sparse_uint8;

// Create Buffer
tflite::BufferBuilder buffer_builder{*_flatbuffer_builder};
buffer_builder.add_data(data);
auto buffer = buffer_builder.Finish();
auto buffer = tflite::CreateBuffer(*_flatbuffer_builder, 0, 1, 1);
_buffer_vec.emplace_back(buffer);
}
else
{
auto data = _flatbuffer_builder->CreateVector(sparse_uint8);

// Update Buffer Index & Vector
buffer_index = _buffer_vec.size();
_buffer_vec.emplace_back(buffer);
// Create Buffer
tflite::BufferBuilder buffer_builder{*_flatbuffer_builder};
buffer_builder.add_data(data);
auto buffer = buffer_builder.Finish();

// Update Buffer Index & Vector
buffer_index = _buffer_vec.size();
_buffer_vec.emplace_back(buffer);
}

// save SparsityParameters
auto traversal_order = _flatbuffer_builder->CreateVector(traversal_order_vec);
Expand Down Expand Up @@ -454,16 +475,27 @@ template <typename T> void ModelChef::cook_operands(const T &graph)
data_vec = data_packed;
}

auto data = _flatbuffer_builder->CreateVector(data_vec);
if (_ext_offset)
{
buffer_index = _buffer_vec.size();
_buffer_data_map[buffer_index] = data_vec;

// Create Buffer
tflite::BufferBuilder buffer_builder{*_flatbuffer_builder};
buffer_builder.add_data(data);
auto buffer = buffer_builder.Finish();
auto buffer = tflite::CreateBuffer(*_flatbuffer_builder, 0, 1, 1);
_buffer_vec.emplace_back(buffer);
}
else
{
auto data = _flatbuffer_builder->CreateVector(data_vec);

// Update Buffer Index & Vector
buffer_index = _buffer_vec.size();
_buffer_vec.emplace_back(buffer);
// Create Buffer
tflite::BufferBuilder buffer_builder{*_flatbuffer_builder};
buffer_builder.add_data(data);
auto buffer = buffer_builder.Finish();

// Update Buffer Index & Vector
buffer_index = _buffer_vec.size();
_buffer_vec.emplace_back(buffer);
}
}
}
else
Expand Down