Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ assert arch in [
"Darwin", # macOS arm64 (x86 not supported)
]

if arch == "comma_arm64":
from openpilot.common.utils import sudo_write
for cpu in range(4, 8):
sudo_write('1', f'/sys/devices/system/cpu/cpu{cpu}/online')
for policy in ('0', '4'):
governor_path = f'/sys/devices/system/cpu/cpufreq/policy{policy}'
sudo_write('performance', f'{governor_path}/scaling_governor')
with open(f'{governor_path}/cpuinfo_max_freq') as f:
sudo_write(f.read().strip(), f'{governor_path}/scaling_max_freq')

pkg_names = ['acados', 'capnproto', 'ffmpeg', 'json11', 'ncurses', 'zeromq', 'zstd']
pkgs = [importlib.import_module(name) for name in pkg_names]
acados = pkgs[pkg_names.index('acados')]
Expand Down
6 changes: 3 additions & 3 deletions openpilot/selfdrive/modeld/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tg_devices = { # which device to put jit inputs to at runtime

USBGPU = usbgpu_present()
if USBGPU:
usbgpu_tg_flags = f'DEBUG=2 DEV=USB+AMD:LLVM WARP_DEV={tg_backend} FLOAT16=1 JIT_BATCH_SIZE=0 GMMU=0 TC_OPT=2'
usbgpu_tg_flags = f'DEBUG=1 DEV=USB+AMD:LLVM WARP_DEV={tg_backend} FLOAT16=1 JIT_BATCH_SIZE=0 GMMU=0 TC_OPT=2'
# the USB+AMD GPU takes an exclusive flock; serialize all targets that touch it
usbgpu_lock = File("models/.usb_gpu.lock").abspath

Expand Down Expand Up @@ -79,8 +79,8 @@ for usbgpu in [False, True] if USBGPU else [False]:
file_prefix, cmd_flags = ('big_', usbgpu_tg_flags) if usbgpu else ('big_' if os.getenv('BIG_INTO_SMALL') else '', tg_flags)
driving_onnx_deps = get_existing_chunks(File(f"models/{file_prefix}driving_supercombo.onnx").abspath)
camera_res_args = ' '.join(f'{cw}x{ch}' for cw, ch in CAMERA_CONFIGS)
# CPU 7 is isolated with isolcpus on AGNOS, so explicitly pin the compiler to it.
taskset = 'taskset -c 7 ' if arch == 'comma_arm64' else ''
# CPU 7 is isolated with isolcpus on AGNOS, so explicitly include it along with the other cores.
taskset = 'taskset -c 0-7 ' if arch == 'comma_arm64' else ''
cmd = (f'{cmd_flags} {mac_brew_string} {taskset}python3 {modeld_dir}/compile_modeld.py '
f'--model-size {model_w}x{model_h} '
f'--camera-resolutions {camera_res_args} '
Expand Down
12 changes: 4 additions & 8 deletions openpilot/selfdrive/modeld/compile_modeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import atexit
import math
import os
import tempfile
import time
import shutil
from functools import partial
from collections import namedtuple

import numpy as np

from openpilot.selfdrive.modeld.helpers import dump_oob, load_oob
from openpilot.selfdrive.modeld.helpers import dump_oob

def _patch_tinygrad_fetch_fw():
import hashlib
Expand All @@ -35,7 +34,6 @@ def fetch_fw(path, name, sha256):
from tinygrad.device import Device
from tinygrad.engine.jit import TinyJit


NV12Frame = namedtuple("NV12Frame", ['width', 'height', 'stride', 'y_height', 'uv_height', 'size'])
WARP_INPUTS = ['tfm', 'big_tfm']
POLICY_INPUTS = ['img_q', 'big_img_q', 'feat_q', 'desire_q', 'packed_npy_inputs']
Expand Down Expand Up @@ -257,11 +255,7 @@ def random_inputs_run(fn, seed, test_val=None, test_buffers=None, expect_match=T

print('capture + replay')
test_val, test_buffers = random_inputs_run(jit, SEED)
print('pickle round trip')
with tempfile.TemporaryFile(dir=".") as f:
dump_oob(jit, f)
f.seek(0)
jit = load_oob(f)
print('validate replay')
random_inputs_run(jit, SEED, test_val, test_buffers, expect_match=True)
random_inputs_run(jit, SEED+1, test_val, test_buffers, expect_match=False)
return jit
Expand All @@ -274,6 +268,8 @@ def _parse_size(s):

def read_file_chunked_to_disk(path):
from openpilot.common.file_chunker import open_file_chunked
if os.path.isfile(path):
return path
tmp_path = f'{path}.unchunked'
with open(tmp_path, 'wb') as f, open_file_chunked(path) as src:
shutil.copyfileobj(src, f)
Expand Down
Loading