aboutsummaryrefslogtreecommitdiff
path: root/Tools/CodeGen
diff options
context:
space:
mode:
authorIan Hinder <ian.hinder@aei.mpg.de>2012-01-23 21:58:24 -0600
committerIan Hinder <ian.hinder@aei.mpg.de>2012-01-23 22:01:57 -0600
commit5488362d2be2ff6f8f524fc199a53ab2bff089ff (patch)
tree5938b510d2e34f199c904f825142987d316deba0 /Tools/CodeGen
parentc814616cad3845b100fe05160a968ecba4d1677f (diff)
Generate basic cakernel.ccl file
Diffstat (limited to 'Tools/CodeGen')
-rw-r--r--Tools/CodeGen/CaKernel.m66
-rw-r--r--Tools/CodeGen/Kranc.m5
-rw-r--r--Tools/CodeGen/KrancThorn.m10
-rw-r--r--Tools/CodeGen/Thorn.m1
4 files changed, 78 insertions, 4 deletions
diff --git a/Tools/CodeGen/CaKernel.m b/Tools/CodeGen/CaKernel.m
new file mode 100644
index 0000000..76ebeac
--- /dev/null
+++ b/Tools/CodeGen/CaKernel.m
@@ -0,0 +1,66 @@
+
+(* Copyright 2012 Ian Hinder
+
+ This file is part of Kranc.
+
+ Kranc is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Kranc is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Kranc; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*)
+
+BeginPackage["CaKernel`", {"Errors`", "Helpers`", "Kranc`", "CodeGenCactus`", "MapLookup`", "Calculation`"}];
+
+CaKernelCCL;
+
+Begin["`Private`"];
+
+DefFn[
+ variableBlock[var_, intent_String] :=
+ CCLBlock["CCTK_CUDA_KERNEL_VARIABLE", "", {"cached" -> "yes", "intent" -> intent}, {var,"\n"}, ToString[var]]];
+
+DefFn[
+ variableBlocks[calc_] :=
+ Module[
+ {in,out,all,inOnly,outOnly,inOut},
+ in = InputGridFunctions[calc];
+ out = OutputGridFunctions[calc];
+ all = Union[in,out];
+
+ inOnly = Complement[in, out];
+ outOnly = Complement[out, in];
+ inOut = Intersection[in,out];
+
+ Riffle[
+ Map[variableBlock[#, Which[MemberQ[inOnly, #], "in",
+ MemberQ[outOnly, #], "out",
+ MemberQ[inOut, #], "inout",
+ True,ThrowError["Unable to determine use of variable "<>ToString[#]]]] &, all],
+ "\n"]]];
+
+DefFn[
+ kernelCCLBlock[calc_] :=
+ CCLBlock["CCTK_CUDA_KERNEL", lookup[calc, Name],
+ {"TYPE" -> "gpu_cuda/3dblock",
+ "STENCIL" -> "0,0,0,0,0,0",
+ "TILE" -> "16,16,16",
+ "SHARECODE" -> "yes"},
+ variableBlocks[calc]]];
+
+DefFn[CaKernelCCL[calcs_List] :=
+ Module[
+ {},
+ Map[kernelCCLBlock, calcs]]];
+
+End[];
+
+EndPackage[];
diff --git a/Tools/CodeGen/Kranc.m b/Tools/CodeGen/Kranc.m
index 3a9cf25..8941eb2 100644
--- a/Tools/CodeGen/Kranc.m
+++ b/Tools/CodeGen/Kranc.m
@@ -78,7 +78,8 @@ ThornOptions =
ProhibitAssignmentToGridFunctionsRead -> False,
IncludeFiles -> {},
CSE -> False,
- UseJacobian -> False};
+ UseJacobian -> False,
+ UseCaKernel -> False};
(* Thorn.m *)
@@ -94,7 +95,7 @@ Contents, ThornName, BaseImplementation, EvolvedGFs, EvolvedArrays, PrimitiveGFs
Groups, Calculation, GridFunctions, Shorthands, Equations, Parameter,
Value, UsesFunctions, ArgString, Conditional, Conditionals, D1, D2, D3, D11, D22,
D33, D21, D31, D32, Textual, TriggerGroups, Include, RHSGroups, Tags,
-Steerable, Never, Always, Recover, Primitives};
+Steerable, Never, Always, Recover, Primitives, CaKernel};
{ExcisionGFs};
diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m
index 0a4003a..e7f3187 100644
--- a/Tools/CodeGen/KrancThorn.m
+++ b/Tools/CodeGen/KrancThorn.m
@@ -29,7 +29,7 @@ BeginPackage["KrancThorn`", {"CodeGen`", "Thorn`",
"MapLookup`", "KrancGroups`", "Differencing`",
"CalculationFunction`", "Errors`", "Helpers`", "CactusBoundary`",
"KrancTensor`", "Param`", "Schedule`", "Interface`", "Kranc`", "Jacobian`",
- "ConservationCalculation`"}];
+ "ConservationCalculation`", "CaKernel`"}];
CreateKrancThorn::usage = "Construct a Kranc thorn";
@@ -95,7 +95,7 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
evolvedODEGroupDefinitions, rhsODEGroupDefinitions, rhsODEGroups,
allParams, boundarySources, reflectionSymmetries,
realParamDefs, intParamDefs,
- pDefs, consCalcs, consCalcsIn, consGroups},
+ pDefs, consCalcs, consCalcsIn, consGroups, cakernel},
(* Parse named arguments *)
@@ -225,6 +225,11 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
Join[rhsGroups,rhsODEGroups], Join[nonevolvedGroups,nonevolvedODEGroups], thornName,
evolutionTimelevels];
+ (* Construct the cakernel file *)
+ If[OptionValue[UseCaKernel],
+ InfoMessage[Terse, "Creating CaKernel file"];
+ cakernel = CaKernelCCL[calcs]];
+
boundarySources = CactusBoundary`GetSources[evolvedGroups, groups,
implementation, thornName];
@@ -287,6 +292,7 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
Interface -> interface,
Schedule -> schedule,
Param -> param,
+ CaKernel -> cakernel,
Makefile -> make,
Sources -> Join[{
{Filename -> "Startup.cc", Contents -> startup},
diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m
index c5e7e42..39ee76a 100644
--- a/Tools/CodeGen/Thorn.m
+++ b/Tools/CodeGen/Thorn.m
@@ -1398,6 +1398,7 @@ CreateThorn[thorn_] :=
GenerateFile[thornDirectory <> "/interface.ccl", lookup[thorn, Interface]];
GenerateFile[thornDirectory <> "/param.ccl", lookup[thorn, Param]];
GenerateFile[thornDirectory <> "/schedule.ccl", lookup[thorn, Schedule]];
+ GenerateFile[thornDirectory <> "/cakernel.ccl", lookup[thorn, CaKernel]];
Map[GenerateFile[sourceDirectory <> "/" <> lookup[#, Filename],
lookup[#, Contents]] &,