diff options
author | Ian Hinder <ian.hinder@aei.mpg.de> | 2013-09-13 15:37:04 +0200 |
---|---|---|
committer | Ian Hinder <ian.hinder@aei.mpg.de> | 2013-09-13 15:37:04 +0200 |
commit | a8e14b3165e9aec46cb28a4e737987b95f3285e1 (patch) | |
tree | dba19793c078821a19a72917ac28dc186e271b05 | |
parent | c712d76df15718269edbbee1eae19d53e0096133 (diff) |
Move CaKernel code processing from KrancThorn.m to CaKernel.m
-rw-r--r-- | Tools/CodeGen/CaKernel.m | 31 | ||||
-rw-r--r-- | Tools/CodeGen/KrancThorn.m | 22 |
2 files changed, 31 insertions, 22 deletions
diff --git a/Tools/CodeGen/CaKernel.m b/Tools/CodeGen/CaKernel.m index f39022d..019502e 100644 --- a/Tools/CodeGen/CaKernel.m +++ b/Tools/CodeGen/CaKernel.m @@ -19,7 +19,7 @@ *) BeginPackage["CaKernel`", {"Errors`", "Helpers`", "Kranc`", "CodeGenCactus`", "CodeGenKranc`", "MapLookup`", - "Calculation`", "CodeGen`", "CodeGenCalculation`", "CodeGenC`"}]; + "Calculation`", "CodeGen`", "CodeGenCalculation`", "CodeGenC`", "Code`", "Object`"}]; CaKernelCCL; CaKernelCode; @@ -28,6 +28,7 @@ CaKernelSchedule; CaKernelConfigurationCLL; CaKernelInterfaceCLL; WithHostCalculations; +CaKernelProcessCode; Begin["`Private`"]; @@ -246,6 +247,34 @@ DefFn[ WithHostCalculations[calcs_List] := Flatten[Map[splitHostCaKernel, calcs],1]]; +Options[CaKernelProcessCode] = ThornOptions; + +DefFn[ + CaKernelProcessCode[c_Code, opts:OptionsPattern[]] := + Module[ + {calcs = GetObjectField[c, "Calculations"], c2}, + + (* Make the CaKernel option calculation-specific *) + calcs = Map[Append[#,UseCaKernel -> OptionValue[UseCaKernel]] &, calcs]; + + If[OptionValue[GenerateHostCode] && OptionValue[UseCaKernel], + calcs = WithHostCalculations[calcs]]; + + If[!And@@Map[ListQ, calcs], Print[Short[calcs//InputForm]]; ThrowError["Result of WithHostCalculations is not a list of lists"]]; + + (* Add ExecuteOn -> Device to any CaKernel calculation that has no ExecuteOn option *) + calcs = Map[If[!lookup[#,UseCaKernel,False], #, If[mapContains[#,ExecuteOn], #, Append[#,ExecuteOn->Device]]] &, calcs]; + + c2 = SetObjectField[c, "Calculations", calcs]; + + If[OptionValue[UseCaKernel], + c2 = AppendObjectField[c2, "IncludeFiles", "CaCUDALib_driver_support.h"]]; + + If[OptionValue[UseCaKernel], + c2 = AppendObjectField[c2, "InheritedImplementations", "Accelerator"]]; + c2]]; + + End[]; EndPackage[]; diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index 18fc175..963fdc7 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -125,27 +125,7 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[ CaKernel ------------------------------------------------------------------------ *) - c = Module[ - {calcs = GetObjectField[c, "Calculations"]}, - - (* Make the CaKernel option calculation-specific *) - calcs = Map[Append[#,UseCaKernel -> OptionValue[UseCaKernel]] &, calcs]; - - If[OptionValue[GenerateHostCode] && OptionValue[UseCaKernel], - calcs = WithHostCalculations[calcs]]; - - If[!And@@Map[ListQ, calcs], Print[Short[calcs//InputForm]]; ThrowError["Result of WithHostCalculations is not a list of lists"]]; - - (* Add ExecuteOn -> Device to any CaKernel calculation that has no ExecuteOn option *) - calcs = Map[If[!lookup[#,UseCaKernel,False], #, If[mapContains[#,ExecuteOn], #, Append[#,ExecuteOn->Device]]] &, calcs]; - - SetObjectField[c, "Calculations", calcs]]; - - If[OptionValue[UseCaKernel], - c = AppendObjectField[c, "IncludeFiles", "CaCUDALib_driver_support.h"]]; - - If[OptionValue[UseCaKernel], - c = AppendObjectField[c, "InheritedImplementations", "Accelerator"]]; + c = CaKernelProcessCode[c, opts]; (* ------------------------------------------------------------------------ Add coordinates group |