Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Format python code with black #2709

Merged
merged 1 commit into from
Feb 18, 2025
Merged
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
76 changes: 52 additions & 24 deletions cmake/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import re
from enum import Enum


## @brief print a sequence of lines
def print_lines(lines, hint = None):
def print_lines(lines, hint=None):
counter = 1
for l in lines:
hint_char = " "
Expand All @@ -34,7 +35,9 @@ def print_lines(lines, hint = None):


## @brief print the whole content of input and match files
def print_content(input_lines, match_lines, ignored_lines, hint_input = None, hint_match = None):
def print_content(
input_lines, match_lines, ignored_lines, hint_input=None, hint_match=None
):
print("------ Input Lines " + "-" * 61)
print_lines(input_lines, hint_input)
print("------ Match Lines " + "-" * 61)
Expand Down Expand Up @@ -91,10 +94,10 @@ def check_status(input_lines, match_lines):
## @brief pattern matching tags.
## Tags are expected to be at the start of the line.
class Tag(Enum):
OPT = "{{OPT}}" # makes the line optional
IGNORE = "{{IGNORE}}" # ignores all input until next match or end of input file
NONDETERMINISTIC = "{{NONDETERMINISTIC}}" # switches on "deterministic mode"
COMMENT = "#" # comment - line ignored
OPT = "{{OPT}}" # makes the line optional
IGNORE = "{{IGNORE}}" # ignores all input until next match or end of input file
NONDETERMINISTIC = "{{NONDETERMINISTIC}}" # switches on "deterministic mode"
COMMENT = "#" # comment - line ignored


## @brief main function for the match file processing script
Expand All @@ -106,7 +109,7 @@ def main():
input_file = sys.argv[1]
match_file = sys.argv[2]

with open(input_file, 'r') as input, open(match_file, 'r') as match:
with open(input_file, "r") as input, open(match_file, "r") as match:
input_lines = input.readlines()
# Filter out empty lines and comments (lines beginning with the comment
# character, ignoring leading whitespace)
Expand Down Expand Up @@ -134,7 +137,9 @@ def main():
remaining_matches = set(range(len(match_lines))) - matched_lines
for m in remaining_matches:
line = match_lines[m]
if line.startswith(Tag.OPT.value) or line.startswith(Tag.NONDETERMINISTIC.value):
if line.startswith(Tag.OPT.value) or line.startswith(
Tag.NONDETERMINISTIC.value
):
continue
print_match_not_found(m + 1, match_lines[m])
print_content(input_lines, match_lines, ignored_lines, hint_match=m)
Expand All @@ -143,38 +148,55 @@ def main():
sys.exit(0)
elif status == Status.MATCH_END:
print_input_not_found(input_idx + 1, input_lines[input_idx])
print_content(input_lines, match_lines, ignored_lines, hint_input=input_idx)
print_content(
input_lines, match_lines, ignored_lines, hint_input=input_idx
)
sys.exit(1)
else:
if (status == Status.INPUT_AND_MATCH_END) or (status == Status.MATCH_END and Tag.IGNORE in tags_in_effect):
if (status == Status.INPUT_AND_MATCH_END) or (
status == Status.MATCH_END and Tag.IGNORE in tags_in_effect
):
# all lines matched or the last line in match file is an ignore tag
sys.exit(0)
elif status == Status.MATCH_END:
print_incorrect_match(input_idx + 1, input_lines[input_idx].strip(), "")
print_content(input_lines, match_lines, ignored_lines, hint_input=input_idx)
print_content(
input_lines, match_lines, ignored_lines, hint_input=input_idx
)
sys.exit(1)
elif status == Status.INPUT_END:
# If we get to the end of the input, but still have pending matches,
# then that's a failure unless all pending matches are optional -
# otherwise we're done
# If we get to the end of the input, but still have pending matches,
# then that's a failure unless all pending matches are optional -
# otherwise we're done
while match_idx < len(match_lines):
if not (match_lines[match_idx].startswith(Tag.OPT.value) or
match_lines[match_idx].startswith(Tag.IGNORE.value) or
match_lines[match_idx].startswith(Tag.NONDETERMINISTIC.value)):
if not (
match_lines[match_idx].startswith(Tag.OPT.value)
or match_lines[match_idx].startswith(Tag.IGNORE.value)
or match_lines[match_idx].startswith(Tag.NONDETERMINISTIC.value)
):
print_incorrect_match(match_idx + 1, "", match_lines[match_idx])
print_content(input_lines, match_lines, ignored_lines, hint_match=match_idx)
print_content(
input_lines,
match_lines,
ignored_lines,
hint_match=match_idx,
)
sys.exit(1)
match_idx += 1
sys.exit(0)

input_line = input_lines[input_idx].strip() if input_idx < len(input_lines) else ""
input_line = (
input_lines[input_idx].strip() if input_idx < len(input_lines) else ""
)
match_line = match_lines[match_idx]

# check for tags
if match_line.startswith(Tag.OPT.value):
tags_in_effect.append(Tag.OPT)
match_line = match_line[len(Tag.OPT.value):]
elif match_line.startswith(Tag.NONDETERMINISTIC.value) and not deterministic_mode:
match_line = match_line[len(Tag.OPT.value) :]
elif (
match_line.startswith(Tag.NONDETERMINISTIC.value) and not deterministic_mode
):
deterministic_mode = True
match_idx = 0
input_idx = 0
Expand All @@ -185,10 +207,10 @@ def main():
sys.exit(2)
tags_in_effect.append(Tag.IGNORE)
match_idx += 1
continue # line with ignore tag should be skipped
continue # line with ignore tag should be skipped

