If movement ops on a BUFFER collapse to a contiguous range, return `offset` in elements. Otherwise None.
(self)
| 752 | return s |
| 753 | |
| 754 | def contiguous_view_offset(self) -> int|None: |
| 755 | """If movement ops on a BUFFER collapse to a contiguous range, return `offset` in elements. Otherwise None.""" |
| 756 | from tinygrad.schedule.rangeify import pm_mops |
| 757 | from tinygrad.uop.symbolic import symbolic |
| 758 | numel = self.numel() |
| 759 | out = graph_rewrite(self.flatten().index(UOp.range(numel, 0)), pm_mops+symbolic, name="contiguous_view_offset") |
| 760 | if out.op is not Ops.INDEX: return None |
| 761 | if out.src[1].op is Ops.CONST and resolve(numel == 1, False): |
| 762 | if not isinstance(out.src[1].arg, int): return None # masked/padded regions produce InvalidType |
| 763 | return out.src[1].arg |
| 764 | if out.src[1].op is Ops.RANGE: return 0 |
| 765 | if out.src[1].op is Ops.ADD and out.src[1].src[0].op is Ops.RANGE and out.src[1].src[1].op is Ops.CONST: |
| 766 | if not isinstance(out.src[1].src[1].arg, int): return None # masked/padded regions produce InvalidType |
| 767 | return out.src[1].src[1].arg |
| 768 | return None |
| 769 | |
| 770 | def has_buffer_identity(self): |
| 771 | """Check if this UOp has a concrete buffer identity in the graph (RESHAPE/MULTI -> BUFFER chain).""" |