@@ -24,19 +24,85 @@ namespace executor {
24
24
*/
25
25
class DataLoader {
26
26
public:
27
+ /* *
28
+ * A struct to pass information about the segment to the data loader.
29
+ */
30
+ struct SegmentInfo {
31
+ /* *
32
+ * Represents the function of the segment.
33
+ */
34
+ enum class Type {
35
+ /* *
36
+ * Data for the actual program. These always comes before the rest of the
37
+ * segments.
38
+ */
39
+ Program,
40
+ /* *
41
+ * Holds constant data, i.e. tensors.
42
+ */
43
+ Constant,
44
+ /* *
45
+ * Data used for initializing a backend.
46
+ */
47
+ Backend
48
+ };
49
+
50
+ // / Type of the segment.
51
+ Type segment_type;
52
+
53
+ // / Index of the segment within the segment list. Irrelevant for program
54
+ // / segments.
55
+ size_t segment_index;
56
+
57
+ // / Some descriptor relevant to the segment type, i.e. this would be backend
58
+ // / id for backend segments and null otherwise.
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 `size` bytes at byte offset `offset` from the underlying data source
90
+ * into a `FreeableBuffer`, which owns the memory. This method also provides
91
+ * information about the segment being loaded in segment_info.
92
+ *
93
+ * NOTE: This must be thread-safe. If this call modifies common state, the
94
+ * implementation must do its own locking.
95
+ *
96
+ * @param offset The offset in the data source to start loading from.
97
+ * @param size The number of bytes to load.
98
+ * @param segment_info Information about the segment being loaded.
99
+ */
100
+ __ET_NODISCARD virtual inline Result<FreeableBuffer>
101
+ load (size_t offset, size_t size, const SegmentInfo& segment_info) {
102
+ (void )segment_info;
103
+ return Load (offset, size);
104
+ }
105
+
40
106
/* *
41
107
* Returns the length of the underlying data source, typically the file size.
42
108
*/
0 commit comments