Skip to content

Commit

Permalink
unwrap existing buffer from assign src [pr] (tinygrad#8252)
Browse files Browse the repository at this point in the history
* unwrap existing buffer from assign src [pr]

* this is a upat
  • Loading branch information
Qazalin authored Dec 15, 2024
1 parent ace654a commit e0aeb2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions tinygrad/engine/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ def to_uop(buf:UOp, ctx:ScheduleContext, cache:Dict[UOp, UOp]) -> UOp:
op = buf.src[1].replace(src=tuple(to_uop(x, ctx, cache) for x in buf.src[1].src))
# ASSIGN uses the target buffer, otherwise we create a new buffer
else:
src = tuple(to_uop(x, ctx, cache) for x in buf.srcs)
buf_uop = src[0].base.buf_uop if buf.op is Ops.ASSIGN else UOp.new_buffer(buf.device, buf.size, dtype)
op = UOp(buf.op, dtype.base, src, buf.arg)
buf_uop = buf.buf_uop if buf.op is Ops.ASSIGN else UOp.new_buffer(buf.device, buf.size, dtype)
op = buf.replace(dtype=dtype.base, src=tuple(to_uop(x, ctx, cache) for x in buf.srcs))
# track the underlying tensor uop for this op
ctx.tensor_uops[buf_uop] = [buf]
# (early) bufferize
Expand Down
4 changes: 2 additions & 2 deletions tinygrad/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ def _device(self) -> Optional[str]:
@property
def buf_uop(self) -> UOp:
if self.op is Ops.BUFFER: return self
assert self.op in {*GroupOp.Buffer, Ops.ASSIGN, Ops.VIEW} and self.src[0].op is Ops.BUFFER, f"buf_uop called on {self.op}"
return self.src[0]
assert self.base.op in {*GroupOp.Buffer, Ops.ASSIGN, Ops.VIEW}, f"buf_uop called on {self.op}"
return self.src[0].buf_uop
@property
def buffer(self) -> Buffer:
if self.base.realized is not None: return self.base.realized
Expand Down

0 comments on commit e0aeb2e

Please sign in to comment.