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

Method valid_dims

tinygrad/dtype.py:141–147  ·  view source on GitHub ↗
(ptr:PtrDType, arch:str)

Source from the content-addressed store, hash-verified

139 # get list of (height, width) that do not require pitch padding
140 @staticmethod
141 def valid_dims(ptr:PtrDType, arch:str) -> list[tuple[int,int]]:
142 if (ALIGN:=next((int(p.split('=')[1]) for p in arch.split(',') if p.startswith("IMAGE_PITCH_ALIGNMENT=")), 0)) == 0: return []
143 MAXW, pxls = 16384, ptr.size // 4
144 if ptr.base not in (dtypes.half, dtypes.float) or ptr.size > 4*MAXW*MAXW: return []
145 # height=1 images just need to abide by alignment requirements in bytes, not pixels!
146 if ptr.size % (ALIGN * 4) != 0: return [] if ptr.nbytes() % (64 if OSX else ALIGN) != 0 or pxls > MAXW else [(1, pxls)]
147 return [(pxls//ALIGN//k, ALIGN*k) for k in range(ceildiv(pxls//ALIGN, MAXW), min(pxls//ALIGN, MAXW//ALIGN)+1) if (pxls//ALIGN)%k == 0]
148
149class dtypes:
150 @staticmethod

Callers 3

expand_indexFunction · 0.80
make_imageFunction · 0.80
hand_coded_optimizationsFunction · 0.80

Calls 3

ceildivFunction · 0.90
splitMethod · 0.80
nbytesMethod · 0.45

Tested by

no test coverage detected