|
| 1 | +include "scalar_type.fbs"; |
| 2 | +namespace executorch_flatbuffer; |
| 3 | + |
| 4 | +// Update after BC breaking changes. |
| 5 | +file_identifier "DT01"; |
| 6 | +file_extension "data"; |
| 7 | + |
| 8 | +table TensorMetadata { |
| 9 | + // The unique id used to connect the data and program. |
| 10 | + fully_qualified_name:string; |
| 11 | + scalar_type:ScalarType; |
| 12 | + |
| 13 | + // Size of each dimension. |
| 14 | + dim_sizes:[int]; |
| 15 | + |
| 16 | + // Specifies in what order the dimensions are laid out in memory (from outer |
| 17 | + // to inner). |
| 18 | + // |
| 19 | + // For example, given a rank 3 Tensor of size (3, 5, 2). If we name |
| 20 | + // dimensions: [row, column, batch], then a dim_order of: |
| 21 | + // - (2, 0, 1) represents a [batch, row, column] ordering where "column" is |
| 22 | + // the innermost dimension, then comes "row", and the outermost dimension is |
| 23 | + // "batch". |
| 24 | + // - (0, 2, 1) represents a [row, batch, column] ordering where "column" is |
| 25 | + // the innermost dimension, then comes "batch", and the outermost dimension |
| 26 | + // is "row". |
| 27 | + dim_order:[ubyte]; |
| 28 | + |
| 29 | + // Offset in scalar_type elements (e.g., multiples of 4 bytes for an int |
| 30 | + // scalar type) from the beginning of the tensor buffer to the beginning of |
| 31 | + // the actual data. Currently, the runtime only supports a value of zero. |
| 32 | + storage_offset:int; |
| 33 | + |
| 34 | + // May not be needed. |
| 35 | + layout:byte; |
| 36 | + |
| 37 | + // Tensor offsets are relative to each TensorSegment. |
| 38 | + // To retrieve a given tensor: |
| 39 | + // 1. segment_base_offset: from the file header. |
| 40 | + // 2. segment offset: segments[tensor_segments[i].segment_index].offset |
| 41 | + // This is likely to be 0 (all the tensors in one segment). |
| 42 | + // 3. tensor offset: tensor_segments[i].tensor_metadata[j].offset |
| 43 | + // May need to binary search over tensor_metadata to find the matching |
| 44 | + // tensor using fqn. |
| 45 | + offset: uint64; |
| 46 | + size: uint64; |
| 47 | +} |
| 48 | + |
| 49 | +table TensorSegment { |
| 50 | + // Index of the segment in Data.segments. |
| 51 | + segment_index: uint; |
| 52 | + |
| 53 | + // Tensor information, including the offset and size. |
| 54 | + tensor_metadata:[TensorMetadata]; |
| 55 | +} |
| 56 | + |
| 57 | +table DataSegment { |
| 58 | + // Segment offsets are relative to the segment base offset provided in |
| 59 | + // the extended file header. Segments will typically be aligned in a |
| 60 | + // way to make it possible to use mmap() to load them. |
| 61 | + offset: uint64; |
| 62 | + |
| 63 | + // The size in bytes of valid data starting at the offset. The segment |
| 64 | + // data may be followed by padding before the segment that follows it, |
| 65 | + // to make it easier to use mmap(). |
| 66 | + size: uint64; |
| 67 | +} |
| 68 | + |
| 69 | +table Data { |
| 70 | + // Schema version. |
| 71 | + version:uint; |
| 72 | + |
| 73 | + // Alignment for each tensor. |
| 74 | + tensor_alignment: uint32; |
| 75 | + |
| 76 | + // Tensor information. |
| 77 | + tensor_segments:[TensorSegment]; |
| 78 | + |
| 79 | + // Data segments. |
| 80 | + segments:[DataSegment]; |
| 81 | +} |
| 82 | + |
| 83 | +root_type Data; |
0 commit comments