From 82f29b5dbfacb356e50cdbf7ce20d29728ec55fe Mon Sep 17 00:00:00 2001 From: George Hotz Date: Wed, 8 Jun 2022 08:01:04 -0700 Subject: [PATCH] better GPU block --- test/test_llops.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_llops.py b/test/test_llops.py index f1a1d9d409..69f44c8756 100644 --- a/test/test_llops.py +++ b/test/test_llops.py @@ -3,14 +3,15 @@ import time import unittest from tqdm import trange import numpy as np -from tinygrad.llops.opencl import GPUBuffer, sync, unary_op, binary_op, reduce_op from tinygrad.tensor import Device +if Device.DEFAULT == Device.GPU: + from tinygrad.llops.opencl import GPUBuffer, sync, unary_op, binary_op, reduce_op -def timeit(fxn, its=1000): +def timeit(fxn, its=1000, done=lambda:None): fxn() st = time.monotonic() - for _ in trange(its): - fxn() + for _ in trange(its): fxn() + done() return its/(time.monotonic() - st) @unittest.skipUnless(Device.DEFAULT == Device.GPU, "Not Implemented") @@ -20,8 +21,7 @@ class TestBenchmarkCL(unittest.TestCase): buf = GPUBuffer(shape, hostbuf=np.ones(shape, dtype=np.float32)) def fxn(): unary_op('1.01*a', buf, buf) - sync() - its_sec = timeit(fxn, 100000) + its_sec = timeit(fxn, 100000, done=lambda: sync()) print(f"unary op (no sync) {its_sec:.2f} its/sec") self.assertGreater(its_sec, 10000)