gpu buffer is shapetracker
MODIFY
tinygrad/llops/ops_gpu.py
tinygrad/llops/ops_gpu.py
@@ -19,10 +19,10 @@ def require_init_gpu():
def roundup(x, n=4): return (x+(n-1))//n * n
-class GPUBuffer:
+class GPUBuffer(ShapeTracker):
def __init__(self, shape, hostbuf=None):
+ super().__init__(*shape)
require_init_gpu()
- self.shape = tuple(shape)
self.cl = hostbuf.cl if isinstance(hostbuf, GPUBuffer) else cl.Buffer(cl_ctx, cl.mem_flags.READ_WRITE, 4*roundup(prod(self.shape))) # padding
if hostbuf is not None and not isinstance(hostbuf, GPUBuffer):
cl.enqueue_copy(cl_queue, self.cl, hostbuf.astype(np.float32).ravel(), is_blocking=False)

MODIFY
tinygrad/shapetracker.py
tinygrad/shapetracker.py
@@ -54,11 +54,11 @@ def strides_for_shape(shape):
class ShapeTracker:
def __init__(self, *shape, strides=None):
+ if len(shape) == 0: shape = (1,)
if isinstance(shape[0], ShapeTracker):
self.views = shape[0].views[:]
else:
assert all([isinstance(x, int) for x in shape])
- if len(shape) == 0: shape = (1,)
self.views = [View(shape, strides_for_shape(shape) if strides == None else strides)]
@property

gpu buffer is shapetracker