mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-10-01 01:43:41 +08:00
modeld: Move from SNPE to tinygrad (#25207)
* compiling, won't work yet
* running with inputs and outputs
* there's some magic chance this works
* no more dlc, include onnx
* yolo tests plz
* bump tinygrad
* files_common + delete dlc
* tinygrad_repo -> tinygrad
* pre commit config
* llops needed
* extra in files_common
* bump tinygrad
* fix indent
* tinygrad/nn/__init__
* tinygrad_repo
* bump tinygrad repo
* bump tinygrad
* bump with native_exp, match maybe
* native_explog is argument
* pyopencl no cache
* 5% chance this matches
* work in float32?
* bump tinygrad
* fix build
* no __init__
* fix recip
* dumb hack
* adding thneed PC support
* fix pc segfault
* pc thneed is working
* to_image
* prints stuff with debug=2
* it sort of works
* copy host ptr is simpler
* bug fix
* build on c3
* this correct?
* reenable float16
* fix private, fixup copy_inputs internal
* bump tinygrad and update ref commit
* fix OPTWG on PC
* maybe fix non determinism
* revert model replay ref commit
* comments, init zeroed out buffers
* upd ref commit
* bump tinygrad to fix initial image
* try this ref
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 40d6f4b65c
This commit is contained in:
+54
-14
@@ -62,25 +62,65 @@ else:
|
||||
|
||||
common_model = lenv.Object(common_src)
|
||||
|
||||
# build thneed model
|
||||
if use_thneed and arch == "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} --in {fn}.dlc --out {fn}.thneed --binary --optimize"
|
||||
|
||||
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 + ".thneed", [fn + ".dlc", kernels, compiler], cmd)
|
||||
|
||||
lenv.Program('_dmonitoringmodeld', [
|
||||
"dmonitoringmodeld.cc",
|
||||
"models/dmonitoring.cc",
|
||||
]+common_model, LIBS=libs)
|
||||
|
||||
lenv.Program('_modeld', [
|
||||
# build thneed model
|
||||
if use_thneed and arch == "larch64" or GetOption('pc_thneed'):
|
||||
fn = File("models/supercombo").abspath
|
||||
|
||||
if GetOption('pc_thneed'):
|
||||
cmd = f"cd {Dir('#').abspath}/tinygrad_repo && NATIVE_EXPLOG=1 OPTWG=1 UNSAFE_FLOAT4=1 DEBUGCL=1 python3 openpilot/compile.py {fn}.onnx {fn}.thneed"
|
||||
else:
|
||||
cmd = f"cd {Dir('#').abspath}/tinygrad_repo && FLOAT16=1 PYOPENCL_NO_CACHE=1 MATMUL=1 NATIVE_EXPLOG=1 OPTWG=1 UNSAFE_FLOAT4=1 DEBUGCL=1 python3 openpilot/compile.py {fn}.onnx {fn}.thneed"
|
||||
|
||||
# is there a better way then listing all of tinygrad?
|
||||
lenv.Command(fn + ".thneed", [fn + ".onnx",
|
||||
"#tinygrad_repo/openpilot/compile.py",
|
||||
"#tinygrad_repo/accel/opencl/conv.cl",
|
||||
"#tinygrad_repo/accel/opencl/matmul.cl",
|
||||
"#tinygrad_repo/accel/opencl/ops_opencl.py",
|
||||
"#tinygrad_repo/accel/opencl/preprocessing.py",
|
||||
"#tinygrad_repo/extra/onnx.py",
|
||||
"#tinygrad_repo/extra/utils.py",
|
||||
"#tinygrad_repo/tinygrad/llops/ops_gpu.py",
|
||||
"#tinygrad_repo/tinygrad/llops/ops_opencl.py",
|
||||
"#tinygrad_repo/tinygrad/helpers.py",
|
||||
"#tinygrad_repo/tinygrad/mlops.py",
|
||||
"#tinygrad_repo/tinygrad/ops.py",
|
||||
"#tinygrad_repo/tinygrad/shapetracker.py",
|
||||
"#tinygrad_repo/tinygrad/tensor.py",
|
||||
"#tinygrad_repo/tinygrad/nn/__init__.py"
|
||||
], cmd)
|
||||
|
||||
# old thneed compiler. TODO: remove this once tinygrad stuff is stable
|
||||
|
||||
#compiler = lenv.Program('thneed/compile', ["thneed/compile.cc"]+common_model, LIBS=libs)
|
||||
#cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} --in {fn}.dlc --out {fn}.thneed --binary --optimize"
|
||||
|
||||
#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 + ".thneed", [fn + ".dlc", kernels, compiler], cmd)
|
||||
|
||||
llenv = lenv.Clone()
|
||||
if GetOption('pc_thneed'):
|
||||
pc_thneed_src = [
|
||||
"thneed/thneed_common.cc",
|
||||
"thneed/thneed_pc.cc",
|
||||
"thneed/serialize.cc",
|
||||
"runners/thneedmodel.cc",
|
||||
]
|
||||
llenv['CFLAGS'].append("-DUSE_THNEED")
|
||||
llenv['CXXFLAGS'].append("-DUSE_THNEED")
|
||||
common_model += llenv.Object(pc_thneed_src)
|
||||
libs += ['dl']
|
||||
|
||||
llenv.Program('_modeld', [
|
||||
"modeld.cc",
|
||||
"models/driving.cc",
|
||||
]+common_model, LIBS=libs + transformations)
|
||||
|
||||
Reference in New Issue
Block a user