[m-rev.] For review: Fix a bug in automatic parallelism analysis.

Paul Bone pbone at csse.unimelb.edu.au
Sat Nov 5 12:08:37 AEDT 2011


For review by Zoltan,

Zoltan has uncommitted changes to the deep_profiler directory, he needs me to
fix bugs such as this one so that he can test his changes.

This change prevents a crash when analysing the compiler's profiling data.

---

The automatic parallelism analysis attempts to create conjunctions that can be
parallelized by pushing lists of goals into other non-atomic goals, creating a
suitable conjunction inside one or more branches of the non-atomic goal.  When
this happens the costs and port counts of the pushed goals need to be updated
so that they reflect what would happen if the code was re-ordered in this way.

There was a problem when the cost of the goal was re-calculated for recursive
calls.  The analysis re-calculated the percall cost from the total cost and the
new number of calls of the goal in this context.  This is incorrect, the
percall cost would not change simply because a call was called less often, the
percall cost would stay the same and the total number of calls would change.

deep_profiler/autopar_search_goals.m:
    Call goal_cost_change_calls which handles the update of a goal's cost when
    the number of calls to it changes.

deep_profiler/measurements.m:
    Create the goal_cost_change_calls function.

Index: deep_profiler/autopar_search_goals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/autopar_search_goals.m,v
retrieving revision 1.5
diff -u -p -b -r1.5 autopar_search_goals.m
--- deep_profiler/autopar_search_goals.m	26 Sep 2011 07:08:57 -0000	1.5
+++ deep_profiler/autopar_search_goals.m	4 Nov 2011 07:15:49 -0000
@@ -674,22 +674,7 @@ push_goals_create_candidate(Info, RevCur
 fix_goal_counts(Info, Count, !Goal) :-
     Annotation0 = !.Goal ^ goal_annotation,
     Cost0 = Annotation0 ^ pgd_cost,
-    (
-        GoalType = Annotation0 ^ pgd_pg_type,
-        GoalType = pgt_call(_, CostAndCallees),
-        % XXX This doesn't work if this is a non-atomic goal containing a
-        % recursive call.
-        set.member(Callee, CostAndCallees ^ cac_callees),
-        % The call is recursive if it calls into the current clique.
-        Info ^ ipi_clique = Callee ^ c_clique
-    ->
-        % for recursive calls.
-        CostTotal = goal_cost_get_total(Cost0),
-        PercallCost = CostTotal / float(Count)
-    ;
-        PercallCost = goal_cost_get_percall(Cost0)
-    ),
-    Cost = call_goal_cost(Count, PercallCost),
+    Cost = goal_cost_change_calls(Cost0, Count),
     !Goal ^ goal_annotation ^ pgd_cost := Cost,
     ( goal_cost_above_par_threshold(Info, Cost) ->
         AboveThreshold = cost_above_par_threshold
Index: deep_profiler/measurements.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/measurements.m,v
retrieving revision 1.30
diff -u -p -b -r1.30 measurements.m
--- deep_profiler/measurements.m	6 May 2011 15:19:32 -0000	1.30
+++ deep_profiler/measurements.m	5 Nov 2011 01:01:27 -0000
@@ -189,6 +189,8 @@
 
 :- func goal_cost_get_calls(goal_cost_csq) = int.
 
+:- func goal_cost_change_calls(goal_cost_csq, int) = goal_cost_csq.
+
 %-----------------------------------------------------------------------------%
 
 :- type recursion_depth.
@@ -847,6 +849,13 @@ goal_cost_get_calls(dead_goal) = 0.
 goal_cost_get_calls(trivial_goal(Calls)) = Calls.
 goal_cost_get_calls(non_trivial_goal(_, Calls)) = Calls.
 
+goal_cost_change_calls(dead_goal, _) =
+    unexpected($module, $pred, "Cannot compute new cost").
+goal_cost_change_calls(trivial_goal(_), Calls) = trivial_goal(Calls).
+goal_cost_change_calls(non_trivial_goal(Cost0, Calls0), Calls) =
+        non_trivial_goal(Cost, Calls) :-
+    Cost = cost_per_call(cost_get_percall(float(Calls0), Cost0)).
+
 %----------------------------------------------------------------------------%
 
 :- type cost
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20111105/7d4841e6/attachment.sig>


More information about the reviews mailing list