Skip to content

Commit

Permalink
[SYSTEMML-2025] Improved codegen optimizer (search space layout)
Browse files Browse the repository at this point in the history
This patch makes a minor improvement to the codegen optimizer. So far we
linearized the search space by sorting cutsets by their scores and
appending all other interesting points. Now, we sort the remaining
interesting points decreasing according to their size, which can improve
the pruning efficiency by skipping larger sub spaces.
  • Loading branch information
mboehm7 committed Nov 23, 2017
1 parent 38162d2 commit 723acfc
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public ReachabilityGraph(PlanPartition part, CPlanMemoTable memo) {
//short-cut for partitions without cutsets
if( tmpCS.isEmpty() ) {
_cutSets = new CutSet[0];
_searchSpace = part.getMatPointsExt();
//sort materialization points in decreasing order of their sizes
//which can improve the pruning efficiency by skipping larger sub-spaces.
_searchSpace = sortBySize(part.getMatPointsExt(), memo, false);
return;
}

Expand Down Expand Up @@ -120,15 +122,17 @@ else if( current.get(0).equals(node) )
.map(p -> p.getLeft()).toArray(CutSet[]::new);

//created sorted order of materialization points
//(cut sets in predetermined order, all other points appended)
//(cut sets in predetermined order, other points sorted by size)
HashMap<InterestingPoint, Integer> probe = new HashMap<>();
ArrayList<InterestingPoint> lsearchSpace = new ArrayList<>();
for( CutSet cs : _cutSets ) {
CollectionUtils.addAll(lsearchSpace, cs.cut);
for( InterestingPoint p : cs.cut )
probe.put(p, probe.size());
}
for( InterestingPoint p : part.getMatPointsExt() )
//sort materialization points in decreasing order of their sizes
//which can improve the pruning efficiency by skipping larger sub-spaces.
for( InterestingPoint p : sortBySize(part.getMatPointsExt(), memo, false) )
if( !probe.containsKey(p) ) {
lsearchSpace.add(p);
probe.put(p, probe.size());
Expand Down Expand Up @@ -258,7 +262,19 @@ private ArrayList<Pair<CutSet,Double>> evaluateCutSets(ArrayList<ArrayList<NodeL

return cutSets;
}


private InterestingPoint[] sortBySize(InterestingPoint[] points, CPlanMemoTable memo, boolean asc) {
return Arrays.stream(points)
.sorted(Comparator.comparing(p -> (asc ? 1 : -1) *
getSize(memo.getHopRefs().get(p.getToHopID()))))
.toArray(InterestingPoint[]::new);
}

private static long getSize(Hop hop) {
return Math.max(hop.getDim1(),1)
* Math.max(hop.getDim2(),1);
}

public static class SubProblem {
public int offset;
public int[] freePos;
Expand Down

0 comments on commit 723acfc

Please sign in to comment.