Repository: systemml Updated Branches: refs/heads/master f59a2dc22 -> c04929fab
[SYSTEMML-2009] Fix codegen thread contention in multi-threaded parfor This patch fixes thread contention issues on cost vector id generation in the codegen optimizer. In scenarios with concurrent dynamic recompilation (e.g., in local parfor w/ unknowns), and thus concurrent codegen optimization, threads were partially contented on the global sequence generator. These cost vector ids are only used for memoization during plan costing and hence we now simply use a separate id sequence for each optimizer instance, which avoids any contention altogether. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/779d4327 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/779d4327 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/779d4327 Branch: refs/heads/master Commit: 779d4327b76ff37f142ce44d8ee2987d3f221d58 Parents: f59a2dc Author: Matthias Boehm <[email protected]> Authored: Sat Nov 11 22:25:02 2017 -0800 Committer: Matthias Boehm <[email protected]> Committed: Sat Nov 11 22:25:02 2017 -0800 ---------------------------------------------------------------------- .../codegen/opt/PlanSelectionFuseCostBasedV2.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/779d4327/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java index 9302573..80013c5 100644 --- a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java +++ b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java @@ -99,10 +99,13 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection //optimizer configuration public static boolean COST_PRUNING = true; public static boolean STRUCTURAL_PRUNING = true; - - private static final IDSequence COST_ID = new IDSequence(); private static final TemplateRow ROW_TPL = new TemplateRow(); + //cost vector id generator, whose ids are only used for memoization per call to getPlanCost; + //hence, we use a sequence generator per optimizer instance to avoid thread contention in + //multi-threaded parfor scenarios with concurrent dynamic recompilation and thus optimization. + private final IDSequence COST_ID = new IDSequence(); + @Override public void selectPlans(CPlanMemoTable memo, ArrayList<Hop> roots) { @@ -196,7 +199,7 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection * @param off offset for recursive invocation, indicating the fixed plan part * @return optimal assignment of materialization points */ - private static boolean[] enumPlans(CPlanMemoTable memo, PlanPartition part, StaticCosts costs, + private boolean[] enumPlans(CPlanMemoTable memo, PlanPartition part, StaticCosts costs, ReachabilityGraph rgraph, InterestingPoint[] matPoints, int off) { //scan linearized search space, w/ skips for branch and bound pruning @@ -750,7 +753,7 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection // Cost model fused operators w/ materialization points ////////// - private static double getPlanCost(CPlanMemoTable memo, PlanPartition part, + private double getPlanCost(CPlanMemoTable memo, PlanPartition part, InterestingPoint[] matPoints,boolean[] plan, HashMap<Long, Double> computeCosts, final double costBound) { @@ -771,7 +774,7 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection return costs; } - private static double rGetPlanCosts(CPlanMemoTable memo, final Hop current, HashSet<VisitMarkCost> visited, + private double rGetPlanCosts(CPlanMemoTable memo, final Hop current, HashSet<VisitMarkCost> visited, PlanPartition part, InterestingPoint[] matPoints, boolean[] plan, HashMap<Long, Double> computeCosts, CostVector costsCurrent, TemplateType currentType, final double costBound) { @@ -1046,7 +1049,7 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection && HopRewriteUtils.isTransposeOperation(hop.getInput().get(index)); } - private static class CostVector { + private class CostVector { public final long ID; public final double outSize; public double computeCosts = 0;
