196 errors
Black found 196 errors
Annotations
Check failure on line 9 in /home/runner/work/kerncraft/kerncraft/kerncraft/__init__.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/__init__.py#L1-L9
"""Kerncraft static analytical performance modeling framework and tool."""
-__version__ = '0.8.15'
+__version__ = "0.8.15"
from .kerncraft import main
+
__main__ = main
# To trigger travis deployment to pypi, do the following:
# 1. Increment __version___
# 2. commit to RRZE-HPC/kerncraft's master branch
Check failure on line 18 in /home/runner/work/kerncraft/kerncraft/kerncraft/__init__.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/__init__.py#L12-L18
def get_header_path() -> str:
"""Return local folder path of header files."""
import os
- return os.path.abspath(os.path.dirname(os.path.realpath(__file__))) + '/headers/'
+
+ return os.path.abspath(os.path.dirname(os.path.realpath(__file__))) + "/headers/"
github-actions / Black
/home/runner/work/kerncraft/kerncraft/examples/machine-files/plot_machine_file.py#L5-L67
import matplotlib.pyplot as plt
from matplotlib.ticker import EngFormatter
from kerncraft import machinemodel
-kernel_colors = 'bgrcmyk'
+kernel_colors = "bgrcmyk"
+
def main():
mm = machinemodel.MachineModel(sys.argv[1])
- kernels = sorted(mm['benchmarks']['kernels'])
- cache_levels = sorted(mm['benchmarks']['measurements'])
+ kernels = sorted(mm["benchmarks"]["kernels"])
+ cache_levels = sorted(mm["benchmarks"]["measurements"])
fig, axs = plt.subplots(len(cache_levels), 1, figsize=(7, 14), tight_layout=True)
lines = {}
for i, cache_level in enumerate(cache_levels):
max_bw = 0
max_bw_core = 0
axs[i].set_title(cache_level)
formatter1 = EngFormatter(places=0) # , sep="\N{THIN SPACE}") # U+2009
axs[i].yaxis.set_major_formatter(formatter1)
- if cache_level == 'L1':
+ if cache_level == "L1":
axs[i].set_ylabel("Bandwidth [B/s]")
else:
axs[i].set_ylabel("Bandwidth [B/s]\n(incl. write-allocate)")
- axs[i].set_xlabel('cores')
+ axs[i].set_xlabel("cores")
# axs[i].set_xscale('log')
for ki, kernel in enumerate(kernels):
- if cache_level == 'L1':
+ if cache_level == "L1":
# L1 does not have write-allocate, so everything is measured correctly
factor = 1.0
else:
- measurement_kernel_info = mm['benchmarks']['kernels'][kernel]
- factor = (float(measurement_kernel_info['read streams']['bytes']) +
- 2.0 * float(measurement_kernel_info['write streams']['bytes']) -
- float(measurement_kernel_info['read+write streams']['bytes'])) / \
- (float(measurement_kernel_info['read streams']['bytes']) +
- float(measurement_kernel_info['write streams']['bytes']))
+ measurement_kernel_info = mm["benchmarks"]["kernels"][kernel]
+ factor = (
+ float(measurement_kernel_info["read streams"]["bytes"])
+ + 2.0 * float(measurement_kernel_info["write streams"]["bytes"])
+ - float(measurement_kernel_info["read+write streams"]["bytes"])
+ ) / (
+ float(measurement_kernel_info["read streams"]["bytes"])
+ + float(measurement_kernel_info["write streams"]["bytes"])
+ )
- for SMT in mm['benchmarks']['measurements'][cache_level]:
+ for SMT in mm["benchmarks"]["measurements"][cache_level]:
measurements = [
- bw*factor
- for bw in mm['benchmarks']['measurements'][cache_level][SMT]['results'][kernel]]
- max_bw = max(measurements+[max_bw])
+ bw * factor
+ for bw in mm["benchmarks"]["measurements"][cache_level][SMT][
+ "results"
+ ][kernel]
+ ]
+ max_bw = max(measurements + [max_bw])
max_bw_core = max(max_bw_core, measurements[0])
- lines[kernel], = axs[i].plot(
+ (lines[kernel],) = axs[i].plot(
range(1, 1 + len(measurements)),
measurements,
- linestyle=['-', '--', '..', '-.'][SMT-1],
- color=kernel_colors[ki])
+ linestyle=["-", "--", "..", "-."][SMT - 1],
+ color=kernel_colors[ki],
+ )
axs[i].set_xlim(1)
- axs[i].axhline(max_bw, color='black')
- axs[i].axhline(max_bw_core, color='black')
- axs[i].set_yticks(np.append(axs[i].get_yticks(), [float(max_bw), float(max_bw_core)]))
- axs[i].set_xticks(range(1, 1+len(measurements)))
- fig.legend(lines.values(), lines.keys(), 'lower center', ncol=10)
- fig.savefig(sys.argv[1]+'.pdf')
- #plt.show()
+ axs[i].axhline(max_bw, color="black")
+ axs[i].axhline(max_bw_core, color="black")
+ axs[i].set_yticks(
+ np.append(axs[i].get_yticks(), [float(max_bw), float(max_bw_core)])
+ )
+ axs[i].set_xticks(range(1, 1 + len(measurements)))
+ fig.legend(lines.values(), lines.keys(), "lower center", ncol=10)
+ fig.savefig(sys.argv[1] + ".pdf")
+ # plt.show()
-if __name__ == '__main__':
+if __name__ == "__main__":
main()
Check failure on line 34 in /home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py#L10-L34
from .machinemodel import MachineModel
from .prefixedunit import PrefixedUnit
def create_parser():
- parser = argparse.ArgumentParser(description='Find optimal tiling sizes using the ECMData '
- 'model.')
- parser.add_argument('--machine', '-m', type=argparse.FileType('r'), required=True,
- help='Path to machine description yaml file.')
- parser.add_argument('--define', '-D', nargs=2, metavar=('KEY', 'VALUE'), default=[],
- action='append',
- help='Define fixed constants. Values must be integer.')
- parser.add_argument('--min-block-length', '-b', type=int, metavar='MIN', default=100)
- parser.add_argument('--verbose', '-v', action='count', default=0,
- help='Increases verbosity level.')
- parser.add_argument('--cores', '-c', metavar='CORES', type=int, default=1,
- help='Number of cores to be used in parallel. (default: 1)')
- parser.add_argument('description_file', metavar='FILE', type=argparse.FileType(),
- help='File with loop kernel description in YAML')
+ parser = argparse.ArgumentParser(
+ description="Find optimal tiling sizes using the ECMData " "model."
+ )
+ parser.add_argument(
+ "--machine",
+ "-m",
+ type=argparse.FileType("r"),
+ required=True,
+ help="Path to machine description yaml file.",
+ )
+ parser.add_argument(
+ "--define",
+ "-D",
+ nargs=2,
+ metavar=("KEY", "VALUE"),
+ default=[],
+ action="append",
+ help="Define fixed constants. Values must be integer.",
+ )
+ parser.add_argument(
+ "--min-block-length", "-b", type=int, metavar="MIN", default=100
+ )
+ parser.add_argument(
+ "--verbose", "-v", action="count", default=0, help="Increases verbosity level."
+ )
+ parser.add_argument(
+ "--cores",
+ "-c",
+ metavar="CORES",
+ type=int,
+ default=1,
+ help="Number of cores to be used in parallel. (default: 1)",
+ )
+ parser.add_argument(
+ "description_file",
+ metavar="FILE",
+ type=argparse.FileType(),
+ help="File with loop kernel description in YAML",
+ )
return parser
def simulate(kernel, model, define_dict, blocking_constant, blocking_length):
"""Setup and execute model with given blocking length"""
Check failure on line 59 in /home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py#L38-L59
kernel.set_constant(k, v)
kernel.set_constant(blocking_constant, blocking_length)
model.analyze()
- return sum([cy for dscr, cy in model.results['cycles']])
+ return sum([cy for dscr, cy in model.results["cycles"]])
def run(parser, args):
# machine information
# Read machine description
machine = MachineModel(args.machine.name)
# process kernel description
description = str(args.description_file.read())
- yaml = ruamel.yaml.YAML(typ='unsafe')
+ yaml = ruamel.yaml.YAML(typ="unsafe")
yaml.register_class(PrefixedUnit)
kernel = KernelDescription(yaml.load(description))
# Add constants from define arguments
define_dict = {}
Check failure on line 80 in /home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py#L68-L80
var_type, var_size = var_info
for size in var_size:
for s in size.atoms(sympy.Symbol):
if s.name not in define_dict:
undefined_constants.add(s)
- assert len(undefined_constants) == 1, "There are multiple or none undefined constants {!r}. " \
+ assert len(undefined_constants) == 1, (
+ "There are multiple or none undefined constants {!r}. "
"Exactly one must be undefined.".format(undefined_constants)
+ )
blocking_constant = undefined_constants.pop()
if args.verbose >= 1:
print("blocking constant:", blocking_constant)
Check failure on line 99 in /home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py#L81-L99
min_length = args.min_block_length
min_runtime = simulate(kernel, model, define_dict, blocking_constant, min_length)
# determain max search length
# upper bound: number of floats that fit into the last level cache
- max_length = int(machine['memory hierarchy'][-2]['size per group'])//4
+ max_length = int(machine["memory hierarchy"][-2]["size per group"]) // 4
if args.verbose >= 1:
print("upper search bound:", max_length)
- length = min_length*3
+ length = min_length * 3
while length < max_length:
runtime = simulate(kernel, model, define_dict, blocking_constant, length)
if args.verbose >= 1:
- print("min", min_length, min_runtime, "current", length, runtime, "max", max_length)
+ print(
+ "min",
+ min_length,
+ min_runtime,
+ "current",
+ length,
+ runtime,
+ "max",
+ max_length,
+ )
# Increase search window
if runtime > min_runtime:
max_length = length # and break
else:
Check failure on line 115 in /home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py#L104-L115
length = (max_length - min_length) // 2 + min_length
# Execute simulation
runtime = simulate(kernel, model, define_dict, blocking_constant, length)
if args.verbose >= 1:
- print("min", min_length, min_runtime, "current", length, runtime, "max", max_length)
+ print(
+ "min",
+ min_length,
+ min_runtime,
+ "current",
+ length,
+ runtime,
+ "max",
+ max_length,
+ )
# Narrow search area
if runtime <= min_runtime:
min_runtime = runtime
min_length = length
Check failure on line 131 in /home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py#L120-L131
print("found for {}:".format(blocking_constant))
print(length)
sys.exit(0)
else:
if args.verbose:
- print("nothing found. exceeded search window and not change in performance found.")
+ print(
+ "nothing found. exceeded search window and not change in performance found."
+ )
sys.exit(1)
def main():
# Create and populate parser
Check failure on line 142 in /home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/cachetile.py#L135-L142
# BUSINESS LOGIC IS FOLLOWING
run(parser, args)
-if __name__ == '__main__':
+if __name__ == "__main__":
main()
Check failure on line 17 in /home/runner/work/kerncraft/kerncraft/kerncraft/intervals.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/intervals.py#L6-L17
"""Very simple interval implementation for integers (might also work on floats)."""
def __init__(self, *args, **kwargs):
"""If keywords *sane* is True (default: False), checks will not be done on given data."""
self.data = list(args)
- if not kwargs.get('sane', False):
+ if not kwargs.get("sane", False):
self.data = [d for d in self.data if d[1] > d[0]]
self._enforce_order()
self._enforce_no_overlap()
def _enforce_order(self):
Check failure on line 53 in /home/runner/work/kerncraft/kerncraft/kerncraft/intervals.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/intervals.py#L18-L53
self.data.sort(key=lambda d: d[0])
def _enforce_no_overlap(self, start_at=0):
"""Enforce that no ranges overlap in internal storage."""
i = start_at
- while i+1 < len(self.data):
- if self.data[i][1] >= self.data[i+1][0]:
+ while i + 1 < len(self.data):
+ if self.data[i][1] >= self.data[i + 1][0]:
# beginning of i+1-th range is contained in i-th range
- if self.data[i][1] < self.data[i+1][1]:
+ if self.data[i][1] < self.data[i + 1][1]:
# i+1-th range is longer, thus enlarge i-th range
- self.data[i][1] = self.data[i+1][1]
+ self.data[i][1] = self.data[i + 1][1]
# removed contained range
- del self.data[i+1]
+ del self.data[i + 1]
i += 1
def __and__(self, other):
"""Combine two intervals, under the assumption that they are sane."""
- return Intervals(*(self.data+other.data))
+ return Intervals(*(self.data + other.data))
def __len__(self):
"""Return sum of range lengths."""
- return int(sum(upper-lower for (lower, upper) in self.data))
+ return int(sum(upper - lower for (lower, upper) in self.data))
def __contains__(self, needle):
"""Return True if needle is contained in intervals."""
return any(lower <= needle < upper for (lower, upper) in self.data)
def __repr__(self):
"""Return string representation of object."""
- return str(self.__class__) + '(' + ', '.join([list.__repr__(d) for d in self.data]) + ')'
+ return (
+ str(self.__class__)
+ + "("
+ + ", ".join([list.__repr__(d) for d in self.data])
+ + ")"
+ )
def __eq__(self, other):
"""Return True if other contains exactly the same interval regions."""
return self.data == other.data
Check failure on line 37 in /home/runner/work/kerncraft/kerncraft/kerncraft/iaca_get.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/iaca_get.py#L10-L37
import platform
from urllib.request import urlopen
url_dict = {
- 'v3.0': {
- 'mac': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-v3.0-mac.zip',
- 'lin64': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-v3.0-lin64.zip',
+ "v3.0": {
+ "mac": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-v3.0-mac.zip",
+ "lin64": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-v3.0-lin64.zip",
},
- 'v2.3': {
- 'mac': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.3-mac.zip',
- 'lin64': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.3-lin64.zip',
+ "v2.3": {
+ "mac": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.3-mac.zip",
+ "lin64": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.3-lin64.zip",
},
- 'v2.2': {
- 'mac': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.2-mac.zip',
- 'lin64': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.2-lin64.zip',
+ "v2.2": {
+ "mac": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.2-mac.zip",
+ "lin64": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.2-lin64.zip",
},
- 'v2.1': {
- 'mac': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.1-mac64.zip',
- 'lin64': 'https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.1-lin64.zip',
- }
+ "v2.1": {
+ "mac": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.1-mac64.zip",
+ "lin64": "https://software.intel.com/content/dam/develop/external/us/en/protected/iaca-version-2.1-lin64.zip",
+ },
}
+
class TemporaryDirectory:
def __enter__(self):
self.tempdir = tempfile.mkdtemp()
return self.tempdir
Check failure on line 112 in /home/runner/work/kerncraft/kerncraft/kerncraft/iaca_get.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/iaca_get.py#L38-L112
def __exit__(self, type_, value, traceback):
shutil.rmtree(self.tempdir)
def get_os():
- os_map = {'Darwin': 'mac', 'Linux': 'lin64'}
+ os_map = {"Darwin": "mac", "Linux": "lin64"}
system = platform.system()
- assert system in os_map, "Unsupported operating system (platform.system() should return " \
- "Linux or Darwin)."
+ assert system in os_map, (
+ "Unsupported operating system (platform.system() should return "
+ "Linux or Darwin)."
+ )
return os_map[system]
def search_path():
"""Return potential locations of IACA installation."""
operating_system = get_os()
# 1st choice: in ~/.kerncraft/iaca-{}
# 2nd choice: in package directory / iaca-{}
- return [os.path.expanduser("~/.kerncraft/iaca/{}/".format(operating_system)),
- os.path.abspath(os.path.dirname(os.path.realpath(__file__))) + '/iaca/{}/'.format(
- operating_system)]
+ return [
+ os.path.expanduser("~/.kerncraft/iaca/{}/".format(operating_system)),
+ os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+ + "/iaca/{}/".format(operating_system),
+ ]
def find_iaca():
"""Return (hopefully) valid installation of IACA."""
- requires = ['iaca2.2', 'iaca2.3', 'iaca3.0']
+ requires = ["iaca2.2", "iaca2.3", "iaca3.0"]
for path in search_path():
- path += 'bin/'
+ path += "bin/"
valid = True
for r in requires:
if not os.path.exists(path + r):
valid = False
break
if valid:
return path
- raise RuntimeError("No IACA installation found in {}. Run iaca_get command to fix this issue."
- "".format(search_path()))
+ raise RuntimeError(
+ "No IACA installation found in {}. Run iaca_get command to fix this issue."
+ "".format(search_path())
+ )
def main():
try:
path = find_iaca()
- print('IACA already installed at', path)
- if '--force' in sys.argv:
- sys.argv.remove('--force')
+ print("IACA already installed at", path)
+ if "--force" in sys.argv:
+ sys.argv.remove("--force")
else:
- print('For forced installation add --force')
+ print("For forced installation add --force")
sys.exit()
except RuntimeError:
pass
- if len(sys.argv) < 2 or sys.argv[1] != \
- "--I-accept-the-Intel-What-If-Pre-Release-License-Agreement-and-please-take-my-soul":
- print("Go to https://software.intel.com/protected-download/267266/157552 and read the"
- "Intel Pre-Release License Agreement.")
+ if (
+ len(sys.argv) < 2
+ or sys.argv[1]
+ != "--I-accept-the-Intel-What-If-Pre-Release-License-Agreement-and-please-take-my-soul"
+ ):
+ print(
+ "Go to https://software.intel.com/protected-download/267266/157552 and read the"
+ "Intel Pre-Release License Agreement."
+ )
print("")
- print("Add "
- "--I-accept-the-Intel-What-If-Pre-Release-License-Agreement-and-please-take-my-soul"
- " for installation of IACA.")
+ print(
+ "Add "
+ "--I-accept-the-Intel-What-If-Pre-Release-License-Agreement-and-please-take-my-soul"
+ " for installation of IACA."
+ )
sys.exit(1)
if len(sys.argv) >= 3:
- assert sys.argv[2] in ['lin64', 'mac']
+ assert sys.argv[2] in ["lin64", "mac"]
operating_system = sys.argv[2]
else:
operating_system = get_os()
# Locate and create IACA base directory, in reverse server order
base_dir = None
for path in reversed(search_path()):
- print("Trying " + path + ": ", end='', file=sys.stderr)
+ print("Trying " + path + ": ", end="", file=sys.stderr)
try:
os.makedirs(path)
base_dir = path
break
except PermissionError:
Check failure on line 263 in /home/runner/work/kerncraft/kerncraft/kerncraft/iaca_get.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/iaca_get.py#L115-L263
except OSError:
# Directory already exists
print("already exists.", file=sys.stderr)
continue
if base_dir is None:
- print('Aborted.', file=sys.stderr)
+ print("Aborted.", file=sys.stderr)
sys.exit(1)
else:
print("selected.", file=sys.stderr)
- print("IACA v2.1 (for manual use - only version analyzing latency):", file=sys.stderr)
- if operating_system == 'mac':
- operating_system_temp = 'mac64'
+ print(
+ "IACA v2.1 (for manual use - only version analyzing latency):", file=sys.stderr
+ )
+ if operating_system == "mac":
+ operating_system_temp = "mac64"
else:
operating_system_temp = operating_system
- url = url_dict['v2.1'][operating_system]
+ url = url_dict["v2.1"][operating_system]
print("Downloading", url, "...", file=sys.stderr)
zfile = zipfile.ZipFile(BytesIO(urlopen(url).read()))
- members = [n
- for n in zfile.namelist()
- if '/.' not in n and n.startswith('iaca-{:}/'.format(operating_system_temp))]
+ members = [
+ n
+ for n in zfile.namelist()
+ if "/." not in n and n.startswith("iaca-{:}/".format(operating_system_temp))
+ ]
# Exctract to temp folder and copy to correct directory
print("Extracting...", file=sys.stderr)
with TemporaryDirectory() as tempdir:
zfile.extractall(tempdir, members=members)
- shutil.copytree(tempdir + '/iaca-{}'.format(operating_system_temp), base_dir + 'v2.1')
+ shutil.copytree(
+ tempdir + "/iaca-{}".format(operating_system_temp), base_dir + "v2.1"
+ )
# Correct permissions of executables
print("Correcting permissions of binary...")
- st = os.stat(base_dir + 'v2.1/bin/iaca')
- os.chmod(
- base_dir + 'v2.1/bin/iaca',
- st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
- )
- st = os.stat(base_dir + 'v2.1/bin/iaca.sh')
- os.chmod(
- base_dir + 'v2.1/bin/iaca.sh',
- st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
+ st = os.stat(base_dir + "v2.1/bin/iaca")
+ os.chmod(
+ base_dir + "v2.1/bin/iaca",
+ st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH,
+ )
+ st = os.stat(base_dir + "v2.1/bin/iaca.sh")
+ os.chmod(
+ base_dir + "v2.1/bin/iaca.sh",
+ st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH,
)
# Fix iaca.sh
print("Fixing iaca.sh...", file=sys.stderr)
- iaca_sh = open(base_dir + 'v2.1/bin/iaca.sh').read()
- iaca_sh = iaca_sh.replace('realpath', 'readlink -f', 1)
- iaca_sh = iaca_sh.replace('mypath=`pwd`', 'mypath=`dirname $0`', 1)
- iaca_sh = iaca_sh.replace('path=$(cd "$(dirname "$0")"; pwd)',
- 'script=`readlink -f $0`\n\tpath=`dirname "$script"`', 1)
- open(base_dir + 'v2.1/bin/iaca.sh', 'w').write(iaca_sh)
- print("IACA v2.1 installed to", os.getcwd() + '/' + base_dir + 'v2.1', file=sys.stderr)
+ iaca_sh = open(base_dir + "v2.1/bin/iaca.sh").read()
+ iaca_sh = iaca_sh.replace("realpath", "readlink -f", 1)
+ iaca_sh = iaca_sh.replace("mypath=`pwd`", "mypath=`dirname $0`", 1)
+ iaca_sh = iaca_sh.replace(
+ 'path=$(cd "$(dirname "$0")"; pwd)',
+ 'script=`readlink -f $0`\n\tpath=`dirname "$script"`',
+ 1,
+ )
+ open(base_dir + "v2.1/bin/iaca.sh", "w").write(iaca_sh)
+ print(
+ "IACA v2.1 installed to", os.getcwd() + "/" + base_dir + "v2.1", file=sys.stderr
+ )
print("IACA v2.2 (for NHM and WSM support):", file=sys.stderr)
- url = url_dict['v2.2'][operating_system]
+ url = url_dict["v2.2"][operating_system]
print("Downloading", url, "...", file=sys.stderr)
zfile = zipfile.ZipFile(BytesIO(urlopen(url).read()))
- members = [n
- for n in zfile.namelist()
- if '/.' not in n and n.startswith('iaca-{:}/'.format(operating_system))]
+ members = [
+ n
+ for n in zfile.namelist()
+ if "/." not in n and n.startswith("iaca-{:}/".format(operating_system))
+ ]
# Exctract to temp folder and copy to correct directory
print("Extracting...", file=sys.stderr)
with TemporaryDirectory() as tempdir:
zfile.extractall(tempdir, members=members)
- shutil.copytree(tempdir + '/iaca-{}'.format(operating_system), base_dir + 'v2.2')
+ shutil.copytree(
+ tempdir + "/iaca-{}".format(operating_system), base_dir + "v2.2"
+ )
# Correct permissions of executables
print("Correcting permissions of binary...")
- st = os.stat(base_dir + 'v2.2/bin/iaca')
- os.chmod(
- base_dir + 'v2.2/bin/iaca',
- st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
- )
- st = os.stat(base_dir + 'v2.2/bin/iaca.sh')
- os.chmod(
- base_dir + 'v2.2/bin/iaca.sh',
- st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
+ st = os.stat(base_dir + "v2.2/bin/iaca")
+ os.chmod(
+ base_dir + "v2.2/bin/iaca",
+ st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH,
+ )
+ st = os.stat(base_dir + "v2.2/bin/iaca.sh")
+ os.chmod(
+ base_dir + "v2.2/bin/iaca.sh",
+ st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH,
)
# Fix iaca.sh
print("Fixing iaca.sh...", file=sys.stderr)
- iaca_sh = open(base_dir + 'v2.2/bin/iaca.sh').read()
- iaca_sh = iaca_sh.replace('realpath', 'readlink -f', 1)
- iaca_sh = iaca_sh.replace('mypath=`pwd`', 'mypath=`dirname $0`', 1)
- iaca_sh = iaca_sh.replace('path=$(cd "$(dirname "$0")"; pwd)',
- 'script=`readlink -f $0`\n\tpath=`dirname "$script"`', 1)
- open(base_dir + 'v2.2/bin/iaca.sh', 'w').write(iaca_sh)
- print("IACA v2.2 installed to", os.getcwd() + '/' + base_dir + 'v2.2', file=sys.stderr)
+ iaca_sh = open(base_dir + "v2.2/bin/iaca.sh").read()
+ iaca_sh = iaca_sh.replace("realpath", "readlink -f", 1)
+ iaca_sh = iaca_sh.replace("mypath=`pwd`", "mypath=`dirname $0`", 1)
+ iaca_sh = iaca_sh.replace(
+ 'path=$(cd "$(dirname "$0")"; pwd)',
+ 'script=`readlink -f $0`\n\tpath=`dirname "$script"`',
+ 1,
+ )
+ open(base_dir + "v2.2/bin/iaca.sh", "w").write(iaca_sh)
+ print(
+ "IACA v2.2 installed to", os.getcwd() + "/" + base_dir + "v2.2", file=sys.stderr
+ )
print("IACA v2.3 (for SNB and IVY support):", file=sys.stderr)
- url = url_dict['v2.3'][operating_system]
+ url = url_dict["v2.3"][operating_system]
print("Downloading", url, "...", file=sys.stderr)
zfile = zipfile.ZipFile(BytesIO(urlopen(url).read()))
- members = [n
- for n in zfile.namelist()
- if '/.' not in n and n.startswith('iaca-{:}/'.format(operating_system))]
+ members = [
+ n
+ for n in zfile.namelist()
+ if "/." not in n and n.startswith("iaca-{:}/".format(operating_system))
+ ]
# Exctract to temp folder and copy to correct directory
print("Extracting...", file=sys.stderr)
with TemporaryDirectory() as tempdir:
zfile.extractall(tempdir, members=members)
- shutil.copytree(tempdir + '/iaca-{}'.format(operating_system), base_dir + 'v2.3')
+ shutil.copytree(
+ tempdir + "/iaca-{}".format(operating_system), base_dir + "v2.3"
+ )
# Correct permissions of executables
print("Correcting permissions of binary...")
- st = os.stat(base_dir + 'v2.3/bin/iaca')
- os.chmod(
- base_dir + 'v2.3/bin/iaca',
- st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
- )
- st = os.stat(base_dir + 'v2.3/bin/iaca.sh')
- os.chmod(
- base_dir + 'v2.3/bin/iaca.sh',
- st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
+ st = os.stat(base_dir + "v2.3/bin/iaca")
+ os.chmod(
+ base_dir + "v2.3/bin/iaca",
+ st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH,
+ )
+ st = os.stat(base_dir + "v2.3/bin/iaca.sh")
+ os.chmod(
+ base_dir + "v2.3/bin/iaca.sh",
+ st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH,
)
# Fix iaca.sh
print("Fixing iaca.sh...", file=sys.stderr)
- iaca_sh = open(base_dir + 'v2.3/bin/iaca.sh').read()
- iaca_sh = iaca_sh.replace('realpath', 'readlink -f', 1)
- iaca_sh = iaca_sh.replace('mypath=`pwd`', 'mypath=`dirname $0`', 1)
- iaca_sh = iaca_sh.replace('path=$(cd "$(dirname "$0")"; pwd)',
- 'script=`readlink -f $0`\n\tpath=`dirname "$script"`', 1)
- open(base_dir + 'v2.3/bin/iaca.sh', 'w').write(iaca_sh)
- print("IACA v2.3 installed to", os.getcwd() + '/' + base_dir + 'v2.3', file=sys.stderr)
+ iaca_sh = open(base_dir + "v2.3/bin/iaca.sh").read()
+ iaca_sh = iaca_sh.replace("realpath", "readlink -f", 1)
+ iaca_sh = iaca_sh.replace("mypath=`pwd`", "mypath=`dirname $0`", 1)
+ iaca_sh = iaca_sh.replace(
+ 'path=$(cd "$(dirname "$0")"; pwd)',
+ 'script=`readlink -f $0`\n\tpath=`dirname "$script"`',
+ 1,
+ )
+ open(base_dir + "v2.3/bin/iaca.sh", "w").write(iaca_sh)
+ print(
+ "IACA v2.3 installed to", os.getcwd() + "/" + base_dir + "v2.3", file=sys.stderr
+ )
print("IACA v3.0 (for HSW, BDW, SKL and SKX support):", file=sys.stderr)
- url = url_dict['v3.0'][operating_system]
+ url = url_dict["v3.0"][operating_system]
print("Downloading", url, "...", file=sys.stderr)
zfile = zipfile.ZipFile(BytesIO(urlopen(url).read()))
- members = [n
- for n in zfile.namelist()
- if '/.' not in n and n.startswith('iaca-{:}/'.format(operating_system))]
+ members = [
+ n
+ for n in zfile.namelist()
+ if "/." not in n and n.startswith("iaca-{:}/".format(operating_system))
+ ]
# Exctract to temp folder and copy to correct directory
print("Extracting...", file=sys.stderr)
with TemporaryDirectory() as tempdir:
zfile.extractall(tempdir, members=members)
- shutil.copytree(tempdir + '/iaca-{}'.format(operating_system), base_dir + 'v3.0')
+ shutil.copytree(
+ tempdir + "/iaca-{}".format(operating_system), base_dir + "v3.0"
+ )
print("Correcting permissions of binary...", file=sys.stderr)
- st = os.stat(base_dir + 'v3.0/iaca')
- os.chmod(
- base_dir + 'v3.0/iaca',
- st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
- )
- print("IACA v3.0 installed to", os.getcwd() + '/' + base_dir + 'v3.0', file=sys.stderr)
+ st = os.stat(base_dir + "v3.0/iaca")
+ os.chmod(
+ base_dir + "v3.0/iaca", st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
+ )
+ print(
+ "IACA v3.0 installed to", os.getcwd() + "/" + base_dir + "v3.0", file=sys.stderr
+ )
# Create unified bin directory to access both operating_systems
- os.mkdir(base_dir + 'bin')
- os.symlink('../v2.1/bin/iaca.sh', base_dir + 'bin/iaca2.1')
- os.symlink('../v2.2/bin/iaca.sh', base_dir + 'bin/iaca2.2')
- os.symlink('../v2.3/bin/iaca.sh', base_dir + 'bin/iaca2.3')
- os.symlink('../v3.0/iaca', base_dir + 'bin/iaca3.0')
- print('export PATH=' + base_dir + 'bin/:$PATH')
-
-
-if __name__ == '__main__':
+ os.mkdir(base_dir + "bin")
+ os.symlink("../v2.1/bin/iaca.sh", base_dir + "bin/iaca2.1")
+ os.symlink("../v2.2/bin/iaca.sh", base_dir + "bin/iaca2.2")
+ os.symlink("../v2.3/bin/iaca.sh", base_dir + "bin/iaca2.3")
+ os.symlink("../v3.0/iaca", base_dir + "bin/iaca3.0")
+ print("export PATH=" + base_dir + "bin/:$PATH")
+
+
+if __name__ == "__main__":
main()
Check failure on line 45 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L33-L45
Numbers can either be evenly distributed in a linear space (if *log* is False) or in a log
space (if *log* is True). If *log* is True, base is used to define the log space basis.
If *endpoint* is True, *stop* will be the last retruned value, as long as *num* >= 2.
"""
- assert type(start) is int and type(stop) is int and type(num) is int, \
- "start, stop and num need to be intergers"
+ assert (
+ type(start) is int and type(stop) is int and type(num) is int
+ ), "start, stop and num need to be intergers"
assert num >= 2, "num has to be atleast 2"
if log:
start = math.log(start, base)
stop = math.log(stop, base)
Check failure on line 126 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L96-L126
if base is given, the integers are evenly spaced on that base (default: 10)
"""
def __call__(self, parser, namespace, values, option_string=None):
"""Execute action."""
- message = ''
+ message = ""
if len(values) != 2:
- message = 'requires 2 arguments'
+ message = "requires 2 arguments"
else:
- m = re.match(r'(?P<start>\d+)(?:-(?P<stop>\d+)(?::(?P<num>\d+)'
- r'(:?(?P<log>log)(:?(?P<base>\d+))?)?)?)?',
- values[1])
+ m = re.match(
+ r"(?P<start>\d+)(?:-(?P<stop>\d+)(?::(?P<num>\d+)"
+ r"(:?(?P<log>log)(:?(?P<base>\d+))?)?)?)?",
+ values[1],
+ )
if m:
gd = m.groupdict()
- if gd['stop'] is None:
- values[1] = [int(gd['start'])]
- elif gd['num'] is None:
- values[1] = list(range(int(gd['start']), int(gd['stop']) + 1))
+ if gd["stop"] is None:
+ values[1] = [int(gd["start"])]
+ elif gd["num"] is None:
+ values[1] = list(range(int(gd["start"]), int(gd["stop"]) + 1))
else:
- log = gd['log'] is not None
- base = int(gd['base']) if gd['base'] is not None else 10
- values[1] = list(space(
- int(gd['start']), int(gd['stop']), int(gd['num']), log=log, base=base))
+ log = gd["log"] is not None
+ base = int(gd["base"]) if gd["base"] is not None else 10
+ values[1] = list(
+ space(
+ int(gd["start"]),
+ int(gd["stop"]),
+ int(gd["num"]),
+ log=log,
+ base=base,
+ )
+ )
else:
- message = 'second argument must match: start[-stop[:num[log[base]]]]'
+ message = "second argument must match: start[-stop[:num[log[base]]]]"
if message:
raise argparse.ArgumentError(self, message)
if hasattr(namespace, self.dest):
Check failure on line 240 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L128-L240
setattr(namespace, self.dest, [values])
class VersionAction(argparse.Action):
"""Reimplementation of the version action, because argparse's version outputs to stderr."""
- def __init__(self, option_strings, version, dest=argparse.SUPPRESS,
- default=argparse.SUPPRESS,
- help="show program's version number and exit"):
+
+ def __init__(
+ self,
+ option_strings,
+ version,
+ dest=argparse.SUPPRESS,
+ default=argparse.SUPPRESS,
+ help="show program's version number and exit",
+ ):
super(VersionAction, self).__init__(
option_strings=option_strings,
dest=dest,
default=default,
nargs=0,
- help=help)
+ help=help,
+ )
self.version = version
def __call__(self, parser, namespace, values, option_string=None):
print(parser.prog, self.version)
parser.exit()
def create_parser():
"""Return argparse parser."""
parser = argparse.ArgumentParser(
- description='Analytical performance modelling and benchmarking toolkit.',
- epilog='For help, examples, documentation and bug reports go to:\nhttps://github.com'
- '/RRZE-HPC/kerncraft\nLicense: AGPLv3',)
- parser.add_argument('--version', action=VersionAction, version='{}'.format(__version__))
- parser.add_argument('--machine', '-m', type=argparse.FileType('r'), required=True,
- help='Path to machine description yaml file.')
- parser.add_argument('--pmodel', '-p', choices=models.__all__, required=True, action='append',
- default=[], help='Performance model to apply')
- parser.add_argument('-D', '--define', nargs=2, metavar=('KEY', 'VALUE'), default=[],
- action=AppendStringRange,
- help='Define constant to be used in C code. Values must be integer or '
- 'match start-stop[:num[log[base]]]. If range is given, all '
- 'permutation s will be tested. Overwrites constants from testcase '
- 'file. Key can be . for default value for all used constants.')
- parser.add_argument('--verbose', '-v', action='count', default=0,
- help='Increases verbosity level.')
- parser.add_argument('code_file', metavar='FILE', type=argparse.FileType(),
- help='File with loop kernel C code')
- parser.add_argument('--asm-block', metavar='BLOCK', default='auto',
- help='Number of ASM block to mark for IACA, "auto" for automatic '
- 'selection or "manual" for interactiv selection.')
- parser.add_argument('--pointer-increment', metavar='INCR', default='auto', type=int_or_str,
- help='Increment of store pointer within one ASM block in bytes. If "auto": '
- 'automatic detection, error on failure to detect, if '
- '"auto_with_manual_fallback": fallback to manual input, or if '
- '"manual": always prompt user.')
- parser.add_argument('--store', metavar='PICKLE', type=argparse.FileType('a+b'),
- help='Addes results to PICKLE file for later processing.')
- parser.add_argument('--json', metavar='JSON', type=argparse.FileType('a+'),
- help='Stores result as JSON file for later processing')
- parser.add_argument('--unit', '-u', choices=['cy/CL', 'cy/It', 'It/s', 'FLOP/s'],
- help='Select the output unit, defaults to model specific if not given.')
- parser.add_argument('--cores', '-c', metavar='CORES', type=int, default=1,
- help='Number of cores to be used in parallel. (default: 1) '
- 'ECM model will consider the scaling of the last level cache and '
- 'predict the overall performance in addition to single-core behavior. '
- 'The benchmark mode will run the code with OpenMP on as many physical '
- 'cores.')
- parser.add_argument('--kernel-description', action='store_true',
- help='Use kernel description instead of analyzing the kernel code.')
- parser.add_argument('--clean-intermediates', action='store_true',
- help='If set, will delete all intermediate files after completion.')
+ description="Analytical performance modelling and benchmarking toolkit.",
+ epilog="For help, examples, documentation and bug reports go to:\nhttps://github.com"
+ "/RRZE-HPC/kerncraft\nLicense: AGPLv3",
+ )
+ parser.add_argument(
+ "--version", action=VersionAction, version="{}".format(__version__)
+ )
+ parser.add_argument(
+ "--machine",
+ "-m",
+ type=argparse.FileType("r"),
+ required=True,
+ help="Path to machine description yaml file.",
+ )
+ parser.add_argument(
+ "--pmodel",
+ "-p",
+ choices=models.__all__,
+ required=True,
+ action="append",
+ default=[],
+ help="Performance model to apply",
+ )
+ parser.add_argument(
+ "-D",
+ "--define",
+ nargs=2,
+ metavar=("KEY", "VALUE"),
+ default=[],
+ action=AppendStringRange,
+ help="Define constant to be used in C code. Values must be integer or "
+ "match start-stop[:num[log[base]]]. If range is given, all "
+ "permutation s will be tested. Overwrites constants from testcase "
+ "file. Key can be . for default value for all used constants.",
+ )
+ parser.add_argument(
+ "--verbose", "-v", action="count", default=0, help="Increases verbosity level."
+ )
+ parser.add_argument(
+ "code_file",
+ metavar="FILE",
+ type=argparse.FileType(),
+ help="File with loop kernel C code",
+ )
+ parser.add_argument(
+ "--asm-block",
+ metavar="BLOCK",
+ default="auto",
+ help='Number of ASM block to mark for IACA, "auto" for automatic '
+ 'selection or "manual" for interactiv selection.',
+ )
+ parser.add_argument(
+ "--pointer-increment",
+ metavar="INCR",
+ default="auto",
+ type=int_or_str,
+ help='Increment of store pointer within one ASM block in bytes. If "auto": '
+ "automatic detection, error on failure to detect, if "
+ '"auto_with_manual_fallback": fallback to manual input, or if '
+ '"manual": always prompt user.',
+ )
+ parser.add_argument(
+ "--store",
+ metavar="PICKLE",
+ type=argparse.FileType("a+b"),
+ help="Addes results to PICKLE file for later processing.",
+ )
+ parser.add_argument(
+ "--json",
+ metavar="JSON",
+ type=argparse.FileType("a+"),
+ help="Stores result as JSON file for later processing",
+ )
+ parser.add_argument(
+ "--unit",
+ "-u",
+ choices=["cy/CL", "cy/It", "It/s", "FLOP/s"],
+ help="Select the output unit, defaults to model specific if not given.",
+ )
+ parser.add_argument(
+ "--cores",
+ "-c",
+ metavar="CORES",
+ type=int,
+ default=1,
+ help="Number of cores to be used in parallel. (default: 1) "
+ "ECM model will consider the scaling of the last level cache and "
+ "predict the overall performance in addition to single-core behavior. "
+ "The benchmark mode will run the code with OpenMP on as many physical "
+ "cores.",
+ )
+ parser.add_argument(
+ "--kernel-description",
+ action="store_true",
+ help="Use kernel description instead of analyzing the kernel code.",
+ )
+ parser.add_argument(
+ "--clean-intermediates",
+ action="store_true",
+ help="If set, will delete all intermediate files after completion.",
+ )
# Needed for ECM, ECMData and RooflineFLOP models:
- parser.add_argument('--cache-predictor', '-P', choices=['LC', 'SIM'], default='SIM',
- help='Change cache predictor to use, options are LC (layer conditions) and '
- 'SIM (cache simulation with pycachesim), default is SIM.')
+ parser.add_argument(
+ "--cache-predictor",
+ "-P",
+ choices=["LC", "SIM"],
+ default="SIM",
+ help="Change cache predictor to use, options are LC (layer conditions) and "
+ "SIM (cache simulation with pycachesim), default is SIM.",
+ )
# Needed for ECM, RooflineASM and Benchmark models:
- parser.add_argument('--compiler', '-C', type=str, default=None,
- help='Compiler to use, default is first in machine description file.')
- parser.add_argument('--compiler-flags', type=str, default=None,
- help='Compiler flags to use. If not set, flags are taken from machine '
- 'description file (-std=c99 is always added).')
+ parser.add_argument(
+ "--compiler",
+ "-C",
+ type=str,
+ default=None,
+ help="Compiler to use, default is first in machine description file.",
+ )
+ parser.add_argument(
+ "--compiler-flags",
+ type=str,
+ default=None,
+ help="Compiler flags to use. If not set, flags are taken from machine "
+ "description file (-std=c99 is always added).",
+ )
# Needed for ECM and RooflineASM models:
- parser.add_argument('--incore-model', '-i', type=str, default=None,
- help='In-core model to use, default is first in machine description file.')
+ parser.add_argument(
+ "--incore-model",
+ "-i",
+ type=str,
+ default=None,
+ help="In-core model to use, default is first in machine description file.",
+ )
for m in models.__all__:
- ag = parser.add_argument_group('arguments for ' + m + ' model', getattr(models, m).name)
+ ag = parser.add_argument_group(
+ "arguments for " + m + " model", getattr(models, m).name
+ )
getattr(models, m).configure_arggroup(ag)
return parser
def check_arguments(args, parser):
"""
Check arguments passed by user that are not checked by argparse itself.
Also register files for closing.
"""
- if args.asm_block not in ['auto', 'manual']:
+ if args.asm_block not in ["auto", "manual"]:
try:
args.asm_block = int(args.asm_block)
except ValueError:
parser.error('--asm-block can only be "auto", "manual" or an integer')
# Set default unit depending on performance model requested
if not args.unit:
- if 'RooflineFLOP' in args.pmodel or 'RooflineASM' in args.pmodel or 'RooflineIACA' in args.pmodel:
- args.unit = 'FLOP/s'
+ if (
+ "RooflineFLOP" in args.pmodel
+ or "RooflineASM" in args.pmodel
+ or "RooflineIACA" in args.pmodel
+ ):
+ args.unit = "FLOP/s"
else:
- args.unit = 'cy/CL'
+ args.unit = "cy/CL"
# Register all opened files for closing at exit.
if args.store:
atexit.register(args.store.close)
if args.json:
Check failure on line 254 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L243-L254
if args.machine:
atexit.register(args.machine.close)
def to_tuple(x):
- '''Transform nested lists (and tuple) in purely nested tuples.'''
+ """Transform nested lists (and tuple) in purely nested tuples."""
if isinstance(x, (list, tuple)):
if len(x) >= 2:
return tuple(to_tuple(x[:1]) + to_tuple(x[1:]))
elif len(x) == 1:
return (to_tuple(x[0]),)
Check failure on line 272 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L261-L272
identifier = []
for k in sorted(args.__dict__):
if k in kwargs:
identifier.append((k, kwargs[k]))
continue
- if k in ['verbose', 'store', 'unit', 'clean_intermediates']:
+ if k in ["verbose", "store", "unit", "clean_intermediates"]:
# Ignore these, as they do not change the outcome
continue
v = args.__dict__[k]
if isinstance(v, list):
v = to_tuple(v)
Check failure on line 286 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L274-L286
if isinstance(v, io.IOBase):
v = v.name
identifier.append((k, v))
return tuple(identifier)
+
def jsonify_obj(obj):
- #print("jsonify {}".format(str(obj) if len(str(obj)) < 15 else str(obj)[:12] + "..."))
+ # print("jsonify {}".format(str(obj) if len(str(obj)) < 15 else str(obj)[:12] + "..."))
# if obj is str, int, or float, keep it this way
if isinstance(obj, str) or isinstance(obj, int) or isinstance(obj, float):
return obj
# if obj is list, use recursion
elif isinstance(obj, list) or isinstance(obj, tuple):
Check failure on line 303 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L290-L303
return tuple(new_list)
return new_list
# if obj is dict, use recursion
elif isinstance(obj, dict):
new_dict = {}
- for k,v in obj.items():
+ for k, v in obj.items():
# key must be one element
- k = str(k) if not (isinstance(k, str) or isinstance(k, int) or isinstance(k, float)) else k
+ k = (
+ str(k)
+ if not (
+ isinstance(k, str) or isinstance(k, int) or isinstance(k, float)
+ )
+ else k
+ )
new_dict[k] = jsonify_obj(v)
return new_dict
else:
return str(obj)
Check failure on line 346 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L321-L346
# process kernel
if not args.kernel_description:
code = str(args.code_file.read())
args.code_file.close()
code = clean_code(code)
- kernel = KernelCode(code, filename=args.code_file.name, machine=machine,
- keep_intermediates=not args.clean_intermediates)
+ kernel = KernelCode(
+ code,
+ filename=args.code_file.name,
+ machine=machine,
+ keep_intermediates=not args.clean_intermediates,
+ )
else:
description = str(args.code_file.read())
args.code_file.close()
- yaml = ruamel.yaml.YAML(typ='unsafe')
+ yaml = ruamel.yaml.YAML(typ="unsafe")
yaml.register_class(PrefixedUnit)
kernel = KernelDescription(yaml.load(description), machine=machine)
- loop_indices = set([symbol_pos_int(l['index']) for l in kernel.get_loop_stack()])
+ loop_indices = set([symbol_pos_int(l["index"]) for l in kernel.get_loop_stack()])
# define constants
required_consts = [v[1] for v in kernel.variables.values() if v[1] is not None]
- required_consts += [[l['start'], l['stop']] for l in kernel.get_loop_stack()]
+ required_consts += [[l["start"], l["stop"]] for l in kernel.get_loop_stack()]
required_consts += [i for a in kernel.sources.values() for i in a if i is not None]
- required_consts += [i for a in kernel.destinations.values() for i in a if i is not None]
+ required_consts += [
+ i for a in kernel.destinations.values() for i in a if i is not None
+ ]
# split into individual consts
required_consts = [i for l in required_consts for i in l]
required_consts = set([i for l in required_consts for i in l.free_symbols])
# remove loop indices
required_consts -= loop_indices
Check failure on line 359 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L347-L359
if len(required_consts) > 0:
# build defines permutations
define_dict = OrderedDict()
args.define.sort()
# Prefill with default value, if any is given
- if '.' in [n for n,v in args.define]:
- default_const_values = dict(args.define)['.']
+ if "." in [n for n, v in args.define]:
+ default_const_values = dict(args.define)["."]
for name in required_consts:
name = str(name)
define_dict[str(name)] = [[str(name), v] for v in default_const_values]
for name, values in args.define:
if name not in [str(n) for n in required_consts]:
Check failure on line 377 in /home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py
github-actions / Black
/home/runner/work/kerncraft/kerncraft/kerncraft/kerncraft.py#L364-L377
for v in values:
if v not in define_dict[name]:
define_dict[name].append([name, v])
define_product = list(itertools.product(*list(define_dict.values())))
# Check that all consts have been defined
- if set(required_consts).difference(set([symbol_pos_int(k) for k in define_dict.keys()])):
- raise ValueError("Not all constants have been defined. Required are: {}".format(
- required_consts))
+ if set(required_consts).difference(
+ set([symbol_pos_int(k) for k in define_dict.keys()])
+ ):
+ raise ValueError(
+ "Not all constants have been defined. Required are: {}".format(
+ required_consts
+ )
+ )
else:
define_product = [{}]
for define in define_product:
# Reset state of kernel