found failing upcast
MODIFY
examples/hlb_cifar10.py
examples/hlb_cifar10.py
@@ -104,7 +104,8 @@ def train_cifar():
# 136 TFLOPS is the theoretical max w float16 on 3080TI
for i in range(10):
- X, Y = fetch_batch(X_train, Y_train, BS=512)
+ # TODO: the real batch size is 512
+ X, Y = fetch_batch(X_train, Y_train, BS=5)
CL.time_sum, CL.kernel_count = 0, -1
CL.ops_sum = 0 # TODO: this should be GlobalCounters.global_ops
st = time.monotonic()

MODIFY
extra/kernel_search.py
extra/kernel_search.py
@@ -228,6 +228,14 @@ if __name__ == "__main__":
op0 = LazyOp(BinaryOps.MUL, (buf0,buf1,), None)
op1 = LazyOp(ReduceOps.SUM, (op0,), (32, 1, 32, 32, 32, 1, 1, 1))
ast = LazyOp(MovementOps.RESHAPE, (op1,), (32, 32, 32, 32))
+ elif int(os.getenv("BROKEN", "0")):
+ buf0 = GPUBuffer(shape=ShapeTracker(shape=(64, 1, 1, 1), views=[View((64, 1, 1, 1), (1, 0, 0, 0), 0)]), hostbuf=GPUBuffer(shape=(64,), force_create=True))
+ buf1 = GPUBuffer(shape=ShapeTracker(shape=(64, 5, 32, 32), views=[View((64, 5, 32, 32), (5120, 1024, 32, 1), 0)]), hostbuf=GPUBuffer(shape=(64, 5, 32, 32), force_create=True))
+ op0 = LazyOp(ReduceOps.SUM, (buf1,), (64, 1, 1, 1))
+ buf2 = GPUBuffer(shape=ShapeTracker(shape=(64, 1, 1, 1), views=[View((64, 1, 1, 1), (0, 0, 0, 0), 0)]), hostbuf=GPUBuffer(shape=(1,), backing=np.array([0.001], dtype=np.float32)))
+ op1 = LazyOp(BinaryOps.MUL, (op0,buf2,), None)
+ op2 = LazyOp(BinaryOps.SUB, (buf0,op1,), None)
+ ast = LazyOp(MovementOps.RESHAPE, (op2,), (64,))
else:
# reduce
buf0 = GPUBuffer(shape=ShapeTracker(shape=(3, 1, 32, 3, 3, 32, 112, 112), views=[View((3, 32, 225, 225), (50176, 150528, 224, 1), 0), ZeroView((3, 32, 224, 224), ((0, 3), (0, 32), (0, 225), (0, 225))), View((3, 1, 32, 3, 3, 32, 112, 112), (1620000, 1620000, 0, 225, 1, 50625, 450, 2), 0)]), hostbuf=GPUBuffer(shape=(32, 3, 224, 224), force_create=True))

MODIFY
extra/lib_test_ast.py
extra/lib_test_ast.py
@@ -14,11 +14,12 @@ def test_ast(k:ASTKernel, device:Type[DeviceBuffer]=CPUBuffer):
in_test = True
print("testing AST", test_cnt)
test_cnt += 1
+ # TODO: this should only copy the base buffer and retain the shapetracker (requires CPU shapetracker implementation)
cpubufs : Dict[DeviceBuffer, DeviceBuffer] = {x:device.fromCPU(x.toCPU()) for x in k.bufs}
real_out = cpubufs[k.bufs[0]].toCPU()
assert hasattr(device, 'exec_ast')
test_out = device.exec_ast(realize_buffers(cpubufs, k.ast)).toCPU()
- if not np.allclose(real_out, test_out, atol=1e-4):
+ if not np.allclose(real_out, test_out, atol=1e-4, rtol=1e-4):
print("MISMATCH")
print(k.print())
sys.tracebacklimit = 0

MODIFY
tinygrad/llops/ops_gpu.py
tinygrad/llops/ops_gpu.py
@@ -345,10 +345,11 @@ class GPUBuffer(ExplicitExecAST):
@staticmethod
def fromCPU(x): return GPUBuffer(x.shape, backing=x.view(np.ndarray).astype(np.float32).ravel())
- def toCPU(self):
- data = np.empty(self.shape, dtype=np.float32)
+ def toCPU(self) -> np.ndarray:
cl_buf = self.contiguous()
cl_buf = cl_buf if isinstance(cl_buf._buf, CLBuffer) else self.movement_op(MovementOps.RESHAPE, list(self.shape)+[1]).unary_op(UnaryOps.NOOP)
+ assert prod(cl_buf._base_shape) == prod(self.shape)
+ data = np.empty(self.shape, dtype=np.float32)
cl_buf._buf.copyout(data)
return data

found failing upcast