MCPcopy Create free account
hub / github.com/tinygrad/tinygrad / flatten_bufferize

Function flatten_bufferize

tinygrad/schedule/rangeify.py:426–434  ·  view source on GitHub ↗
(x:UOp)

Source from the content-addressed store, hash-verified

424
425# collapse any BUFFERIZE to single input BUFFERIZE
426def flatten_bufferize(x:UOp):
427 if len(x.src) == 2: return None
428 ret = x.replace(src=(x.src[0], get_single_element(apply_movement_op(Ops.RESHAPE, (prod(x.shape),), x.shape, x.src[1:]))))
429 rngs = x.src[1:]
430 ret = ret.reshape(x.shape)
431 if any(r.op is Ops.RANGE and r.src[0].op is not Ops.CONST for r in rngs):
432 sym_shape = tuple([r.src[0] if r.op is not Ops.CONST else 1 for r in rngs])
433 ret = ret.shrink(tuple([(0,x) for x in sym_shape]))
434 return ret
435pm_flatten_bufferize = PatternMatcher([(UPat(Ops.STAGE, name="x"), flatten_bufferize)])
436
437pm_add_buffers = pm_mops+pm_flatten_bufferize+to_bufferview+PatternMatcher([

Callers

nothing calls this directly

Calls 6

get_single_elementFunction · 0.90
apply_movement_opFunction · 0.90
prodFunction · 0.90
reshapeMethod · 0.80
shrinkMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…