Skip to content

Commit

Permalink
+ Merging the parallel extensions.
Browse files Browse the repository at this point in the history
  + parallel and kernel functions are handled in the Front-end now. 
  + parallel variables are handled in the Front-end now.
  - some checks and restrictions remain, but nothing that
    affects the normal OM compilation.
  * so far so good. 

+ A fix for operator overloading problem on encapsulated classes with imports. (should have been a separate update)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11224 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Feb 28, 2012
1 parent c081701 commit 307f047
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -1056,6 +1056,8 @@ public
uniontype FunctionRestriction
record FR_NORMAL_FUNCTION "a normal function" end FR_NORMAL_FUNCTION;
record FR_OPERATOR_FUNCTION "an operator function" end FR_OPERATOR_FUNCTION;
record FR_PARALLEL_FUNCTION "an OpenCL/CUDA parallel/device function" end FR_PARALLEL_FUNCTION;
record FR_KERNEL_FUNCTION "an OpenCL/CUDA kernel function" end FR_KERNEL_FUNCTION;
end FunctionRestriction;

public
Expand Down
16 changes: 13 additions & 3 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -884,16 +884,17 @@ public uniontype CodeType
end C_VARIABLENAMES;
end CodeType;

public constant FunctionAttributes FUNCTION_ATTRIBUTES_BUILTIN = FUNCTION_ATTRIBUTES(NO_INLINE(),true,FUNCTION_BUILTIN(NONE()));
public constant FunctionAttributes FUNCTION_ATTRIBUTES_DEFAULT = FUNCTION_ATTRIBUTES(NO_INLINE(),true,FUNCTION_NOT_BUILTIN());
public constant FunctionAttributes FUNCTION_ATTRIBUTES_IMPURE = FUNCTION_ATTRIBUTES(NO_INLINE(),false,FUNCTION_NOT_BUILTIN());
public constant FunctionAttributes FUNCTION_ATTRIBUTES_BUILTIN = FUNCTION_ATTRIBUTES(NO_INLINE(),true,FUNCTION_BUILTIN(NONE()),FP_NON_PARALLEL());
public constant FunctionAttributes FUNCTION_ATTRIBUTES_DEFAULT = FUNCTION_ATTRIBUTES(NO_INLINE(),true,FUNCTION_NOT_BUILTIN(),FP_NON_PARALLEL());
public constant FunctionAttributes FUNCTION_ATTRIBUTES_IMPURE = FUNCTION_ATTRIBUTES(NO_INLINE(),false,FUNCTION_NOT_BUILTIN(),FP_NON_PARALLEL());

public
uniontype FunctionAttributes
record FUNCTION_ATTRIBUTES
InlineType inline;
Boolean isPure;
FunctionBuiltin isBuiltin;
FunctionParallelism functionParallelism;
end FUNCTION_ATTRIBUTES;
end FunctionAttributes;

Expand All @@ -911,6 +912,15 @@ uniontype FunctionBuiltin

end FunctionBuiltin;

//This was a function restriction in SCode and Absyn
//Now it is part of function attributes.
public
uniontype FunctionParallelism
record FP_NON_PARALLEL "a normal function i.e non_parallel" end FP_NON_PARALLEL;
record FP_PARALLEL_FUNCTION "an OpenCL/CUDA parallel/device function" end FP_PARALLEL_FUNCTION;
record FP_KERNEL_FUNCTION "an OpenCL/CUDA kernel function" end FP_KERNEL_FUNCTION;
end FunctionParallelism;

type Dimensions = list<Dimension> "a list of dimensions";

public
Expand Down
16 changes: 15 additions & 1 deletion Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -1370,7 +1370,7 @@ protected function dumpFunction
algorithm
_ := matchcontinue (inElement)
local
String fstr,inlineTypeStr,daestr,str, ext_decl_str;
String fstr,inlineTypeStr,daestr,str, ext_decl_str, parallelism_str;
Absyn.Path fpath;
list<DAE.Element> daeElts;
DAE.Type t;
Expand All @@ -1380,6 +1380,8 @@ algorithm

case DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_DEF(body = daeElts)::_),type_ = t, comment = c)
equation
parallelism_str = dumpParallelismStr(t);
Print.printBuf(parallelism_str);
Print.printBuf("function ");
fstr = Absyn.pathStringNoQual(fpath);
Print.printBuf(fstr);
Expand Down Expand Up @@ -1434,6 +1436,17 @@ algorithm
end matchcontinue;
end dumpFunction;

