[llvm] [MCA] New option to report scheduling information: -scheduling-info (PR #126703)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 11 02:00:59 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r a0587414cbb1520cfd7e886de1d18c408539ac9f...f0b7db933a191450962535b9f8b0e927c3c1030d llvm/utils/update_mca_test_checks.py
``````````
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- update_mca_test_checks.py 2025-02-11 08:13:15.000000 +0000
+++ update_mca_test_checks.py 2025-02-11 10:00:26.361460 +0000
@@ -64,18 +64,20 @@
metavar="<path>",
default="llvm-mca",
help="the binary to use to generate the test case " "(default: llvm-mca)",
)
parser.add_argument(
- "--check-sched-info", action="store_true",
+ "--check-sched-info",
+ action="store_true",
help="check scheduling info if references are given "
- "in comment after each instruction"
+ "in comment after each instruction",
)
parser.add_argument(
- "--update-sched-info", action="store_true",
+ "--update-sched-info",
+ action="store_true",
help="updating scheduling info references given "
- "in comment after each instruction"
+ "in comment after each instruction",
)
parser.add_argument("tests", metavar="<test-path>", nargs="+")
return parser
def _get_run_infos(run_lines, args):
@@ -253,58 +255,65 @@
# we've inserted some blocks.
return True
return False
-def _check_sched_values(line,scheds,units,err,updates):
+
+def _check_sched_values(line, scheds, units, err, updates):
"""Check for scheduling values differences
between values reported by llvm-mca with -scheduling-info option
and values in comment at the end of assembly instruction line (//).
Reference units must be included in the list reported by llvm-mca.
"""
_err = []
# Got zip of llvm output and values from comment
- infos = ["MicroOps","Latency","Forward latency","Throughput"]
- sched_info = zip(infos,scheds[0].split(),scheds[1].split())
+ infos = ["MicroOps", "Latency", "Forward latency", "Throughput"]
+ sched_info = zip(infos, scheds[0].split(), scheds[1].split())
for si in sched_info:
if float(si[1]) != float(si[2]):
updates.add("sched")
_err.append(
- "\t=> {} LLVM value {} != reference value in comment {}\n".
- format(si[0],si[1],si[2]))
+ "\t=> {} LLVM value {} != reference value in comment {}\n".format(
+ si[0], si[1], si[2]
+ )
+ )
for u in units[1]:
if not u in units[0]:
updates.add("units")
_err.append(
- "\t=> LLVM units {} != reference units in comment {}\n".
- format(units[0],units[1]))
+ "\t=> LLVM units {} != reference units in comment {}\n".format(
+ units[0], units[1]
+ )
+ )
break
if len(_err) > 0:
- err.append("{}\n{}".format(line,"".join(_err)))
+ err.append("{}\n{}".format(line, "".join(_err)))
return True
return False
-def _replace_values(oldvalue,newvalue):
+
+def _replace_values(oldvalue, newvalue):
"""Replacing values with the same format (spaces)
than oldvalue
"""
- fmt = re.sub("[0-9.]+","{}", oldvalue)
+ fmt = re.sub("[0-9.]+", "{}", oldvalue)
return fmt.format(*newvalue.split())
-def _has_comment(line,cmt_format):
+
+def _has_comment(line, cmt_format):
"""Returns True if line contains C++ or C style
comment. Set cmt_format first and optional second
comment caracters.
"""
- cpp_comment = re.search("\/\/",line)
- c_comment = re.search("\/\*",line)
+ cpp_comment = re.search("\/\/", line)
+ c_comment = re.search("\/\*", line)
if "//" in line:
cmt_format.append("//")
return True
if "/*" in line:
@@ -312,12 +321,12 @@
cmt_format.append("*/")
return True
return False
-def _sched_info(raw_tool_output, test_path,
- check_sched_info, update_sched_info):
+
+def _sched_info(raw_tool_output, test_path, check_sched_info, update_sched_info):
"""Check scheduling info if passed in assembly comment after each
instructions.
Recognized form is:
1 | 2 | 2 | 4.00 | ABSv1i64 | V1UnitV, | abs d15, d23
@@ -339,36 +348,39 @@
doing code review of scheduling info merge requests.
If a difference is found, the comment should be fixed and checked
against documentation.
"""
- scheduling_info = re.compile("(^\s+|\\\\\s+)([0-9]+[\s|]+[0-9]+"
- "[\s|]+[0-9]+[\s|]+\s+[0-9.]+)")
- units_info = re.compile("(^\s+|\\\\\s+)[0-9]+[\s|]+[0-9]+"
- "[\s|]+[0-9]+[\s|]+\s+[0-9.]+[\s|]+([^|*/]+)")
+ scheduling_info = re.compile(
+ "(^\s+|\\\\\s+)([0-9]+[\s|]+[0-9]+" "[\s|]+[0-9]+[\s|]+\s+[0-9.]+)"
+ )
+ units_info = re.compile(
+ "(^\s+|\\\\\s+)[0-9]+[\s|]+[0-9]+" "[\s|]+[0-9]+[\s|]+\s+[0-9.]+[\s|]+([^|*/]+)"
+ )
fixes = {}
err = []
instr_idx = 0
for b in raw_tool_output.split("\n\n"):
for line in b.splitlines():
cmt_format = []
- if _has_comment(line,cmt_format):
+ if _has_comment(line, cmt_format):
scheds = scheduling_info.findall(line)
- scheds = [s[1].replace("|","") for s in scheds]
+ scheds = [s[1].replace("|", "") for s in scheds]
if len(scheds) == 2:
cmt = cmt_format[0] + line.split(cmt_format[0])[1]
units = units_info.findall(line)
- c_units = [re.sub("\s","",u[1]).split(",") for u in units]
+ c_units = [re.sub("\s", "", u[1]).split(",") for u in units]
updates = set()
- if _check_sched_values(line,scheds,c_units,err,updates):
+ if _check_sched_values(line, scheds, c_units, err, updates):
if update_sched_info:
if "sched" in updates:
- cmt = cmt.replace(scheds[1],
- _replace_values(scheds[1],scheds[0]))
+ cmt = cmt.replace(
+ scheds[1], _replace_values(scheds[1], scheds[0])
+ )
if "units" in updates:
- cmt = cmt.replace(units[1][1],units[0][1])
+ cmt = cmt.replace(units[1][1], units[0][1])
fixes[instr_idx] = cmt
instr_idx = instr_idx + 1
if update_sched_info:
@@ -379,11 +391,11 @@
instr_idx = 0
for line in f:
out = line.rstrip()
cmt_format = []
- if _has_comment(line,cmt_format) and not re.match("^#",line):
+ if _has_comment(line, cmt_format) and not re.match("^#", line):
if fixes.get(instr_idx) is not None:
out = line.split(cmt_format[0])[0] + fixes[instr_idx]
instr_idx = instr_idx + 1
@@ -440,18 +452,21 @@
line if line.strip() else "" for line in raw_tool_output.splitlines()
)
# Check if -scheduling-info passed to llvm-mca to check comments if any
if "-scheduling-info" in tool_args:
- _sched_info(raw_tool_output, test_path,
- args.check_sched_info, args.update_sched_info)
+ _sched_info(
+ raw_tool_output,
+ test_path,
+ args.check_sched_info,
+ args.update_sched_info,
+ )
else:
if args.check_sched_info:
_warn("--check-sched-info: ignored: need llvm-mca -scheduling-info")
if args.update_sched_info:
_warn("--update-sched-info: ignored: need llvm-mca -scheduling-info")
-
# Split blocks, stripping all trailing whitespace, but keeping preceding
# whitespace except for newlines so that columns will line up visually.
all_blocks[key] = [
b.lstrip("\n").rstrip() for b in raw_tool_output.split("\n\n")
``````````
</details>
https://github.com/llvm/llvm-project/pull/126703
More information about the llvm-commits
mailing list