new-style dcache_flush (#16602)

This commit is contained in:
Christopher Milan 2026-06-12 19:25:08 -07:00 committed by GitHub
commit 8862c7549c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

15
test/device/test_qcom.py Normal file
View file

@ -0,0 +1,15 @@
import ctypes, platform, unittest
from tinygrad import Device
from tinygrad.renderer.cstyle import ClangRenderer
class TestQCOM(unittest.TestCase):
# although part of the QCOM runtime, this tests flushing the CPU's dcache
@unittest.skipUnless(isinstance(Device["CPU"].renderer, ClangRenderer) and platform.machine().lower() in {"arm64", "aarch64"},
"dcache_flush's inline asm needs ClangRenderer, and runs on arm64")
def test_dcache_flush(self):
from tinygrad.runtime.ops_qcom import dcache_flush
buf = (ctypes.c_uint8 * 64)()
dcache_flush().fxn(buf, 0)
if __name__ == '__main__':
unittest.main()

View file

@ -20,8 +20,8 @@ BUFTYPE_BUF, BUFTYPE_TEX, BUFTYPE_IBO = 0, 1, 2
def dcache_flush():
from tinygrad.uop.ops import UOp, Ops, KernelInfo
from tinygrad.codegen import to_program
buf, n = UOp.param(0, dtypes.uint8.ptr()), UOp.param(1, dtypes.uint8.ptr())
i = UOp.range(n.cast(dtypes.int), 0, dtype=dtypes.int)
buf, n = UOp.param(0, dtypes.uint8.ptr(1)), UOp.param(1, dtypes.int, shape=(1,), name="n", addrspace=None)
i = UOp.range(n, 0, dtype=dtypes.int)
flush = UOp(Ops.CUSTOM, dtypes.void, (buf.cast(dtypes.ulong) + i.cast(dtypes.ulong) * UOp.const(dtypes.ulong, 64),),
arg='__asm__ volatile("dc cvac, %0" :: "r"({0}) : "memory");')
sink = UOp.sink(flush.end(i), UOp(Ops.CUSTOM, dtypes.void, (), arg='__asm__ volatile("dsb sy" ::: "memory");'), arg=KernelInfo(name="dcache_flush"))