Skip to content

Commit

Permalink
Set requirements correctly for OpenCL
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed Dec 18, 2011
1 parent 06a5d44 commit 0a36b4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Tools/CodeGen/KrancThorn.m
Expand Up @@ -130,7 +130,7 @@ Thorn generation (main entry point for non-tensorial thorns)

CheckGroups[groupsOrig];

groups = Join[groupsOrig, {coordGroup}];
groups = Union[Join[groupsOrig, {coordGroup}]];
includeFiles = Join[includeFiles, {"GenericFD.h", "Symmetry.h", "sbp_calc_coeffs.h"}];

inheritedImplementations = Join[inheritedImplementations, {"Grid",
Expand Down Expand Up @@ -202,7 +202,7 @@ Thorn generation (main entry point for non-tensorial thorns)
InfoMessage[Terse, "Creating schedule file"];
schedule = CreateKrancScheduleFile[calcs, groups, Join[evolvedGroups,evolvedODEGroups],
Join[rhsGroups,rhsODEGroups], Join[nonevolvedGroups,nonevolvedODEGroups], thornName,
evolutionTimelevels];
evolutionTimelevels, opts];

boundarySources = CactusBoundary`GetSources[evolvedGroups, groups,
implementation, thornName];
Expand Down
29 changes: 17 additions & 12 deletions Tools/CodeGen/Schedule.m
Expand Up @@ -54,15 +54,24 @@
eqs = lookup[calc, Equations];
lhss = Map[First, eqs];
gfsInLHS = Union[Cases[lhss, _ ? (MemberQ[gfs,#] &), Infinity]];

lhsGroupNames = containingGroups[gfsInLHS, groups];
Return[lhsGroupNames]
];

groupsReadInCalc[calc_, groups_] :=
Module[{gfs, eqs, lhss, gfsInLHS, lhsGroupNames},
gfs = allGroupVariables[groups];
eqs = lookup[calc, Equations];
rhss = Map[Last, eqs];
gfsInRHS = Union[Cases[rhss, _ ? (MemberQ[gfs,#] &), Infinity]];
rhsGroupNames = containingGroups[gfsInRHS, groups];
Return[rhsGroupNames]
];

(* Each calculation can be scheduled at multiple points, so this
function returns a LIST of schedule structures for each calculation
*)
scheduleCalc[calc_, groups_, thornName_] :=
scheduleCalc[calc_, groups_, thornName_, useOpenCL_] :=
Module[{points, conditional, conditionals, keywordConditional,
keywordConditionals, triggered, keyword, value, keywordvaluepairs,
groupsToSync, tags,
Expand Down Expand Up @@ -97,19 +106,13 @@

(* TODO: Pass this as {keyword,value} pair instead of a string,
once Thorn.m understands this format *)
(* TODO: This doesn't work -- I don't know how to access
OptionValue[] in this file.
tags = If[OptionValue[UseOpenCL], "OpenCL=1", ""];
*)
tags = "OpenCL=1";
tags = If[useOpenCL, "OpenCL=1", ""];

prefixWithScope[group_] :=
If[StringMatchQ[ToString[group], __~~"::"~~__],
ToString[group],
thornName <> "::" <> ToString[group]];
(* TODO: Don't blindly require/provide all groups, check the
equations instead *)
groupsToRequire = prefixWithScope /@ Map[First, groups];
groupsToRequire = prefixWithScope /@ groupsReadInCalc[calc, groups];
groupsToProvide = prefixWithScope /@ groupsSetInCalc[calc, groups];

before = lookupDefault[calc, Before, None];
Expand Down Expand Up @@ -210,12 +213,14 @@
bcGroupSched["in "<>groupName <> " after " <> lookup[calc, Name]],
bcGroupSched["in MoL_PseudoEvolutionBoundaries after MoL_PostStep"]},{}]]]];

Options[CreateKrancScheduleFile] = ThornOptions;

CreateKrancScheduleFile[calcs_, groups_, evolvedGroups_, rhsGroups_, nonevolvedGroups_, thornName_,
evolutionTimelevels_] :=
evolutionTimelevels_, opts:OptionsPattern[]] :=
Module[{scheduledCalcs, scheduledStartup, scheduleMoLRegister, globalStorageGroups, scheduledFunctions, schedule},

scheduledCalcs =
Flatten[Map[scheduleCalc[#, groups, thornName] &, calcs], 1];
Flatten[Map[scheduleCalc[#, groups, thornName, OptionValue[UseOpenCL]] &, calcs], 1];
scheduledStartup =
{
Name -> thornName <> "_Startup",
Expand Down
5 changes: 3 additions & 2 deletions Tools/CodeGen/TensorTools.m
Expand Up @@ -140,6 +140,7 @@
Checkpoint;
IsTensor;
toggleIndex;
replaceConflicting;

(* This is for compatibility with MathTensor notation *)
(*OD = PD;*)
Expand Down Expand Up @@ -352,7 +353,7 @@
TensorProduct represents a Times that has already been checked for
conflicting dummy indices. It can have any expressions in it. *)

SetAttributes[TensorProduct, {Flat, OneIdentity}];
SetAttributes[TensorProduct, {Flat, OneIdentity, Orderless}];

(* For some reason this causes infinite loops - might want to check this later *)
(*TensorProduct[t:(Tensor[_,__])] := t;*)
Expand Down Expand Up @@ -757,7 +758,7 @@

(* Things we can do with covariant derivatives:
(1) Liebnitz: CD[x_ y_,i_] -> CD[x,i] y + x CD[y,i]
(1) Leibnitz: CD[x_ y_,i_] -> CD[x,i] y + x CD[y,i]
(2) Linear: CD[x_ + y_,i_] -> CD[x,i] + CD[y,i]
(3) Linear: CD[i_Integer x_] -> i CD[x]
(4) High order derivatives: CD[x_, i_, is__] -> CD[CD[x,i],is]
Expand Down
3 changes: 1 addition & 2 deletions Tools/CodeGen/Thorn.m
Expand Up @@ -384,7 +384,6 @@
(* Insert a SYNC line for each group we want to synchronize. *)
Map[{"SYNC: ", #, "\n"} &, lookupDefault[spec, SynchronizedGroups, {}]],


Map[{"TRIGGERS: ", #, "\n"} &, lookupDefault[spec, TriggerGroups, {}]],

(* TODO: Expect a set of keyword/value pairs instead of a string *)
Expand All @@ -399,7 +398,7 @@
storage for *)
Map[groupStorage, lookupDefault[spec, StorageGroups, {}]]},

Quote[lookup[spec, Comment]]]};
Quote[lookup[spec, Comment]]]};

(* Handle the aspect of scheduling the function conditionally *)
scheduleFunction[spec_] :=
Expand Down

0 comments on commit 0a36b4f

Please sign in to comment.