Files
dragonpilot/selfdrive/modeld/SConscript

85 lines
2.5 KiB
Python
Raw Normal View History

2020-05-31 13:22:49 -07:00
Import('env', 'arch', 'cereal', 'messaging', 'common', 'gpucommon', 'visionipc')
2020-01-15 14:05:04 -08:00
lenv = env.Clone()
2019-12-13 13:03:08 -08:00
2021-05-15 01:20:48 +00:00
libs = [cereal, messaging, common, visionipc, gpucommon,
'OpenCL', 'SNPE', 'symphony-cpu', 'capnp', 'zmq', 'kj', 'yuv']
2020-05-31 13:22:49 -07:00
2021-02-23 16:46:22 -08:00
def get_dlsym_offset():
"""Returns the offset between dlopen and dlsym in libdl.so"""
import ctypes
libdl = ctypes.PyDLL('libdl.so')
dlopen = ctypes.cast(libdl.dlopen, ctypes.c_void_p).value
dlsym = ctypes.cast(libdl.dlsym, ctypes.c_void_p).value
return dlsym - dlopen
2020-01-15 14:05:04 -08:00
common_src = [
2020-11-24 21:53:25 +00:00
"models/commonmodel.cc",
2020-01-15 14:05:04 -08:00
"runners/snpemodel.cc",
2020-12-18 10:57:05 +00:00
"transforms/loadyuv.cc",
2020-11-24 21:53:25 +00:00
"transforms/transform.cc"
2020-07-14 21:26:01 +00:00
]
2020-01-15 14:05:04 -08:00
2021-02-23 16:46:22 -08:00
thneed_src = [
"thneed/thneed.cc",
"thneed/serialize.cc",
"runners/thneedmodel.cc",
]
if arch == "aarch64" or arch == "larch64":
libs += ['gsl', 'CB']
libs += ['gnustl_shared'] if arch == "aarch64" else ['pthread', 'dl']
common_src += thneed_src
dlsym_offset = get_dlsym_offset()
2020-12-18 10:57:05 +00:00
lenv['CXXFLAGS'].append("-DUSE_THNEED")
2021-02-23 16:46:22 -08:00
lenv['CXXFLAGS'].append(f"-DDLSYM_OFFSET={dlsym_offset}")
2019-12-13 13:03:08 -08:00
else:
2020-10-02 01:45:44 +00:00
libs += ['pthread']
2019-12-13 13:03:08 -08:00
2021-06-07 22:13:57 +00:00
if not GetOption('snpe'):
# for onnx support
common_src += ['runners/onnxmodel.cc']
2020-07-14 21:26:01 +00:00
2021-06-07 22:13:57 +00:00
# tell runners to use onnx
lenv['CFLAGS'].append("-DUSE_ONNX_MODEL")
lenv['CXXFLAGS'].append("-DUSE_ONNX_MODEL")
2020-01-15 14:05:04 -08:00
2020-07-14 21:26:01 +00:00
if arch == "Darwin":
# fix OpenCL
del libs[libs.index('OpenCL')]
lenv['FRAMEWORKS'] = ['OpenCL']
# no SNPE on Mac
del libs[libs.index('SNPE')]
del libs[libs.index('symphony-cpu')]
del common_src[common_src.index('runners/snpemodel.cc')]
2021-07-02 12:49:43 +08:00
elif arch == "jarch64":
# no SNPE on arm64 linux
del libs[libs.index('SNPE')]
del libs[libs.index('symphony-cpu')]
del common_src[common_src.index('runners/snpemodel.cc')]
2021-02-23 16:46:22 -08:00
common_model = lenv.Object(common_src)
# build thneed model
if arch == "aarch64" or arch == "larch64":
2021-06-07 22:13:57 +00:00
compiler = lenv.Program('thneed/compile', ["thneed/compile.cc"]+common_model, LIBS=libs)
2021-02-23 16:46:22 -08:00
cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} ../../models/supercombo.dlc ../../models/supercombo.thneed --binary"
lib_paths = ':'.join([Dir(p).abspath for p in lenv["LIBPATH"]])
cenv = Environment(ENV={'LD_LIBRARY_PATH': f"{lib_paths}:{lenv['ENV']['LD_LIBRARY_PATH']}"})
cenv.Command("../../models/supercombo.thneed", ["../../models/supercombo.dlc", compiler], cmd)
2019-12-13 13:03:08 -08:00
2020-02-06 13:51:42 -08:00
lenv.Program('_dmonitoringmodeld', [
"dmonitoringmodeld.cc",
"models/dmonitoring.cc",
2021-02-23 16:46:22 -08:00
]+common_model, LIBS=libs)
2019-12-13 13:03:08 -08:00
2020-01-15 14:05:04 -08:00
lenv.Program('_modeld', [
2019-12-13 13:03:08 -08:00
"modeld.cc",
"models/driving.cc",
2021-02-23 16:46:22 -08:00
]+common_model, LIBS=libs)
2020-01-15 14:05:04 -08:00