Skip to content

Commit f39c52b

Browse files
committed
feat: snakify hackers delight
1 parent 6c4a80b commit f39c52b

File tree

4 files changed

+146
-2
lines changed

4 files changed

+146
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ test-semantics/*.llvm
3838
lakefile.olean
3939
.lake/
4040
SSA/Projects/InstCombine/tests/logs/generalizer
41-
41+
.snakemake
4242
**/.ruff_cache

bv-evaluation/Snakefile

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import os
4+
import random
5+
import subprocess
6+
import concurrent.futures
7+
import shutil
8+
import multiprocessing
9+
import psutil
10+
import time
11+
import threading
12+
import platform
13+
from functools import partial
14+
from pathlib import Path
15+
import sys
16+
import liblimits
17+
18+
configfile: "config.yaml"
19+
20+
# get Git root
21+
GIT_ROOT = Path(subprocess.check_output(
22+
["git", "rev-parse", "--show-toplevel"]
23+
).decode().strip())
24+
print("Git root:", GIT_ROOT)
25+
26+
HACKERSDELIGHT_FILE_NAMES, = glob_wildcards(GIT_ROOT / "SSA/Projects/InstCombine/HackersDelight/{file}.lean")
27+
28+
SED = "gsed" if platform.system() == "Darwin" else "sed"
29+
hdel_nreps = config["hdel_nreps"]
30+
31+
rule venv:
32+
output:
33+
GIT_ROOT / "venv/bin/activate"
34+
shell:
35+
"""
36+
python3 -m venv venv
37+
venv/bin/pip install -r {GIT_ROOT}/requirements.txt
38+
"""
39+
40+
rule hdel_compare_make_lean:
41+
input:
42+
GIT_ROOT / "SSA/Projects/InstCombine/HackersDelight/{file}.lean"
43+
output:
44+
GIT_ROOT / "bv-evaluation/results/HackersDelight/{file}_{width}_{hdel_nreps}.lean"
45+
shell:
46+
"cp {input} {output} && "
47+
"{SED} -i -e \"s/all_goals sorry/all_goals bv_compare'/g\" -e \"s/WIDTH/{wildcards.width}/g\" {output} "
48+
49+
rule hdel_compare_make_output:
50+
input:
51+
lambda wc: GIT_ROOT / f"bv-evaluation/results/HackersDelight/{wc.file}_{wc.width}_{hdel_nreps}.lean"
52+
output:
53+
GIT_ROOT / "bv-evaluation/results/HackersDelight/{file}_{width}_r{r}.txt"
54+
resources:
55+
# TODO: actually impose memory and time limit, using a python script.
56+
run:
57+
status, stdout, stderr = run_with_limits(cmd=["lake", "lean", input[0]], timeout=int(config["hdel_timeout_sec"]), memout_mb=int(config["hdel_memout_mb"]))
58+
with open(output[0], "w") as f:
59+
f.write(stdout)
60+
f.write(stderr)
61+
if not isinstance(status, int) or status != 0:
62+
raise Exception(f"rule failed with status '{status}'. See {output[0]} for possible more details.")
63+
64+
# We can eventually split these, if we carefully understand the naming convention
65+
# of 'collect' for hacker's delight.
66+
# We currently make a monolithic job that runs both collect and plot,
67+
# Since the naming convention is a little opaque to @bollu.
68+
rule hdel_collect_and_plot:
69+
input:
70+
rules.venv.output,
71+
expand(GIT_ROOT / "bv-evaluation/results/HackersDelight/{file}_{width}_r{r}.txt",
72+
file=HACKERSDELIGHT_FILE_NAMES,
73+
width=config["hdel_bv_widths"],
74+
r=range(hdel_nreps))
75+
params:
76+
nreps = lambda wc: hdel_nreps,
77+
nthreads = lambda wc: config["hdel_nthreads"]
78+
output:
79+
tex=GIT_ROOT / "bv-evaluation/performance-hackersdelight.tex",
80+
pdf_stacked=GIT_ROOT / "bv-evaluation/plots/bv_decide_stacked_perc_HackersDelight_bvw64.pdf"
81+
# TODO: track the exact files generated by 'collect.py'.
82+
# We currently just bother asking for the two outputs we care for.
83+
shell:
84+
"bash -c 'source venv/bin/activate && cd bv-evaluation && python3 collect.py hackersdelight' && "
85+
"bash -c 'source venv/bin/activate && cd bv-evaluation && python3 plot.py hackersdelight'"
86+
87+
rule all:
88+
input:
89+
rules.hdel_collect_and_plot.output
90+
91+

config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
hdel_ntests: 100 # default number of goals to take.
2+
hdel_bv_widths: [4, 8, 16, 32, 64] # number of hackers delight widths.
3+
hdel_nreps: 2 # number of repetitions to run hacker's delight tests.
4+
hdel_timeout_sec: 1800
5+
hdel_memout_mb: 3600
6+
hdel_nthreads: 8 # number of threads to use for hacker's delight tests.
7+
seed: 42 # random number generator seed.
8+
9+

requirements.txt

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,65 @@
1+
appdirs==1.4.4
2+
argparse-dataclass==2.0.0
3+
attrs==25.3.0
4+
certifi==2025.8.3
5+
charset-normalizer==3.4.3
6+
conda-inject==1.3.2
7+
ConfigArgParse==1.7.1
8+
connection_pool==0.0.3
19
contourpy==1.3.1
210
cycler==0.12.1
11+
docopt==0.6.2
12+
docutils==0.22
13+
dpath==2.2.0
14+
fastjsonschema==2.21.2
315
fonttools==4.56.0
16+
gitdb==4.0.12
17+
GitPython==3.1.45
18+
humanfriendly==10.0
19+
idna==3.10
20+
immutables==0.21
421
importlib_metadata==8.6.1
22+
Jinja2==3.1.6
23+
jsonschema==4.25.1
24+
jsonschema-specifications==2025.4.1
25+
jupyter_core==5.8.1
526
kiwisolver==1.4.8
27+
MarkupSafe==3.0.2
628
matplotlib==3.10.1
29+
nbformat==5.10.4
30+
num2words==0.5.14
731
numpy==2.2.2
832
packaging==24.2
933
pandas==2.2.3
1034
pillow==11.1.0
35+
platformdirs==4.3.8
1136
polars==1.24.0
1237
psutil==7.0.0
38+
PuLP==3.2.2
1339
pyparsing==3.2.1
1440
python-dateutil==2.9.0.post0
1541
pytz==2025.1
42+
PyYAML==6.0.2
43+
referencing==0.36.2
44+
requests==2.32.5
45+
reretry==0.11.8
46+
rpds-py==0.27.0
1647
six==1.17.0
48+
smart_open==7.3.0.post1
49+
smmap==5.0.2
50+
snakemake==9.9.0
51+
snakemake-interface-common==1.21.0
52+
snakemake-interface-executor-plugins==9.3.9
53+
snakemake-interface-logger-plugins==1.2.4
54+
snakemake-interface-report-plugins==1.2.0
55+
snakemake-interface-storage-plugins==4.2.2
1756
tabulate==0.9.0
57+
throttler==1.2.2
58+
traitlets==5.14.3
59+
typing_extensions==4.15.0
1860
tzdata==2025.1
61+
urllib3==2.5.0
1962
visidata==3.1.1
63+
wrapt==1.17.3
64+
yte==1.9.0
2065
zipp==3.21.0
21-
num2words==0.5.14

0 commit comments

Comments
 (0)