diff options
author | Erik Schnetter <schnetter@gmail.com> | 2011-11-26 10:24:34 -0500 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2011-11-29 13:50:15 -0500 |
commit | 954963c1b3dd9252f835f675e59c8a1ff0b471ae (patch) | |
tree | 7e84fb5f73787b65d50b65852ca6a5eb60a25d71 /Tools/CodeGen | |
parent | 9cc50992ec7b20fcb359c80358a787a0551364fa (diff) |
Support provides/requires statements in the schedule.
Wrap cctk_time in ToReal.
Simplify non-OpenCL vectorised store operations
Diffstat (limited to 'Tools/CodeGen')
-rw-r--r-- | Tools/CodeGen/CalculationFunction.m | 43 | ||||
-rw-r--r-- | Tools/CodeGen/CodeGenCactus.m | 21 | ||||
-rw-r--r-- | Tools/CodeGen/Kranc.m | 1 | ||||
-rw-r--r-- | Tools/CodeGen/Schedule.m | 36 | ||||
-rw-r--r-- | Tools/CodeGen/Thorn.m | 8 |
5 files changed, 64 insertions, 45 deletions
diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m index b04aa46..31399d3 100644 --- a/Tools/CodeGen/CalculationFunction.m +++ b/Tools/CodeGen/CalculationFunction.m @@ -273,7 +273,7 @@ assignVariableFromExpression[dest_, expr_, declare_, vectorise_, noSimplify:Bool code = StringReplace[code, "normal2" -> "normal[1]"]; code = StringReplace[code, "normal3" -> "normal[2]"]; code = StringReplace[code, "BesselJ"-> "gsl_sf_bessel_Jn"]; - code = StringReplace[code, ToString@tSym -> "cctk_time"]; + code = StringReplace[code, ToString@tSym -> "ToReal(cctk_time)"]; code = StringReplace[code, "\"" -> ""]; {code}]; @@ -301,7 +301,7 @@ generateCodeFromExpression[expr_, vectorise_, noSimplify:Boolean : False] := code = StringReplace[code, "normal2" -> "normal[1]"]; code = StringReplace[code, "normal3" -> "normal[2]"]; code = StringReplace[code, "BesselJ"-> "gsl_sf_bessel_Jn"]; - code = StringReplace[code, ToString@tSym -> "cctk_time"]; + code = StringReplace[code, ToString@tSym -> "ToReal(cctk_time)"]; code = StringReplace[code, "\"" -> ""]; {code}]; @@ -778,38 +778,13 @@ DefFn[ Map[InfoVariable[#[[1]]] &, (eqs2 /. localMap)], ""], - Which[OptionValue[UseOpenCL], - CommentedBlock["Copy local copies back to grid functions", - Map[StorePartialVariableInLoop[GridName[#], localName[#]] &, gfsInLHS]], - OptionValue[UseVectors], - { - CommentedBlock["If necessary, store only partial vectors after the first iteration", - ConditionalOnParameterTextual["CCTK_REAL_VEC_SIZE > 2 && CCTK_BUILTIN_EXPECT(i < lc_imin && i+CCTK_REAL_VEC_SIZE > lc_imax, 0)", - { - DeclareAssignVariable["ptrdiff_t", "elt_count_lo", "lc_imin-i"], - DeclareAssignVariable["ptrdiff_t", "elt_count_hi", "lc_imax-i"], - Map[StoreMiddlePartialVariableInLoop[GridName[#], localName[#], "elt_count_lo", "elt_count_hi"] &, gfsInLHS], - "break;\n" - }]], - CommentedBlock["If necessary, store only partial vectors after the first iteration", - ConditionalOnParameterTextual["CCTK_REAL_VEC_SIZE > 1 && CCTK_BUILTIN_EXPECT(i < lc_imin, 0)", - { - DeclareAssignVariable["ptrdiff_t", "elt_count", "lc_imin-i"], - Map[StoreHighPartialVariableInLoop[GridName[#], localName[#], "elt_count"] &, gfsInLHS], - "continue;\n" - }]], - CommentedBlock["If necessary, store only partial vectors after the last iteration", - ConditionalOnParameterTextual["CCTK_REAL_VEC_SIZE > 1 && CCTK_BUILTIN_EXPECT(i+CCTK_REAL_VEC_SIZE > lc_imax, 0)", - { - DeclareAssignVariable["ptrdiff_t", "elt_count", "lc_imax-i"], - Map[StoreLowPartialVariableInLoop[GridName[#], localName[#], "elt_count"] &, gfsInLHS], - "break;\n" - }]], - Map[StoreVariableInLoop[GridName[#], localName[#]] &, gfsInLHS] - }, - True, - CommentedBlock["Copy local copies back to grid functions", - Map[AssignVariableInLoop[GridName[#], localName[#]] &, gfsInLHS]]], + If[OptionValue[UseVectors] || OptionValue[UseOpenCL], + CommentedBlock["Copy local copies back to grid functions", + { PrepareStorePartialVariableInLoop["i", "lc_imin", "lc_imax"], + Map[StorePartialVariableInLoop[GridName[#], localName[#]] &, + gfsInLHS] }], + CommentedBlock["Copy local copies back to grid functions", + Map[AssignVariableInLoop[GridName[#], localName[#]] &, gfsInLHS]]], If[debugInLoop, Map[InfoVariable[GridName[#]] &, gfsInLHS], ""]}, opts]}]]; diff --git a/Tools/CodeGen/CodeGenCactus.m b/Tools/CodeGen/CodeGenCactus.m index f206ec3..6c405f8 100644 --- a/Tools/CodeGen/CodeGenCactus.m +++ b/Tools/CodeGen/CodeGenCactus.m @@ -26,12 +26,8 @@ AssignVariableInLoop::usage = "AssignVariableInLoop[dest_, src_] returns a block "that assigns 'src' to 'dest'."; StoreVariableInLoop::usage = "StoreVariableInLoop[dest_, src_] returns a block of code " <> "that assigns 'src' to 'dest'."; -StoreLowPartialVariableInLoop::usage = "StoreLowPartialVariableInLoop[dest_, src_, count_] returns a block of code " <> - "that assigns 'src' to 'dest'."; -StoreHighPartialVariableInLoop::usage = "StoreHighPartialVariableInLoop[dest_, src_, count_] returns a block of code " <> - "that assigns 'src' to 'dest'."; -StoreMiddlePartialVariableInLoop::usage = "StoreMiddlePartialVariableInLoop[dest_, src_, countLow_, countHigh_] returns a block of code " <> - "that assigns 'src' to 'dest'."; +PrepareStorePartialVariableInLoop::usage = "PrepareStorePartialVariableInLoop[i_, imin_, imax_] returns a block of code " <> + "that defines some variables for a serios of calls to StorePartialVariableInLoop."; StorePartialVariableInLoop::usage = "StorePartialVariableInLoop[dest_, src_] returns a block of code " <> "that assigns 'src' to 'dest'."; DeclareAssignVariableInLoop::usage = "DeclareAssignVariableInLoop[type_, dest_, src_] returns a block of code " <> @@ -103,6 +99,7 @@ DefFn[ StoreVariableInLoop[dest:(_String|_Symbol), src:(_String|_Symbol)] := {"vec_store_nta(", dest, ",", src, ")", EOL[]}]; +(* DefFn[ StoreLowPartialVariableInLoop[dest:(_String|_Symbol), src:(_String|_Symbol), count_String] := {"vec_store_nta_partial_lo(", dest, ",", src, ",", count, ")", EOL[]}]; @@ -114,6 +111,13 @@ DefFn[ DefFn[ StoreMiddlePartialVariableInLoop[dest:(_String|_Symbol), src:(_String|_Symbol), countLow_String, countHigh_String] := {"vec_store_nta_partial_mid(", dest, ",", src, ",", countLow, ",", countHigh, ")", EOL[]}]; +*) + +DefFn[ + PrepareStorePartialVariableInLoop[i:(_String|_Symbol), + ilo:(_String|_Symbol), + ihi:(_String|_Symbol)] := + {"vec_store_partial_prepare(", i, ",", ilo, ",", ihi, ")", EOL[]}]; DefFn[ StorePartialVariableInLoop[dest:(_String|_Symbol), src:(_String|_Symbol)] := @@ -214,8 +218,9 @@ DefFn[ DeclareAssignVariable[DataType[], "dx", "ToReal(CCTK_DELTA_SPACE(0))"], DeclareAssignVariable[DataType[], "dy", "ToReal(CCTK_DELTA_SPACE(1))"], DeclareAssignVariable[DataType[], "dz", "ToReal(CCTK_DELTA_SPACE(2))"], - DeclareAssignVariable[DataType[], "dt", "ToReal(CCTK_DELTA_TIME)"], - DeclareAssignVariable[DataType[], "t", "ToReal(cctk_time)"]}]; + DeclareAssignVariable[DataType[], "dt", "ToReal(CCTK_DELTA_TIME)"] + (* DeclareAssignVariable[DataType[], "t", "ToReal(cctk_time)"]*) + }]; DefFn[ InitialiseFDSpacingVariablesFortran[] := diff --git a/Tools/CodeGen/Kranc.m b/Tools/CodeGen/Kranc.m index 09becb4..2b70161 100644 --- a/Tools/CodeGen/Kranc.m +++ b/Tools/CodeGen/Kranc.m @@ -83,6 +83,7 @@ ThornOptions = {AccumulatorBase, ThornImplementation, Name, Type, Extend, Default, Comment, Range, Implementation, Group, SchedulePoint, Language, +RequiredGroups, ProvidedGroups, SynchronizedGroups, StorageGroups, Timelevels, MaxTimelevels, VariableType, GridType, Dim, Size, Visibility, Variables, Implementations, Value, AllowedValues, diff --git a/Tools/CodeGen/Schedule.m b/Tools/CodeGen/Schedule.m index f596ad1..4a57d7b 100644 --- a/Tools/CodeGen/Schedule.m +++ b/Tools/CodeGen/Schedule.m @@ -62,10 +62,12 @@ groupsSetInCalc[calc_, groups_] := (* Each calculation can be scheduled at multiple points, so this function returns a LIST of schedule structures for each calculation *) -scheduleCalc[calc_, groups_] := +scheduleCalc[calc_, groups_, thornName_] := Module[{points, conditional, conditionals, keywordConditional, keywordConditionals, triggered, keyword, value, keywordvaluepairs, - groupsToSync, groupName, userSchedule, groupSched, fnSched, + groupsToSync, tags, + prefixWithScope, groupsToRequire, groupsToProvide, + groupName, userSchedule, groupSched, fnSched, selbcSched, appbcSched, bcGroupName, condParams, bcGroupSched, before, after, relStr}, conditional = mapContains[calc, ConditionalOnKeyword]; conditionals = mapContains[calc, ConditionalOnKeywords]; @@ -93,6 +95,23 @@ scheduleCalc[calc_, groups_] := groupsSetInCalc[calc, groups], {}]; + (* 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"; + + 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]; + groupsToProvide = prefixWithScope /@ groupsSetInCalc[calc, groups]; + before = lookupDefault[calc, Before, None]; after = lookupDefault[calc, After, None]; @@ -110,6 +129,9 @@ scheduleCalc[calc_, groups_] := {}, groupsToSync], Language -> CodeGenC`SOURCELANGUAGE, + Tags -> tags, + RequiredGroups -> groupsToRequire, + ProvidedGroups -> groupsToProvide, Comment -> lookup[calc, Name] }, If[triggered, {TriggerGroups -> lookup[calc, TriggerGroups]}, @@ -144,10 +166,17 @@ scheduleCalc[calc_, groups_] := } ~Join~ condParams; + (* We set required/provided groups here with the actual + function, since (at least in principle) the driver should be + able to deduce the synchronization and boundary condition + treatment from this information. *) fnSched = { Name -> lookup[calc, Name], SchedulePoint -> "in " <> groupName, Language -> CodeGenC`SOURCELANGUAGE, + Tags -> tags, + RequiredGroups -> groupsToRequire, + ProvidedGroups -> groupsToProvide, Comment -> lookup[calc, Name] }; @@ -185,7 +214,8 @@ CreateKrancScheduleFile[calcs_, groups_, evolvedGroups_, rhsGroups_, nonevolvedG evolutionTimelevels_] := Module[{scheduledCalcs, scheduledStartup, scheduleMoLRegister, globalStorageGroups, scheduledFunctions, schedule}, - scheduledCalcs = Flatten[Map[scheduleCalc[#, groups] &, calcs], 1]; + scheduledCalcs = + Flatten[Map[scheduleCalc[#, groups, thornName] &, calcs], 1]; scheduledStartup = { Name -> thornName <> "_Startup", diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m index dfd309a..8731c26 100644 --- a/Tools/CodeGen/Thorn.m +++ b/Tools/CodeGen/Thorn.m @@ -387,6 +387,14 @@ scheduleUnconditionalFunction[spec_] := Map[{"TRIGGERS: ", #, "\n"} &, lookupDefault[spec, TriggerGroups, {}]], + (* TODO: Expect a set of keyword/value pairs instead of a string *) + If[lookupDefault[spec, Tags, ""] != "", + "TAGS: " <> lookup[spec, Tags] <> "\n", + ""], + + Map[{"REQUIRES: ", #, "\n"} &, lookupDefault[spec, RequiredGroups, {}]], + Map[{"PROVIDES: ", #, "\n"} &, lookupDefault[spec, ProvidedGroups, {}]], + (* Insert a storage block for each group we want to allocate storage for *) Map[groupStorage, lookupDefault[spec, StorageGroups, {}]]}, |