Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion npbench/infrastructure/dace_framework.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
import importlib
import os
import pkg_resources
import traceback
Expand Down Expand Up @@ -69,7 +70,9 @@ def implementations(self, bench: Benchmark) -> Sequence[Tuple[Callable, str]]:
from dace.transformation.interstate import LoopToMap
import dace.transformation.auto.auto_optimize as opt

exec("from {m} import {f} as ct_impl".format(m=module_str, f=func_str))
module = importlib.import_module(module_str)
ct_impl = getattr(module, func_str)

except Exception as e:
print("Failed to load the DaCe implementation.")
raise (e)
Expand Down
4 changes: 3 additions & 1 deletion npbench/infrastructure/dpnp_framework.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
import os
import pathlib
import tempfile
Expand Down Expand Up @@ -87,7 +88,8 @@ def implementations(self, bench: Benchmark) -> Sequence[Tuple[Callable, str]]:
ldict = dict()
try:
# Load the same implementation regardless of CPU or GPU, and set device later
exec(f"from {module_str} import {func_str} as impl", ldict)
module = importlib.import_module(module_str)
ldict["impl"] = getattr(module, func_str)
except Exception as e:
print(f"Failed to load the {self.fname} implementation of {func_str}.")
raise e
Expand Down
11 changes: 7 additions & 4 deletions npbench/infrastructure/framework.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
import importlib
import json
import numpy as np
import pathlib
Expand Down Expand Up @@ -77,7 +78,8 @@ def implementations(self, bench: Benchmark) -> Sequence[Tuple[Callable, str]]:

ldict = dict()
try:
exec("from {m} import {f} as impl".format(m=module_str, f=func_str), ldict)
module = importlib.import_module(module_str)
ldict["impl"] = getattr(module, func_str)
except Exception as e:
print("Failed to load the {r} {f} implementation.".format(r=self.info["full_name"], f=func_str))
raise e
Expand Down Expand Up @@ -178,9 +180,10 @@ def generate_framework(fname: str, save_strict: bool = False, load_strict: bool
print("Framework JSON file {f} could not be opened.".format(f=frmwrk_filename))
raise (e)

exec("from npbench.infrastructure import {}".format(info["class"]))
module = importlib.import_module("npbench.infrastructure")
cls = getattr(module, info["class"])
if fname.startswith('dace'):
frmwrk = eval(f"{info['class']}(fname, {save_strict}, {load_strict})")
frmwrk = cls(fname, save_strict, load_strict)
else:
frmwrk = eval("{}(fname)".format(info["class"]))
frmwrk = cls(fname)
return frmwrk
8 changes: 6 additions & 2 deletions npbench/infrastructure/jax_framework.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
import importlib
import pathlib

try:
Expand Down Expand Up @@ -79,7 +80,9 @@ def implementations(self, bench: Benchmark):
# appending the default implementation
try:
ldict = dict()
exec("from {m} import {f} as impl".format(m=module_str, f=func_str), ldict)

module = importlib.import_module(module_str)
ldict['impl'] = getattr(module, func_str)
implementations.append((ldict['impl'], 'default'))
except Exception as e:
print("Failed to load the {r} {f} implementation.".format(r=self.info["full_name"], f=func_str))
Expand All @@ -88,7 +91,8 @@ def implementations(self, bench: Benchmark):
for impl_name, impl_postfix in _impl.items():
ldict = dict()
try:
exec("from {m}_{p} import {f} as impl".format(m=module_str, p=impl_postfix, f=func_str), ldict)
module = importlib.import_module("{m}_{p}".format(m=module_str, p=impl_postfix))
ldict['impl'] = getattr(module, func_str)
implementations.append((ldict['impl'], impl_name))
except ImportError:
continue
Expand Down
4 changes: 3 additions & 1 deletion npbench/infrastructure/numba_framework.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
import importlib
import pathlib

from npbench.infrastructure import Benchmark, Framework
Expand Down Expand Up @@ -59,7 +60,8 @@ def implementations(self, bench: Benchmark) -> Sequence[Tuple[Callable, str]]:
for impl_name, impl_postfix in _impl.items():
ldict = dict()
try:
exec("from {m}_{p} import {f} as impl".format(m=module_str, p=impl_postfix, f=func_str), ldict)
module = importlib.import_module("{m}_{p}".format(m=module_str, p=impl_postfix))
ldict['impl'] = getattr(module, func_str)
implementations.append((ldict['impl'], impl_name))
except ImportError:
continue
Expand Down