nopenpilot/selfdrive/modeld/SConscript

96 lines
3.0 KiB
Python
Raw Normal View History

import os
Import('env', 'arch', 'cereal', 'messaging', 'common', 'gpucommon', 'visionipc')
lenv = env.Clone()
libs = [cereal, messaging, common, visionipc, gpucommon,
'OpenCL', 'SNPE', 'symphony-cpu', 'capnp', 'zmq', 'kj', 'yuv']
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
common_src = [
Torch model (#2452) * refactor draw model * rebase master * correct valid_len * rename function * rename variables * white space * rebase to master * e16c13ac-927d-455e-ae0a-81b482a2c787 * start rewriting * save proress * compiles! * oops * many fixes * seems to work * fix desires * finally cleaned * wrong std for ll * dont pulse none * compiles! * ready to test * WIP does not compile * compiles * various fixes * does something! * full 3d * not needed * draw up to 100m * fix segfault * wrong sign * fix flicker * add road edges * finish v2 packet * Added pytorch supercombo * fix rebase * no more keras * Hacky solution to the NCHW/NHWC incompatibility between SNPE and our frame data * dont break dmonitoringd, final model 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 * fix hack * Revert "fix hack" This reverts commit 5550fc01a7881d065a5eddbbb42dac55ef7ec36c. * Removed axis permutation hack * Folded padding layers into conv layers * Removed the last pad layer from the dlc * Revert "Removed the last pad layer from the dlc" This reverts commit b85f24b9e1d04abf64e85901a7ff49e00d82020a. * Revert "Folded padding layers into conv layers" This reverts commit b8d1773e4e76dea481acebbfad6a6235fbb58463. * vision model: 5034ac8b-5703-4a49-948b-11c064d10880/780 temporal model: 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 with permute + pool opt * fix ui drawing with clips * ./compile_torch.py 5034ac8b-5703-4a49-948b-11c064d10880/780 dfcd2375-81d8-49df-95bf-1d2d6ad86010/450 with variable history length * std::clamp * not sure how this compiled before * 2895ace6-a296-47ac-86e6-17ea800a74e5/550 * db090195-8810-42de-ab38-bb835d775d87/601 * 5m is very little * onnx runner * add onnxruntime to pipfile * run in real time without using the whole CPU * bump cereal; * add stds * set road edge opacity based on stddev * don't access the model packet in paint * convert mat.h to a c++ header file (#2499) * update tests * safety first Co-authored-by: deanlee <deanlee3@gmail.com> Co-authored-by: mitchell <mitchell@comma.ai> Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: George Hotz <george@comma.ai> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2020-11-11 21:31:46 -07:00
"models/commonmodel.cc",
"runners/snpemodel.cc",
"transforms/loadyuv.cc",
Torch model (#2452) * refactor draw model * rebase master * correct valid_len * rename function * rename variables * white space * rebase to master * e16c13ac-927d-455e-ae0a-81b482a2c787 * start rewriting * save proress * compiles! * oops * many fixes * seems to work * fix desires * finally cleaned * wrong std for ll * dont pulse none * compiles! * ready to test * WIP does not compile * compiles * various fixes * does something! * full 3d * not needed * draw up to 100m * fix segfault * wrong sign * fix flicker * add road edges * finish v2 packet * Added pytorch supercombo * fix rebase * no more keras * Hacky solution to the NCHW/NHWC incompatibility between SNPE and our frame data * dont break dmonitoringd, final model 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 * fix hack * Revert "fix hack" This reverts commit 5550fc01a7881d065a5eddbbb42dac55ef7ec36c. * Removed axis permutation hack * Folded padding layers into conv layers * Removed the last pad layer from the dlc * Revert "Removed the last pad layer from the dlc" This reverts commit b85f24b9e1d04abf64e85901a7ff49e00d82020a. * Revert "Folded padding layers into conv layers" This reverts commit b8d1773e4e76dea481acebbfad6a6235fbb58463. * vision model: 5034ac8b-5703-4a49-948b-11c064d10880/780 temporal model: 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 with permute + pool opt * fix ui drawing with clips * ./compile_torch.py 5034ac8b-5703-4a49-948b-11c064d10880/780 dfcd2375-81d8-49df-95bf-1d2d6ad86010/450 with variable history length * std::clamp * not sure how this compiled before * 2895ace6-a296-47ac-86e6-17ea800a74e5/550 * db090195-8810-42de-ab38-bb835d775d87/601 * 5m is very little * onnx runner * add onnxruntime to pipfile * run in real time without using the whole CPU * bump cereal; * add stds * set road edge opacity based on stddev * don't access the model packet in paint * convert mat.h to a c++ header file (#2499) * update tests * safety first Co-authored-by: deanlee <deanlee3@gmail.com> Co-authored-by: mitchell <mitchell@comma.ai> Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: George Hotz <george@comma.ai> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2020-11-11 21:31:46 -07:00
"transforms/transform.cc"
2020-07-10 16:26:16 -06:00
]
thneed_src = [
"thneed/thneed.cc",
"thneed/serialize.cc",
"thneed/optimizer.cc",
"runners/thneedmodel.cc",
]
use_thneed = not GetOption('no_thneed')
if arch == "aarch64" or arch == "larch64":
libs += ['gsl', 'CB']
libs += ['gnustl_shared'] if arch == "aarch64" else ['pthread', 'dl']
if use_thneed:
common_src += thneed_src
dlsym_offset = get_dlsym_offset()
lenv['CXXFLAGS'].append("-DUSE_THNEED")
lenv['CXXFLAGS'].append(f"-DDLSYM_OFFSET={dlsym_offset}")
else:
2020-09-28 03:46:51 -06:00
libs += ['pthread']
if not GetOption('snpe'):
# for onnx support
common_src += ['runners/onnxmodel.cc']
2020-07-10 16:26:16 -06:00
# tell runners to use onnx
lenv['CFLAGS'].append("-DUSE_ONNX_MODEL")
lenv['CXXFLAGS'].append("-DUSE_ONNX_MODEL")
2020-07-10 16:26:16 -06: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')]
common_model = lenv.Object(common_src)
# build thneed model
if use_thneed and arch in ("aarch64", "larch64"):
fn = File("#models/supercombo").abspath
compiler = lenv.Program('thneed/compile', ["thneed/compile.cc"]+common_model, LIBS=libs)
cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} {fn}.dlc {fn}_badweights.thneed --binary"
2021-02-05 01:54:57 -07:00
lib_paths = ':'.join(Dir(p).abspath for p in lenv["LIBPATH"])
kernel_path = os.path.join(Dir('.').abspath, "thneed", "kernels")
cenv = Environment(ENV={'LD_LIBRARY_PATH': f"{lib_paths}:{lenv['ENV']['LD_LIBRARY_PATH']}", 'KERNEL_PATH': kernel_path})
kernels = [os.path.join(kernel_path, x) for x in os.listdir(kernel_path) if x.endswith(".cl")]
cenv.Command(fn + "_badweights.thneed", [fn + ".dlc", kernels, compiler], cmd)
from selfdrive.modeld.thneed.weights_fixup import weights_fixup
def weights_fixup_action(target, source, env):
weights_fixup(target[0].abspath, source[0].abspath, source[1].abspath)
env = Environment(BUILDERS = {'WeightFixup' : Builder(action = weights_fixup_action)})
env.WeightFixup(target=fn + ".thneed", source=[fn+"_badweights.thneed", fn+".dlc"])
2020-01-30 20:12:44 -07:00
lenv.Program('_dmonitoringmodeld', [
"dmonitoringmodeld.cc",
"models/dmonitoring.cc",
]+common_model, LIBS=libs)
lenv.Program('_modeld', [
"modeld.cc",
"models/driving.cc",
]+common_model, LIBS=libs)