mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
61 lines
2.5 KiB
Python
61 lines
2.5 KiB
Python
import os
|
|
import glob
|
|
|
|
Import('env', 'envCython', 'arch', 'cereal', 'messaging', 'common', 'gpucommon', 'visionipc', 'transformations')
|
|
lenv = env.Clone()
|
|
lenvCython = envCython.Clone()
|
|
|
|
libs = [cereal, messaging, visionipc, gpucommon, common, 'capnp', 'kj', 'pthread']
|
|
frameworks = []
|
|
|
|
common_src = [
|
|
"models/commonmodel.cc",
|
|
"transforms/loadyuv.cc",
|
|
"transforms/transform.cc",
|
|
]
|
|
|
|
# OpenCL is a framework on Mac
|
|
if arch == "Darwin":
|
|
frameworks += ['OpenCL']
|
|
else:
|
|
libs += ['OpenCL']
|
|
|
|
# Set path definitions to repository-relative paths so prebuilt artifacts stay relocatable.
|
|
for pathdef, fn in {'TRANSFORM': 'selfdrive/modeld/transforms/transform.cl', 'LOADYUV': 'selfdrive/modeld/transforms/loadyuv.cl'}.items():
|
|
for xenv in (lenv, lenvCython):
|
|
xenv['CXXFLAGS'].append(f'-D{pathdef}_PATH=\\"{fn}\\"')
|
|
|
|
# Compile cython
|
|
cython_libs = envCython["LIBS"] + libs
|
|
commonmodel_lib = lenv.Library('commonmodel', common_src)
|
|
lenvCython.Program('models/commonmodel_pyx.so', 'models/commonmodel_pyx.pyx', LIBS=[commonmodel_lib, *cython_libs], FRAMEWORKS=frameworks)
|
|
tinygrad_files = ["#"+x for x in glob.glob(env.Dir("#tinygrad_repo").relpath + "/**", recursive=True, root_dir=env.Dir("#").abspath) if 'pycache' not in x]
|
|
skip_dm_tinygrad_pkl = os.getenv("SP_SKIP_DM_TINYGRAD_PKL", "").lower() in {"1", "true", "yes", "on"}
|
|
allow_host_tinygrad_pkl = os.getenv("SP_ALLOW_HOST_TINYGRAD_PKL", "").lower() in {"1", "true", "yes", "on"}
|
|
build_dm_artifacts = os.getenv("SP_BUILD_MODEL_TINYGRAD_PKL", "").lower() in {"1", "true", "yes", "on"} or allow_host_tinygrad_pkl
|
|
if build_dm_artifacts and not skip_dm_tinygrad_pkl:
|
|
dm_rel_path = "selfdrive/modeld/models/dmonitoring_model"
|
|
dm_node_path = f"#{dm_rel_path}"
|
|
metadata_script = "#selfdrive/modeld/get_model_metadata.py"
|
|
lenv.Command(
|
|
dm_node_path + "_metadata.pkl",
|
|
[dm_node_path + ".onnx", metadata_script],
|
|
f'python3 selfdrive/modeld/get_model_metadata.py {dm_rel_path}.onnx',
|
|
)
|
|
|
|
flags = (
|
|
'DEV=QCOM FLOAT16=1 NOLOCALS=1 IMAGE=2 JIT_BATCH_SIZE=0 DEBUG=0'
|
|
if arch == 'larch64'
|
|
else 'DEV=CPU IMAGE=0 NOLOCALS=1 DEBUG=0 HOME=/tmp'
|
|
)
|
|
pythonpath_string = 'PYTHONPATH="${PYTHONPATH}:tinygrad_repo"'
|
|
compile_script = "#tinygrad_repo/examples/openpilot/compile3.py"
|
|
lenv.Command(
|
|
dm_node_path + "_tinygrad.pkl",
|
|
[dm_node_path + ".onnx"] + tinygrad_files + [compile_script],
|
|
f'{pythonpath_string} {flags} python3 tinygrad_repo/examples/openpilot/compile3.py '
|
|
f'{dm_rel_path}.onnx {dm_rel_path}_tinygrad.pkl',
|
|
)
|
|
else:
|
|
print("Using prebuilt unified driving and driver-monitoring artifacts")
|