Skip to content

Commit

Permalink
- Fix #3335 and #3336
Browse files Browse the repository at this point in the history
  - Update assert defines
  - Fix boxed function issues for functions with parallel variables.
  - Fix arg types for parallel arguments
  • Loading branch information
mahge authored and OpenModelica-Hudson committed Aug 31, 2015
1 parent 010b686 commit e747152
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
39 changes: 39 additions & 0 deletions Compiler/SimCode/SimCodeFunctionUtil.mo
Expand Up @@ -1086,6 +1086,45 @@ algorithm
end match;
end isBoxedArg;

public function funcHasParallelInOutArrays
"checks if a boxed function can be generated.
currently this is not the case if the input/output
involves parallel (global/local) array variables."
input SimCode.Function fn;
output Boolean b;
protected
list<SimCode.Variable> inVars, outVars;
algorithm
SimCode.FUNCTION(functionArguments = inVars, outVars = outVars) := fn;
for e in inVars loop
if isParallelArrayVar(e) then
b := true;
return;
end if;
end for;

for e in outVars loop
if isParallelArrayVar(e) then
b := true;
return;
end if;
end for;

b := false;
end funcHasParallelInOutArrays;

protected function isParallelArrayVar
"Checks if a variable is a boxed datatype"
input SimCode.Variable var;
output Boolean b;
algorithm
b := match var
case SimCode.VARIABLE(ty = DAE.T_ARRAY(), parallelism = DAE.PARGLOBAL()) then true;
case SimCode.VARIABLE(ty = DAE.T_ARRAY(), parallelism = DAE.PARLOCAL()) then true;
else false;
end match;
end isParallelArrayVar;

public function findLiterals
"Finds all literal expressions in functions"
input list<DAE.Function> fns;
Expand Down
15 changes: 12 additions & 3 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -319,7 +319,7 @@ template functionHeader(Function fn, Boolean inFunc, Boolean isSimulation, Text
case FUNCTION(__) then
<<
<%functionHeaderNormal(underscorePath(name), functionArguments, outVars, inFunc, visibility, false, isSimulation, staticPrototypes)%>
<%functionHeaderBoxed(underscorePath(name), functionArguments, outVars, inFunc, isBoxedFunction(fn), visibility, false, isSimulation, staticPrototypes)%>
<%if not funcHasParallelInOutArrays(fn) then functionHeaderBoxed(underscorePath(name), functionArguments, outVars, inFunc, isBoxedFunction(fn), visibility, false, isSimulation, staticPrototypes)%>
>>
case KERNEL_FUNCTION(__) then
<<
Expand Down Expand Up @@ -983,7 +983,7 @@ case FUNCTION(__) then
/* Needs to be done last as it messes with the tmp ticks :) */
let &varDecls += addRootsTempArray()

let boxedFn = functionBodyBoxed(fn, isSimulation)
let boxedFn = if not funcHasParallelInOutArrays(fn) then functionBodyBoxed(fn, isSimulation) else ""
<<
<%auxFunction%>
<% match visibility case PUBLIC(__) then "DLLExport" %>
Expand Down Expand Up @@ -1510,6 +1510,10 @@ end boxRecordConstructor;
template funArgUnbox(Variable var, Text &varDecls, Text &varBox, Text &auxFunction)
::=
match var
case VARIABLE(ty=T_ARRAY(__), parallelism = PARGLOBAL(__)) then
error(sourceInfo(), 'Trying to generate a boxed function with non protected parglobal array.')
case VARIABLE(ty=T_ARRAY(__), parallelism = PARLOCAL(__)) then
error(sourceInfo(), 'Trying to generate a boxed function with non protected parlocal array.')
case VARIABLE(__) then
let varName = contextCref(name,contextFunction,&auxFunction)
unboxVariable(varName, ty, &varBox, &varDecls)
Expand Down Expand Up @@ -1756,7 +1760,7 @@ case var as VARIABLE(parallelism = PARGLOBAL(__)) then
let defaultValue = varAllocDefaultValue(var, outStruct, varName, defaultAlloc, &varDecls, &varInits, &auxFunction)
let &varInits += defaultValue

let &varFrees += 'free_device_array(&<%varName%>);<%\n%>'
// let &varFrees += 'free_device_array(&<%varName%>);<%\n%>'
""
else
(match var.value
Expand Down Expand Up @@ -3426,18 +3430,23 @@ end literalExpConstArrayVal;

template varType(Variable var)
"Generates type for a variable."
// TODO: mahge: rewrite from here downstream
::=
match var
case var as VARIABLE(parallelism = NON_PARALLEL()) then
if instDims then
expTypeArray(var.ty)
else
expTypeArrayIf(var.ty)
case var as VARIABLE(ty=T_ARRAY(__), parallelism = PARGLOBAL(__)) then
'device_<%expTypeArray(var.ty)%>'
case var as VARIABLE(parallelism = PARGLOBAL()) then
if instDims then
'device_<%expTypeArray(var.ty)%>'
else
'<%expTypeArrayIf(var.ty)%>'
case var as VARIABLE(ty=T_ARRAY(__), parallelism = PARLOCAL(__)) then
'device_local_<%expTypeArray(var.ty)%>'
case var as VARIABLE(parallelism = PARLOCAL()) then
if instDims then
'device_local_<%expTypeArray(var.ty)%>'
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -934,6 +934,11 @@ package SimCodeFunctionUtil
output Boolean b;
end isBoxedFunction;

function funcHasParallelInOutArrays
input SimCode.Function fn;
output Boolean b;
end funcHasParallelInOutArrays;

function incrementInt
input Integer inInt;
input Integer increment;
Expand Down
Expand Up @@ -56,10 +56,14 @@
#endif

#ifdef PRINTF_AVAILABLE
#define omc_assert(i,s) (printf("Assertion: %s\n File %s, Line %d\n", s, __LINE__, i))
#define omc_assert(td,i,s) (printf("Assertion: %s, Line %d, info %d\n", s, __LINE__, i))
#define omc_assert_withEquationIndexes(td,i,idx,s) (printf("Assertion: %s, Line %d, info %d\n", s, __LINE__, i))
#define throwStreamPrint(td,str,exp) (printf("Assertion: %s\n, expression %s, Line %d\n", str, exp, __LINE__))
#define printline() printf("At line %d\n", __LINE__)
#else
#define omc_assert(i,s)
#define omc_assert(td,i,s)
#define omc_assert_withEquationIndexes(td,i,idx,s)
#define throwStreamPrint(td,str,exp)
#define printline()
#endif

Expand All @@ -75,6 +79,8 @@


#define FILE_INFO modelica_integer
#define threadData_t integer
#define threadData NULL
#define omc_dummyFileInfo __LINE__

#define sin(v,m) (sin(v))
Expand Down

0 comments on commit e747152

Please sign in to comment.