| 466 | } |
| 467 | |
| 468 | StatusOr<BufferAllocation::Slice> BufferAssignment::GetUniqueSlice( |
| 469 | const HloInstruction* instruction, const ShapeIndex& index) const { |
| 470 | VLOG(3) << "Trying to find unique slice for " << instruction->name() << " [" |
| 471 | << index << "]"; |
| 472 | BufferAllocation::Slice result; |
| 473 | for (const HloValue* value : |
| 474 | dataflow_analysis().GetValueSet(instruction, index).values()) { |
| 475 | VLOG(3) << "Examining value " << *value; |
| 476 | if (HasAllocation(*value)) { |
| 477 | VLOG(3) << "Has allocation"; |
| 478 | const BufferAllocation::Slice slice = |
| 479 | GetAssignedAllocation(*value).GetSlice(*value); |
| 480 | if (result.allocation() == nullptr) { |
| 481 | result = slice; |
| 482 | } else if (result != slice) { |
| 483 | return FailedPrecondition( |
| 484 | "BufferAllocation::Slice for instruction %s at index %s cannot " |
| 485 | "be determined at compile-time.", |
| 486 | instruction->name(), index.ToString()); |
| 487 | } |
| 488 | } else { |
| 489 | VLOG(3) << "No allocation"; |
| 490 | } |
| 491 | } |
| 492 | if (result.allocation() == nullptr) { |
| 493 | return FailedPrecondition( |
| 494 | "BufferAllocation::Slice not assigned for instruction %s at index %s", |
| 495 | instruction->name(), index.ToString()); |
| 496 | } |
| 497 | return result; |
| 498 | } |
| 499 | |
| 500 | StatusOr<BufferAllocation::Slice> BufferAssignment::GetUniqueTopLevelSlice( |
| 501 | const HloInstruction* instruction) const { |