MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / image_fixup

Function image_fixup

tinygrad/codegen/late/devectorizer.py:205–216  ·  view source on GitHub ↗
(ls:UOp)

Source from the content-addressed store, hash-verified

203 return idx.replace(src=(idx.src[0].src[0], idx_y.valid(valid), idx_x.valid(valid)))
204
205def image_fixup(ls:UOp):
206 # normal image load or store, with the CAST from expand_index
207 if isinstance(dt:=ls.src[0].src[0].dtype, ImageDType) and ls.src[0].op is Ops.CAST:
208 assert ls.src[0].dtype.count == 4, "image must be casted to 4"
209 return ls.replace(src=(get_image_idx(ls.src[0].src[0], dt.shape[1]),)+ls.src[1:])
210
211 # this is an unprocessed image without a cast, we should just make it a buffer
212 if isinstance(dt, ImageDType) and len(ls.src[0].src) == 2:
213 off = ls.src[0].src[1]
214 assert ls.src[0].src[0].op is Ops.RESHAPE, "image idx must be on reshape"
215 idx = ls.src[0].src[0].src[0].replace(dtype=(new_dt:=dtypes.half if dt.itemsize == 2 else dtypes.float).ptr(dt.size)).index(off)
216 return ls.replace(src=(idx,), dtype=new_dt).cast(dtypes.float) if ls.op is Ops.LOAD else ls.replace(src=(idx, ls.src[1].cast(new_dt)))
217
218correct_load_store = PatternMatcher([
219 # split LOAD/STORE

Callers

nothing calls this directly

Calls 5

get_image_idxFunction · 0.85
replaceMethod · 0.45
indexMethod · 0.45
ptrMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…