Skip to content

Commit

Permalink
Test if costs were assigned to DPIs
Browse files Browse the repository at this point in the history
Signed-off-by: Bartłomiej Chmiel <bchmiel@antmicro.com>
  • Loading branch information
b-chmiel committed Jan 20, 2025
1 parent 751013f commit e39c278
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/V3Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ class TaskVisitor final : public VNVisitor {
// STATE - across all visitors
DpiCFuncs m_dpiNames; // Map of all created DPI functions
VDouble0 m_statInlines; // Statistic tracking
VDouble0 m_statHierDpisWithCosts; // Statistic tracking

// METHODS

Expand Down Expand Up @@ -981,6 +982,11 @@ class TaskVisitor final : public VNVisitor {
funcp->isMethod(false);
funcp->protect(false);
funcp->dpiPure(nodep->dpiPure());

const int cost = static_cast<int>(V3Config::getProfileData(funcp->name()));
m_statHierDpisWithCosts += (cost != 0);
funcp->cost(cost);

// Add DPI Import to top, since it's a global function
m_topScopep->scopep()->addBlocksp(funcp);
makePortList(nodep, funcp);
Expand Down Expand Up @@ -1260,10 +1266,7 @@ class TaskVisitor final : public VNVisitor {
if (nodep->name() == "new") cfuncp->isConstructor(true);
if (cfuncp->dpiExportImpl()) cfuncp->cname(nodep->cname());

if (cfuncp->dpiImportWrapper()) {
cfuncp->cname(nodep->cname());
cfuncp->cost(V3Config::getProfileData(cfuncp->cname()));
}
if (cfuncp->dpiImportWrapper()) cfuncp->cname(nodep->cname());

if (!nodep->dpiImport() && !nodep->taskPublic()) {
// Need symbol table
Expand Down Expand Up @@ -1619,7 +1622,11 @@ class TaskVisitor final : public VNVisitor {
: m_statep{statep} {
iterate(nodep);
}
~TaskVisitor() { V3Stats::addStat("Optimizations, Functions inlined", m_statInlines); }
~TaskVisitor() {
V3Stats::addStat("Optimizations, Functions inlined", m_statInlines);
V3Stats::addStat("Optimizations, Hierarchical DPI wrappers with costs",
m_statHierDpisWithCosts);
}
};

//######################################################################
Expand Down
8 changes: 7 additions & 1 deletion test_regress/t/t_hier_block_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
THREADS = int(os.environ["SIM_THREADS"]) if "SIM_THREADS" in os.environ else 2

test.compile(benchmarksim=1,
v_flags2=["+define+SIM_CYCLES=" + str(test.cycles), "--prof-exec", "--hierarchical"],
v_flags2=[
"+define+SIM_CYCLES=" + str(test.cycles), "--prof-exec", "--hierarchical",
"--stats"
],
threads=(THREADS if test.vltmt else 1))

test.file_grep(test.obj_dir + "/V" + test.name + "__hier.dir/V" + test.name + "__stats.txt",
r'Optimizations, Hierarchical DPI wrappers with costs\s+(\d+)', 3)

test.execute(all_run_flags=[
"+verilator+prof+exec+start+2",
" +verilator+prof+exec+window+2",
Expand Down

0 comments on commit e39c278

Please sign in to comment.