Skip to content

Commit

Permalink
- estimate execution costs for removedEquations as well
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25554 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed Apr 15, 2015
1 parent 4960dab commit 0bbced2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
21 changes: 16 additions & 5 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -708,7 +708,7 @@ uniontype DifferentiationType "Define the behaviour of differentiation method fo
end GENERIC_GRADIENT;
end DifferentiationType;

public uniontype compInfo"types to count operations for the components"
public uniontype CompInfo"types to count operations for the components"
record COUNTER // single equation
StrongComponent comp;
Integer numAdds;
Expand All @@ -723,19 +723,30 @@ public uniontype compInfo"types to count operations for the components"

record SYSTEM//linear system of equations
StrongComponent comp;
compInfo allOperations;
CompInfo allOperations;
Integer size;
Real density;
end SYSTEM;

record TORN_ANALYSE//torn system of equations
StrongComponent comp;
compInfo tornEqs;
compInfo otherEqs;
CompInfo tornEqs;
CompInfo otherEqs;
Integer tornSize;
end TORN_ANALYSE;

record NO_COMP // assert...
Integer numAdds;
Integer numMul;
Integer numDiv;
Integer numTrig;
Integer numRelations;
Integer numLog; // logical operations
Integer numOth; // pow,...
Integer funcCalls;
end NO_COMP;

end compInfo;
end CompInfo;


annotation(__OpenModelica_Interface="backend");
Expand Down
12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1818,7 +1818,7 @@ protected function countOperations0 "author: Frenkel TUD 2011-05"
output BackendDAE.Shared outShared = inShared;
output Boolean outChanged = inChanged;
protected
list<BackendDAE.compInfo> compInfos;
list<BackendDAE.CompInfo> compInfos;
BackendDAE.StrongComponents comps;
algorithm
BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps)) := isyst;
Expand All @@ -1829,8 +1829,8 @@ public function countOperationstraverseComps "author: Frenkel TUD 2012-05"
input BackendDAE.StrongComponents inComps;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input list<BackendDAE.compInfo> compInfosIn;
output list<BackendDAE.compInfo> compInfosOut;
input list<BackendDAE.CompInfo> compInfosIn;
output list<BackendDAE.CompInfo> compInfosOut;
algorithm
compInfosOut := matchcontinue (inComps,isyst,ishared,compInfosIn)
local
Expand All @@ -1842,7 +1842,7 @@ algorithm
BackendDAE.EquationArray eqns;
BackendDAE.Variables vars;
BackendDAE.Equation eqn;
BackendDAE.compInfo compInfo, allOps, torn,other;
BackendDAE.CompInfo compInfo, allOps, torn,other;
list<BackendDAE.Equation> eqnlst;
BackendDAE.Jacobian jac;
DAE.FunctionTree funcs;
Expand Down Expand Up @@ -1998,8 +1998,8 @@ end getNumJacEntries;
protected function countOperationsJac
input BackendDAE.Jacobian inJac;
input BackendDAE.Shared shared;
input BackendDAE.compInfo compInfoIn;
output BackendDAE.compInfo compInfoOut;
input BackendDAE.CompInfo compInfoIn;
output BackendDAE.CompInfo compInfoOut;
algorithm
compInfoOut := match(inJac,shared,compInfoIn)
local
Expand Down
11 changes: 8 additions & 3 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -3526,21 +3526,21 @@ end dumpNrOfEquations;

public function dumpCompInfo"dumps the information about the operations in the component.
author Waurich TUD 2014-04"
input BackendDAE.compInfo compInfo;
input BackendDAE.CompInfo compInfo;
algorithm
print(printCompInfo(compInfo));
end dumpCompInfo;