protected function dumpParallelismStr
input DAE.Type inType;
output String outString;
algorithm
outString := match(inType)
case (DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(_, _, _, DAE.FP_NON_PARALLEL()), _)) then "";
case (DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(_, _, _, DAE.FP_PARALLEL_FUNCTION()), _)) then "parallel ";
case (DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(_, _, _, DAE.FP_KERNEL_FUNCTION()), _)) then "kernel ";
end match;
end dumpParallelismStr;

protected function dumpInlineTypeStr
input DAE.InlineType inlineType;
output String str;
Expand Down Expand Up @@ -3394,6 +3407,7 @@ algorithm

case (DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_DEF(body = daeElts)::_),type_ = t, comment = c), str)
equation
str = IOStream.append(str, dumpParallelismStr(t));
fstr = Absyn.pathStringNoQual(fpath);
str = IOStream.append(str, "function ");
str = IOStream.append(str, fstr);
Expand Down
14 changes: 14 additions & 0 deletions Compiler/FrontEnd/Dump.mo
Expand Up @@ -592,6 +592,8 @@ algorithm
case Absyn.R_PACKAGE() then "package";
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION()) then "function";
case Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION()) then "operator function";
case Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION()) then "parallel function";
case Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION()) then "kernel function";
case Absyn.R_PREDEFINED_INTEGER() then "Integer";
case Absyn.R_PREDEFINED_REAL() then "Real";
case Absyn.R_PREDEFINED_STRING() then "String";
Expand Down Expand Up @@ -884,6 +886,8 @@ algorithm
case Absyn.R_PACKAGE() equation Print.printBuf("Absyn.R_PACKAGE"); then ();
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION)"); then ();
case Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION)"); then ();
case Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION)"); then ();
case Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION)"); then ();
case Absyn.R_ENUMERATION() equation Print.printBuf("Absyn.R_ENUMERATION"); then ();
case Absyn.R_PREDEFINED_INTEGER() equation Print.printBuf("Absyn.R_PREDEFINED_INTEGER"); then ();
case Absyn.R_PREDEFINED_REAL() equation Print.printBuf("Absyn.R_PREDEFINED_REAL"); then ();
Expand Down Expand Up @@ -5733,6 +5737,16 @@ algorithm
Print.printBuf("record Absyn.FR_OPERATOR_FUNCTION end Absyn.FR_OPERATOR_FUNCTION;");
then ();

case Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION())
equation
Print.printBuf("record Absyn.FR_PARALLEL_FUNCTION end Absyn.FR_PARALLEL_FUNCTION;");
then ();

case Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION())
equation
Print.printBuf("record Absyn.FR_KERNEL_FUNCTION end Absyn.FR_KERNEL_FUNCTION;");
then ();

case Absyn.R_OPERATOR()
equation
Print.printBuf("record Absyn.R_OPERATOR end Absyn.R_OPERATOR;");
Expand Down
6 changes: 4 additions & 2 deletions Compiler/FrontEnd/Env.mo
Expand Up @@ -139,6 +139,8 @@ type CSetsType = tuple<list<DAE.ComponentRef>,DAE.ComponentRef>;
public uniontype ScopeType
record FUNCTION_SCOPE end FUNCTION_SCOPE;
record CLASS_SCOPE end CLASS_SCOPE;

record PARALLEL_SCOPE end PARALLEL_SCOPE;
end ScopeType;

public
Expand Down Expand Up @@ -2456,9 +2458,9 @@ public function restrictionToScopeType
output Option<ScopeType> outType;
algorithm
outType := matchcontinue(inRestriction)
case SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION()) then SOME(PARALLEL_SCOPE());
case SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION()) then SOME(PARALLEL_SCOPE());
case SCode.R_FUNCTION(_) then SOME(FUNCTION_SCOPE());
// case SCode.R_EXT_FUNCTION() then SOME(FUNCTION_SCOPE());
// case SCode.R_OPERATOR_FUNCTION() then SOME(FUNCTION_SCOPE());
case _ then SOME(CLASS_SCOPE());
end matchcontinue;
end restrictionToScopeType;
Expand Down
13 changes: 11 additions & 2 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -17312,13 +17312,22 @@ algorithm
name = SCode.isBuiltinFunction(cl,List.map(inVars,Types.varName),List.map(outVars,Types.varName));
inlineType = isInlineFunc2(cl);
purity = not SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_Impure");
then (DAE.FUNCTION_ATTRIBUTES(inlineType,purity,DAE.FUNCTION_BUILTIN(SOME(name))));
then (DAE.FUNCTION_ATTRIBUTES(inlineType,purity,DAE.FUNCTION_BUILTIN(SOME(name)),DAE.FP_NON_PARALLEL()));

