def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--schema_dir', required=True) parser.add_argument('--schema', required=True, choices=SCHEMAS) parser.add_argument('--root_schema_path', default=None) parser.add_argument('--patch_path', required=True) parser.add_argument('--patch_format', required=True, choices=FORMATS) parser.add_argument('root') parser.add_argument('patch') parser.add_argument('output') args = parser.parse_args() patch_path = args.patch_path.split('.') root_schema = get_schema(args.schema_dir, args.schema, args.root_schema_path) with open(args.root, 'rb') as f: message = read_capnp_file(root_schema, f) message = message.as_builder() with open(args.patch, 'rb') as f: patch_capnp(message, patch_path, args.patch_format, f) with open(args.output, 'wb') as f: write_capnp_file(message, f)
def test_get_schemas(self): schema_dir = os.environ['INTERCHANGE_SCHEMA_PATH'] interchange = Interchange( schema_directory=os.environ['INTERCHANGE_SCHEMA_PATH']) self.assertSameSchema(interchange.device_resources_schema.Device, get_schema(schema_dir, 'device')) self.assertSameSchema(interchange.device_resources_schema.Device, get_schema(schema_dir, 'device', 'Device')) self.assertSameSchema( interchange.device_resources_schema.Device.SiteType, get_schema(schema_dir, 'device', 'Device.SiteType')) self.assertSameSchema(interchange.logical_netlist_schema.Netlist, get_schema(schema_dir, 'logical')) self.assertSameSchema(interchange.logical_netlist_schema.Netlist, get_schema(schema_dir, 'logical', 'Netlist')) self.assertSameSchema(interchange.physical_netlist_schema.PhysNetlist, get_schema(schema_dir, 'physical')) self.assertSameSchema( interchange.physical_netlist_schema.PhysNetlist, get_schema(schema_dir, 'physical', 'PhysNetlist'))
def round_read_write_message(self, schema, message): schema_dir = os.environ['INTERCHANGE_SCHEMA_PATH'] schema = get_schema(schema_dir, schema) for format1 in FORMATS: f = io.BytesIO() write_format(message, format1, f) f.seek(0) message_out = read_format(schema, format1, f) compare_capnp(self, message, message_out) for format2 in FORMATS: f2 = io.BytesIO() write_format(message_out, format2, f2) f2.seek(0) message_out2 = read_format(schema, format2, f2) compare_capnp(self, message, message_out2) compare_capnp(self, message_out, message_out2)
def setUp(self): schema = get_schema(os.environ['INTERCHANGE_SCHEMA_PATH'], 'device', 'Device.Constraints') path = os.path.join(__dir__, 'data', 'series7_constraints.yaml') with open(path, 'rb') as f: constraints = read_format(schema, 'yaml', f) self.model = Constraints() self.model.read_constraints(constraints) interchange = Interchange( schema_directory=os.environ['INTERCHANGE_SCHEMA_PATH']) phys_netlist = example_physical_netlist() with open( os.path.join(os.environ['DEVICE_RESOURCE_PATH'], phys_netlist.part + '.device'), 'rb') as f: device = interchange.read_device_resources(f) self.placement_oracle = PlacementOracle() self.placement_oracle.add_sites_from_device(device)
def test_patch_series7_constraints(self): phys_netlist = example_physical_netlist() interchange = Interchange( schema_directory=os.environ['INTERCHANGE_SCHEMA_PATH']) with open( os.path.join(os.environ['DEVICE_RESOURCE_PATH'], phys_netlist.part + '.device'), 'rb') as f: dev_message = interchange.read_device_resources_raw(f) dev_message = dev_message.as_builder() path = os.path.join(__dir__, 'data', 'series7_constraints.yaml') with open(path, 'rb') as f: patch_capnp(dev_message, ['constraints'], 'yaml', f) schema = get_schema(os.environ['INTERCHANGE_SCHEMA_PATH'], 'device', 'Device.Constraints') with open(path, 'rb') as f: series7 = read_format(schema, 'yaml', f) compare_capnp(self, series7, dev_message.constraints)
def test_parse_ecp5_constraints(self): schema = get_schema(os.environ['INTERCHANGE_SCHEMA_PATH'], 'device', 'Device.Constraints') path = os.path.join(__dir__, 'data', 'ecp5_constraints.yaml') with open(path, 'rb') as f: _ = read_format(schema, 'yaml', f)
def main(): parser = argparse.ArgumentParser( description="Add timing information to Device") parser.add_argument("--schema_dir", required=True) parser.add_argument("--timing_dir", required=True) parser.add_argument("--family", required=True) parser.add_argument("device") parser.add_argument("patched_device") args = parser.parse_args() device_schema = get_schema(args.schema_dir, "device") with open(args.device, 'rb') as f: dev = read_capnp_file(device_schema, f) dev = dev.as_builder() node_model_map, wire_node_map = create_wire_to_node_map(dev) tileType_wire_name_wire_list_map = create_tile_type_wire_name_to_wire_list( dev) string_map = create_string_to_dev_string_map(dev) tile_name_tileType_map = create_tile_type_name_to_tile_type(dev) tileType_wires_pip_map = create_tile_type_wire0_wire1_pip_map(dev) siteName_siteType_map = create_site_name_to_site_type_map(dev) siteType_name_sitePin_map = create_site_type_name_to_site_pin_map(dev) tile_type_name_to_number = {} for i, tileType in enumerate(dev.tileTypeList): name = dev.strList[tileType.name] tile_type_name_to_number[name] = i pip_models = {} family_map = {"xc7": prjxray_db_reader} timing_dir = args.timing_dir timing_reader = family_map[args.family](timing_dir) timing_data = timing_reader.extract_data() for tile, _data in timing_data.items(): if tile not in string_map: continue tile_name = string_map[tile] tileType = tile_name_tileType_map[tile_name] for name, data in _data['wires'].items(): wire_name = string_map[name] for wire in tileType_wire_name_wire_list_map[(tileType, wire_name)]: if wire not in wire_node_map: continue node = wire_node_map[wire] model = node_model_map[node] res = list(model[0]) cap = list(model[1]) for i in range(len(res)): res[i] += data[0][i] for i in range(len(cap)): cap[i] += data[1][i] model = (tuple(res), tuple(cap)) node_model_map[node] = model for old_key, data in _data['pips'].items(): wire0 = string_map[old_key[0]] wire1 = string_map[old_key[1]] key = (tileType, wire0, wire1) if key not in tileType_wires_pip_map: continue pip = tileType_wires_pip_map[key] pip_models[pip] = data for site, data in _data['sites'].items(): siteType = siteName_siteType_map[string_map[site]] for sitePin, model in data.items(): sitePin_obj = siteType_name_sitePin_map[(siteType, string_map[sitePin])] if model[0][0] is not None and model[0][0] == 'r': sitePin_obj.model.init('resistance') corner_model = sitePin_obj.model.resistance populate_corner_model(corner_model, *model[0][1]) elif model[0][0] is not None and model[0][0] == 'c': sitePin_obj.model.init('capacitance') corner_model = sitePin_obj.model.capacitance populate_corner_model(corner_model, *model[0][1]) sitePin_obj.init('delay') corner_model = sitePin_obj.delay populate_corner_model(corner_model, *model[1]) timing_set = set() for timing in node_model_map.values(): timing_set.add(timing) timing_dict = {timing: i for i, timing in enumerate(timing_set)} dev.init("nodeTimings", len(timing_dict)) for model, i in timing_dict.items(): corner_model = dev.nodeTimings[i].resistance populate_corner_model(corner_model, *model[0]) corner_model = dev.nodeTimings[i].capacitance populate_corner_model(corner_model, *model[1]) for node, timing in node_model_map.items(): node.nodeTiming = timing_dict[timing] timing_set = set() for model in pip_models.values(): timing_set.add(model) timing_dict = {timing: i for i, timing in enumerate(timing_set)} dev.init("pipTimings", len(timing_dict)) for model, i in timing_dict.items(): pipTiming = dev.pipTimings[i] corner_model = pipTiming.inputCapacitance populate_corner_model(corner_model, *model[0]) corner_model = pipTiming.internalCapacitance populate_corner_model(corner_model, *model[1]) corner_model = pipTiming.internalDelay populate_corner_model(corner_model, *model[2]) corner_model = pipTiming.outputResistance populate_corner_model(corner_model, *model[3]) corner_model = pipTiming.outputCapacitance populate_corner_model(corner_model, *model[4]) for pip, timing in pip_models.items(): pip.timing = timing_dict[timing] with open(args.patched_device, "wb") as fp: write_capnp_file(dev, fp)