protected function printCompInfo""
input BackendDAE.compInfo compInfo;
input BackendDAE.CompInfo compInfo;
output String sOut;
algorithm
sOut := matchcontinue(compInfo)
local
Integer numAdds,numMul,numDiv,numOth,numTrig,numRel,numLog,numFuncs, size;
Real dens;
String s;
BackendDAE.compInfo allOps, tornEqs ,otherEqs;
BackendDAE.CompInfo allOps, tornEqs ,otherEqs;
BackendDAE.StrongComponent comp;
case(BackendDAE.COUNTER(comp=comp,numAdds=numAdds,numMul=numMul,numDiv=numDiv,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
Expand All @@ -3566,6 +3566,11 @@ algorithm
s = s + "\tthe torn eqs:\t"+ printCompInfo(tornEqs);
s = s + "\tthe other eqs:\t" + printCompInfo(otherEqs);
then s;
case(BackendDAE.NO_COMP(numAdds=numAdds,numMul=numMul,numDiv=numDiv,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
s = "NC";
s = s+"\tadd|"+intString(numAdds)+"\tmul|"+intString(numMul)+"\tdiv|"+intString(numDiv)+"\ttrig|"+intString(numTrig)+"\trel|"+intString(numRel)+"\tlog|"+intString(numLog)+"\toth|"+intString(numOth)+"\tfuncs|"+intString(numFuncs)+"\n";
then s;
else
then "Dont know this compInfo\n";
end matchcontinue;
Expand Down
33 changes: 28 additions & 5 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -4414,7 +4414,7 @@ author: Waurich TUD 2013-09"
protected
BackendDAE.StrongComponents comps;
BackendDAE.EqSystem eqSys;
list<BackendDAE.compInfo> compsInfos;
list<BackendDAE.CompInfo> compsInfos;
algorithm
comps := listGet(compsLstIn,systIdx);
eqSys := listGet(eqSystemsIn,systIdx);
Expand All @@ -4424,15 +4424,15 @@ end estimateCosts0;

public function calculateCosts "calculates the estimated costs for a compInfo. this has been benchmarked using the Cpp runtime
author: Waurich TUD 2014-12"
input BackendDAE.compInfo compInfo;
input BackendDAE.CompInfo compInfo;
output tuple<Integer,Real> exeCost;
algorithm
exeCost := matchcontinue(compInfo)
local
Integer numAdds,numMul,numDiv,numOth,numTrig,numRel,numLog,numFuncs, costs, ops,ops1, offset,size;
Real allOpCosts,tornCosts,otherCosts,dens;
BackendDAE.StrongComponent comp;
BackendDAE.compInfo allOps, torn, other;
BackendDAE.CompInfo allOps, torn, other;

case(BackendDAE.COUNTER(comp=comp,numAdds=numAdds,numMul=numMul,numDiv=numDiv,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
Expand All @@ -4457,6 +4457,13 @@ algorithm
allOpCosts = realAdd(realAdd(3000.0,realMul(7.62,realPow(intReal(size),3.0))),realAdd(realMul(2.0,tornCosts),realMul(1.4,otherCosts)));
then (ops+ops1,allOpCosts);

case(BackendDAE.NO_COMP(numAdds=numAdds,numMul=numMul,numDiv=numDiv,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
ops = numAdds+numMul+numOth+numTrig+numRel+numLog;
offset = 50; // this was just estimated, not benchmarked
costs = offset + 12*numAdds + 32*numMul + 37*numDiv + 236*numTrig + 2*numRel + 4*numLog + 110*numOth + 375*numFuncs;
then (ops,intReal(costs));

else
equation
print("calculate costs failed!\n");
Expand Down Expand Up @@ -5776,6 +5783,7 @@ algorithm
TaskGraph graph;
TaskGraphMeta graphData;
BackendDAE.EquationArray remEqs;
BackendDAE.Shared shared;
list<BackendDAE.Equation> eqLst;
list<list<DAE.ComponentRef>> crefsLst;
list<tuple<Integer,Integer>> tplLst;
Expand All @@ -5791,7 +5799,8 @@ algorithm
array<ComponentInfo> compInformations1, compInformations2;
case(_,_,_)
equation
BackendDAE.DAE(shared = BackendDAE.SHARED(removedEqs=remEqs)) = dae;
BackendDAE.DAE(shared = shared) = dae;
BackendDAE.SHARED(removedEqs=remEqs) = shared;
TASKGRAPHMETA(varCompMapping=varCompMap) = graphDataIn;
eqLst = BackendEquation.equationList(remEqs);
numNewComps = listLength(eqLst);
Expand All @@ -5811,7 +5820,7 @@ algorithm
compNames2 = arrayCreate(numNewComps,"assert");
compDescs2 = listArray(List.map(eqLst,BackendDump.equationString));
nodeMark2 = arrayCreate(numNewComps,-2);
exeCosts2 = arrayCreate(numNewComps,(1,30.0)); //TODO: Estimate them correctly!
exeCosts2 = listArray(List.map1(eqLst,estimateEquationCosts,shared));
compInformations2 = arrayCreate(numNewComps, COMPONENTINFO(false, false, true));
inComps1 = arrayAppend(inComps1,inComps2);
compNames1 = arrayAppend(compNames1,compNames2);
Expand All @@ -5826,6 +5835,20 @@ algorithm
end matchcontinue;
end appendRemovedEquations;

protected function estimateEquationCosts"estimates costs for equations.
author: Waurich TUD 2015-04"
input BackendDAE.Equation eqIn;
input BackendDAE.Shared sharedIn;
output tuple<Integer,Real> tplOut; //<Operations,Costs>
protected
Integer numAdd,numMul,numDiv,numTrig,numRel,numOth, numFuncs, numLog;
BackendDAE.CompInfo compInfo;
algorithm
(_,(numAdd,numMul,numDiv,numTrig,numRel,numLog,numOth,numFuncs)) := BackendEquation.traverseExpsOfEquation(eqIn,function BackendDAEOptimize.countOperationsExp(shared=sharedIn),(0,0,0,0,0,0,0,0));
compInfo := BackendDAE.NO_COMP(numAdd,numMul,numDiv,numTrig,numRel,numLog,numOth,numFuncs);
tplOut := calculateCosts(compInfo);
end estimateEquationCosts;

protected function printNodeVars
input list<tuple<Integer,Integer>> nodes;
output String s;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/SimCode/HpcOmSimCodeMain.mo
Expand Up @@ -1395,7 +1395,7 @@ algorithm
local
Real exeCost, estimate;
list<Real> restCosts;
BackendDAE.compInfo compInfo;
BackendDAE.CompInfo compInfo;
BackendDAE.EqSystem eqSys;
BackendDAE.StrongComponent comp;
list<BackendDAE.EqSystem> eqSysRest;
Expand Down

0 comments on commit 0bbced2

Please sign in to comment.