-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rapidwright.util.VivadoTools #684
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1b2fcac
utility function to spawn vivado and run a tcl script
zakn-amd a4c4fe6
test for RunVivado utility
zakn-amd 97f9fb4
rename RunVivado -> VivadoTools
zakn-amd 0a6cfbb
runVivadoTask -> runTcl, and use runCommand instead of job
zakn-amd 23c2bd5
rename runVivadoTask -> runTcl
zakn-amd df34421
fix kludge-y dcp access in testOpenDcpReadLog
zakn-amd c5e778d
add reportRouteStatus()
zakn-amd baca3e7
clean up ReportRouteStatusResult to avoid lots of getters
zakn-amd bef6a85
fix comment/whitespace formatting
zakn-amd de5a93a
clean up work dir removal code
zakn-amd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright (c) 2023, Advanced Micro Devices, Inc. | ||
* All rights reserved. | ||
* | ||
* Author: Zak Nafziger, 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.util; | ||
|
||
import java.io.File; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.xilinx.rapidwright.design.Design; | ||
|
||
/** | ||
* Utility methods to provide access to vivado and parse logs | ||
* | ||
*/ | ||
public class VivadoTools { | ||
|
||
public static class ReportRouteStatusResult { | ||
|
||
public final int logicalNets; | ||
public final int netsNotNeedingRouting; | ||
public final int internallyRoutedNets; | ||
public final int netsWithNoLoads; | ||
public final int implicitlyRoutedPorts; | ||
public final int routableNets; | ||
public final int unroutedNets; | ||
public final int fullyRoutedNets; | ||
public final int netsWithRoutingErrors; | ||
|
||
private static int parseLog(List<String> log, String key) { | ||
return Integer.parseInt( | ||
VivadoTools.searchVivadoLog(log, key).get(0).replaceAll("[^\\d]", "")); | ||
} | ||
|
||
/** | ||
* builds a Tcl script to open the Design d in vivado and run the command | ||
* `report_route_status` | ||
* | ||
* @param d the design to be analyzed | ||
*/ | ||
ReportRouteStatusResult(Design d) { | ||
final Path workdir = FileSystems.getDefault() | ||
.getPath("vivadoToolsWorkdir" + FileTools.getUniqueProcessAndHostID()); | ||
File workdirHandle = new File(workdir.toString()); | ||
workdirHandle.mkdirs(); | ||
final Path dcp = workdir.resolve("checkpoint.dcp"); | ||
final Path tclScript = workdir.resolve("tclScript.tcl"); | ||
|
||
d.writeCheckpoint(dcp); | ||
List<String> lines = new ArrayList<>(); | ||
lines.add("open_checkpoint " + dcp); | ||
lines.add("report_route_status"); | ||
lines.add("exit"); | ||
FileTools.writeLinesToTextFile(lines, tclScript.toString()); | ||
List<String> log = new ArrayList<>(); | ||
log = VivadoTools.runTcl(workdir.resolve("outputLog.log"), tclScript, true); | ||
|
||
logicalNets = parseLog(log, "# of logical nets"); | ||
netsNotNeedingRouting = parseLog(log, "# of nets not needing routing"); | ||
internallyRoutedNets = parseLog(log, "# of internally routed nets"); | ||
netsWithNoLoads = parseLog(log, "# of nets with no loads"); | ||
implicitlyRoutedPorts = parseLog(log, "# of implicitly routed ports"); | ||
routableNets = parseLog(log, "# of routable nets"); | ||
unroutedNets = parseLog(log, "# of unrouted nets"); | ||
fullyRoutedNets = parseLog(log, "# of fully routed nets"); | ||
netsWithRoutingErrors = parseLog(log, "# of nets with routing errors"); | ||
|
||
FileTools.deleteFolder(workdirHandle.toString()); | ||
} | ||
} | ||
|
||
/** | ||
* method to search a vivado log for a specific key phrase | ||
* | ||
* @param log Vivado log as list of strings | ||
* @param key Key phrase to search for | ||
* @return List of lines that contain the key phrase | ||
*/ | ||
public static List<String> searchVivadoLog(List<String> log, String key) { | ||
List<String> results = new ArrayList<>(); | ||
for (String l : log) { | ||
if (l.contains(key)) { | ||
results.add(l); | ||
} | ||
} | ||
return results; | ||
} | ||
|
||
/** | ||
* method to run a single Tcl command in vivado | ||
* | ||
* @param outputLog Path to the log file that vivado will generate | ||
* @param tclCmd Tcl command to run | ||
* @param verbose If true vivado command line and std.out/err will be printed | ||
* to std.out | ||
* @return the contents of the log file as a list of strings | ||
*/ | ||
public static List<String> runTcl(Path outputLog, String tclCmd, boolean verbose) { | ||
Path tclScript = outputLog.getParent().resolve("tclScript.tcl"); | ||
List<String> lines = new ArrayList<>(); | ||
lines.add(tclCmd); | ||
FileTools.writeLinesToTextFile(lines, tclScript.toString()); | ||
return runTcl(outputLog, tclScript, verbose); | ||
} | ||
|
||
/** | ||
* method to run a Tcl script in vivado | ||
* | ||
* @param outputLog Path to the log file that vivado will generate | ||
* @param tclScript Path to the Tcl script that will be run | ||
* @param verbose If true vivado command line and std.out/err will be printed | ||
* to std.out | ||
* @return the contents of the log file as a list of strings | ||
*/ | ||
public static List<String> runTcl(Path outputLog, Path tclScript, boolean verbose) { | ||
final String vivadoCmd = "vivado -log " + outputLog.toString() + " -mode batch -source " | ||
+ tclScript.toString(); | ||
FileTools.runCommand(vivadoCmd, verbose); | ||
List<String> log = new ArrayList<>(); | ||
log = FileTools.getLinesFromTextFile(outputLog.toString()); | ||
return log; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2023, Advanced Micro Devices, Inc. | ||
* All rights reserved. | ||
* | ||
* Author: Zak Nafziger, 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.util; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import com.xilinx.rapidwright.design.Design; | ||
import com.xilinx.rapidwright.support.RapidWrightDCP; | ||
|
||
public class TestVivadoTools { | ||
@Test | ||
public void testRunTclCmd(@TempDir Path tempDir) { | ||
Assumptions.assumeTrue(FileTools.isVivadoOnPath()); | ||
|
||
List<String> log = new ArrayList<>(); | ||
log = VivadoTools.runTcl(tempDir.resolve("outputLog.log"), "exit", true); | ||
|
||
List<String> results = new ArrayList<>(); | ||
results = VivadoTools.searchVivadoLog(log, "INFO"); | ||
Assertions.assertTrue(results.get(0).contains("Exiting Vivado")); | ||
} | ||
|
||
@Test | ||
public void testReportRouteStatus() throws IOException { | ||
Assumptions.assumeTrue(FileTools.isVivadoOnPath()); | ||
String dcp = RapidWrightDCP.getPath("picoblaze_partial.dcp").toString(); | ||
Design d = Design.readCheckpoint(dcp); | ||
VivadoTools.ReportRouteStatusResult r = new VivadoTools.ReportRouteStatusResult(d); | ||
|
||
Assertions.assertEquals(12144, r.unroutedNets); | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea to have multiple classes going forward dedicated to each task? If so, I would suggest that we create a dedicated package for Vivado instead of putting them all into the same class. We have tried to avoid inner classes because they tend to complicate compilation and a few other areas.
Alternatively, the class could be converted into a static method and just return a
Map<String,Integer>
that contains the results. This would be simpler and would probably be the preferred method in my opinion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eddieh-xlnx has been directing some of the architecture decisions here, but I think the idea is to add classes for future vivado tasks, so maybe a separate package is warranted.
Returning a
Map<String,Integer>
is perhaps little more awkward, since the user then needs to know exactly what vivado output log key phrase they want (i.e."# of unrouted nets"
). I was mostly following the proposed system from here: #684 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sure. Let's keep it the way it is for now and we can revisit it in the future if the file seems becomes unwieldly.
Sure, I can see how that is a bit cumbersome and error prone. For simplicity, let's keep it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've modelled this package under the "Tools" packages like
DesignTools
. It's also feels a little unweildy to doVivadoTools.<tool>.<method>()
. I do agree that the inner class should be moved outside (though I don't necessarily agree they are a bad thing entirely -- they can be used for class-level (as opposed to package-level) encapsulation and do appear in the standard Java library too.The problem with returning a
Map
is that I can't attach a method to it -- like aisFullyRouted()
query.