@@ -24,19 +24,85 @@ namespace executor {
24
24
*/
25
25
class DataLoader {
26
26
public:
27
+ /* *
28
+ * Describes the content of the segment.
29
+ */
30
+ struct SegmentInfo {
31
+ /* *
32
+ * Represents the purpose of the segment.
33
+ */
34
+ enum class Type {
35
+ /* *
36
+ * Data for the actual program.
37
+ */
38
+ Program,
39
+ /* *
40
+ * Holds constant tensor data.
41
+ */
42
+ Constant,
43
+ /* *
44
+ * Data used for initializing a backend.
45
+ */
46
+ Backend,
47
+ };
48
+
49
+ // / Type of the segment.
50
+ Type segment_type;
51
+
52
+ // / Index of the segment within the segment list. Undefined for program
53
+ // / segments.
54
+ size_t segment_index;
55
+
56
+ // / An optional, null-terminated string describing the segment. For
57
+ // / `Backend` segments, this is the backend ID. Null for other segment
58
+ // / types.
59
+ const char * descriptor;
60
+
61
+ SegmentInfo () = default ;
62
+
63
+ explicit SegmentInfo (
64
+ Type segment_type,
65
+ size_t segment_index = 0 ,
66
+ const char * descriptor = nullptr )
67
+ : segment_type(segment_type),
68
+ segment_index(segment_index),
69
+ descriptor(descriptor) {}
70
+ };
71
+
27
72
virtual ~DataLoader () = default ;
28
73
29
74
/* *
75
+ * DEPRECATED: Use `load()` going forward for access to segment info during
76
+ * the load.
77
+ *
30
78
* Loads `size` bytes at byte offset `offset` from the underlying data source
31
79
* into a `FreeableBuffer`, which owns the memory.
32
80
*
33
81
* NOTE: This must be thread-safe. If this call modifies common state, the
34
82
* implementation must do its own locking.
35
83
*/
36
- __ET_NODISCARD virtual Result<FreeableBuffer> Load (
84
+ __ET_DEPRECATED __ET_NODISCARD virtual Result<FreeableBuffer> Load (
37
85
size_t offset,
38
86
size_t size) = 0;
39
87
88
+ /* *
89
+ * Loads data from the underlying data source.
90
+ *
91
+ * NOTE: This must be thread-safe. If this call modifies common state, the
92
+ * implementation must do its own locking.
93
+ *
94
+ * @param offset The byte offset in the data source to start loading from.
95
+ * @param size The number of bytes to load.
96
+ * @param segment_info Information about the segment being loaded.
97
+ *
98
+ * @returns a `FreeableBuffer` that owns the loaded data.
99
+ */
100
+ __ET_NODISCARD virtual Result<FreeableBuffer>
101
+ load (size_t offset, size_t size, const SegmentInfo& segment_info) {
102
+ (void )segment_info;
103
+ return Load (offset, size); // NOLINT
104
+ }
105
+
40
106
/* *
41
107
* Returns the length of the underlying data source, typically the file size.
42
108
*/
0 commit comments