Skip to content

Commit

Permalink
Generate better json for other projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 14, 2023
1 parent 63ad63b commit 5981b75
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Update site directory before running: `poetry run mkdocs build`

for ext in ["lsx", "lasx"]:

def parse_fn(line, skip_last):
before_paren = line.split("(")[0].split(" ")
between_parens = line.split("(")[1].split(")")[0]
Expand All @@ -19,7 +20,6 @@ def parse_fn(line, skip_last):

return tuple(result)


# gcc intrinsics
gcc_intrinsics = set()
for line in open(f"gcc_{ext}intrin.h", "r"):
Expand Down
2 changes: 1 addition & 1 deletion check_instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@

args = " ".join(inst.split(";")[0].split(" ")[1:])
if args != fmt:
print("Mismatch inst=", inst, ",args=", args, ",fmt=", fmt)
print("Mismatch inst=", inst, ",args=", args, ",fmt=", fmt)
87 changes: 56 additions & 31 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@

# read latency & throughput
cpus = ["3A6000", "3C5000"]
measure = {
"3A6000": {},
"3C5000": {}
}
measure = {"3A6000": {}, "3C5000": {}}
for cpu in cpus:
with open(f'code/measure-{cpu}.csv', newline='') as csvfile:
with open(f"code/measure-{cpu}.csv", newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
latency = []
for part in row['latency'].split('/'):
for part in row["latency"].split("/"):
if part == "":
lat = "N/A"
else:
Expand All @@ -31,21 +28,22 @@
latency.append(lat)
latency = sorted(list(set(latency)))

throughput_cpi = float(row['throughput(cpi)'])
throughput_cpi = float(row["throughput(cpi)"])
if abs(throughput_cpi - round(throughput_cpi)) < 0.03:
throughput_cpi = round(throughput_cpi)

# TODO: handle small cpi better by 1/ipc
throughput_ipc = float(row['throughput(ipc)'])
throughput_ipc = float(row["throughput(ipc)"])
if abs(throughput_ipc - round(throughput_ipc)) < 0.03:
throughput_ipc = round(throughput_ipc)

measure[cpu][row['name']] = {
'latency': ", ".join(map(str, latency)),
'throughput(cpi)': throughput_cpi,
'throughput(ipc)': throughput_ipc,
measure[cpu][row["name"]] = {
"latency": ", ".join(map(str, latency)),
"throughput(cpi)": throughput_cpi,
"throughput(ipc)": throughput_ipc,
}


# depends on implementation of env.macro()
def my_macro(env):
def wrap(fn):
Expand All @@ -54,16 +52,21 @@ def vfn(*args):
cur_simd = "lsx"
cur_vlen = 128
return fn(*args)

env.macros[f"{fn.__name__}"] = vfn

def xvfn(*args):
global cur_simd, cur_vlen
cur_simd = "lasx"
cur_vlen = 256
return fn(*args)

env.macros[f"x{fn.__name__}"] = xvfn
return fn

return wrap


def define_env(env):
widths = {
"b": 8,
Expand Down Expand Up @@ -128,8 +131,8 @@ def instruction(intrinsic, instr, desc):
for cpu in cpus:
if instr_name in measure[cpu]:
show_cpus.append(cpu)
latencies.append(measure[cpu][instr_name]['latency'])
throughputs.append(measure[cpu][instr_name]['throughput(cpi)'])
latencies.append(measure[cpu][instr_name]["latency"])
throughputs.append(measure[cpu][instr_name]["throughput(cpi)"])

if len(show_cpus) > 0:
latency_throughput = f"""
Expand All @@ -139,7 +142,9 @@ def instruction(intrinsic, instr, desc):
|-----|---------|------------------|
"""
for i in range(len(show_cpus)):
latency_throughput += f"| {show_cpus[i]} | {latencies[i]} | {throughputs[i]} |\n"
latency_throughput += (
f"| {show_cpus[i]} | {latencies[i]} | {throughputs[i]} |\n"
)
else:
latency_throughput = ""

Expand Down Expand Up @@ -590,7 +595,7 @@ def xvinsve0(name):
@env.macro
def vext2xv(name, name2):
global cur_simd
cur_simd = "lsx" # avoid replacing vext2xv to xvext2xv
cur_simd = "lsx" # avoid replacing vext2xv to xvext2xv
width = widths[name]
width2 = widths[name2]
signedness = signednesses[name]
Expand Down Expand Up @@ -1800,7 +1805,7 @@ def vldi():
)

@env.macro
def all_intrinsics():
def all_intrinsics(render=True):
result = []
for file in glob.glob("docs/*/*.md"):
for line in open(file, "r"):
Expand All @@ -1824,17 +1829,36 @@ def all_intrinsics():
extension = "LSX"
else:
extension = "LASX"
result.append(
{
"name": intrinsic,
"content": markdown.markdown(
body,
extensions=["fenced_code", "codehilite", "tables"],
),
"group": title,
"extension": extension
}
)

if render:
result.append(
{
"name": intrinsic,
"content": markdown.markdown(
body,
extensions=[
"fenced_code",
"codehilite",
"tables",
],
),
"group": title,
"extension": extension,
}
)
else:
# do not render
result.append(
{
"name": intrinsic.split("(")[0]
.strip()
.split(" ")[-1],
"full_name": intrinsic,
"content": body.strip(),
"group": title,
"extension": extension,
}
)
break
return json.dumps(sorted(result, key=lambda e: e["name"]))

Expand Down Expand Up @@ -1877,7 +1901,8 @@ def latency_throughput_table():
result += "</tbody>"
return result

if __name__ == '__main__':

if __name__ == "__main__":
# Fake an env
class Env:
def __init__(self):
Expand All @@ -1888,5 +1913,5 @@ def macro(self, fn):

env = Env()
define_env(env)
result = env.macros["all_intrinsics"]()
json.dump(json.loads(result), open("intrinsics.json", 'w'), indent=True)
result = env.macros["all_intrinsics"](render=False)
json.dump(json.loads(result), open("intrinsics.json", "w"), indent=True)

0 comments on commit 5981b75

Please sign in to comment.