SIGN IN SIGN UP

Serialize NamedData in PTE file (#8847)

1. Serialize NamedData in PTE file
2. Add NamedDataStore to EdgeProgramManager
---
Serializing NamedData is slightly different to constant/delegate data as each segment comes with its own alignment.

**An example:**
Given NamedData = {"key": data}. Data is 250 bytes.

- BackendA requires data with alignment=3
- BackendB requires data with alignment=4

Then, data0 should be serialized with alignment of lcm(3, 4) = 12

At serialization, ExecuTorch has a 'segment_alignment' that defaults to 128. Data is now serialized to lcm(12, 128) = 384.

Inside the DataSegment, we want to store the original size of the data (250). The offset of the subsequent DataSegment would be 384 bytes after the start of this one.

**Design**
Introduce a new dataclass 'AlignedData' that stores the buffer and any alignment that's required. This is used when assembling Program.segments to ensure we get lcm(buffer_alignment, segment_alignment).


Note: The default segment_alignment can be overridden inside 'ExecutorchBackendConfig'.

Differential Revision: [D69764150](https://our.internmc.facebook.com/intern/diff/D69764150/)

ghstack-source-id: 269030449
Pull Request resolved: https://github.com/pytorch/executorch/pull/8835

Co-authored-by: lucylq <lfq@meta.com>
P
pytorchbot committed
314ab18f488602473818883988b6f790b12a1d30
Parent: 781b082
Committed by GitHub <noreply@github.com> on 2/28/2025, 9:53:13 PM