# split into parts at {{ }}
match_parts = re.split(r'\{{(.*?)\}}', match_line.strip())
match_parts = re.split(r"\{{(.*?)\}}", match_line.strip())
pattern = ""
for j, part in enumerate(match_parts):
if j % 2 == 0:
Expand Down Expand Up @@ -218,7 +240,13 @@ def main():
input_idx += 1
else:
print_incorrect_match(match_idx + 1, input_line, match_line.strip())
print_content(input_lines, match_lines, ignored_lines, hint_match=match_idx, hint_input=input_idx)
print_content(
input_lines,
match_lines,
ignored_lines,
hint_match=match_idx,
hint_input=input_idx,
)
sys.exit(1)


Expand Down
31 changes: 20 additions & 11 deletions scripts/add_experimental_feature.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"""
Copyright (C) 2023 Intel Corporation
Copyright (C) 2023 Intel Corporation

Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

"""

import argparse
import sys
from util import makoWrite
import re
import subprocess


def verify_kebab_case(input: str) -> bool:
kebab_case_re = r"[a-z0-9]+(?:-[a-z0-9]+)*"
pattern = re.compile(kebab_case_re)
Expand All @@ -37,19 +39,25 @@ def get_user_name_email_from_git_config():
def main():

argParser = argparse.ArgumentParser()
argParser.add_argument("name", help="must be lowercase and kebab case i.e. command-buffer", type=str)
argParser.add_argument("--dry_run", help="run the script without generating any files", action='store_true')
argParser.add_argument(
"name", help="must be lowercase and kebab case i.e. command-buffer", type=str
)
argParser.add_argument(
"--dry_run",
help="run the script without generating any files",
action="store_true",
)
args = argParser.parse_args()

if not verify_kebab_case(args.name):
print("Name must be lowercase and kebab-case i.e. command-buffer.")
sys.exit(1)

user_name, user_email = get_user_name_email_from_git_config()
user = {'email':user_email, 'name': user_name}
user = {"email": user_email, "name": user_name}

exp_feat_name = args.name

out_yml_name = f"exp-{exp_feat_name}.yml"
out_rst_name = f"EXP-{exp_feat_name.upper()}.rst"

Expand All @@ -62,14 +70,15 @@ def main():
makoWrite(yaml_template_path, out_yml_path, name=exp_feat_name)
makoWrite(rst_template_path, out_rst_path, name=exp_feat_name, user=user)


print(f"""\
print(
f"""\
Successfully generated the template files needed for {exp_feat_name}.

You can now implement your feature in the following files:
* {out_yml_name}
* {out_rst_name}
""")
"""
)


if __name__ == "__main__":
Expand Down
23 changes: 14 additions & 9 deletions scripts/benchmarks/benches/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,30 @@
import urllib.request
import tarfile


class Benchmark:
def __init__(self, directory, suite):
self.directory = directory
self.suite = suite

@staticmethod
def get_adapter_full_path():
for libs_dir_name in ['lib', 'lib64']:
for libs_dir_name in ["lib", "lib64"]:
adapter_path = os.path.join(
options.ur, libs_dir_name, f"libur_adapter_{options.ur_adapter}.so")
options.ur, libs_dir_name, f"libur_adapter_{options.ur_adapter}.so"
)
if os.path.isfile(adapter_path):
return adapter_path
assert False, \
f"could not find adapter file {adapter_path} (and in similar lib paths)"
assert (
False
), f"could not find adapter file {adapter_path} (and in similar lib paths)"

def run_bench(self, command, env_vars, ld_library=[], add_sycl=True):
env_vars = env_vars.copy()
if options.ur is not None:
env_vars.update(
{'UR_ADAPTERS_FORCE_LOAD': Benchmark.get_adapter_full_path()})
{"UR_ADAPTERS_FORCE_LOAD": Benchmark.get_adapter_full_path()}
)

env_vars.update(options.extra_env_vars)

Expand All @@ -43,22 +47,22 @@ def run_bench(self, command, env_vars, ld_library=[], add_sycl=True):
env_vars=env_vars,
add_sycl=add_sycl,
cwd=options.benchmark_cwd,
ld_library=ld_libraries
ld_library=ld_libraries,
).stdout.decode()

def create_data_path(self, name, skip_data_dir = False):
def create_data_path(self, name, skip_data_dir=False):
if skip_data_dir:
data_path = os.path.join(self.directory, name)
else:
data_path = os.path.join(self.directory, 'data', name)
data_path = os.path.join(self.directory, "data", name)
if options.rebuild and Path(data_path).exists():
shutil.rmtree(data_path)

Path(data_path).mkdir(parents=True, exist_ok=True)

return data_path

def download(self, name, url, file, untar = False, unzip = False, skip_data_dir = False):
def download(self, name, url, file, untar=False, unzip=False, skip_data_dir=False):
self.data_path = self.create_data_path(name, skip_data_dir)
return download(self.data_path, url, file, untar, unzip)

Expand All @@ -83,6 +87,7 @@ def stddev_threshold(self):
def get_suite_name(self) -> str:
return self.suite.name()


class Suite:
def benchmarks(self) -> list[Benchmark]:
raise NotImplementedError()
Expand Down
Loading