From cdc98c92566eac0f4694e537d0aca90bb243bd4f Mon Sep 17 00:00:00 2001 From: Natalia Gavrilenko Date: Tue, 1 Jul 2025 12:00:35 +0200 Subject: [PATCH] Warning if cbar synchronizes across workgroups Print a warning if control barriers with the same instance id are used across different workgroups. Update existing tests with such barriers to use acquire-release memory accesses instead. Signed-off-by: Natalia Gavrilenko --- alloy/litmus.cpp | 14 +++++++++++--- alloy/tests/scopeaccum.test | 4 ++-- alloy/tests/test6.test | 8 ++++---- alloy/tests/test7.test | 8 ++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/alloy/litmus.cpp b/alloy/litmus.cpp index 02ae5dc..f4637fc 100644 --- a/alloy/litmus.cpp +++ b/alloy/litmus.cpp @@ -116,11 +116,12 @@ using namespace std; // instances. class LoadStore { public: - LoadStore() : var(), value(-1), value2(-1), cbarInstance(-1) {} + LoadStore() : var(), value(-1), value2(-1), cbarInstance(-1), workgroup(-1) {} string var; int value; int value2; int cbarInstance; + int workgroup; }; // Track what instruction fields are set for each instruction. @@ -141,14 +142,14 @@ class InstructionState { int getReadValue(int instnum) const { if (!isRead(instnum)) { - printf("WARNING: calling getReadValue on a non-read"); + printf("WARNING: calling getReadValue on a non-read\n"); } return loadStore[instnum].value; } int getWriteValue(int instnum) const { if (!isWrite(instnum)) { - printf("WARNING: calling getWriteValue on a non-write"); + printf("WARNING: calling getWriteValue on a non-write\n"); } return (isRead(instnum) && isWrite(instnum)) ? loadStore[instnum].value2 : loadStore[instnum].value; } @@ -340,6 +341,7 @@ int main(int argc, char *argv[]) stringstream o; + int workgroupnum = 0; int threadnum = 0; int numEvents = 0; int bitwidth = 0; @@ -390,6 +392,7 @@ int main(int argc, char *argv[]) o << " no ("; sequenceInSuffix(o, 0, instnum+1, true, ") & X.swg"); firstInstInWG = instnum+1; } + workgroupnum++; continue; } @@ -452,6 +455,7 @@ int main(int argc, char *argv[]) line = line.substr(firstspace); line = line.substr(line.find_first_not_of(" ")); instState.loadStore[instnum].cbarInstance = atoi(line.c_str()); + instState.loadStore[instnum].workgroup = workgroupnum; } else { line = line.substr(firstspace); line = line.substr(line.find_first_not_of(" =")); @@ -602,12 +606,16 @@ int main(int argc, char *argv[]) set cbarInsts; for (int j = 0; j <= instnum; ++j) { int v = instState.loadStore[j].cbarInstance; + int w = instState.loadStore[j].workgroup; if (v != -1 && cbarInsts.find(v) == cbarInsts.end()) { cbarInsts.insert(v); o << " "; bool first = true; for (int i = j+1; i <= instnum; ++i) { if (instState.loadStore[i].cbarInstance == v) { + if (instState.loadStore[i].workgroup != w) { + printf("WARNING: matching control barriers in different workgroups\n"); + } if (!first) { o << "+"; } diff --git a/alloy/tests/scopeaccum.test b/alloy/tests/scopeaccum.test index 171c060..f09f63e 100644 --- a/alloy/tests/scopeaccum.test +++ b/alloy/tests/scopeaccum.test @@ -10,11 +10,11 @@ cbar.scopewg.semsc0.rel.acq 1 NEWSG NEWTHREAD cbar.scopewg.semsc0.rel.acq 1 -cbar.scopedev.semsc0.rel.acq 2 +st.atom.rel.scopedev.sc0.semsc0 y = 1 NEWWG NEWSG NEWTHREAD -cbar.scopedev.semsc0.rel.acq 2 +ld.atom.acq.scopedev.sc0.semsc0 y = 1 ld.vis.scopedev.sc0 x SATISFIABLE consistent[X] && #dr=0 NOSOLUTION consistent[X] && #dr>0 diff --git a/alloy/tests/test6.test b/alloy/tests/test6.test index c68b4f7..20f9a99 100644 --- a/alloy/tests/test6.test +++ b/alloy/tests/test6.test @@ -11,15 +11,15 @@ cbar.acq.rel.scopewg.semsc0 0 NEWSG NEWTHREAD cbar.acq.rel.scopewg.semsc0 0 -cbar.acq.rel.scopedev.semsc0 1 +st.atom.rel.scopedev.sc0.semsc0 y = 1 NEWWG NEWSG NEWTHREAD -cbar.acq.rel.scopedev.semsc0 1 -cbar.acq.rel.scopewg.semsc0 2 +ld.atom.acq.scopedev.sc0.semsc0 y = 1 +cbar.acq.rel.scopewg.semsc0 1 NEWSG NEWTHREAD -cbar.acq.rel.scopewg.semsc0 2 +cbar.acq.rel.scopewg.semsc0 1 ld.vis.scopedev.sc0 a SATISFIABLE consistent[X] && #dr=0 NOSOLUTION consistent[X] && #dr>0 diff --git a/alloy/tests/test7.test b/alloy/tests/test7.test index f50ab81..27c7779 100644 --- a/alloy/tests/test7.test +++ b/alloy/tests/test7.test @@ -11,15 +11,15 @@ cbar.acq.rel.scopewg.semsc0 0 NEWSG NEWTHREAD cbar.acq.rel.scopewg.semsc0 0 -cbar.acq.rel.scopedev.semsc1 1 +st.atom.rel.scopedev.sc0.semsc1 y = 1 NEWWG NEWSG NEWTHREAD -cbar.acq.rel.scopedev.semsc1 1 -cbar.acq.rel.scopewg.semsc0 2 +ld.atom.acq.scopedev.sc0.semsc1 y = 1 +cbar.acq.rel.scopewg.semsc0 1 NEWSG NEWTHREAD -cbar.acq.rel.scopewg.semsc0 2 +cbar.acq.rel.scopewg.semsc0 1 ld.vis.scopedev.sc0 a NOSOLUTION consistent[X] && #dr=0 SATISFIABLE consistent[X] && #dr>0