From 0a36b4fafc1293d056e1e1cdc759f5abb8da90ba Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sun, 18 Dec 2011 14:52:10 -0500 Subject: [PATCH] Set requirements correctly for OpenCL --- Tools/CodeGen/KrancThorn.m | 4 ++-- Tools/CodeGen/Schedule.m | 29 +++++++++++++++++------------ Tools/CodeGen/TensorTools.m | 5 +++-- Tools/CodeGen/Thorn.m | 3 +-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index 16287d78..e086090d 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -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", @@ -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]; diff --git a/Tools/CodeGen/Schedule.m b/Tools/CodeGen/Schedule.m index 4a57d7b3..f83578f1 100644 --- a/Tools/CodeGen/Schedule.m +++ b/Tools/CodeGen/Schedule.m @@ -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, @@ -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]; @@ -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", diff --git a/Tools/CodeGen/TensorTools.m b/Tools/CodeGen/TensorTools.m index 7b623f55..48a848ad 100644 --- a/Tools/CodeGen/TensorTools.m +++ b/Tools/CodeGen/TensorTools.m @@ -140,6 +140,7 @@ Checkpoint; IsTensor; toggleIndex; +replaceConflicting; (* This is for compatibility with MathTensor notation *) (*OD = PD;*) @@ -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;*) @@ -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] diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m index 8731c261..a82a23d6 100644 --- a/Tools/CodeGen/Thorn.m +++ b/Tools/CodeGen/Thorn.m @@ -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 *) @@ -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_] :=