Skip to content

Commit ff317c0

Browse files
Expand dataloader interface.
Differential Revision: D60775460 Pull Request resolved: #4546
1 parent 2718dd4 commit ff317c0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

runtime/core/data_loader.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class DataLoader {
4444
* Data used for initializing a backend.
4545
*/
4646
Backend,
47+
/**
48+
* Data used for initializing mutable tensors.
49+
*/
50+
Mutable,
4751
};
4852

4953
/// Type of the segment.
@@ -86,6 +90,35 @@ class DataLoader {
8690
__ET_NODISCARD virtual Result<FreeableBuffer>
8791
load(size_t offset, size_t size, const SegmentInfo& segment_info) = 0;
8892

93+
/**
94+
* Loads data from the underlying data source into the provided buffer.
95+
*
96+
* NOTE: This must be thread-safe. If this call modifies common state, the
97+
* implementation must do its own locking.
98+
*
99+
* @param offset The byte offset in the data source to start loading from.
100+
* @param size The number of bytes to load.
101+
* @param segment_info Information about the segment being loaded.
102+
* @param buffer The buffer to load data into. Must point to at least `size`
103+
* bytes of memory.
104+
*
105+
* @returns an Error indicating if the load was successful.
106+
*/
107+
__ET_NODISCARD virtual Error load_into(
108+
size_t offset,
109+
size_t size,
110+
const SegmentInfo& segment_info,
111+
void* buffer) {
112+
// Using a stub implementation here instead of pure virtual to expand the
113+
// data_loader interface in a backwards compatible way.
114+
(void)buffer;
115+
(void)offset;
116+
(void)size;
117+
(void)segment_info;
118+
ET_LOG(Error, "load_into() not implemented for this data loader.");
119+
return Error::NotImplemented;
120+
}
121+
89122
/**
90123
* Returns the length of the underlying data source, typically the file size.
91124
*/

0 commit comments

Comments
 (0)