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/export] Revise encodeOpBufferByDType for extended Buffer #13878

Merged
merged 1 commit into from
Sep 2, 2024
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
17 changes: 16 additions & 1 deletion compiler/luci/export/src/CircleTensorExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ flatbuffers::Offset<circle::Buffer> encodeOpBuffer(FlatBufferBuilder &builder,

template <loco::DataType DT>
flatbuffers::Offset<circle::Buffer>
encodeOpBufferByDType(FlatBufferBuilder &builder, SerializedModelData &, luci::CircleConst *c)
encodeOpBufferByDType(FlatBufferBuilder &builder, SerializedModelData &md, luci::CircleConst *c)
{
using NativeType = typename loco::DataTypeImpl<DT>::Type;

Expand All @@ -358,6 +358,21 @@ encodeOpBufferByDType(FlatBufferBuilder &builder, SerializedModelData &, luci::C
raw_data.push_back(c->at<DT>(i));
}
const size_t raw_size = size * sizeof(NativeType);

if (md._ext_buffer)
{
// TODO optimize this if this operation takes long or much memory
SerializedModelData::BufferData buffer_data;
buffer_data.resize(raw_size);
std::memcpy(buffer_data.data(), raw_data.data(), raw_size);

int32_t buffer_index = md._buffers.size();
md._buffer_data_map.emplace(buffer_index, buffer_data);

// create fake indicator buffer
return circle::CreateBuffer(builder, 0 /* data */, 1 /* offset */, 1 /* size */);
Comment on lines +372 to +373
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this fake indicator buffer?
Is it used elsewhere? 😅

Copy link
Contributor Author

@seanshpark seanshpark Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

real (!fake) Buffer holds actual data,
but this fake Buffer won,t and the offset will point to the file offset to the actual Data.


we initialize two values, offset and size to 1.
then when we produce the file data for export, we update each Buffer offset/size to actual values. so, in import, if we meet the Buffer offset/size as 1, this Buffer is invalid, as there was some problem with the update of actual value.

}

auto array_offset = builder.CreateVector(reinterpret_cast<uint8_t *>(raw_data.data()), raw_size);
return CreateBuffer(builder, array_offset);
}
Expand Down