Permalink
Browse files

CaKernel.m: Wrap host/device routines in a schedule group

  • Loading branch information...
1 parent 68d9347 commit 86bafb7588ec88ab829c9daf2850fceee138b23c @ianhinder committed Apr 23, 2012
Showing with 30 additions and 9 deletions.
  1. +30 −9 Tools/CodeGen/CaKernel.m
View
@@ -202,16 +202,37 @@ CCTK_POINTER FUNCTION Device_GetVarI (CCTK_POINTER IN cctkGH, CCTK_INT IN vi, CC
If[lookup[calc,ExecuteOn,Automatic] === Host,
{calc},
- {mapReplaceAdd[
+
+ Module[
+ {deviceCalc, hostCalc, newCalcs},
+
+ deviceCalc =
+ mapReplaceAdd[
+ mapReplaceAdd[
+ mapReplace[
+ calc,
+ Name,"DEVICE_"<>lookup[calc,Name]],
+ UseCaKernel, True],
+ ExecuteOn, Device];
+
+ hostCalc =
mapReplaceAdd[
- AddConditionSuffix[calc, "Accelerator::device_process"],
- UseCaKernel, True],
- ExecuteOn, Device],
- mapReplaceAdd[
- mapReplaceAdd[
- AddConditionSuffix[mapReplace[calc,Name,"HOST__"<>lookup[calc,Name]], "Accelerator::host_process"],
- UseCaKernel,False],
- ExecuteOn, Host]}]];
+ mapReplaceAdd[
+ mapReplace[
+ calc,
+ Name,"HOST_"<>lookup[calc,Name]],
+ UseCaKernel,False],
+ ExecuteOn, Host];
+
+ newCalcs = Map[InNewScheduleGroup[lookup[calc,Name],#] &, {hostCalc, deviceCalc}];
+
+ (* Apply the conditional to the routines, not to the group *)
+ newCalcs = MapThread[AddConditionSuffix,
+ {newCalcs,
+ {"Accelerator::host_process",
+ "Accelerator::device_process"}}];
+
+ newCalcs]]];
DefFn[
WithHostCalculations[calcs_List] :=

0 comments on commit 86bafb7

Please sign in to comment.