//parallel functions: never builtin and never inlined.
case (SCode.CLASS(restriction=SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION())),_)
then DAE.FUNCTION_ATTRIBUTES(DAE.NO_INLINE(),true,DAE.FUNCTION_NOT_BUILTIN(),DAE.FP_PARALLEL_FUNCTION());

//kernel functions: never builtin and never inlined.
case (SCode.CLASS(restriction=SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION())),_)
then DAE.FUNCTION_ATTRIBUTES(DAE.NO_INLINE(),true,DAE.FUNCTION_NOT_BUILTIN(),DAE.FP_KERNEL_FUNCTION());

case (SCode.CLASS(restriction=restriction),_)
equation
inlineType = isInlineFunc2(cl);
isBuiltin = Util.if_(SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_BuiltinPtr"), DAE.FUNCTION_BUILTIN_PTR(), DAE.FUNCTION_NOT_BUILTIN());
purity = not SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_Impure");
then DAE.FUNCTION_ATTRIBUTES(inlineType,purity,isBuiltin);
then DAE.FUNCTION_ATTRIBUTES(inlineType,purity,isBuiltin,DAE.FP_NON_PARALLEL());
end matchcontinue;
end getFunctionAttributes;

Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -100,6 +100,8 @@ uniontype FunctionRestriction
record FR_OPERATOR_FUNCTION "an operator function" end FR_OPERATOR_FUNCTION;
record FR_EXTERNAL_FUNCTION "an external function" end FR_EXTERNAL_FUNCTION;
record FR_RECORD_CONSTRUCTOR "record constructor" end FR_RECORD_CONSTRUCTOR;
record FR_PARALLEL_FUNCTION "an OpenCL/CUDA parallel/device function" end FR_PARALLEL_FUNCTION;
record FR_KERNEL_FUNCTION "an OpenCL/CUDA kernel function" end FR_KERNEL_FUNCTION;
end FunctionRestriction;

public
Expand Down Expand Up @@ -1135,6 +1137,9 @@ algorithm
case (FR_NORMAL_FUNCTION(),FR_NORMAL_FUNCTION()) then true;
case (FR_EXTERNAL_FUNCTION(),FR_EXTERNAL_FUNCTION()) then true;
case (FR_OPERATOR_FUNCTION(),FR_OPERATOR_FUNCTION()) then true;
case (FR_RECORD_CONSTRUCTOR(),FR_RECORD_CONSTRUCTOR()) then true;
case (FR_PARALLEL_FUNCTION(),FR_PARALLEL_FUNCTION()) then true;
case (FR_KERNEL_FUNCTION(),FR_KERNEL_FUNCTION()) then true;
else false;
end match;
end funcRestrictionEqual;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/SCodeDump.mo
Expand Up @@ -90,6 +90,8 @@ algorithm
case SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()) then "OPERATOR_FUNCTION";
case SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION()) then "EXTERNAL_FUNCTION";
case SCode.R_FUNCTION(SCode.FR_RECORD_CONSTRUCTOR()) then "RECORD_CONSTRUCTOR";
case SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION()) then "PARALLEL FUNCTION";
case SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION()) then "KERNEL_FUNCTION";
case SCode.R_OPERATOR_RECORD() then "OPERATOR_RECORD";
case SCode.R_TYPE() then "TYPE";
case SCode.R_PACKAGE() then "PACKAGE";
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/SCodeFlatDump.mo
Expand Up @@ -457,6 +457,8 @@ algorithm
case SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()) then "OF";
case SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION()) then "EF";
case SCode.R_FUNCTION(SCode.FR_RECORD_CONSTRUCTOR()) then "RC";
case SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION()) then "PF";
case SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION()) then "KF";
case SCode.R_ENUMERATION() then "EN";
case SCode.R_PREDEFINED_INTEGER() then "Ti";
case SCode.R_PREDEFINED_REAL() then "Tr";
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -313,6 +313,8 @@ algorithm
then Util.if_(containsExternalFuncDecl(d), SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION()) ,SCode.R_FUNCTION(SCode.FR_NORMAL_FUNCTION()));

case (_,Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION())) then SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION());
case (_,Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION())) then SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION());
case (_,Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION())) then SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION());

case (_,Absyn.R_CLASS()) then SCode.R_CLASS();
case (_,Absyn.R_OPTIMIZATION()) then SCode.R_OPTIMIZATION();
Expand Down

0 comments on commit 307f047

Please sign in to comment.