modeld: autodetect tinygrad backend (#35405)

* modeld: autodetect tinygrad backend

* modeld: autodetect tinygrad CUDA backend

* Revert "modeld: autodetect tinygrad CUDA backend"

This reverts commit 0e9755fb3c5c2021de27f4d230bd0a162883bc37.

* comment why llvm@19

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* backend from jit

* fix static analysis

* simplify

* compile flags log

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
Andrei Radulescu
2025-07-12 05:48:35 +03:00
committed by GitHub
parent f4b017a75b
commit ce92fd1a0f
5 changed files with 38 additions and 13 deletions
+21 -8
View File
@@ -14,9 +14,11 @@ common_src = [
"transforms/transform.cc",
]
# OpenCL is a framework on Mac
if arch == "Darwin":
# OpenCL is a framework on Mac
frameworks += ['OpenCL']
# Fix for METAL Error: $HOME must be set to run brew
lenv['ENV']['HOME'] = os.environ['HOME']
else:
libs += ['OpenCL']
@@ -47,19 +49,30 @@ def tg_compile(flags, model_name):
f'{pythonpath_string} {flags} python3 {Dir("#tinygrad_repo").abspath}/examples/openpilot/compile3.py {fn}.onnx {fn}_tinygrad.pkl'
)
# because tg doesn't support multi-process
import subprocess
devs = subprocess.check_output('python3 -c "from tinygrad import Device; print(list(Device.get_available_devices()))"', shell=True, cwd=env.Dir('#').abspath)
print("Available tinygrad devices:", devs)
if b"QCOM" in devs:
flags = 'QCOM=1'
elif b"METAL" in devs:
flags = 'METAL=1 IMAGE=0 NOLOCALS=0'
elif b"GPU" in devs:
flags = 'GPU=1'
elif b"LLVM" in devs:
flags = 'LLVM=1 LLVMOPT=1 BEAM=0 IMAGE=0 JIT=2'
else:
flags = 'CPU=1 IMAGE=0 JIT=2'
print(f"Compiling models with flags: '{flags}'")
# Compile small models
for model_name in ['driving_vision', 'driving_policy', 'dmonitoring_model']:
flags = {
'larch64': 'QCOM=1',
'Darwin': 'CPU=1 IMAGE=0 JIT=2',
}.get(arch, 'LLVM=1 LLVMOPT=1 BEAM=0 IMAGE=0 JIT=2')
tg_compile(flags, model_name)
# Compile BIG model if USB GPU is available
if "USBGPU" in os.environ:
import subprocess
# because tg doesn't support multi-process
devs = subprocess.check_output('python3 -c "from tinygrad import Device; print(list(Device.get_available_devices()))"', shell=True, cwd=env.Dir('#').abspath)
if b"AMD" in devs:
print("USB GPU detected... building")
flags = "AMD=1 AMD_IFACE=USB AMD_LLVM=1 NOLOCALS=0 IMAGE=0"