Archived
The core's HIP use is already behind the DeviceBackend vtable except three core kernels (advance, wtab, xprefetch), the engine's interposed hipLaunchKernel that plugins launch through, and build switches; each site is listed with file and line. The minimal set for MiniCPM5-2B is measured with --debug-graph on the test suite's synthetic llama containers (13 model ops, 13 sampler ops; fp8 adds gemm_nt_q / gemm_nt_q_gated), since no MiniCPM5 container is in the model library. The design: a fourth DeviceBackend over SYCL, a RadSyclStream hand-off for plugins with its own version instead of an ABI bump, libxe2 AOT for bmg-g31, and on that backend a fatal error where the planner would otherwise put a weighted op on the CPU. scripts/sycl/op_inventory.sh generates the 238-op appendix: libref's schemas through rad-schemas, libr4d's 407 rows parsed from source by r4d_rows.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
45 lines
1.9 KiB
Python
45 lines
1.9 KiB
Python
"""r4d_rows.py ROWS_CPP -- the kKernels rows of libr4d/r4d_rows.cpp as TSV: op, kernel, dtypes, domain.
|
|
|
|
Read as source because a build without HIP has no libr4d.so to ask. A row is
|
|
{ "kernel", "op", "family", "computes", "shape", "dtypes", RAD_DOMAIN_..., ... }; adjacent string
|
|
literals are joined as the C compiler joins them, so a dtypes string split over lines stays whole.
|
|
"""
|
|
import re
|
|
import sys
|
|
|
|
src = open(sys.argv[1], encoding="utf-8").read()
|
|
start = src.index("static const RadKernelInfo kKernels[] = {")
|
|
body = src[start:]
|
|
# Comments out, so prose in them cannot look like a row.
|
|
body = re.sub(r"/\*.*?\*/", " ", body, flags=re.S)
|
|
body = re.sub(r"//[^\n]*", " ", body)
|
|
|
|
body = body.replace("\\\n", "\n") # macro line continuations
|
|
|
|
lit = r'"(?:[^"\\]|\\.)*"'
|
|
# Between literals a row may splice in a macro: R4D_XSTR(X), a stringised #PARAM, or a name such as
|
|
# KVDOC. Each is kept as <NAME>, so a template row's kernel reads attn_window_h<HD>_gqa<G>_<KVN>.
|
|
mac = r"R4D_XSTR\(\s*\w+\s*\)|#\w+|\b(?!RAD_DOMAIN_)[A-Z][A-Z0-9_]*\b"
|
|
row_re = re.compile(r"\{\s*((?:(?:" + lit + "|" + mac + r")\s*,?\s*)+?)(RAD_DOMAIN_[A-Z]+)")
|
|
for m in row_re.finditer(body):
|
|
if not m.group(1).lstrip().startswith('"'):
|
|
continue
|
|
# Split the run into arguments at commas; join adjacent literals and macros within one.
|
|
args, cur = [], []
|
|
for tok in re.finditer(lit + "|" + mac + r"|,", m.group(1)):
|
|
t = tok.group(0)
|
|
if t == ",":
|
|
args.append("".join(cur))
|
|
cur = []
|
|
elif t.startswith('"'):
|
|
cur.append(re.sub(r"\\(.)", r"\1", t[1:-1]))
|
|
else:
|
|
name = re.sub(r"^R4D_XSTR\(\s*|\s*\)$|^#", "", t)
|
|
cur.append(f"<{name}>")
|
|
if cur:
|
|
args.append("".join(cur))
|
|
if len(args) < 6:
|
|
continue
|
|
kern, op, dtypes = args[0], args[1], " ".join(args[5].split())
|
|
print(f"{op}\t{kern}\t{dtypes}\t{m.group(2)[len('RAD_DOMAIN_'):].lower()}")
|