| |
|
|
| |
| |
| |
|
|
| import os |
| import sys |
| import os.path |
| import re |
| import itertools |
| import glob |
|
|
| PUBLIC = ["nangate45", "sky130hd", "sky130hs", "asap7"] |
|
|
| |
| |
| NumFilesPerChunk = 50000 |
|
|
| |
| OriginalSDC = "constraint.sdc" |
|
|
| |
| |
| |
|
|
| |
| ShellName = "runMassive" |
| |
| MetricsShellName = "%s_metrics_collect.sh" % (ShellName) |
|
|
|
|
| |
| |
| |
|
|
| |
| |
| PLATFORM_DESIGN = ["sky130hd-gcd"] |
|
|
|
|
| |
| CLK_PERIOD = [] |
|
|
| |
| |
| |
| UNCERTAINTY = [] |
| IO_DELAY = [] |
|
|
|
|
| |
| |
| |
|
|
| |
| |
| ABC_CLOCK_PERIOD = [] |
| |
| |
| FLATTEN = [] |
|
|
|
|
| |
| |
| |
|
|
|
|
| |
| |
| CORE_UTIL = [] |
|
|
| |
| ASPECT_RATIO = [] |
| |
| CORE_DIE_MARGIN = [] |
|
|
| |
| |
| PINS_DISTANCE = [] |
|
|
| |
| |
| |
|
|
| |
| GP_PAD = [] |
| |
| DP_PAD = [] |
|
|
| |
| |
| |
| |
| |
| PLACE_DENSITY = [] |
| PLACE_DENSITY_LB_ADDON = [] |
|
|
|
|
| |
| |
| |
|
|
| |
| CTS_CLUSTER_SIZE = [] |
| CTS_CLUSTER_DIAMETER = [] |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
| |
| LAYER_ADJUST = [] |
|
|
| LAYER_ADJUST_M1 = [] |
| LAYER_ADJUST_M2 = [] |
| LAYER_ADJUST_M3 = [] |
| LAYER_ADJUST_M4 = [] |
| LAYER_ADJUST_M5 = [] |
| LAYER_ADJUST_M6 = [] |
| LAYER_ADJUST_M7 = [] |
| LAYER_ADJUST_M8 = [] |
| LAYER_ADJUST_M9 = [] |
|
|
| |
| GR_SEED = [] |
|
|
| |
| |
| GR_OVERFLOW = [0] |
|
|
| |
| |
| |
|
|
| |
| DR_SEED = [] |
|
|
| SweepingAttributes = { |
| "PLATFORM_DESIGN": PLATFORM_DESIGN, |
| "CP": CLK_PERIOD, |
| "ABC_CP": ABC_CLOCK_PERIOD, |
| "FLATTEN": FLATTEN, |
| "UNCERTAINTY": UNCERTAINTY, |
| "IO_DELAY": IO_DELAY, |
| "UTIL": CORE_UTIL, |
| "AR": ASPECT_RATIO, |
| "GAP": CORE_DIE_MARGIN, |
| "PINS_DISTANCE": PINS_DISTANCE, |
| "GP_PAD": GP_PAD, |
| "DP_PAD": DP_PAD, |
| "PD": PLACE_DENSITY, |
| "PD_LB_ADD": PLACE_DENSITY_LB_ADDON, |
| "CTS_CLUSTER_SIZE": CTS_CLUSTER_SIZE, |
| "CTS_CLUSTER_DIAMETER": CTS_CLUSTER_DIAMETER, |
| "LAYER_ADJUST": LAYER_ADJUST, |
| "M1": LAYER_ADJUST_M1, |
| "M2": LAYER_ADJUST_M2, |
| "M3": LAYER_ADJUST_M3, |
| "M4": LAYER_ADJUST_M4, |
| "M5": LAYER_ADJUST_M5, |
| "M6": LAYER_ADJUST_M6, |
| "M7": LAYER_ADJUST_M7, |
| "M8": LAYER_ADJUST_M8, |
| "M9": LAYER_ADJUST_M9, |
| "GR_SEED": GR_SEED, |
| "GR_OVERFLOW": GR_OVERFLOW, |
| "DR_SEED": DR_SEED, |
| } |
|
|
|
|
| def assignEmptyAttrs(dicts): |
| knobs = {} |
| for k, v in dicts.items(): |
| if len(v) == 0: |
| knobs.setdefault(k, ["empty"]) |
| else: |
| knobs.setdefault(k, v) |
| return knobs |
|
|
|
|
| def writeDoeLog(dicts, ProductDicts): |
| fo = open("./doe.log", "w") |
| numRuns = 1 |
| for k, v in dicts.items(): |
| if len(v) > 0: |
| print("%s has %s number of values" % (k, len(v))) |
| fo.write("%s has %s number of values\n" % (k, len(v))) |
| numRuns = numRuns * len(v) |
| fo.write("\nTotal Number of Runs = %s\n\n" % numRuns) |
| print("\nTotal Number of Runs = %s\n\n" % numRuns) |
|
|
| knobValuesList = [] |
| knobNamesList = [] |
| for CurAttrs in ProductAttrs: |
| knobValues = [] |
| knobNames = [] |
| for k, v in CurAttrs.items(): |
| if v == "empty": |
| continue |
| else: |
| knobNames.append(str(k)) |
| knobValues.append(str(v)) |
| knobValuesList.append(knobValues) |
| knobNamesList.append(knobNames) |
| fo.write(str(knobNamesList[0]) + "\n") |
| for knobSet in knobValuesList: |
| fo.write(str(knobSet) + "\n") |
|
|
| fo.close() |
|
|
|
|
| def productDict(dicts): |
| return (dict(zip(dicts, x)) for x in itertools.product(*dicts.values())) |
|
|
|
|
| def adjustFastRoute(filedata, adjSet, GrOverflow): |
| if adjSet[0] != "empty": |
| filedata = re.sub( |
| "(set_global_routing_layer_adjustment .* )[0-9\\.]+", |
| "\\g<1>{:.2f}".format(float(adjSet[0])), |
| filedata, |
| ) |
| sep_la_cmds = "" |
| for i, sep_la in enumerate(adjSet): |
| if i == 0 or sep_la == "empty": |
| continue |
| |
| |
| layer_name = "met%s" % i |
| sep_la_cmds += ( |
| "set_global_routing_layer_adjustment " |
| + layer_name |
| + " {:.2f}\n".format(float(sep_la)) |
| ) |
| filedata = re.sub( |
| "set_global_routing_layer_adjustment.*\n", "\\g<0>" + sep_la_cmds, filedata |
| ) |
| if int(GrOverflow) == 1: |
| filedata = re.sub( |
| "(global_route.*(\n\\s+.*)*)", |
| "\\g<1> \\\n -allow_overflow", |
| filedata, |
| ) |
|
|
| return filedata |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| def writeConfigs(CurAttrs, CurChunkNum): |
| CurPlatform, CurDesign = CurAttrs.get("PLATFORM_DESIGN").split("-") |
| CurClkPeriod = CurAttrs.get("CP") |
| CurAbcClkPeriod = CurAttrs.get("ABC_CP") |
| CurFlatten = CurAttrs.get("FLATTEN") |
| CurUncertainty = CurAttrs.get("UNCERTAINTY") |
| CurIoDelay = CurAttrs.get("IO_DELAY") |
| CurCoreUtil = CurAttrs.get("UTIL") |
| CurAspectRatio = CurAttrs.get("AR") |
| CurCoreDieMargin = CurAttrs.get("GAP") |
| CurPinsDistance = CurAttrs.get("PINS_DISTANCE") |
| CurGpPad = CurAttrs.get("GP_PAD") |
| CurDpPad = CurAttrs.get("DP_PAD") |
| CurPlaceDensity = CurAttrs.get("PD") |
| CurPlaceDensityLbAddon = CurAttrs.get("PD_LB_ADD") |
| CurCtsClusterSize = CurAttrs.get("CTS_CLUSTER_SIZE") |
| CurCtsClusterDiameter = CurAttrs.get("CTS_CLUSTER_DIAMETER") |
| CurLayerAdjust = CurAttrs.get("LAYER_ADJUST") |
| CurLayerAdjustM1 = CurAttrs.get("M1") |
| CurLayerAdjustM2 = CurAttrs.get("M2") |
| CurLayerAdjustM3 = CurAttrs.get("M3") |
| CurLayerAdjustM4 = CurAttrs.get("M4") |
| CurLayerAdjustM5 = CurAttrs.get("M5") |
| CurLayerAdjustM6 = CurAttrs.get("M6") |
| CurLayerAdjustM7 = CurAttrs.get("M7") |
| CurLayerAdjustM8 = CurAttrs.get("M8") |
| CurLayerAdjustM9 = CurAttrs.get("M9") |
| CurGrSeed = CurAttrs.get("GR_SEED") |
| CurGrOverflow = CurAttrs.get("GR_OVERFLOW") |
| CurDrSeed = CurAttrs.get("DR_SEED") |
|
|
| if not os.path.isdir("./designs/%s/%s/chunks" % (CurPlatform, CurDesign)): |
| os.mkdir("./designs/%s/%s/chunks" % (CurPlatform, CurDesign)) |
| CurDesignDir = "./designs/%s/%s" % (CurPlatform, CurDesign) |
| CurChunkDir = "./designs/%s/%s/chunks/chunk%s" % ( |
| CurPlatform, |
| CurDesign, |
| CurChunkNum, |
| ) |
|
|
| if not os.path.isdir(CurChunkDir): |
| os.mkdir(CurChunkDir) |
|
|
| if MakeArg == "clean": |
| fileList = glob.glob("%s/*-DoE-*" % (CurChunkDir)) |
| if fileList is not None: |
| for file in fileList: |
| os.remove(file) |
| return |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| variantName = "" |
| for k, v in CurAttrs.items(): |
| if v != "empty" and k != "PLATFORM_DESIGN": |
| variantName = variantName + "-" + str(k) + "_" + str(v) |
| variantName = variantName[1:] |
| |
| fileName = "config-DoE-" + variantName + ".mk" |
|
|
| fo = open("%s/%s" % (CurChunkDir, fileName), "w") |
|
|
| fo.write("include $(realpath $(DESIGN_DIR)../../)/config.mk\n") |
| fo.write("\n") |
| fo.write("FLOW_VARIANT = %s\n" % (variantName)) |
| fo.write("\n") |
|
|
| if CurClkPeriod != "empty" or CurUncertainty != "empty" or CurIoDelay != "empty": |
| fOrigSdc = open("%s/%s" % (CurDesignDir, OriginalSDC), "r") |
| filedata = fOrigSdc.read() |
| fOrigSdc.close() |
| if CurClkPeriod != "empty": |
| filedata = re.sub( |
| "-period [0-9\\.]+", "-period " + str(CurClkPeriod), filedata |
| ) |
| |
| filedata = re.sub("-waveform [{}\\s0-9\\.]+[\\s|\n]", "", filedata) |
| if CurUncertainty != "empty": |
| filedata = re.sub( |
| "set uncertainty [0-9\\.]+", |
| "set uncertainty " + str(CurUncertainty), |
| filedata, |
| ) |
| if CurIoDelay != "empty": |
| filedata = re.sub( |
| "set io_delay [0-9\\.]+", "set io_delay " + str(CurIoDelay), filedata |
| ) |
|
|
| |
| fOutSdc = open("%s/constraint-DoE-" % (CurChunkDir) + variantName + ".sdc", "w") |
| fOutSdc.write(filedata) |
| fOutSdc.close() |
| fo.write( |
| "export SDC_FILE = $(DESIGN_DIR)/constraint-DoE-%s.sdc\n" % variantName |
| ) |
|
|
| if CurAbcClkPeriod != "empty": |
| fo.write("export ABC_CLOCK_PERIOD_IN_PS = %s\n" % CurAbcClkPeriod) |
| if CurFlatten != "empty": |
| if CurFlatten == 0: |
| fo.write("export SYNTH_ARGS = \n") |
|
|
| if CurCoreUtil != "empty": |
| fo.write("export CORE_UTILIZATION = %s\n" % CurCoreUtil) |
| if CurPlaceDensity != "empty": |
| fo.write("export PLACE_DENSITY = %.2f\n" % CurPlaceDensity) |
| if CurPlaceDensityLbAddon != "empty": |
| fo.write("export PLACE_DENSITY_LB_ADDON = %.2f\n" % CurPlaceDensityLbAddon) |
| if CurAspectRatio != "empty": |
| fo.write("export CORE_ASPECT_RATIO = %s\n" % CurAspectRatio) |
| if CurCoreDieMargin != "empty": |
| fo.write("export CORE_MARGIN = %s\n" % CurCoreDieMargin) |
| if CurPinsDistance != "empty": |
| fo.write("export PLACE_PINS_ARGS = -min_distance %s\n" % CurPinsDistance) |
| if CurGpPad != "empty": |
| fo.write("export CELL_PAD_IN_SITES_GLOBAL_PLACEMENT = %s\n" % CurGpPad) |
| if CurDpPad != "empty": |
| fo.write("export CELL_PAD_IN_SITES_DETAIL_PLACEMENT = %s\n" % CurDpPad) |
|
|
| if CurCtsClusterSize != "empty": |
| fo.write("export CTS_CLUSTER_SIZE = %s\n" % CurCtsClusterSize) |
| if CurCtsClusterDiameter != "empty": |
| fo.write("export CTS_CLUSTER_DIAMETER = %s\n" % CurCtsClusterDiameter) |
| if CurDrSeed != "empty": |
| fo.write("export OR_K = 1.0\n") |
| fo.write("export OR_SEED = %s\n" % CurDrSeed) |
| if ( |
| CurLayerAdjust != "empty" |
| or CurLayerAdjustM1 != "empty" |
| or CurLayerAdjustM2 != "empty" |
| or CurLayerAdjustM3 != "empty" |
| or CurLayerAdjustM4 != "empty" |
| or CurLayerAdjustM5 != "empty" |
| or CurLayerAdjustM6 != "empty" |
| or CurLayerAdjustM7 != "empty" |
| or CurLayerAdjustM8 != "empty" |
| or CurLayerAdjustM9 != "empty" |
| or CurGrSeed != "empty" |
| ): |
| fo.write( |
| "export FASTROUTE_TCL = $(DESIGN_DIR)/fastroute-DoE-%s.tcl" % variantName |
| ) |
|
|
| if CurPlatform in PUBLIC: |
| PLATFORM_DIR = "./platforms/%s" % CurPlatform |
| else: |
| PLATFORM_DIR = "../../%s" % CurPlatform |
|
|
| fFrIn = open("%s/fastroute.tcl" % PLATFORM_DIR, "r") |
| filedata = fFrIn.read() |
| fFrIn.close() |
|
|
| CurLayerAdjustSet = [ |
| CurLayerAdjust, |
| CurLayerAdjustM1, |
| CurLayerAdjustM2, |
| CurLayerAdjustM3, |
| CurLayerAdjustM4, |
| CurLayerAdjustM5, |
| CurLayerAdjustM6, |
| CurLayerAdjustM7, |
| CurLayerAdjustM8, |
| CurLayerAdjustM9, |
| ] |
| filedata = adjustFastRoute(filedata, CurLayerAdjustSet, CurGrOverflow) |
| FrName = "fastroute-DoE-" + variantName + ".tcl" |
| fOutFr = open("%s/%s" % (CurChunkDir, FrName), "w") |
| fOutFr.write(filedata) |
| if CurGrSeed != "empty": |
| fOutFr.write("set_global_routing_random -seed %s" % CurGrSeed) |
| fOutFr.close() |
|
|
| fo.close() |
|
|
| frun = open("./%s.sh" % ShellName, "a") |
| RunName = "DESIGN_CONFIG=%s/%s make\n" % (CurChunkDir, fileName) |
| frun.write(RunName) |
| frun.close() |
|
|
| with open("./metrics/%s" % MetricsShellName, "a") as fcollect: |
| CollectName = ( |
| "python util/genMetrics.py -x -p %s -d %s -v %s -o metrics/metrics_%s/%s.json\n" |
| % (CurPlatform, CurDesign, variantName, ShellName, variantName) |
| ) |
| fcollect.write(CollectName) |
|
|
|
|
| MakeArg = sys.argv[1] |
|
|
|
|
| if not os.path.isdir("./metrics"): |
| os.mkdir("./metrics") |
| if not os.path.isdir("./metrics/metrics_%s" % ShellName): |
| os.mkdir("./metrics/metrics_%s" % ShellName) |
|
|
| knobs = assignEmptyAttrs(SweepingAttributes) |
| ProductAttrs = list(productDict(knobs)) |
| writeDoeLog(SweepingAttributes, ProductAttrs) |
| if os.path.isfile("./%s.sh" % ShellName): |
| os.remove("./%s.sh" % ShellName) |
| if os.path.isfile("./metrics/%s" % MetricsShellName): |
| os.remove("./metrics/%s" % MetricsShellName) |
| CurChunkNum = 0 |
| for i, CurAttrs in enumerate(ProductAttrs, 1): |
| if i % NumFilesPerChunk == 0: |
| writeConfigs(CurAttrs, CurChunkNum) |
| CurChunkNum = CurChunkNum + 1 |
| else: |
| writeConfigs(CurAttrs, CurChunkNum) |
|
|
|
|
| |
| |
| |
| |
|
|
| |
| |
|
|