Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

tools/air: read a device run with the same table, and say what it cannot mean

vcvkk4bc51e760e0a
diff --git a/tools/air/kernelcheck.py b/tools/air/kernelcheck.py
index d7c91f0..d88053e 100755
--- a/tools/air/kernelcheck.py
+++ b/tools/air/kernelcheck.py
@@ -20,7 +20,15 @@ about -- an exclusion without its own number. A table that cannot fail to add
up is worth more than a careful author.
usage: kernelcheck.py [--list] [FILE.metallib...]
+ kernelcheck.py --log RUN.log [FILE.metallib...]
(no files: the five libraries of the corpus, as check.sh has them)
+
+--log reads a device run instead of dispatching here, so the table from the
+phone is generated by the same code and checked against the same total. What it
+can say is narrower than what the host table says, and the difference is not a
+detail: softpipe will not run 38 of these kernels, so there is no executed
+reference for them anywhere, and a number out of the Adreno has nothing to be
+compared against. The rows mean dispatched or refused. They do not mean right.
"""
import os
@@ -85,8 +93,48 @@ def classify(text):
return None
+def from_log(path, ks):
+ """Each kernel's outcome as a device run reported it.
+
+ Keyed on the name air_run prints, not on the order of the lines: a console
+ shared with launchd interleaves them, and the loader's log drops its own
+ middle when it grows (README, "Как врут собственные проверки"). A kernel
+ whose block never appears is "not in the log", which is its own row rather
+ than being folded into a refusal -- the two have different causes and the
+ log being truncated is one of them.
+ """
+ import re
+ blocks, cur = {}, None
+ for line in open(path, errors="replace"):
+ m = re.match(r"^air_run: (\S+) on ", line)
+ if m:
+ cur = m.group(1)
+ blocks.setdefault(cur, [])
+ continue
+ if cur:
+ blocks[cur].append(line)
+ out = {}
+ for _, name in ks:
+ b = blocks.get(name)
+ if b is None:
+ out[name] = ("missing", "")
+ continue
+ text = "".join(b)
+ if "came back as" in text or "after the dispatch" in text:
+ out[name] = ("dispatched", "")
+ else:
+ why = next((l.strip() for l in b if "air_run:" in l or "Assertion" in l), "")
+ out[name] = ("refused", why[:100])
+ return out
+
+
def main(argv):
want_list = "--list" in argv
+ log = None
+ if "--log" in argv:
+ i = argv.index("--log")
+ log = argv[i + 1]
+ argv = argv[:i] + argv[i + 2:]
libs = [a for a in argv if not a.startswith("--")] or LIBS
for prog in (AIR2NIR, AIR_RUN):
if not os.path.exists(prog):
@@ -97,6 +145,43 @@ def main(argv):
ks = kernels(libs)
counts = {key: [] for key, _, _ in CAUSES}
unmatched = []
+
+ if log:
+ res = from_log(log, ks)
+ # A log with not one of these kernels in it is the wrong log, not a run
+ # where every one went missing. Those two read identically -- 0, 0, 47 --
+ # and only one of them is a result, so it is refused rather than
+ # tabulated. (The same shape as intrincheck's refusal to judge a log
+ # older than its manifest.)
+ if all(v[0] == "missing" for v in res.values()):
+ print("kernelcheck: %s holds no block for any of the %d kernels, so it is a log "
+ "of some other run rather than a run where all of them vanished"
+ % (os.path.basename(log), len(ks)), file=sys.stderr)
+ return 1
+ got = sum(1 for v in res.values() if v[0] == "dispatched")
+ ref = {n: v[1] for n, v in res.items() if v[0] == "refused"}
+ miss = [n for n, v in res.items() if v[0] == "missing"]
+ print("kernelcheck: %d compute kernels, as %s reports them"
+ % (len(ks), os.path.basename(log)))
+ print(" %2d dispatched and read back" % got)
+ print(" %2d refused, with a reason in the log" % len(ref))
+ print(" %2d not in the log at all (the loader drops its middle when it grows)"
+ % len(miss))
+ if want_list:
+ for n in sorted(ref):
+ print(" %-44s %s" % (n, ref[n]))
+ for n in sorted(miss):
+ print(" %-44s (absent)" % n)
+ total = got + len(ref) + len(miss)
+ if total != len(ks):
+ print("kernelcheck: the rows add to %d and there are %d kernels" % (total, len(ks)),
+ file=sys.stderr)
+ return 1
+ print("kernelcheck: the rows add to %d, which is every kernel. These rows say "
+ "dispatched or refused, never right: softpipe runs too few of these for there "
+ "to be a reference." % total)
+ return 0
+
for path, name in ks:
q = subprocess.run([AIR_RUN, path, name], capture_output=True, timeout=300)
if q.returncode == 0:
diff --git a/userland/rc.jobs.airkernels b/userland/rc.jobs.airkernels
new file mode 100644
index 0000000..391d02d
--- /dev/null
+++ b/userland/rc.jobs.airkernels
@@ -0,0 +1,65 @@
+# Commands run by the launchd job com.redwood.demo (RC_JOBS=rc.jobs.airkernels).
+#
+# Every compute kernel of the corpus, dispatched on the Adreno. This is the question softpipe
+# cannot answer and has been deferred twice: of the 47, six dispatch on software and 38 stop in
+# nir_to_tgsi, which has no scratch memory and lacks compute intrinsics that ir3 has
+# (tools/air/kernelcheck.py). So those 38 are not a statement about the frontend or the GPU --
+# they are a statement about a software rasteriser, and only the phone can replace it.
+#
+# What this run can establish is capability, not correctness. There is no executed reference for
+# these kernels anywhere: softpipe will not run them, so a number from the Adreno has nothing on
+# this machine to be compared against, and air_run's own buffer and image readback is the only
+# output. A kernel that dispatches and prints plausible numbers has been shown to RUN; whether it
+# computed what Metal says is a separate question with no second source today. Read the lines as
+# "dispatched" or "refused", not as agreement.
+#
+# The first line is the shader M1 is stated against, with --disasm: it proves the GPU is there and
+# that ir3 compiled what ran, which the screen name alone does not.
+/redwood/bin/air_run --disasm /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib clearFragment01
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib BlitLumaKernel_Uint
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib BlitChromaKernel_Uint
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib BlitLumaKernel_UintPacked
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib BlitChromaKernel_UintPacked
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib BlitLumaKernel_Unorm
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib BlitChromaKernel_Unorm
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib BlitKernel_Unorm
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib FilmGrainLumaKernel_Uint
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib FilmGrainChromaKernel_Uint
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib FilmGrainLumaKernel_Unorm
+/redwood/bin/air_run /System/Library/VideoDecoders/AV1SW.metallib FilmGrainChromaKernel_Unorm
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_Clear
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_InitMinMax
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_MinMax
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_CalcCubeInputScaling
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_PopulateCube
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_DilateCubeLuma
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_DilateCubeChroma1
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_DilateCubeChroma2
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_ErodeCubeLuma
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_ErodeCubeChroma1
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_ErodeCubeChroma2
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_InitSpanTable
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_GenerateMask
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_GenerateToothMask
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_ConnectSpans
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_PropagateParents
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_PropogateAssociations
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_ResolveAssociations
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_AddSeedPoint
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_DrawSpans
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib MetalFaceMask_DrawEye
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_bistochastize_init
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_bistochastize_iter
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_bistochastize_final
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_pcg_init
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_pcg_iter1
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_pcg_iter2
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_pcg_iter3
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_slice
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib fbs_slice_trilinear
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib spillCorrectionPreProcess
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib spillCorrectionPostProcess
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib image_calcminmax0
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib image_calcminmax1
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib image_calcminmax2
+/redwood/bin/air_run /System/Library/CoreImage/PortraitFilters.cifilter/default.metallib confidence