Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tsoc
hg-misc-tools
Commits
13caa19c
Commit
13caa19c
authored
Feb 22, 2026
by
one
Browse files
Add extract.py for rocHPL
parent
1b16108d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
0 deletions
+102
-0
projects/rocHPL/extract.py
projects/rocHPL/extract.py
+102
-0
No files found.
projects/rocHPL/extract.py
0 → 100644
View file @
13caa19c
import
argparse
import
re
parser
=
argparse
.
ArgumentParser
(
description
=
"Aggregate extrema for selected columns in HPL tables"
)
parser
.
add_argument
(
"-i"
,
"--input"
,
required
=
True
,
help
=
"Input file path, e.g. log/result.txt"
)
parser
.
add_argument
(
"-t"
,
"--target"
,
action
=
"append"
,
required
=
True
,
help
=
"Column name to aggregate; repeatable, supports regex, e.g. -t 'GFLOPS' -t 'pdfact'"
,
)
parser
.
add_argument
(
"--op"
,
choices
=
(
"max"
,
"min"
),
default
=
"max"
,
help
=
"Aggregation: max or min (default: max)"
,
)
args
=
parser
.
parse_args
()
# Merge patterns into a single regex, using non-capturing group (?:) to ensure safe priority
pattern
=
re
.
compile
(
"|"
.
join
(
f
"(?:
{
t
}
)"
for
t
in
args
.
target
))
agg_op
=
max
if
args
.
op
==
"max"
else
min
tables
=
[]
cur_cols
=
None
cur_best
=
{}
def
flush
():
if
cur_best
:
tables
.
append
(
cur_best
.
copy
())
with
open
(
args
.
input
)
as
f
:
for
line
in
f
:
if
"|"
in
line
:
if
pattern
.
search
(
line
):
flush
()
# Split by | and strip whitespace, then filter columns by regex pattern
parts
=
[
c
.
strip
()
for
c
in
line
.
split
(
"|"
)]
cur_cols
=
{
name
:
i
for
i
,
name
in
enumerate
(
parts
)
if
name
and
pattern
.
search
(
name
)
}
cur_best
=
{}
continue
if
not
cur_cols
:
continue
# Table end: strictly match {"-", "|"} combination, ignore pure dashes ---
stripped
=
line
.
strip
()
if
not
stripped
or
set
(
stripped
)
==
{
"-"
,
"|"
}:
flush
()
cur_cols
=
None
cur_best
=
{}
continue
parts
=
line
.
split
(
"|"
)
for
name
,
idx
in
cur_cols
.
items
():
try
:
val
=
float
(
parts
[
idx
])
# Dictionary update logic
cur_best
[
name
]
=
agg_op
(
val
,
cur_best
.
get
(
name
,
val
))
except
(
IndexError
,
ValueError
):
pass
flush
()
if
not
tables
:
print
(
"No tables detected."
)
raise
SystemExit
(
0
)
actual_cols
=
list
(
tables
[
0
].
keys
())
print
(
f
"op:
{
args
.
op
}
"
)
# Build data rows in one step. str(t.get(name, "")) handles None conversion to empty string.
headers
=
[
"Table"
]
+
actual_cols
rows
=
[
[
str
(
i
)]
+
[
str
(
t
.
get
(
name
,
""
))
for
name
in
actual_cols
]
for
i
,
t
in
enumerate
(
tables
,
1
)
]
# Use zip(*) matrix transpose to calculate column widths in one line
all_data
=
[
headers
]
+
rows
widths
=
[
max
(
len
(
cell
)
for
cell
in
col
)
for
col
in
zip
(
*
all_data
)]
def
fmt
(
row
):
return
" | "
.
join
(
cell
.
ljust
(
w
)
for
cell
,
w
in
zip
(
row
,
widths
))
print
(
fmt
(
headers
))
print
(
"-+-"
.
join
(
"-"
*
w
for
w
in
widths
))
for
row
in
rows
:
print
(
fmt
(
row
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment