Skip to content

Commit

Permalink
Chemora: Better literals. New assign_from_func.
Browse files Browse the repository at this point in the history
 Remove special ChemoraNLiteral type.
 Put literals in source list, they no longer use a special "assign_from" call.
 Identify Identity operations (RHS does not have an operator or function).
 Emit new "assign_from_func" (which counts arith operators as funcs).
 Don't emit differencing operators separately. (Remove chemoraCDifferenceOp.
  • Loading branch information
dmkoppelman committed Jun 26, 2015
1 parent 5f87a03 commit 581c053
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 43 deletions.
57 changes: 17 additions & 40 deletions Tools/CodeGen/CodeGenCalculation.m
Expand Up @@ -318,7 +318,8 @@ General Utility Functions (could be moved outside this package)
Parameter[a_] -> a
};

chemoraCountOperations[ChemoraNLiteral[expr_]]:= chemoraQuote["Literal"];
chemoraCountOperations[expr:(_String|_Symbol)]:=chemoraQuote["Identity"];
chemoraCountOperations[expr_?NumberQ]:= chemoraQuote["Literal"];

chemoraCountOperations[expr_]:=
Module[ { opInfoRaw, opInfo },
Expand Down Expand Up @@ -362,6 +363,12 @@ General Utility Functions (could be moved outside this package)
chemoraGenerateQuotedExpr[expr_,vectorise_] :=
"\"" <> GenerateCodeFromExpression[expr,vectorise] <> "\""

chemoraQuoteArgument[Parameter[n_]]:= chemoraQuoteArgument[n]
chemoraQuoteArgument[n_?NumberQ]:= "\"=" <> ToString[CForm[n]] <> "\""
chemoraQuoteArgument[n_]:= "\"" <> ToString[n] <> "\""
chemoraQuoteArguments[args_List]:=
StringJoin[ chemoraQuoteArgument[#] <> ", " & /@ args ]

chemoraExpandRulesSeqNum = 1;

chemoraExpandRules =
Expand All @@ -374,12 +381,6 @@ General Utility Functions (could be moved outside this package)
],
Rule[lhs_, chemoraIfElse[Parameter[cond_],rest___]] :>
lhs -> chemoraIfElse[cond,rest],
Rule[lhs_, h1_?(Not[MemberQ[{ChemoraNLiteral},#]]&)
[op1___, h2_?(NumberQ), op3___]] :>
Sequence@@Module[{lhs2, seq = chemoraExpandRulesSeqNum++},
lhs2 = Symbol[ ToString[lhs] <> "xLiteralx" <> ToString[seq] ];
{ lhs2 -> ChemoraNLiteral[h2],
lhs -> h1[op1,lhs2,op3] }],
Rule[lhs_, h1_[op1___,
h2_String?(StringMatchQ[#,RegularExpression["^KRANC.*"]]&),
op3___]] :>
Expand Down Expand Up @@ -423,12 +424,14 @@ General Utility Functions (could be moved outside this package)
<> chemoraQuote[dk]
<> ");\n"];

chemoraCExpressionEQstr[lhs_->ChemoraNLiteral[val_]]:=
Module[{},
" assign_from_expr("
chemoraCExpressionEQstr[lhs_->fn_[operands__]]:=
Module[{},
" assign_from_func("
<> chemoraQuote[lhs] <> ", "
<> chemoraQuote["Literal"] <> ", "
<> chemoraQuote[CForm[val]] <> ", NULL);\n"];
<> chemoraQuote[fn] <> ", "
<> chemoraGenerateQuotedExpr[fn[operands],False] <> ", "
<> chemoraQuoteArguments[{operands}]
<> "NULL );\n"];

chemoraCExpressionEQstr[lhs_->rhs_]:=
Module[{},
Expand All @@ -437,10 +440,8 @@ General Utility Functions (could be moved outside this package)
<> chemoraCountOperations[rhs] <> ", "
<> chemoraGenerateQuotedExpr[rhs,False]
<> ", "
<> StringJoin[
chemoraQuote[#] <> ", " &
/@ chemoraCalculationExpressionVariables[rhs] ]
<> "NULL );\n"];
<> chemoraQuoteArgument[rhs]
<> ", NULL );\n"];

chemoraCExpressionEQ[c_,lhs_->rhs_]:=
mapRefAppend[c,ChemoraContents,chemoraCExpressionEQstr[lhs->rhs]]
Expand All @@ -453,29 +454,6 @@ General Utility Functions (could be moved outside this package)
<> chemoraQuote[ip] <> ", "
<> chemoraQuote[ep] <> ");\n"];

chemoraCDifferenceOp[opNameBase_[u_,ind___] -> rhs_ ]:=
Module[{offsetsAndVars = chemoraDExpressionInfo[rhs],
offsets,offsetVars,
opName = ToString[opNameBase] <> StringJoin[ ToString /@ {ind} ] },
{offsetVars,offsets} = offsetsAndVars;
" set_differencing_op("
<> chemoraQuote[opName] <> ", "
<> chemoraCountOperations[rhs] <> ", "
<> chemoraGenerateQuotedExpr[rhs,False] <> ", "
<> StringJoin[
chemoraQuote[#] <> ", " &
/@ Union[ offsetVars,
chemoraCalculationExpressionVariablesDO[rhs]]]
<> "NULL, "
<> ToString[Length[offsets]]
<> StringJoin[","<>ToString[#]& /@ Flatten[offsets]]
<> ");\n"];

(* Called from KrancThorn.m:CreateKrancThorn *)
chemoraCDifferenceOps[] :=
StringJoin[
chemoraCDifferenceOp[#] & /@ ( Flatten @@ $DifferencingMacroExpansions ) ];

chemoraCSimpleExpression[c_, lhs_ -> rhs_ ]:=
Module[ { localName = ToString[lhs] <> "xxxL", diffOp, gf },
{diffOp,gf} =
Expand Down Expand Up @@ -914,7 +892,6 @@ it is only possible to do this outside all if(){} statements. *)
StringJoin[ " assign_from_gf_load("
<> chemoraQuote[localName[#]] <> ", "
<> chemoraQuote[#]
<> ", NULL"
<> ");\n" &
/@ gfsInRHS ]];

Expand Down
2 changes: 0 additions & 2 deletions Tools/CodeGen/Kranc.m
Expand Up @@ -171,9 +171,7 @@
(* Chemora Symobls *)

chemoraQuote;
chemoraCDifferenceOps;

ChemoraNLiteral;
ChemoraNDO;
ChemoraNOffset;

Expand Down
1 change: 0 additions & 1 deletion Tools/CodeGen/KrancThorn.m
Expand Up @@ -411,7 +411,6 @@ Thorn generation (main entry point for non-tensorial thorns)
<> "{\n"
<> " CHEMORA_CG_KRANC_INIT_THORN_START("
<> chemoraQuote[thornName] <> ");\n"
<> chemoraCDifferenceOps[]
<> StringJoin[ Map[
"\n\n CHEMORA_CG_KRANC_INIT_THORN_KERNEL("
<> chemoraQuote[lookup[#,Name]] <> ");\n"
Expand Down

0 comments on commit 581c053

Please sign in to comment.