Skip to content

Commit 31335d3

Browse files
jackzhxngfacebook-github-bot
authored andcommitted
Introduce new DataLoader::load() with segment info (#4158)
Summary: Pull Request resolved: #4158 Adds a new `DataLoader::load()` function with an additonal parameter, SegmentInfo. Makes the old `DataLoader::Load()` function deprecated. Differential Revision: D59399538
1 parent 561c035 commit 31335d3

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

runtime/core/data_loader.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,85 @@ namespace executor {
2424
*/
2525
class DataLoader {
2626
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+
2772
virtual ~DataLoader() = default;
2873

2974
/**
75+
* DEPRECATED: Use `load()` going forward for access to segment info during
76+
* the load.
77+
*
3078
* Loads `size` bytes at byte offset `offset` from the underlying data source
3179
* into a `FreeableBuffer`, which owns the memory.
3280
*
3381
* NOTE: This must be thread-safe. If this call modifies common state, the
3482
* implementation must do its own locking.
3583
*/
36-
__ET_NODISCARD virtual Result<FreeableBuffer> Load(
84+
__ET_DEPRECATED __ET_NODISCARD virtual Result<FreeableBuffer> Load(
3785
size_t offset,
3886
size_t size) = 0;
3987

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+
40106
/**
41107
* Returns the length of the underlying data source, typically the file size.
42108
*/

0 commit comments

Comments
 (0)