| 233 | } |
| 234 | |
| 235 | void BufferAllocation::AddAssignment(const HloValue& buffer, int64 offset, |
| 236 | int64 size) { |
| 237 | VLOG(4) << "Adding the following buffer to allocation #" << index() |
| 238 | << absl::StrFormat(" (size=%d, offset=%d) %s", size, offset, |
| 239 | buffer.ToShortString()); |
| 240 | CHECK(!assigned_buffers_.contains(&buffer)) |
| 241 | << "LogicalBuffer " << buffer << " already assigned to allocation " |
| 242 | << index_; |
| 243 | CHECK_LE(offset, size_) << "LogicalBuffer " << buffer |
| 244 | << " offset out of range"; |
| 245 | CHECK_LE(offset + size, size_) |
| 246 | << "LogicalBuffer " << buffer |
| 247 | << " size out of range at offset: " << offset << " with size: " << size; |
| 248 | CHECK_EQ(buffer.color(), color()) |
| 249 | << "Buffer color " << buffer.color() << " for buffer " << buffer |
| 250 | << " does not match allocation color " << color() << "."; |
| 251 | OffsetSize offset_size; |
| 252 | offset_size.offset = offset; |
| 253 | offset_size.size = size; |
| 254 | assigned_buffers_.emplace(&buffer, offset_size); |
| 255 | // For debugging purposes, store the assigned memory space in the |
| 256 | // instruction's layout. |
| 257 | for (HloPosition position : buffer.positions()) { |
| 258 | Shape* shape = ShapeUtil::GetMutableSubshape( |
| 259 | position.instruction->mutable_shape(), position.index); |
| 260 | if (shape->has_layout()) { |
| 261 | shape->mutable_layout()->set_memory_space(buffer.color().value()); |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | BufferAllocationProto BufferAllocation::ToProto() const { |
| 267 | BufferAllocationProto proto; |
no test coverage detected