|
|
@ -14,9 +14,11 @@ common_src = [ |
|
|
|
"transforms/transform.cc", |
|
|
|
"transforms/transform.cc", |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
# OpenCL is a framework on Mac |
|
|
|
|
|
|
|
if arch == "Darwin": |
|
|
|
if arch == "Darwin": |
|
|
|
|
|
|
|
# OpenCL is a framework on Mac |
|
|
|
frameworks += ['OpenCL'] |
|
|
|
frameworks += ['OpenCL'] |
|
|
|
|
|
|
|
# Fix for "Error: $HOME must be set to run brew" |
|
|
|
|
|
|
|
lenv['ENV']['HOME'] = os.environ['HOME'] |
|
|
|
else: |
|
|
|
else: |
|
|
|
libs += ['OpenCL'] |
|
|
|
libs += ['OpenCL'] |
|
|
|
|
|
|
|
|
|
|
@ -47,22 +49,40 @@ def tg_compile(flags, model_name): |
|
|
|
f'{pythonpath_string} {flags} python3 {Dir("#tinygrad_repo").abspath}/examples/openpilot/compile3.py {fn}.onnx {fn}_tinygrad.pkl' |
|
|
|
f'{pythonpath_string} {flags} python3 {Dir("#tinygrad_repo").abspath}/examples/openpilot/compile3.py {fn}.onnx {fn}_tinygrad.pkl' |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# Compile small models |
|
|
|
def tg_dump_flags(flags, prefix): |
|
|
|
for model_name in ['driving_vision', 'driving_policy', 'dmonitoring_model']: |
|
|
|
flags_dict = {} |
|
|
|
flags = { |
|
|
|
for flag_pair in flags.split(): |
|
|
|
'larch64': 'QCOM=1', |
|
|
|
k, v = flag_pair.split('=') |
|
|
|
'Darwin': 'CPU=1 IMAGE=0 JIT=2', |
|
|
|
flags_dict[k] = v |
|
|
|
}.get(arch, 'LLVM=1 LLVMOPT=1 BEAM=0 IMAGE=0 JIT=2') |
|
|
|
import json |
|
|
|
tg_compile(flags, model_name) |
|
|
|
with open(f'models/{prefix}_flags.json', 'w') as f: |
|
|
|
|
|
|
|
json.dump(flags_dict, f) |
|
|
|
|
|
|
|
|
|
|
|
# Compile BIG model if USB GPU is available |
|
|
|
|
|
|
|
import subprocess |
|
|
|
import subprocess |
|
|
|
from tinygrad import Device |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# because tg doesn't support multi-process |
|
|
|
# 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) |
|
|
|
devs = subprocess.check_output('python3 -c "from tinygrad import Device; print(list(Device.get_available_devices()))"', shell=True) |
|
|
|
|
|
|
|
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' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Compile small models |
|
|
|
|
|
|
|
for model_name in ['driving_vision', 'driving_policy', 'dmonitoring_model']: |
|
|
|
|
|
|
|
tg_compile(flags, model_name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tg_dump_flags(flags, 'dmonitoringmodeld') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Compile BIG model if USB GPU is available |
|
|
|
if b"AMD" in devs: |
|
|
|
if b"AMD" in devs: |
|
|
|
del Device |
|
|
|
|
|
|
|
print("USB GPU detected... building") |
|
|
|
print("USB GPU detected... building") |
|
|
|
flags = "AMD=1 AMD_IFACE=USB AMD_LLVM=1 NOLOCALS=0 IMAGE=0" |
|
|
|
flags = "AMD=1 AMD_IFACE=USB AMD_LLVM=1 NOLOCALS=0 IMAGE=0" |
|
|
|
bp = tg_compile(flags, "big_driving_policy") |
|
|
|
bp = tg_compile(flags, "big_driving_policy") |
|
|
@ -70,3 +90,5 @@ if b"AMD" in devs: |
|
|
|
lenv.SideEffect('lock', [bp, bv]) # tg doesn't support multi-process so build serially |
|
|
|
lenv.SideEffect('lock', [bp, bv]) # tg doesn't support multi-process so build serially |
|
|
|
else: |
|
|
|
else: |
|
|
|
print("USB GPU not detected... skipping") |
|
|
|
print("USB GPU not detected... skipping") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tg_dump_flags(flags, 'modeld') |
|
|
|