@@ -45,7 +45,7 @@ class BufferAllocations {
45
45
// Same as above, but also adjusts the returned address for the offset and
46
46
// size contained in the given slice.
47
47
absl::StatusOr<se::DeviceMemoryBase> GetDeviceAddress (
48
- const BufferAllocation::Slice& slice) const ;
48
+ BufferAllocation::Slice slice) const ;
49
49
50
50
// Unchecked version of `GetDeviceAddress` that does not check the buffer
51
51
// index and assumes it is valid.
@@ -55,16 +55,19 @@ class BufferAllocations {
55
55
// Unchecked version of `GetDeviceAddress` that does not check the slice
56
56
// buffer index, offset and size and assumes they all are valid.
57
57
se::DeviceMemoryBase GetDeviceAddressUnchecked (
58
- const BufferAllocation::Slice& slice) const ;
58
+ BufferAllocation::Slice slice) const ;
59
59
60
60
private:
61
61
std::vector<se::DeviceMemoryBase> buffers_;
62
+ se::DeviceMemoryBase* buffers_data_; // buffers_.data()
62
63
size_t num_buffers_;
63
64
};
64
65
65
66
inline BufferAllocations::BufferAllocations (
66
67
absl::Span<const MaybeOwningDeviceMemory> buffers)
67
- : buffers_(buffers.size()), num_buffers_(buffers_.size()) {
68
+ : buffers_(buffers.size()),
69
+ buffers_data_(buffers_.data()),
70
+ num_buffers_(buffers_.size()) {
68
71
for (size_t i = 0 ; i < buffers.size (); ++i) {
69
72
buffers_[i] = buffers[i].AsDeviceMemoryBase ();
70
73
}
@@ -82,8 +85,7 @@ BufferAllocations::GetDeviceAddress(BufferAllocation::Index index) const {
82
85
}
83
86
84
87
inline ABSL_ATTRIBUTE_ALWAYS_INLINE absl::StatusOr<se::DeviceMemoryBase>
85
- BufferAllocations::GetDeviceAddress (
86
- const BufferAllocation::Slice& slice) const {
88
+ BufferAllocations::GetDeviceAddress (BufferAllocation::Slice slice) const {
87
89
// Handle empty slices explicitly and return a null pointer device memory to
88
90
// guarantee that we do not accidentally write through the empty slice which
89
91
// would hide a real bug in the code.
@@ -97,7 +99,7 @@ BufferAllocations::GetDeviceAddress(
97
99
" Invalid buffer index %d. It must be in the range [0, %d)" , index ,
98
100
num_buffers_);
99
101
}
100
- const se::DeviceMemoryBase& base = buffers_ [index ];
102
+ const se::DeviceMemoryBase& base = buffers_data_ [index ];
101
103
102
104
int64_t offset = slice.offset ();
103
105
int64_t extent = offset + slice.size ();
@@ -125,15 +127,16 @@ BufferAllocations::GetDeviceAddress(
125
127
inline ABSL_ATTRIBUTE_ALWAYS_INLINE se::DeviceMemoryBase
126
128
BufferAllocations::GetDeviceAddressUnchecked (
127
129
BufferAllocation::Index buffer_index) const {
128
- return buffers_ [buffer_index];
130
+ return buffers_data_ [buffer_index];
129
131
}
130
132
131
133
// Unchecked version of `GetDeviceAddress` that does not check the slice
132
134
// buffer index, offset and size and assumes they are valid.
133
135
inline ABSL_ATTRIBUTE_ALWAYS_INLINE se::DeviceMemoryBase
134
136
BufferAllocations::GetDeviceAddressUnchecked (
135
- const BufferAllocation::Slice& slice) const {
136
- return buffers_[slice.index ()].GetByteSlice (slice.offset (), slice.size ());
137
+ BufferAllocation::Slice slice) const {
138
+ return buffers_data_[slice.index ()].GetByteSlice (slice.offset (),
139
+ slice.size ());
137
140
}
138
141
139
142
} // namespace xla::cpu
0 commit comments