added config.vh
This commit is contained in:
132
hw/scripts/gen_config.py
Executable file
132
hw/scripts/gen_config.py
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding=utf-8
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import os.path as path
|
||||
import re
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
|
||||
script_dir = path.dirname(path.realpath(__file__))
|
||||
|
||||
defines = {}
|
||||
for k, v in os.environ.items():
|
||||
if k.upper().startswith('V_'):
|
||||
defines[k[2:]] = v
|
||||
|
||||
print('Custom params:', ', '.join(['='.join(x) for x in defines.items()]))
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--outc', default='none', help='Output C header')
|
||||
parser.add_argument('--outv', default='none', help='Output Verilog header')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.outc == 'none' and args.outv == 'none':
|
||||
print('Warning: not emitting any files. Specify arguments')
|
||||
|
||||
if args.outv != 'none':
|
||||
with open(args.outv, 'w') as f:
|
||||
print('''
|
||||
// auto-generated by gen_config.py. DO NOT EDIT
|
||||
// Generated at {date}
|
||||
|
||||
`ifndef VX_USER_CONFIG
|
||||
`define VX_USER_CONFIG
|
||||
'''[1:].format(date=datetime.now()), file=f)
|
||||
|
||||
for k, v in defines.items():
|
||||
print('`define {} {}'.format(k, v), file=f)
|
||||
|
||||
print('\n`endif', file=f)
|
||||
|
||||
if args.outc != 'none':
|
||||
with open(args.outc, 'w') as f:
|
||||
print('''
|
||||
// auto-generated by gen_config.py. DO NOT EDIT
|
||||
// Generated at {date}
|
||||
|
||||
#ifndef VX_USER_CONFIG
|
||||
#define VX_USER_CONFIG
|
||||
'''[1:].format(date=datetime.now()), file=f)
|
||||
|
||||
for k, v in defines.items():
|
||||
print('#define {} {}'.format(k, v), file=f)
|
||||
|
||||
print('\n#endif', file=f)
|
||||
|
||||
translation_rules = [
|
||||
(re.compile(r'^$'), r''),
|
||||
(re.compile(r'^( *)`ifndef ([^ ]+)$'), r'\1#ifndef \2'),
|
||||
(re.compile(r'^( *)`define ([^ ]+)$'), r'\1#define \2'),
|
||||
# (re.compile(r'^( *)`include "\./VX_define_synth\.v"$'), r'\1#include "VX_define_synth.h"'),
|
||||
(re.compile(r'^( *)`include "VX_user_config\.vh"$'), r''),
|
||||
(re.compile(r'^( *)`define ([^ ]+) (.+)$'), r'\1#define \2 \3'),
|
||||
(re.compile(r'^( *)`endif$'), r'\1#endif'),
|
||||
(re.compile(r'^( *)// (.*)$'), r'\1// \2'),
|
||||
]
|
||||
|
||||
post_rules = [
|
||||
(re.compile(r"\d+'d(\d+)"), r'\1'),
|
||||
|
||||
# non-standard C but supported by GCC and Clang
|
||||
(re.compile(r"\d+'b([01]+)"), r'0b\1'),
|
||||
(re.compile(r"\d+'h([\da-fA-F]+)"), r'0x\1'),
|
||||
|
||||
# fix macro references (does not support escaped identifiers §5.6.1)
|
||||
(re.compile(r"`([A-Za-z_][$_0-9A-Za-z]*)"), r'\1'),
|
||||
]
|
||||
|
||||
|
||||
def post_process_line(line):
|
||||
for pat, repl in post_rules:
|
||||
line = pat.sub(repl, line)
|
||||
return line
|
||||
|
||||
|
||||
in_expansion = False
|
||||
|
||||
if args.outc != 'none':
|
||||
with open(args.outc, 'a') as f:
|
||||
print('''
|
||||
// auto-generated by gen_config.py. DO NOT EDIT
|
||||
// Generated at {date}
|
||||
|
||||
// Translated from VX_config.vh:
|
||||
'''[1:].format(date=datetime.now()), file=f)
|
||||
with open(path.join(script_dir, '../rtl/VX_config.vh'), 'r') as r:
|
||||
for line in r:
|
||||
if in_expansion:
|
||||
f.write(post_process_line(line))
|
||||
if not line.strip().endswith('\\'):
|
||||
in_expansion = False
|
||||
else:
|
||||
for pat, repl in translation_rules:
|
||||
if pat.match(line):
|
||||
if line.strip().endswith('\\'):
|
||||
in_expansion = True
|
||||
f.write(post_process_line(pat.sub(repl, line)))
|
||||
break
|
||||
else:
|
||||
raise ValueError('failed to find rule for: ' + line)
|
||||
|
||||
print('''
|
||||
// Misc
|
||||
|
||||
#define THREADS_PER_WARP NUM_THREADS
|
||||
#define WARPS_PER_CORE NUM_WARPS
|
||||
#define NUMBER_WI (NUM_WARPS * NUM_THREADS * NUMBER_CORES_PER_CLUSTER * NUMBER_CLUSTERS)
|
||||
|
||||
// legacy
|
||||
#define TOTAL_THREADS NUMBER_WI
|
||||
#define TOTAL_WARPS (NUM_WARPS * NUMBER_CORES_PER_CLUSTER * NUMBER_CLUSTERS)
|
||||
|
||||
// COLORS
|
||||
#define GREEN "\\033[32m"
|
||||
#define RED "\\033[31m"
|
||||
#define DEFAULT "\\033[39m"
|
||||
'''[1:], file=f)
|
||||
|
||||
|
||||
|
||||
48
hw/scripts/gen_synth_configs.py
Executable file
48
hw/scripts/gen_synth_configs.py
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import glob
|
||||
|
||||
config_location = 'configs'
|
||||
|
||||
name_template = '{clusters}cl-{cores}c-{warps}w-{threads}t-{l2}Kl2-{dcache}Kd-{icache}Ki{name_suffix}.sh'
|
||||
|
||||
template = """
|
||||
|
||||
export V_NT={threads}
|
||||
export V_NW={warps}
|
||||
export V_NUMBER_CORES_PER_CLUSTER={cores}
|
||||
export V_NUMBER_CLUSTERS={clusters}
|
||||
export V_DCACHE_SIZE_BYTES={dcachek}
|
||||
export V_ICACHE_SIZE_BYTES={icachek}
|
||||
|
||||
# L2 Cache size
|
||||
export V_L2CACHE_SIZE_BYTES={l2k}
|
||||
|
||||
{codegen}
|
||||
|
||||
"""
|
||||
|
||||
# cluster, cores, warps, threads, l2, dcache, icache
|
||||
configs = [
|
||||
(1, 2, 8, 4, 8, 4, 1),
|
||||
(1, 2, 8, 8, 8, 4, 1),
|
||||
(1, 2, 8, 8, 16, 8, 1),
|
||||
|
||||
(1, 4, 8, 8, 16, 4, 1),
|
||||
(1, 4, 8, 8, 16, 8, 1),
|
||||
(1, 4, 16, 8, 16, 8, 1),
|
||||
|
||||
(2, 4, 8, 4, 8, 4, 1),
|
||||
(2, 4, 8, 8, 16, 8, 1),
|
||||
]
|
||||
|
||||
files = glob.glob(config_location + '/*.sh')
|
||||
for f in files:
|
||||
os.remove(f)
|
||||
|
||||
for clusters, cores, warps, threads, l2, dcache, icache in configs:
|
||||
l2k, dcachek, icachek = 1024 * l2, 1024 * dcache, 1024 * icache
|
||||
name_suffix = ''
|
||||
with open(config_location + '/' + name_template.format(**locals()), 'w') as f:
|
||||
codegen = ''
|
||||
f.write(template.format(**locals()))
|
||||
Reference in New Issue
Block a user