Skip to content

Commit

Permalink
Enables large devices for placement (#658)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lavin <[email protected]>
  • Loading branch information
clavin-xlnx authored Apr 28, 2023
1 parent 78490c3 commit c2e2464
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 65 deletions.
27 changes: 15 additions & 12 deletions src/com/xilinx/rapidwright/interchange/DeviceResourcesExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,38 @@

package com.xilinx.rapidwright.interchange;

import java.io.File;
import java.io.IOException;

import com.xilinx.rapidwright.device.Device;
import com.xilinx.rapidwright.tests.CodePerfTracker;

public class DeviceResourcesExample {

public static final String SKIP_ROUTE_RESOURCES_OPTION = "--skip_route_resources";

public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("USAGE: <device name>");
if (args.length != 1 && args.length != 2) {
System.out.println("USAGE: <device name> [" + SKIP_ROUTE_RESOURCES_OPTION + "]");
System.out.println(" Example dump of device information for interchange format.");
return;
}

boolean skipRouteResources = false;
if (args.length == 2 && args[1].equals(SKIP_ROUTE_RESOURCES_OPTION)) {
skipRouteResources = true;
}

CodePerfTracker t = new CodePerfTracker("Device Resources Dump: " + args[0]);
t.useGCToTrackMemory(true);

// Create device resource file if it doesn't exist
String capnProtoFileName = args[0] + ".device";
//if (!new File(capnProtoFileName).exists()) {
//MessageGenerator.waitOnAnyKey();
t.start("Load Device");
Device device = Device.getDevice(args[0]);
t.stop();
// Write Netlist to Cap'n Proto Serialization file
DeviceResourcesWriter.writeDeviceResourcesFile(args[0], device, t, capnProtoFileName);
Device.releaseDeviceReferences();
//}
t.start("Load Device");
Device device = Device.getDevice(args[0]);
t.stop();
// Write Netlist to Cap'n Proto Serialization file
DeviceResourcesWriter.writeDeviceResourcesFile(args[0], device, t, capnProtoFileName, skipRouteResources);
Device.releaseDeviceReferences();

t.start("Verify file");
// Verify device resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static boolean verifyDeviceResources(String devResFileName, String device
design.setPartName(deviceName);

DeviceResources.Device.Reader dReader = null;
ReaderOptions readerOptions = new ReaderOptions(1024L*1024L*1024L*16L, 64);
ReaderOptions readerOptions = new ReaderOptions(1024L * 1024L * 1024L * 64L, 64);
MessageReader readMsg = null;
readMsg = Interchange.readInterchangeFile(devResFileName, readerOptions);

Expand Down
74 changes: 41 additions & 33 deletions src/com/xilinx/rapidwright/interchange/DeviceResourcesWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,43 @@
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.TreeSet;

import org.capnproto.MessageBuilder;
import org.capnproto.PrimitiveList;
import org.capnproto.PrimitiveList.Int;
import org.capnproto.StructList;
import org.capnproto.Text;
import org.capnproto.TextList;
import org.capnproto.PrimitiveList.Int;
import org.capnproto.Void;

import com.xilinx.rapidwright.design.Design;
import com.xilinx.rapidwright.design.DesignTools;
import com.xilinx.rapidwright.design.SiteInst;
import com.xilinx.rapidwright.design.Unisim;
import com.xilinx.rapidwright.design.VivadoPropType;
import com.xilinx.rapidwright.design.VivadoProp;
import com.xilinx.rapidwright.device.Series;
import com.xilinx.rapidwright.design.VivadoPropType;
import com.xilinx.rapidwright.device.BEL;
import com.xilinx.rapidwright.device.BELClass;
import com.xilinx.rapidwright.device.BELPin;
import com.xilinx.rapidwright.device.Device;
import com.xilinx.rapidwright.device.IntentCode;
import com.xilinx.rapidwright.device.Node;
import com.xilinx.rapidwright.device.Package;
import com.xilinx.rapidwright.device.Grade;
import com.xilinx.rapidwright.device.IOStandard;
import com.xilinx.rapidwright.device.PackagePin;
import com.xilinx.rapidwright.device.IntentCode;
import com.xilinx.rapidwright.device.Node;
import com.xilinx.rapidwright.device.PIP;
import com.xilinx.rapidwright.device.PIPType;
import com.xilinx.rapidwright.device.Package;
import com.xilinx.rapidwright.device.PackagePin;
import com.xilinx.rapidwright.device.PseudoPIPHelper;
import com.xilinx.rapidwright.device.Series;
import com.xilinx.rapidwright.device.Site;
import com.xilinx.rapidwright.device.SitePIP;
import com.xilinx.rapidwright.device.SiteTypeEnum;
Expand All @@ -78,24 +78,24 @@
import com.xilinx.rapidwright.edif.EDIFLibrary;
import com.xilinx.rapidwright.edif.EDIFNetlist;
import com.xilinx.rapidwright.edif.EDIFTools;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.BEL.Builder;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.BELCategory;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.BELInverter;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.CellInversion;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.CellParameterDefinition;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.CellPinInversion;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.CellPinInversionParameter;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterDefinition;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterDefinitions;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterFormat;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterMapEntry;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterMapRule;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.PrimToMacroExpansion;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.PseudoCell;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.SitePin;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.SiteType;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.SiteWire;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.TileType;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.BEL.Builder;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterDefinition;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.CellParameterDefinition;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterDefinitions;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterFormat;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterMapEntry;
import com.xilinx.rapidwright.interchange.DeviceResources.Device.ParameterMapRule;
import com.xilinx.rapidwright.interchange.LogicalNetlist.Netlist;
import com.xilinx.rapidwright.interchange.LogicalNetlist.Netlist.Direction;
import com.xilinx.rapidwright.interchange.LogicalNetlist.Netlist.PropertyMap;
Expand Down Expand Up @@ -267,7 +267,12 @@ private static boolean containsUnusedMacros(EDIFCell cell, Set<EDIFCell> unusedM
}

public static void writeDeviceResourcesFile(String part, Device device, CodePerfTracker t,
String fileName) throws IOException {
String fileName) throws IOException {
writeDeviceResourcesFile(part, device, t, fileName, false);
}

public static void writeDeviceResourcesFile(String part, Device device, CodePerfTracker t,
String fileName, boolean skipRouteResources) throws IOException {
Design design = new Design();
design.setPartName(part);
Series series = device.getSeries();
Expand All @@ -293,7 +298,7 @@ public static void writeDeviceResourcesFile(String part, Device device, CodePerf
writeAllTilesToBuilder(device, devBuilder, tileTypeIndicies);

t.stop().start("Wires&Nodes");
writeAllWiresAndNodesToBuilder(device, devBuilder);
writeAllWiresAndNodesToBuilder(device, devBuilder, skipRouteResources);

t.stop().start("Prims&Macros");
// Create an EDIFNetlist populated with just primitive and macro libraries
Expand Down Expand Up @@ -805,20 +810,23 @@ private static long makeKey(Tile tile, int wire) {
return key;
}

public static void writeAllWiresAndNodesToBuilder(Device device, DeviceResources.Device.Builder devBuilder) {
public static void writeAllWiresAndNodesToBuilder(Device device, DeviceResources.Device.Builder devBuilder,
boolean skipRouteResources) {
LongEnumerator allWires = new LongEnumerator();
ArrayList<Long> allNodes = new ArrayList();

for (Tile tile : device.getAllTiles()) {
for (int i=0; i < tile.getWireCount(); i++) {
Wire wire = new Wire(tile,i);
allWires.addObject(makeKey(wire.getTile(), wire.getWireIndex()));

Node node = wire.getNode();
if (node == null)
continue;
if (node.getTile() == tile && node.getWire() == i)
allNodes.add(makeKey(node.getTile(), node.getWire()));
ArrayList<Long> allNodes = new ArrayList<>();

if (!skipRouteResources) {
for (Tile tile : device.getAllTiles()) {
for (int i = 0; i < tile.getWireCount(); i++) {
Wire wire = new Wire(tile, i);
allWires.addObject(makeKey(wire.getTile(), wire.getWireIndex()));

Node node = wire.getNode();
if (node == null)
continue;
if (node.getTile() == tile && node.getWire() == i)
allNodes.add(makeKey(node.getTile(), node.getWire()));
}
}
}

Expand Down
46 changes: 27 additions & 19 deletions src/com/xilinx/rapidwright/interchange/EnumerateCellBelMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,34 +741,42 @@ public static void populateCellBelPin(Enumerator<String> allStrings, Map<SiteTyp
}

for (List<String> parameters : getParametersFor(series, cell.getName())) {
HashSet<Map.Entry<String, String>> pinMapping = null;

for (Site site : siteMap.get(siteType)) {
SiteInst siteInst = design.createSiteInst("test_site", siteType, site);
if (pinMapping == null) {
SiteInst siteInst = design.createSiteInst("test_site", siteType, site);

String[] parameterArray = parameters.toArray(new String[parameters.size()]);
physCell = design.createAndPlaceCell("test", Unisim.valueOf(cell.getName()), site.getName() + "/" + bel, parameterArray);
String[] parameterArray = parameters.toArray(new String[parameters.size()]);
physCell = design.createAndPlaceCell("test", Unisim.valueOf(cell.getName()),
site.getName() + "/" + bel, parameterArray);

// Build complete P2L map.
Map<String, String> pinMap = new HashMap<String, String>();
// Build complete P2L map.
Map<String, String> pinMap = new HashMap<String, String>();

for (Map.Entry<String, Set<String>> pinPair : physCell.getPinMappingsL2P().entrySet()) {
for (String physPin : pinPair.getValue()) {
pinMap.put(physPin, pinPair.getKey());
for (Map.Entry<String, Set<String>> pinPair : physCell.getPinMappingsL2P().entrySet()) {
for (String physPin : pinPair.getValue()) {
pinMap.put(physPin, pinPair.getKey());
}
}
}

pinMap.putAll(physCell.getPinMappingsP2L());
pinMap.putAll(physCell.getPinMappingsP2L());

HashSet<Map.Entry<String, String>> pinMapping = new HashSet<Map.Entry<String, String>>();
for (Map.Entry<String, String> pinPair : pinMap.entrySet()) {
pinMapping.add(new AbstractMap.SimpleEntry<String, String>(pinPair.getValue(), pinPair.getKey()));
}
pinMapping = new HashSet<Map.Entry<String, String>>();
for (Map.Entry<String, String> pinPair : pinMap.entrySet()) {
pinMapping.add(
new AbstractMap.SimpleEntry<String, String>(pinPair.getValue(), pinPair.getKey()));
}

data.addInstance(siteType, site, bel, pinMapping, parameters);
data.addInstance(siteType, site, bel, pinMapping, parameters);

design.removeCell(physCell);
design.removeSiteInst(siteInst);
topLevelCell.removeCellInst("test");
design.getTopEDIFCell().removeCellInst("test");
design.removeCell(physCell);
design.removeSiteInst(siteInst);
topLevelCell.removeCellInst("test");
design.getTopEDIFCell().removeCellInst("test");
} else {
data.addInstance(siteType, site, bel, pinMapping, parameters);
}
}
}
}
Expand Down

0 comments on commit c2e2464

Please sign in to comment.