From a374b62bfef310f2ea49335fcb737200d1966c21 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Fri, 7 Jul 2023 18:29:05 -0700 Subject: [PATCH] Revert "Fix ShapeTracker mismatch in LazyBuffer.fromCPU (#1156)" (#1181) This reverts commit 8ff7184b1b9b8d09a20658214db7d457a0a0f60c. --- test/test_lazybuffer.py | 25 ------------------------- tinygrad/lazy.py | 4 ++-- 2 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 test/test_lazybuffer.py diff --git a/test/test_lazybuffer.py b/test/test_lazybuffer.py deleted file mode 100644 index f3aa0bac91..0000000000 --- a/test/test_lazybuffer.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python -import numpy as np -import unittest -from tinygrad.lazy import LazyBuffer - -class TestLazyBuffer(unittest.TestCase): - def test_fromcpu_buffer_sharing(self): - a = np.arange(8) - assert LazyBuffer.fromCPU(a).realized._buf is a - - def test_fromcpu_shape_tracker(self): - def helper(a: np.ndarray): - print(a.shape, a.strides, a.flags.c_contiguous) - b = LazyBuffer.fromCPU(a).realize() - assert b.st.contiguous == a.flags.c_contiguous - assert b.st.shape == a.shape - - for ndims in range(1, 4): - a = np.random.randn(*(4,)*ndims).astype(np.float32) - for stride in [-2, 1, 2]: - for start in [0, 1]: - helper(a[(slice(start, None, stride),)*ndims]) - -if __name__ == "__main__": - unittest.main() diff --git a/tinygrad/lazy.py b/tinygrad/lazy.py index 735238449a..7806bf44e9 100644 --- a/tinygrad/lazy.py +++ b/tinygrad/lazy.py @@ -8,7 +8,7 @@ import numpy as np from tinygrad.helpers import GRAPH, DEBUG, prod, getenv, DType, dtypes, flatten, ImageDType, LightWeakSet, LightWeakValueDictionary from tinygrad.runtime.ops_cpu import RawNumpyBuffer from tinygrad.runtime.ops_disk import RawDiskBuffer -from tinygrad.shape.shapetracker import MovementOps, ShapeTracker, View, get_contraction +from tinygrad.shape.shapetracker import MovementOps, ShapeTracker, get_contraction from tinygrad.ops import Compiled, Interpreted, UnaryOps, BinaryOps, ReduceOps, LoadOps, OpType, LazyOp from tinygrad.runtime.lib import RawBufferMapped, RawConst, RawBuffer @@ -176,7 +176,7 @@ class LazyBuffer: @staticmethod def fromCPU(x: np.ndarray) -> LazyBuffer: - return LazyBuffer("CPU", ShapeTracker(x.shape, [View(x.shape, tuple(st//x.itemsize for st in x.strides))]), LoadOps, LazyOp(LoadOps.EMPTY, (), None), dtypes.from_np(x.dtype), RawNumpyBuffer.fromCPU(x)) + return LazyBuffer("CPU", ShapeTracker(x.shape), LoadOps, LazyOp(LoadOps.EMPTY, (), None), dtypes.from_np(x.dtype), RawNumpyBuffer.fromCPU(x)) # create a constant with the shape and dtype of self def const_like(self, val) -> LazyBuffer: