Skip to content

Commit

Permalink
Move CaKernel code processing from KrancThorn.m to CaKernel.m
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhinder committed Sep 13, 2013
1 parent c712d76 commit a8e14b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
31 changes: 30 additions & 1 deletion Tools/CodeGen/CaKernel.m
Expand Up @@ -19,7 +19,7 @@
*)

BeginPackage["CaKernel`", {"Errors`", "Helpers`", "Kranc`", "CodeGenCactus`", "CodeGenKranc`", "MapLookup`",
"Calculation`", "CodeGen`", "CodeGenCalculation`", "CodeGenC`"}];
"Calculation`", "CodeGen`", "CodeGenCalculation`", "CodeGenC`", "Code`", "Object`"}];

CaKernelCCL;
CaKernelCode;
Expand All @@ -28,6 +28,7 @@
CaKernelConfigurationCLL;
CaKernelInterfaceCLL;
WithHostCalculations;
CaKernelProcessCode;

Begin["`Private`"];

Expand Down Expand Up @@ -246,6 +247,34 @@ CCTK_POINTER FUNCTION Device_GetVarI (CCTK_POINTER IN cctkGH, CCTK_INT IN vi, CC
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[];
22 changes: 1 addition & 21 deletions Tools/CodeGen/KrancThorn.m
Expand Up @@ -125,27 +125,7 @@ Thorn generation (main entry point for non-tensorial thorns)
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
Expand Down

0 comments on commit a8e14b3

Please sign in to comment.