remove const/var from the kernel graph [pr] (#9240)

This commit is contained in:
qazal
2025-02-25 12:21:55 +01:00
committed by GitHub
parent b4c3780df0
commit 48dfed064a
2 changed files with 4 additions and 3 deletions
+3
View File
@@ -252,6 +252,9 @@ def append_to_kernel(ctx:KernelContext, x:UOp):
create_kernels = merge_views+PatternMatcher([
(UPat(GroupOp.All-{Ops.KERNEL, Ops.BUFFER}, name="x"), create_kernel),
(UPat(Ops.KERNEL, name="x"), append_to_kernel),
# remove CONST/BIND from the kernel graph
(UPat(Ops.SINK, name="x"), lambda x: x.replace(src=new_src)
if (new_src:=tuple(dedup(s.base for s in x.src if s.op not in {Ops.CONST,Ops.BIND}))) != x.src else None),
])
# **** fix kernel AST
+1 -3
View File
@@ -126,9 +126,7 @@ kernel_spec = buffer_spec+PatternMatcher([
(UPat(Ops.KERNEL, src=UPat((Ops.BUFFER, Ops.ASSIGN))), lambda: True),
# assign has a buffer view and kernel source, it can optionally depend on other assigns
(UPat(Ops.ASSIGN, src=UPat((Ops.BUFFER, Ops.VIEW, Ops.KERNEL, Ops.ASSIGN))), lambda: True),
# view/sink/const/bind/var can also exist in the kernel graph
(UPat((Ops.VIEW, Ops.SINK, Ops.CONST, Ops.BIND, Ops.DEFINE_VAR)), lambda: True),
(UPat(GroupOp.All), lambda: False),
(UPat(GroupOp.All-{Ops.SINK, Ops.VIEW}), lambda: False),
])
# *** this is the UOp shape spec ***