Skip to content

[executorch][flat_tensor] update flat tensor header test #8109

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

Merged
merged 1 commit into from
Jan 31, 2025
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
3 changes: 2 additions & 1 deletion extension/flat_tensor/serialize/flat_tensor_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ uint64_t GetUInt64LE(const uint8_t* data) {
if (size < FlatTensorHeader::kNumHeadBytes) {
return Error::InvalidArgument;
}
const uint8_t* header = reinterpret_cast<const uint8_t*>(data);
const uint8_t* header =
reinterpret_cast<const uint8_t*>(data) + kHeaderOffset;

// Check magic bytes.
if (std::memcmp(
Expand Down
6 changes: 6 additions & 0 deletions extension/flat_tensor/serialize/flat_tensor_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ struct FlatTensorHeader {
*/
static constexpr size_t kNumHeadBytes = 64;

/**
* The offset into the serialized FlatTensor data where the FlatTensor
* header should begin.
*/
static constexpr size_t kHeaderOffset = 8;

/**
* The magic bytes that identify the header. This should be in sync with
* the magic in executorch/extension/flat_tensor/serialize/serialize.py
Expand Down
2 changes: 1 addition & 1 deletion extension/flat_tensor/test/flat_tensor_header_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ std::vector<uint8_t> CreateExampleFlatTensorHeader() {
memset(ret.data(), 0x55, ret.size());
// Copy the example header into the right offset.
memcpy(
ret.data(),
ret.data() + FlatTensorHeader::kHeaderOffset,
kExampleHeaderData,
sizeof(kExampleHeaderData));
return ret;
Expand Down
Loading