Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self,
path: Path,
backend: str,
name_ext_file: str,
native=False,
xsimd=False,
openmp=False,
str_accelerator_flags: Optional[str] = None,
parallel=True,
force=True,
):
if not force:
path_out = path.with_name(name_ext_file)
if not has_to_build(path_out, path):
logger.warning(
f"Do not {backend}ize {path} because it seems up-to-date "
"(but the compilation options may have changed). "
"You can force the compilation with the option -f."
)
return
if mpi.rank == 0:
logger.info(f"Schedule {backend}ization of file {path}")
if str_accelerator_flags is not None:
flags = str_accelerator_flags.strip().split()
else:
flags = []
def update_flags(flag):
if flag not in flags:
name_ext_file: Optional[str] = None,
native=False,
xsimd=False,
openmp=False,
str_pythran_flags: Optional[str] = None,
parallel=True,
force=True,
):
if name_ext_file is None:
name_ext_file = name_ext_from_path_backend(path)
if not force:
path_out = path.with_name(name_ext_file)
if not has_to_build(path_out, path):
logger.warning(
f"Do not pythranize {path} because it seems up-to-date "
"(but the compilation options may have changed). "
"You can force the compilation with the option -f."
)
return
if mpi.rank == 0:
logger.info(f"Schedule pythranization of file {path}")
if str_pythran_flags is not None:
flags = str_pythran_flags.strip().split()
else:
flags = []
def update_flags(flag):
if flag not in flags:
"""
if is_method(func):
return self.transonic_def_method(func)
if is_transpiling or not has_to_replace or not self.is_transpiled:
return func
if not hasattr(self.module_backend, func.__name__):
self.reload_module_backend()
try:
func_tmp = getattr(self.module_backend, func.__name__)
except AttributeError:
# TODO: improve what happens in this case
logger.warning(
f"{self.backend.name_capitalized} file does not seem to be up-to-date:\n"
f"{self.module_backend}\nfunc: {func.__name__}"
)
func_tmp = func
if self.is_compiling:
return functools.wraps(func)(CheckCompiling(self, func_tmp))
return func_tmp
def run():
"""Run the transonic commandline
See :code:`transonic -h`
"""
args = parse_args()
if args.version:
print(__version__)
return
if not args.path and not args.clear_cache:
logger.warning("No python files given. Nothing to do! ✨ 🍰 ✨.")
return
if args.clear_cache:
clear_cached_extensions(args.clear_cache, args.force, args.backend)
return
if args.verbose is None:
logger.set_level(None)
elif args.verbose == 1:
logger.set_level("info")
elif args.verbose > 1:
logger.set_level("debug")
logger.info(args)
path = args.path
)
for file_name, code in codes_ext["class"].items():
path_ext_file = (
path_dir.parent / f"__{self.name}__" / (file_name + ".py")
)
write_if_has_to_write(
path_ext_file, format_str(code), logger.info, force
)
written = write_if_has_to_write(
path_backend, code_backend, logger.info, force
)
if not written:
logger.warning(f"Code in file {path_backend} already up-to-date.")
return
if self.suffix_header:
path_header = (path_dir / path_py.name).with_suffix(
self.suffix_header
)
write_if_has_to_write(path_header, code_header, logger.info, force)
logger.info(f"File {path_backend} updated")
return path_backend
self.is_compiling, self.process = backend.compile_extension(
path_backend, name_ext_file=self.path_extension.name
)
self.is_compiled = not self.is_compiling
self.is_transpiled = True
if not path_ext.exists() and not self.is_compiling:
path_ext_alt = path_backend.with_suffix(backend.suffix_extension)
if path_ext_alt.exists():
self.path_extension = path_ext = path_ext_alt
self.reload_module_backend(module_backend_name)
if not self.is_transpiled:
logger.warning(
f"Module {path_mod} has not been compiled for "
f"Transonic-{backend.name_capitalized}"
)
else:
self.is_compiled = backend.check_if_compiled(self.module_backend)
if self.is_compiled:
module = inspect.getmodule(frame[0])
# module can be None if (at least) it has been run with runpy
if module is not None:
if backend.name == "pythran":
module.__pythran__ = self.module_backend.__pythran__
module.__transonic__ = self.module_backend.__transonic__
if hasattr(self.module_backend, "arguments_blocks"):
self.arguments_blocks = getattr(
self.module_backend, "arguments_blocks"
if not path_py.exists():
raise FileNotFoundError(f"Input file {path_py} not found")
if path_py.absolute().parent.name == f"__{self.name}__":
logger.debug(f"skip file {path_py}")
return None, None, None
if not path_py.name.endswith(".py"):
raise ValueError(
"transonic only processes Python file. Cannot process {path_py}"
)
path_dir = path_py.parent / str(f"__{self.name}__")
path_backend = (path_dir / path_py.name).with_suffix(self.suffix_backend)
if not has_to_build(path_backend, path_py) and not force:
logger.warning(f"File {path_backend} already up-to-date.")
return None, None, None
if path_dir is None:
return
if not analyse:
with open(path_py) as file:
code = file.read()
analyse = analyse_aot(code, path_py, self.name)
code_backend, codes_ext, code_header = self._make_backend_code(
path_py, analyse
)
if not code_backend:
return
logger.debug(f"code_{self.name}:\n{code_backend}")
def __call__(self, func):
if not has_to_replace:
return func
if is_method(func):
return TransonicTemporaryJITMethod(
func, self.native, self.xsimd, self.openmp
)
if not can_import_accelerator(self.backend.name):
logger.warning(
"Cannot accelerate a jitted function because "
f"{self.backend.name_capitalized} is not importable."
)
return func
func_name = func.__name__
backend = self.backend
mod = self.mod
mod.jit_functions[func_name] = self
module_name = mod.module_name
path_jit = mpi.Path(backend.jit.path_base)
path_backend = path_jit / module_name.replace(".", os.path.sep)
if mpi.rank == 0: