Skip to content

Commit

Permalink
[Interchange] Refactor & speedup reader/writers (#677)
Browse files Browse the repository at this point in the history
* Refactor Interchange Log/Phys Reader/Writer

Signed-off-by: Eddie Hung <[email protected]>

* More tidying up

Signed-off-by: Eddie Hung <[email protected]>

* Fix broken test

Signed-off-by: Eddie Hung <[email protected]>

* More refactoring/improvements

Signed-off-by: Eddie Hung <[email protected]>

* Fix collapse macro collision, plus optimize

Signed-off-by: Eddie Hung <[email protected]>

* Test for collapseMacroUnisims() does not collide

Signed-off-by: Eddie Hung <[email protected]>

* EDIFNetlist.getHDIPrimitive() to deep copy too

Signed-off-by: Eddie Hung <[email protected]>

* Split Enumerator into {Identity,String}Enumerator

Signed-off-by: Eddie Hung <[email protected]>

* Get rid of EDIFEnumerable

Signed-off-by: Eddie Hung <[email protected]>

Conflicts:
	src/com/xilinx/rapidwright/edif/EDIFCell.java
	src/com/xilinx/rapidwright/edif/EDIFCellInst.java
	src/com/xilinx/rapidwright/edif/EDIFPort.java

* Interchange.benchmark() to return Path

Signed-off-by: Eddie Hung <[email protected]>

* Bump copyright year

Signed-off-by: Eddie Hung <[email protected]>

* Fix EDIFNetlist.getHDIPrimitive()

Signed-off-by: Eddie Hung <[email protected]>

* Fix EDIFNetlist.getHDIPrimitive()

Signed-off-by: Eddie Hung <[email protected]>

* Another EDIFNetlist.getHDIPrimitive() fix

Signed-off-by: Eddie Hung <[email protected]>

* Update src/com/xilinx/rapidwright/interchange/IdentityEnumerator.java

Signed-off-by: eddieh-xlnx <[email protected]>

* Address some review comments

Signed-off-by: Eddie Hung <[email protected]>

* Address some more review

Signed-off-by: Eddie Hung <[email protected]>

---------

Signed-off-by: Eddie Hung <[email protected]>
Signed-off-by: eddieh-xlnx <[email protected]>
  • Loading branch information
eddieh-xlnx authored Jun 13, 2023
1 parent 9d25e84 commit 70670e1
Show file tree
Hide file tree
Showing 10 changed files with 1,247 additions and 628 deletions.
6 changes: 5 additions & 1 deletion src/com/xilinx/rapidwright/edif/EDIFNet.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
*
* Copyright (c) 2017-2022, Xilinx, Inc.
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* Copyright (c) 2022-2023, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Author: Chris Lavin, Xilinx Research Labs.
Expand Down Expand Up @@ -224,6 +224,10 @@ public EDIFPortInst createPortInst(EDIFPort port, EDIFCellInst cellInst) {
return new EDIFPortInst(port, this, cellInst);
}

public EDIFPortInst createPortInst(EDIFPort port, EDIFCellInst cellInst, boolean deferSort) {
return new EDIFPortInst(port, this, cellInst, deferSort);
}

public EDIFPortInst createPortInst(EDIFPort port, int index, EDIFCellInst cellInst) {
return new EDIFPortInst(port, this, index, cellInst);
}
Expand Down
19 changes: 18 additions & 1 deletion src/com/xilinx/rapidwright/edif/EDIFPortInst.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public EDIFPortInst(EDIFPortInst portInst) {
public EDIFPortInst(EDIFPort port, EDIFNet parentNet, int index) {
this(port,parentNet,index,null);
}

/**
* Constructor to create a single bit port ref and associate it with its
* net and instance.
Expand All @@ -73,7 +74,23 @@ public EDIFPortInst(EDIFPort port, EDIFNet parentNet, int index) {
* @param cellInst The instance this port ref belongs to
*/
public EDIFPortInst(EDIFPort port, EDIFNet parentNet, EDIFCellInst cellInst) {
this(port, parentNet, -1, cellInst);
this(port, parentNet, -1, cellInst, false);
}

/**
* Constructor to create a single bit port ref and associate it with its
* net and instance.
* @param port The port on the cell this port ref uses
* @param parentNet The net this port ref should belong to
* @param cellInst The instance this port ref belongs to
* @param deferSort The EDIFPortInstList maintains a sorted list of EDIFPortInst
* objects and sorts them upon insertion. Setting this flag to true will skip a sort addition
* but the caller is responsible to conclude a batch of additions with a call to
* {@link EDIFPortInstList#reSortList()}. This is useful when a large number of EDIFPortInsts
* will be added consecutively (such as parsing a netlist).
*/
public EDIFPortInst(EDIFPort port, EDIFNet parentNet, EDIFCellInst cellInst, boolean deferSort) {
this(port, parentNet, -1, cellInst, deferSort);
}

/**
Expand Down
101 changes: 101 additions & 0 deletions src/com/xilinx/rapidwright/interchange/BELPinCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2023, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Author: Eddie Hung, Advanced Micro Devices, Inc.
*
* This file is part of RapidWright.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.xilinx.rapidwright.interchange;

import com.xilinx.rapidwright.design.SiteInst;
import com.xilinx.rapidwright.device.BEL;
import com.xilinx.rapidwright.device.BELPin;
import com.xilinx.rapidwright.device.SiteTypeEnum;

import java.util.List;
import java.util.Map;

/**
* Class for caching BELPin lookups, given a SiteInst object, and string
* indices for the BEL and BELPin names.
*/
public class BELPinCache {
private static class Key {
private final SiteTypeEnum siteTypeEnum;
private final int belStringIdx;
private final int pinStringIdx;

public Key(SiteInst siteInst, int belStringIdx, int pinStringIdx) {
siteTypeEnum = siteInst.getSiteTypeEnum();
this.belStringIdx = belStringIdx;
this.pinStringIdx = pinStringIdx;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + siteTypeEnum.ordinal();
result = prime * result + belStringIdx;
result = prime * result + pinStringIdx;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Key other = (Key) obj;
return belStringIdx == other.belStringIdx &&
pinStringIdx == other.pinStringIdx &&
siteTypeEnum == other.siteTypeEnum;
}
}

private final Map<Key, BELPin> map;

private final List<String> strings;

public BELPinCache(Map<Key, BELPin> map, List<String> strings) {
this.map = map;
this.strings = strings;
}

public BELPin getBELPin(SiteInst siteInst, int belStringIdx, int pinStringIdx) {
Key key = new Key(siteInst, belStringIdx, pinStringIdx);
return map.computeIfAbsent(key, (k) -> {
String belName = strings.get(k.belStringIdx);
BEL bel = siteInst.getBEL(belName);
if (bel == null) {
throw new RuntimeException(String.format("ERROR: Failed to get BEL %s", belName));
}

String belPinName = strings.get(k.pinStringIdx);
BELPin belPin = bel.getPin(belPinName);
if (belPin == null) {
throw new RuntimeException(String.format("ERROR: Failed to get BEL pin %s/%s", belName, belPinName));
}

return belPin;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public static void writeDeviceResourcesFile(String part, Device device, CodePerf
put(series+"_"+EDIFTools.MACRO_PRIMITIVES_LIB, LogNetlistWriter.DEVICE_MACROS_LIB);
}}
);
writer.populateNetlistBuilder(netlist, netlistBuilder);
writer.populateNetlistBuilder(netlist, netlistBuilder, CodePerfTracker.SILENT);

writeCellParameterDefinitions(series, netlist, devBuilder.getParameterDefs());

Expand Down
Loading

0 comments on commit 70670e1

Please sign in to comment.