-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load model libraries at runtime in cython ekf (#37)
* RednoseCompileFilter tool * Refactor sconscripts * Move lst_sq and feature_handler to examples * add ekf_load_code_if_needed * Fat binary for cython ext * Restructure. Remove common_ekf. Load libs at runtime * Build compatibility with openpilot * ekf_lib_init * Fix styling issues * Fix linker flags for mac * Remove useless pyx imports * Build static lib instead of shared * newlines * Remove lst_sq_computer and feature_handler
- Loading branch information
Showing
17 changed files
with
155 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ __pycache__/ | |
*$py.class | ||
|
||
# C extensions | ||
*.a | ||
*.o | ||
*.so | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Import('env') | ||
|
||
gen_dir = Dir('generated/').abspath | ||
|
||
env.RednoseCompileFilter( | ||
target="live", | ||
filter_gen_script="live_kf.py", | ||
output_dir=gen_dir, | ||
) | ||
env.RednoseCompileFilter( | ||
target="kinematic", | ||
filter_gen_script="kinematic_kf.py", | ||
output_dir=gen_dir, | ||
) | ||
env.RednoseCompileFilter( | ||
target="compare", | ||
filter_gen_script="test_compare.py", | ||
output_dir=gen_dir, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,17 @@ | ||
Import('env', 'envCython', 'arch', 'rednose_config', 'common') | ||
Import('env', 'envCython', 'common') | ||
|
||
generated_folder = rednose_config['generated_folder'] | ||
|
||
templates = Glob('#rednose/templates/*') | ||
|
||
sympy_helpers = "#rednose/helpers/sympy_helpers.py" | ||
ekf_sym = "#rednose/helpers/ekf_sym.py" | ||
ekf_sym_pyx = "#rednose/helpers/ekf_sym_pyx.pyx" | ||
ekf_sym_cc = env.Object("#rednose/helpers/ekf_sym.cc") | ||
common_ekf = "#rednose/helpers/common_ekf.cc" | ||
|
||
found = {} | ||
for target, (command, *args) in rednose_config['to_build'].items(): | ||
if File(command).exists(): | ||
found[target] = (command, *args) | ||
|
||
lib_target = [common_ekf] | ||
for target, (command, combined_lib, extra_generated, deps) in found.items(): | ||
target_files = File([f'{generated_folder}/{target}.cpp', f'{generated_folder}/{target}.h']) | ||
extra_generated = [File(f'{generated_folder}/{x}') for x in extra_generated] | ||
command_file = File(command) | ||
|
||
env.Command(target_files + extra_generated, | ||
[templates, command_file, sympy_helpers, ekf_sym] + deps, | ||
command_file.get_abspath() + " " + target + " " + Dir(generated_folder).get_abspath()) | ||
|
||
if combined_lib: | ||
lib_target.append(target_files[0]) | ||
else: | ||
env.SharedLibrary(f'{generated_folder}/' + target, [target_files[0], common_ekf]) | ||
|
||
libkf = env.SharedLibrary(f'{generated_folder}/libkf', lib_target) | ||
|
||
lenv = envCython.Clone() | ||
lenv["LINKFLAGS"] += [libkf[0].get_labspath()] | ||
|
||
# for SWAGLOG support | ||
cc_sources = [ | ||
"helpers/ekf_load.cc", | ||
"helpers/ekf_sym.cc", | ||
] | ||
libs = ["dl"] | ||
if common != "": | ||
lenv["LIBS"] = ['zmq', common] + lenv["LIBS"] | ||
# for SWAGLOG support | ||
libs += [common, 'zmq'] | ||
|
||
ekf_sym_so = lenv.Program('#rednose/helpers/ekf_sym_pyx.so', [ekf_sym_pyx, ekf_sym_cc, common_ekf]) | ||
lenv.Depends(ekf_sym_so, libkf) | ||
ekf_objects = env.SharedObject(cc_sources) | ||
rednose = env.Library("helpers/ekf_sym", ekf_objects, LIBS=libs) | ||
rednose_python = envCython.Program("helpers/ekf_sym_pyx.so", ["helpers/ekf_sym_pyx.pyx", ekf_objects], | ||
LIBS=libs + envCython["LIBS"]) | ||
|
||
Export('libkf') | ||
Export('rednose', 'rednose_python') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "ekf_load.h" | ||
#include <dlfcn.h> | ||
|
||
std::vector<const EKF*>& ekf_get_all() { | ||
static std::vector<const EKF*> vec; | ||
return vec; | ||
} | ||
|
||
void ekf_register(const EKF* ekf) { | ||
ekf_get_all().push_back(ekf); | ||
} | ||
|
||
const EKF* ekf_lookup(const std::string& ekf_name) { | ||
for (const auto& ekfi : ekf_get_all()) { | ||
if (ekf_name == ekfi->name) { | ||
return ekfi; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
void ekf_load_and_register(const std::string& ekf_directory, const std::string& ekf_name) { | ||
if (ekf_lookup(ekf_name)) { | ||
return; | ||
} | ||
|
||
#ifdef __APPLE__ | ||
std::string dylib_ext = ".dylib"; | ||
#else | ||
std::string dylib_ext = ".so"; | ||
#endif | ||
std::string ekf_path = ekf_directory + "/lib" + ekf_name + dylib_ext; | ||
void* handle = dlopen(ekf_path.c_str(), RTLD_NOW); | ||
assert(handle); | ||
void* (*ekf_get)() = (void*(*)())dlsym(handle, "ekf_get"); | ||
assert(ekf_get != NULL); | ||
const EKF* ekf = (const EKF*)ekf_get(); | ||
ekf_register(ekf); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <vector> | ||
#include <string> | ||
|
||
#include "ekf.h" | ||
|
||
std::vector<const EKF*>& ekf_get_all(); | ||
const EKF* ekf_lookup(const std::string& ekf_name); | ||
void ekf_register(const EKF* ekf); | ||
void ekf_load_and_register(const std::string& ekf_directory, const std::string& ekf_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.