| 119 | |
| 120 | @classmethod |
| 121 | def storage_overlap(cls, lhs_spec: TensorSpec, rhs_spec: TensorSpec) -> bool: |
| 122 | intervals = [] |
| 123 | if lhs_spec.mem_id != rhs_spec.mem_id: |
| 124 | return False |
| 125 | for spec in [lhs_spec, rhs_spec]: |
| 126 | internal_assert( |
| 127 | spec.allocated_memory >= 0, |
| 128 | f"{spec} should have non-zero allocated memory", |
| 129 | ) |
| 130 | internal_assert( |
| 131 | isinstance(spec.mem_offset, int) and spec.mem_offset >= 0, |
| 132 | f"{spec} should have specified memory offset", |
| 133 | ) |
| 134 | intervals.append( |
| 135 | [spec.mem_offset, spec.mem_offset + spec.allocated_memory - 1] |
| 136 | ) |
| 137 | has_overlap = cls.has_overlap(*intervals) |
| 138 | |
| 139 | return has_overlap |
| 140 | |
| 141 | @classmethod |
| 142 | def _debug_message_from_specs( |