MCPcopy
hub / github.com/tinygrad/tinygrad / contiguous_view_offset

Method contiguous_view_offset

tinygrad/uop/ops.py:754–768  ·  view source on GitHub ↗

If movement ops on a BUFFER collapse to a contiguous range, return `offset` in elements. Otherwise None.

(self)

Source from the content-addressed store, hash-verified

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)."""

Callers 4

bufferMethod · 0.95
_make_buffer_viewFunction · 0.80

Calls 6

graph_rewriteFunction · 0.85
resolveFunction · 0.85
numelMethod · 0.80
flattenMethod · 0.80
indexMethod · 0.45
rangeMethod · 0.45

Tested by 2