/** * Merge the list of loopVertices into a single LoopVertex. * @param loopVertices list of LoopVertices to merge. * @return the merged single LoopVertex. */ private LoopVertex mergeLoopVertices(final Set<LoopVertex> loopVertices) { final String newName = String.join("+", loopVertices.stream().map(LoopVertex::getName).collect(Collectors.toList())); final LoopVertex mergedLoopVertex = new LoopVertex(newName); loopVertices.forEach(loopVertex -> { final DAG<IRVertex, IREdge> dagToCopy = loopVertex.getDAG(); dagToCopy.topologicalDo(v -> { mergedLoopVertex.getBuilder().addVertex(v); dagToCopy.getIncomingEdgesOf(v).forEach(mergedLoopVertex.getBuilder()::connectVertices); }); loopVertex.getDagIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagIncomingEdge)); loopVertex.getIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addIterativeIncomingEdge)); loopVertex.getNonIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addNonIterativeIncomingEdge)); loopVertex.getDagOutgoingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagOutgoingEdge)); }); return mergedLoopVertex; } }
public boolean terminationConditionEquals(final LoopVertex that) { if (this.maxNumberOfIterations.equals(that.getMaxNumberOfIterations()) && Util .checkEqualityOfIntPredicates(this.terminationCondition, that.getTerminationCondition(), this.maxNumberOfIterations)) { return true; } return false; }
/** * @return whether or not the loop termination condition has been met. */ public Boolean loopTerminationConditionMet() { return loopTerminationConditionMet(maxNumberOfIterations); } /**
@Override public ObjectNode getPropertiesAsJsonNode() { final ObjectNode node = getIRVertexPropertiesAsJsonNode(); node.put("remainingIteration", maxNumberOfIterations); node.set("DAG", getDAG().asJsonNode()); node.set("dagIncomingEdges", crossingEdgesToJSON(dagIncomingEdges)); node.set("dagOutgoingEdges", crossingEdgesToJSON(dagOutgoingEdges)); final ObjectNode edgeMappings = node.putObject("edgeWithLoopToEdgeWithInternalVertex"); edgeWithLoopToEdgeWithInternalVertex.entrySet() .forEach(entry -> edgeMappings.put(entry.getKey().getId(), entry.getValue().getId())); return node; }
if (rootLoopVertex == null || !loopVertex.getName().contains(rootLoopVertex.getName())) { // initial root loop rootLoopVertex = loopVertex; loopVerticesOfSameLoop.putIfAbsent(rootLoopVertex, rootLoopVertex); equivalentVerticesOfLoops.putIfAbsent(rootLoopVertex, new HashMap<>()); for (IRVertex vertex : rootLoopVertex.getDAG().getTopologicalSort()) { equivalentVerticesOfLoops.get(rootLoopVertex).putIfAbsent(vertex, vertex); finalRootLoopVertex.increaseMaxNumberOfIterations(); finalRootLoopVertex.getDAG().getTopologicalSort().iterator(); final Iterator<IRVertex> verticesOfCurrentLoopVertex = loopVertex.getDAG().getTopologicalSort().iterator(); final HashMap<IRVertex, IRVertex> equivalentVertices = equivalentVerticesOfLoops.get(finalRootLoopVertex); while (verticesOfRootLoopVertex.hasNext() && verticesOfCurrentLoopVertex.hasNext()) { finalRootLoopVertex.getNonIterativeIncomingEdges().clear(); finalRootLoopVertex.getIterativeIncomingEdges().clear(); loopVertex.getDagIncomingEdges().forEach((dstVertex, edges) -> edges.forEach(edge -> { final IRVertex srcVertex = edge.getSrc(); final IRVertex equivalentDstVertex = equivalentVertices.get(dstVertex); equivalentSrcVertex, equivalentDstVertex); edge.copyExecutionPropertiesTo(newIrEdge); finalRootLoopVertex.addIterativeIncomingEdge(newIrEdge); } else { srcVertex, equivalentDstVertex); edge.copyExecutionPropertiesTo(newIrEdge); finalRootLoopVertex.addNonIterativeIncomingEdge(newIrEdge);
final DAG<IRVertex, IREdge> dagToAdd = getDAG(); decreaseMaxNumberOfIterations(); getDagIncomingEdges().forEach((dstVertex, irEdges) -> irEdges.forEach(edge -> { final IREdge newIrEdge = new IREdge(edge.getPropertyValue(CommunicationPatternProperty.class).get(), edge.getSrc(), originalToNewIRVertex.get(dstVertex)); })); if (loopTerminationConditionMet()) { getDagOutgoingEdges().forEach((srcVertex, irEdges) -> irEdges.forEach(edge -> { final IREdge newIrEdge = new IREdge(edge.getPropertyValue(CommunicationPatternProperty.class).get(), originalToNewIRVertex.get(srcVertex), edge.getDst()); this.getDagIncomingEdges().clear(); this.nonIterativeIncomingEdges.forEach((dstVertex, irEdges) -> irEdges.forEach(this::addDagIncomingEdge)); this.iterativeIncomingEdges.forEach((dstVertex, irEdges) -> irEdges.forEach(edge -> { originalToNewIRVertex.get(edge.getSrc()), dstVertex); edge.copyExecutionPropertiesTo(newIrEdge); this.addDagIncomingEdge(newIrEdge); }));
final List<Map.Entry<IRVertex, Set<IREdge>>> candidates = loopVertex.getNonIterativeIncomingEdges().entrySet() .stream().filter(entry -> loopVertex.getDAG().getIncomingEdgesOf(entry.getKey()).size() == 0 // no internal inEdges && loopVertex.getIterativeIncomingEdges().getOrDefault(entry.getKey(), new HashSet<>()).size() == 0) .collect(Collectors.toList()); candidates.forEach(candidate -> { loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addDagIncomingEdge); loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addNonIterativeIncomingEdge); listToModify.addAll(edgesToAdd); loopVertex.getBuilder().removeVertex(candidate.getKey()); loopVertex.getDagIncomingEdges().remove(candidate.getKey()); loopVertex.getNonIterativeIncomingEdges().remove(candidate.getKey()); }); });
/** * Copy Constructor for LoopVertex. * * @param that the source object for copying */ public LoopVertex(final LoopVertex that) { super(that); this.compositeTransformFullName = new String(that.compositeTransformFullName); // Copy all elements to the clone final DAG<IRVertex, IREdge> dagToCopy = that.getDAG(); dagToCopy.topologicalDo(v -> { this.getBuilder().addVertex(v, dagToCopy); dagToCopy.getIncomingEdgesOf(v).forEach(this.getBuilder()::connectVertices); }); that.dagIncomingEdges.forEach(((v, es) -> es.forEach(this::addDagIncomingEdge))); that.iterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addIterativeIncomingEdge)); that.nonIterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addNonIterativeIncomingEdge)); that.dagOutgoingEdges.forEach(((v, es) -> es.forEach(this::addDagOutgoingEdge))); that.edgeWithLoopToEdgeWithInternalVertex.forEach((eLoop, eInternal) -> this.mapEdgeWithLoop(eLoop, eInternal)); this.maxNumberOfIterations = that.maxNumberOfIterations; this.terminationCondition = that.terminationCondition; }
assignedLoopVertex.getBuilder().addVertex(dstVertex, dag); final LoopVertex srcLoopVertex = dag.getAssignedLoopVertexOf(irEdge.getSrc()); if (srcLoopVertex.equals(assignedLoopVertex)) { // connecting within the composite loop DAG. assignedLoopVertex.getBuilder().connectVertices(irEdge); } else { // loop -> loop connection assignedLoopVertex.addDagIncomingEdge(irEdge); final IREdge edgeToLoop = new IREdge(irEdge.getPropertyValue(CommunicationPatternProperty.class).get(), srcLoopVertex, assignedLoopVertex); irEdge.copyExecutionPropertiesTo(edgeToLoop); builder.connectVertices(edgeToLoop); assignedLoopVertex.mapEdgeWithLoop(edgeToLoop, irEdge); assignedLoopVertex.addDagIncomingEdge(irEdge); final IREdge edgeToLoop = new IREdge(irEdge.getPropertyValue(CommunicationPatternProperty.class).get(), irEdge.getSrc(), assignedLoopVertex); irEdge.copyExecutionPropertiesTo(edgeToLoop); builder.connectVertices(edgeToLoop); assignedLoopVertex.mapEdgeWithLoop(edgeToLoop, irEdge);
final IntPredicate terminationCondition = loopVertex.getTerminationCondition(); final Integer numberOfIterations = loopVertex.getMaxNumberOfIterations(); independentLoops.forEach(independentLoop -> { if (loopVertex.terminationConditionEquals(independentLoop)) { loopsToBeFused.add(independentLoop);
if (irVertex instanceof LoopVertex) { LoopVertex loopVertex = (LoopVertex) irVertex; loopVertex.markDuplicateEdges(); while (!loopVertex.loopTerminationConditionMet()) { loopVertex = loopVertex.unRollIteration(builder);
@Override public LoopVertex getClone() { return new LoopVertex(this); }
srcLoopVertex.addDagOutgoingEdge(irEdge); final IREdge edgeFromLoop = new IREdge( irEdge.getPropertyValue(CommunicationPatternProperty.class).get(), srcLoopVertex, operatorVertex); irEdge.copyExecutionPropertiesTo(edgeFromLoop); builder.connectVertices(edgeFromLoop); srcLoopVertex.mapEdgeWithLoop(edgeFromLoop, irEdge); } else { // connecting outside the composite loop: operator -> operator. builder.connectVertices(irEdge);
if (rootLoopVertex == null || !loopVertex.getName().contains(rootLoopVertex.getName())) { // initial root loop rootLoopVertex = loopVertex; loopVerticesOfSameLoop.putIfAbsent(rootLoopVertex, rootLoopVertex); equivalentVerticesOfLoops.putIfAbsent(rootLoopVertex, new HashMap<>()); for (IRVertex vertex : rootLoopVertex.getDAG().getTopologicalSort()) { equivalentVerticesOfLoops.get(rootLoopVertex).putIfAbsent(vertex, vertex); finalRootLoopVertex.increaseMaxNumberOfIterations(); finalRootLoopVertex.getDAG().getTopologicalSort().iterator(); final Iterator<IRVertex> verticesOfCurrentLoopVertex = loopVertex.getDAG().getTopologicalSort().iterator(); final HashMap<IRVertex, IRVertex> equivalentVertices = equivalentVerticesOfLoops.get(finalRootLoopVertex); while (verticesOfRootLoopVertex.hasNext() && verticesOfCurrentLoopVertex.hasNext()) { finalRootLoopVertex.getNonIterativeIncomingEdges().clear(); finalRootLoopVertex.getIterativeIncomingEdges().clear(); loopVertex.getDagIncomingEdges().forEach((dstVertex, edges) -> edges.forEach(edge -> { final IRVertex srcVertex = edge.getSrc(); final IRVertex equivalentDstVertex = equivalentVertices.get(dstVertex); equivalentSrcVertex, equivalentDstVertex); edge.copyExecutionPropertiesTo(newIrEdge); finalRootLoopVertex.addIterativeIncomingEdge(newIrEdge); } else { srcVertex, equivalentDstVertex); edge.copyExecutionPropertiesTo(newIrEdge); finalRootLoopVertex.addNonIterativeIncomingEdge(newIrEdge);
final DAG<IRVertex, IREdge> dagToAdd = getDAG(); decreaseMaxNumberOfIterations(); getDagIncomingEdges().forEach((dstVertex, irEdges) -> irEdges.forEach(edge -> { final IREdge newIrEdge = new IREdge(edge.getPropertyValue(CommunicationPatternProperty.class).get(), edge.getSrc(), originalToNewIRVertex.get(dstVertex)); })); if (loopTerminationConditionMet()) { getDagOutgoingEdges().forEach((srcVertex, irEdges) -> irEdges.forEach(edge -> { final IREdge newIrEdge = new IREdge(edge.getPropertyValue(CommunicationPatternProperty.class).get(), originalToNewIRVertex.get(srcVertex), edge.getDst()); this.getDagIncomingEdges().clear(); this.nonIterativeIncomingEdges.forEach((dstVertex, irEdges) -> irEdges.forEach(this::addDagIncomingEdge)); this.iterativeIncomingEdges.forEach((dstVertex, irEdges) -> irEdges.forEach(edge -> { originalToNewIRVertex.get(edge.getSrc()), dstVertex); edge.copyExecutionPropertiesTo(newIrEdge); this.addDagIncomingEdge(newIrEdge); }));
final List<Map.Entry<IRVertex, Set<IREdge>>> candidates = loopVertex.getNonIterativeIncomingEdges().entrySet() .stream().filter(entry -> loopVertex.getDAG().getIncomingEdgesOf(entry.getKey()).size() == 0 // no internal inEdges && loopVertex.getIterativeIncomingEdges().getOrDefault(entry.getKey(), new HashSet<>()).size() == 0) .collect(Collectors.toList()); candidates.forEach(candidate -> { loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addDagIncomingEdge); loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addNonIterativeIncomingEdge); listToModify.addAll(edgesToAdd); loopVertex.getBuilder().removeVertex(candidate.getKey()); loopVertex.getDagIncomingEdges().remove(candidate.getKey()); loopVertex.getNonIterativeIncomingEdges().remove(candidate.getKey()); }); });
/** * Copy Constructor for LoopVertex. * * @param that the source object for copying */ public LoopVertex(final LoopVertex that) { super(that); this.compositeTransformFullName = new String(that.compositeTransformFullName); // Copy all elements to the clone final DAG<IRVertex, IREdge> dagToCopy = that.getDAG(); dagToCopy.topologicalDo(v -> { this.getBuilder().addVertex(v, dagToCopy); dagToCopy.getIncomingEdgesOf(v).forEach(this.getBuilder()::connectVertices); }); that.dagIncomingEdges.forEach(((v, es) -> es.forEach(this::addDagIncomingEdge))); that.iterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addIterativeIncomingEdge)); that.nonIterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addNonIterativeIncomingEdge)); that.dagOutgoingEdges.forEach(((v, es) -> es.forEach(this::addDagOutgoingEdge))); that.edgeWithLoopToEdgeWithInternalVertex.forEach((eLoop, eInternal) -> this.mapEdgeWithLoop(eLoop, eInternal)); this.maxNumberOfIterations = that.maxNumberOfIterations; this.terminationCondition = that.terminationCondition; }
assignedLoopVertex.getBuilder().addVertex(dstVertex, dag); final LoopVertex srcLoopVertex = dag.getAssignedLoopVertexOf(irEdge.getSrc()); if (srcLoopVertex.equals(assignedLoopVertex)) { // connecting within the composite loop DAG. assignedLoopVertex.getBuilder().connectVertices(irEdge); } else { // loop -> loop connection assignedLoopVertex.addDagIncomingEdge(irEdge); final IREdge edgeToLoop = new IREdge(irEdge.getPropertyValue(CommunicationPatternProperty.class).get(), srcLoopVertex, assignedLoopVertex); irEdge.copyExecutionPropertiesTo(edgeToLoop); builder.connectVertices(edgeToLoop); assignedLoopVertex.mapEdgeWithLoop(edgeToLoop, irEdge); assignedLoopVertex.addDagIncomingEdge(irEdge); final IREdge edgeToLoop = new IREdge(irEdge.getPropertyValue(CommunicationPatternProperty.class).get(), irEdge.getSrc(), assignedLoopVertex); irEdge.copyExecutionPropertiesTo(edgeToLoop); builder.connectVertices(edgeToLoop); assignedLoopVertex.mapEdgeWithLoop(edgeToLoop, irEdge);
@Override public ObjectNode getPropertiesAsJsonNode() { final ObjectNode node = getIRVertexPropertiesAsJsonNode(); node.put("remainingIteration", maxNumberOfIterations); node.set("DAG", getDAG().asJsonNode()); node.set("dagIncomingEdges", crossingEdgesToJSON(dagIncomingEdges)); node.set("dagOutgoingEdges", crossingEdgesToJSON(dagOutgoingEdges)); final ObjectNode edgeMappings = node.putObject("edgeWithLoopToEdgeWithInternalVertex"); edgeWithLoopToEdgeWithInternalVertex.entrySet() .forEach(entry -> edgeMappings.put(entry.getKey().getId(), entry.getValue().getId())); return node; }
if (irVertex instanceof LoopVertex) { LoopVertex loopVertex = (LoopVertex) irVertex; loopVertex.markDuplicateEdges(); while (!loopVertex.loopTerminationConditionMet()) { loopVertex = loopVertex.unRollIteration(builder);