use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class SymmetryEncoder method encodeSymmetryClass.
public BooleanFormula encodeSymmetryClass(EquivalenceClass<Thread> symmClass, SolverContext ctx) {
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
if (rel == null || symmClass.getEquivalence() != symm) {
return enc;
}
Thread rep = symmClass.getRepresentative();
List<Thread> symmThreads = new ArrayList<>(symmClass);
symmThreads.sort(Comparator.comparingInt(Thread::getId));
// ===== Construct row =====
// IMPORTANT: Each thread writes to its own special location for the purpose of starting/terminating threads
// These need to get skipped.
Thread t1 = symmThreads.get(0);
List<Tuple> r1Tuples = new ArrayList<>();
for (Tuple t : rel.getMaxTupleSet()) {
Event a = t.getFirst();
Event b = t.getSecond();
if (!a.is(Tag.C11.PTHREAD) && !b.is(Tag.C11.PTHREAD) && a.getThread() == t1) {
r1Tuples.add(t);
}
}
sort(r1Tuples);
// Construct symmetric rows
for (int i = 1; i < symmThreads.size(); i++) {
Thread t2 = symmThreads.get(i);
Function<Event, Event> p = symm.createTransposition(t1, t2);
List<Tuple> r2Tuples = r1Tuples.stream().map(t -> t.permute(p)).collect(Collectors.toList());
List<BooleanFormula> r1 = Lists.transform(r1Tuples, t -> rel.getSMTVar(t, ctx));
List<BooleanFormula> r2 = Lists.transform(r2Tuples, t -> rel.getSMTVar(t, ctx));
final String id = "_" + rep.getId() + "_" + i;
// r1 >= r2
enc = bmgr.and(enc, encodeLexLeader(id, r2, r1, ctx));
t1 = t2;
r1Tuples = r2Tuples;
}
return enc;
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class CoSymmetryBreaking method computeMustEdges.
/*
Computes co must-edges that are implied by this symmetry breaking
May return an empty list.
*/
public List<Tuple> computeMustEdges() {
List<Tuple> mustEdges = new ArrayList<>();
for (Info info : infoMap.values()) {
if (!info.hasMustEdges) {
continue;
}
Store w = info.writes.get(0);
final int numThreads = info.threads.size();
for (int i = 0; i < numThreads; i++) {
for (int j = i + 1; j < numThreads; j++) {
mustEdges.add(new Tuple(symm.map(w, info.threads.get(i)), symm.map(w, info.threads.get(j))));
}
}
}
return mustEdges;
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class CoSymmetryBreaking method encode.
public BooleanFormula encode(EquivalenceClass<Thread> symmClass, SolverContext ctx) {
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
if (symmClass.getEquivalence() != symm) {
return enc;
}
Info info = infoMap.get(symmClass);
if (info == null) {
logger.warn("Cannot encode co-symmetry because no information has been computed. " + "Make sure that <initialize> gets called before encoding.");
return enc;
}
List<Thread> symmThreads = info.threads;
// ============= Construct rows =============
Thread t1 = symmThreads.get(0);
List<Thread> otherThreads = symmThreads.subList(1, symmThreads.size());
List<Tuple> r1Tuples = new ArrayList<>();
for (Store w : info.writes) {
for (Thread t2 : otherThreads) {
r1Tuples.add(new Tuple(w, symm.map(w, t2)));
}
}
// Starting row
List<BooleanFormula> r1 = new ArrayList<>(r1Tuples.size() + 1);
if (info.hasMustEdges) {
r1.add(info.writes.get(0).exec());
}
r1.addAll(Lists.transform(r1Tuples, t -> co.getSMTVar(t, ctx)));
// Construct symmetric rows
Thread rep = symmClass.getRepresentative();
for (int i = 1; i < symmThreads.size(); i++) {
Thread t2 = symmThreads.get(i);
Function<Event, Event> p = symm.createTransposition(t1, t2);
List<Tuple> r2Tuples = r1Tuples.stream().map(t -> t.permute(p)).collect(Collectors.toList());
List<BooleanFormula> r2 = new ArrayList<>(r2Tuples.size() + 1);
if (info.hasMustEdges) {
r2.add(symm.map(info.writes.get(0), t2).exec());
}
r2.addAll(Lists.transform(r2Tuples, t -> co.getSMTVar(t, ctx)));
final String id = "_" + rep.getId() + "_" + i;
// NOTE: We want to have r1 >= r2 but lexLeader encodes r1 <= r2, so we swap r1 and r2.
enc = bmgr.and(enc, SymmetryEncoder.encodeLexLeader(id, r2, r1, ctx));
t1 = t2;
r1Tuples = r2Tuples;
r1 = r2;
}
return enc;
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class Acyclic method getEncodeTupleSet.
@Override
public TupleSet getEncodeTupleSet() {
logger.info("Computing encodeTupleSet for " + this);
// ====== Construct [Event -> Successor] mapping ======
Map<Event, Collection<Event>> succMap = new HashMap<>();
TupleSet relMaxTuple = rel.getMaxTupleSet();
for (Tuple t : relMaxTuple) {
succMap.computeIfAbsent(t.getFirst(), key -> new ArrayList<>()).add(t.getSecond());
}
// ====== Compute SCCs ======
DependencyGraph<Event> depGraph = DependencyGraph.from(succMap.keySet(), succMap);
TupleSet result = new TupleSet();
for (Set<DependencyGraph<Event>.Node> scc : depGraph.getSCCs()) {
for (DependencyGraph<Event>.Node node1 : scc) {
for (DependencyGraph<Event>.Node node2 : scc) {
Tuple t = new Tuple(node1.getContent(), node2.getContent());
if (relMaxTuple.contains(t)) {
result.add(t);
}
}
}
}
logger.info("encodeTupleSet size " + result.size());
if (GlobalSettings.REDUCE_ACYCLICITY_ENCODE_SETS) {
reduceWithMinSets(result);
logger.info("reduced encodeTupleSet size " + result.size());
}
return result;
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class Acyclic method consistent.
@Override
public BooleanFormula consistent(SolverContext ctx) {
FormulaManager fmgr = ctx.getFormulaManager();
BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
IntegerFormulaManager imgr = fmgr.getIntegerFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
for (Tuple tuple : rel.getEncodeTupleSet()) {
Event e1 = tuple.getFirst();
Event e2 = tuple.getSecond();
enc = bmgr.and(enc, bmgr.implication(rel.getSMTVar(tuple, ctx), imgr.lessThan(Utils.intVar(rel.getName(), e1, ctx), Utils.intVar(rel.getName(), e2, ctx))));
}
return enc;
}
Aggregations