Skip to content

Commit

Permalink
[luci/export] Revise encodeOpBufferByDType for extended Buffer (#13878)
Browse files Browse the repository at this point in the history
This will revise encodeOpBufferByDType for extended Buffer mode.
- store buffer content to extra map instead of creating Buffer
- return fake Buffer with offset/size of 1 and 1.

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark authored Sep 2, 2024
1 parent b8e9c9f commit fa0a1ca
Showing 1 changed file with 16 additions and 1 deletion.
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 */);
}

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

0 comments on commit fa0a1ca

Please sign in to comment.