returnn.util.native_code_compiler
¶
Native code compiler
- class returnn.util.native_code_compiler.NativeCodeCompiler(base_name, code_version, code, is_cpp=True, c_macro_defines=None, ld_flags=None, include_paths=(), include_deps=None, static_version_name=None, should_cleanup_old_all=True, should_cleanup_old_mydir=False, use_cxx11_abi=False, log_stream=None, verbose=False)[source]¶
Helper class to compile native C/C++ code on-the-fly.
- Parameters:
base_name (str) – base name for the module, e.g. “zero_out”
code_version (int|tuple[int]) – check for the cache whether to reuse
code (str) – the source code itself
is_cpp (bool) – if False, C is assumed
c_macro_defines (dict[str,str|int|None]|None) – e.g. {“TENSORFLOW”: 1}
ld_flags (list[str]|None) – e.g. [“-lblas”]
include_paths (list[str]|tuple[str])
include_deps (list[str]|None) – if provided and an existing lib file, we will check if any dependency is newer and we need to recompile. we could also do it automatically via -MD but that seems overkill and too slow.
static_version_name (str|None) – normally, we use …/base_name/hash as the dir but this would use …/base_name/static_version_name.
should_cleanup_old_all (bool) – whether we should look in the cache dir and check all ops if we can delete some old ones which are older than some limit (self._cleanup_time_limit_days)
should_cleanup_old_mydir (bool) – whether we should delete our op dir before we compile there.
log_stream (TextIO|None) – file stream for print statements
verbose (bool) – be slightly more verbose
- CollectedCompilers: List[NativeCodeCompiler] | None = None[source]¶