MCPcopy
hub / github.com/tinygrad/tinygrad / _make_buffer_view

Function _make_buffer_view

tinygrad/callify.py:58–63  ·  view source on GitHub ↗

If movement ops on src collapse to a contiguous range, return BUFFER_VIEW.reshape(src.shape). Otherwise None.

(src:UOp)

Source from the content-addressed store, hash-verified

56 if assigned_to.op is not Ops.BUFFER: return src.contiguous(tag=u.tag)
57
58def _make_buffer_view(src:UOp) -> UOp|None:
59 """If movement ops on src collapse to a contiguous range, return BUFFER_VIEW.reshape(src.shape). Otherwise None."""
60 if (offset := src.contiguous_view_offset()) is None: return None
61 buf = src.base
62 if buf.op is Ops.BUFFER_VIEW: offset, buf = offset + buf.arg[1], buf.src[0]
63 return UOp(Ops.BUFFER_VIEW, src.dtype, (buf,), (src.numel(), offset)).reshape(src.shape)
64
65def contiguous_mops_to_view(c:UOp, src:UOp):
66 """CONTIGUOUS(MOPS(BUFFER)) → CONTIGUOUS(BUFFER_VIEW) when movement ops collapse to a contiguous range."""

Callers 1

contiguous_mops_to_viewFunction · 0.85

Calls 4

UOpClass · 0.90
reshapeMethod · 0.80
numelMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…