mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-08-29 12:56:07 +00:00
assert kernel buffer limit at compile time [pr] (#8595)
* remove the BUF_LIMIT assert * skip the base one
This commit is contained in:
+3
-2
@@ -9,6 +9,7 @@ from onnx2torch import convert
|
||||
from extra.onnx import get_run_onnx
|
||||
from tinygrad.helpers import OSX, DEBUG, fetch
|
||||
from tinygrad import Tensor, Device
|
||||
from tinygrad.device import CompileError
|
||||
|
||||
MODELS = {
|
||||
"resnet50": "https://github.com/onnx/models/raw/main/validated/vision/classification/resnet/model/resnet50-caffe2-v1-9.onnx",
|
||||
@@ -72,10 +73,10 @@ def benchmark_model(m, devices, validate_outs=False):
|
||||
for _ in range(3): {k:v.numpy() for k,v in tinygrad_jitted_model(**inputs).items()}
|
||||
benchmark(m, f"tinygrad_{device.lower()}_jit", lambda: {k:v.numpy() for k,v in tinygrad_jitted_model(**inputs).items()}) # noqa: F821
|
||||
del inputs, tinygrad_model, tinygrad_jitted_model
|
||||
except RuntimeError as e:
|
||||
except CompileError as e:
|
||||
# TODO: we don't run the dm model on METAL for now
|
||||
if Device.DEFAULT == "METAL":
|
||||
assert "buffer count limit" in str(e)
|
||||
assert "no 'buffer' resource location available" in str(e)
|
||||
return
|
||||
else: raise e
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ from tinygrad.shape.shapetracker import ShapeTracker
|
||||
from tinygrad.shape.view import View
|
||||
# from tinygrad.ops import Variable
|
||||
from tinygrad.tensor import Tensor, _to_np_dtype
|
||||
from tinygrad.engine.schedule import BUF_LIMIT
|
||||
from tinygrad.engine.realize import run_schedule, lower_schedule, CompiledRunner
|
||||
from tinygrad.helpers import prod, Context, getenv, CI, flatten, dedup, AMX
|
||||
from tinygrad.dtype import DType, dtypes
|
||||
@@ -1701,7 +1700,7 @@ class TestHandCodedOpts(unittest.TestCase):
|
||||
# float4/other hcopt shouldn't upcast last axis, since we already have 7 upcast, and the last axis is not very contiguous
|
||||
assert k.upcasted == 1 and k.full_shape[-1] == 7
|
||||
|
||||
@unittest.skipIf((buf_max:=BUF_LIMIT.get(Device.DEFAULT)) is not None and buf_max <= 37, "this test uses too many bufs")
|
||||
@unittest.skipIf(Device.DEFAULT == "METAL", "METAL can only run kernels with up to 32 buffers")
|
||||
def test_masked_upcast_wino(self):
|
||||
monster = Tensor.stack(*[Tensor.stack(*[Tensor.rand(16) for _ in range(6)]) for _ in range(6)])
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from tinygrad.shape.view import View
|
||||
from tinygrad.ops import PatternMatcher, UOp, Ops, UPat, graph_rewrite, track_rewrites, view_supported_devices, symbolic_simple, merge_views
|
||||
from tinygrad.helpers import CI, DEBUG, FUSE_ARANGE, GlobalCounters, getenv, SPLIT_REDUCEOP, unwrap, prod, Context
|
||||
from tinygrad.codegen.kernel import verify_ast
|
||||
from tinygrad.engine.schedule import BUF_LIMIT, ScheduleItem, create_schedule_with_vars, view_right, view_left, remove_movement_ops
|
||||
from tinygrad.engine.schedule import ScheduleItem, create_schedule_with_vars, view_right, view_left, remove_movement_ops
|
||||
from tinygrad.engine.realize import CompiledRunner, run_schedule, lower_schedule
|
||||
from extra.models.llama import precompute_freqs_cis
|
||||
|
||||
@@ -1363,8 +1363,9 @@ class TestSchedule(unittest.TestCase):
|
||||
@unittest.expectedFailure
|
||||
def test_conv2d_fused_half(self): _test_conv2d(5, dtype=dtypes.half)
|
||||
|
||||
@unittest.skip("splitting kernels exceeding device buffer count is not yet supported")
|
||||
def _test_buf_cnt(self, cnt:int, allowed:int):
|
||||
if (m:=BUF_LIMIT.get(Device.DEFAULT)) is None or m != 32: self.skipTest(f"test needs a buf_max of 32 {Device.DEFAULT}")
|
||||
#if (m:=BUF_LIMIT.get(Device.DEFAULT)) is None or m != 32: self.skipTest(f"test needs a buf_max of 32 {Device.DEFAULT}")
|
||||
alu = functools.reduce(lambda x,y: x+y, [Tensor.ones((1, 1)).contiguous().realize() for _ in range(cnt-1)])
|
||||
s = alu.schedule()
|
||||
assert len(s) == allowed
|
||||
|
||||
@@ -13,8 +13,6 @@ from tinygrad.device import Buffer
|
||||
# creation can recurse a lot
|
||||
sys.setrecursionlimit(10000)
|
||||
|
||||
BUF_LIMIT = {"METAL":32}
|
||||
|
||||
# **** big graph spec
|
||||
|
||||
tensor_uop_spec = PatternMatcher([
|
||||
@@ -236,10 +234,6 @@ def schedule_uop(pre:UOp, ctx:ScheduleContext) -> ScheduleItem:
|
||||
sink = graph_rewrite(graph_rewrite(sink, view_left), view_right)
|
||||
# convert to AST
|
||||
sink = graph_rewrite(graph_rewrite(sink, to_si+check_preload if len(si_ctx.assigns) != 0 else to_si, si_ctx), append_bufs, si_ctx)
|
||||
# assert buffer count limit
|
||||
if (limit:=BUF_LIMIT.get(device:=si_ctx.bufs[0].device)) is not None and len(si_ctx.bufs) >= limit:
|
||||
if DEBUG >= 3: print(sink)
|
||||
raise RuntimeError(f"Kernel for {si_ctx.metadata} exceeded the {limit} buffer count limit for {device} with {len(si_ctx.bufs)} buffers.")
|
||||
# we also allow masked views. if it has a single view and it's equal when you shrink a contig, it's fine
|
||||
for ubuf,ops in si_ctx.assign_adj.items():
|
||||
if si_ctx.sinked.get(ubuf) is not None and not all((s:=x.st_arg).contiguous or (len(s.views) == 1 and (m:=s.views[0].mask) is not None \
|
||||
|
||||
Reference in New Issue
Block a user