Skip to content

Commit

Permalink
- get more precise information with countOperations
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23770 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed Dec 12, 2014
1 parent 3cf7b75 commit d89adcd
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 313 deletions.
22 changes: 22 additions & 0 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -697,5 +697,27 @@ uniontype DifferentiationType "Define the behaviour of differentiation method fo
end GENERIC_GRADIENT;
end DifferentiationType;

public uniontype compInfo"types to count operations for the components"
record COUNTER // single equation
StrongComponent comp;
Integer numAdds;
Integer numMul;
Integer numTrig;
Integer numRelations;
Integer numLog; // logical operations
Integer numOth; // pow,...
Integer funcCalls;
end COUNTER;

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

end compInfo;


annotation(__OpenModelica_Interface="backend");
end BackendDAE;
413 changes: 268 additions & 145 deletions Compiler/BackEnd/BackendDAEOptimize.mo

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -8037,5 +8037,27 @@ algorithm
end matchcontinue;
end getConditionList1;

public function isWhenComp
input BackendDAE.StrongComponent comp;
output Boolean isWhen;
algorithm
isWhen := match(comp)
case(BackendDAE.SINGLEWHENEQUATION())
then true;
else then false;
end match;
end isWhenComp;

public function isSingleEquationComp
input BackendDAE.StrongComponent comp;
output Boolean isWhen;
algorithm
isWhen := match(comp)
case(BackendDAE.SINGLEEQUATION())
then true;
else then false;
end match;
end isSingleEquationComp;

annotation(__OpenModelica_Interface="backend");
end BackendDAEUtil;
26 changes: 26 additions & 0 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -3796,5 +3796,31 @@ algorithm
print(preStr + " NrOfEquations: " + intString(n) + "\n");
end dumpNrOfEquations;

public function dumpCompInfo"dumps the information about the operations in the component"
input BackendDAE.compInfo compInfo;
algorithm
_ := match(compInfo)
local
Integer numAdds,numMul,numOth,numTrig,numRel,numLog,numFuncs, size;
Real dens;
BackendDAE.compInfo allOps;
BackendDAE.StrongComponent comp;
case(BackendDAE.COUNTER(comp=comp,numAdds=numAdds,numMul=numMul,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
print("COUNTER "+printComponent(comp)+"\tadd|"+intString(numAdds)+"\tmul|"+intString(numMul)+"\ttrig|"+intString(numTrig)+"\trel|"+intString(numRel)+"\tlog|"+intString(numLog)+"\toth|"+intString(numOth)+"\tfuncs|"+intString(numFuncs)+"\n");
then ();
case(BackendDAE.LES_ANALYSE(allOperations=allOps,comp=comp,size=size,density=dens))
equation
print("LES_INFO "+printComponent(comp)+"\tsize|"+intString(size)+"\tdens|"+realString(dens)+"\n\t");
dumpCompInfo(allOps);
print("\n");
then ();
else
equation
print("Dont know this compInfo\n");
then ();
end match;
end dumpCompInfo;

annotation(__OpenModelica_Interface="backend");
end BackendDump;
2 changes: 1 addition & 1 deletion Compiler/BackEnd/HpcOmEqSystems.mo
Expand Up @@ -195,7 +195,7 @@ algorithm
comp = listGet(compsIn,compIdx);
BackendDAE.TORNSYSTEM(tearingvars = tvarIdcs, residualequations = resEqIdcs, otherEqnVarTpl = otherEqnVarTpl, linear = linear) = comp;
true = linear;
true = intLe(listLength(tvarIdcs),3);
//true = intLe(listLength(tvarIdcs),3);
print("LINEAR TORN SYSTEM OF SIZE "+intString(listLength(tvarIdcs))+"\n");

// build the new components, the new variables and the new equations
Expand Down
100 changes: 37 additions & 63 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -97,7 +97,6 @@ public uniontype TaskGraphMeta // stores all the metadata for the TaskGraph
end TASKGRAPHMETA;
end TaskGraphMeta; //TODO: Remove rootNodes from structure


//----------------------------------------------------------
// Functions to build the task graph from the BLT structure
//----------------------------------------------------------
Expand Down Expand Up @@ -2937,7 +2936,6 @@ algorithm
print("--------------------------------\n");
print(intString(arrayLength(inComps))+" nodes include components:\n");
printInComps(inComps,1);
/*
print(intString(arrayLength(varCompMapping))+" vars are solved in the nodes \n");
printVarCompMapping(varCompMapping,1);
print(intString(arrayLength(eqCompMapping))+" equations are computed in the nodes \n");
Expand All @@ -2955,7 +2953,6 @@ algorithm
print("the nodeMark of the nodes\n");
printNodeMark(nodeMark,1);
print("\n");
*/
end printTaskGraphMeta;

public function printInComps " prints the information about the assigned components to a taskgraph node.
Expand Down Expand Up @@ -4229,7 +4226,8 @@ algorithm
then tmpTaskGraphMeta;
else
equation
tmpTaskGraphMeta = estimateCosts(iDae,iTaskGraphMeta);
//tmpTaskGraphMeta = estimateCosts(iDae,iTaskGraphMeta);
tmpTaskGraphMeta = iTaskGraphMeta;
print("Warning: The costs have been estimated. Maybe " + benchFilePrefix + "-file is missing.\n");
then tmpTaskGraphMeta;
end matchcontinue;
Expand Down Expand Up @@ -4278,37 +4276,48 @@ author: Waurich TUD 2013-09"
protected
BackendDAE.StrongComponents comps;
BackendDAE.EqSystem eqSys;
list<BackendDAE.compInfo> compsInfos;
algorithm
comps := listGet(compsLstIn,systIdx);
eqSys := listGet(eqSystemsIn,systIdx);
exeCostsOut := List.map2(comps,estimateCosts1,eqSys,sharedIn);
compsInfos := BackendDAEOptimize.countOperationstraverseComps(comps,eqSys,sharedIn,{});
exeCostsOut := List.map(compsInfos,calculateCosts);
end estimateCosts0;

protected function estimateCosts1 " estimates the exeCost for one StrongComponent
author: Waurich TUD 2013-09"
input BackendDAE.StrongComponent compIn;
input BackendDAE.EqSystem eqSysIn;
input BackendDAE.Shared sharedIn;
output tuple<Integer,Real> exeCostOut;
public function calculateCosts "calculates the estimated costs for a compInfo
author: Waurich TUD 2014-12"
input BackendDAE.compInfo compInfo;
output tuple<Integer,Real> exeCost;
algorithm
exeCostOut := matchcontinue(compIn,eqSysIn,sharedIn)
exeCost := match(compInfo)
local
Integer costAdd, costMul, costTrig, numOps;
Real costs;
case(_,_,_)
Integer numAdds,numMul,numOth,numTrig,numRel,numLog,numFuncs, costs, ops, offset,size;
Real allOpCosts,dens;
BackendDAE.StrongComponent comp;
BackendDAE.compInfo allOps;

case(BackendDAE.COUNTER(comp=comp,numAdds=numAdds,numMul=numMul,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
((costAdd,costMul,costTrig)) = countOperations(compIn, eqSysIn, sharedIn);
numOps = costAdd+costMul+costTrig;
costs = realAdd(realMul(intReal(numOps),25.0),70.0); // feel free to change this
then
((numOps,costs));
else
ops = numAdds+numMul+numOth+numTrig+numRel+numLog;
if BackendDAEUtil.isSingleEquationComp(comp) then offset=30;
elseif BackendDAEUtil.isWhenComp(comp) then offset=800;
else offset = 0;
end if;
costs = offset+ 5*numAdds+ 25*numMul+ 150*numOth+250*numTrig+ 5*numRel+ 10*numLog+400*numFuncs;
then (ops,intReal(costs));

case(BackendDAE.LES_ANALYSE(allOperations=allOps,size=size,density=dens))
equation
print("estimateCosts1 failed1\n");
then
fail();
end matchcontinue;
end estimateCosts1;
(ops,allOpCosts) = calculateCosts(allOps);
allOpCosts = 5000+allOpCosts+realMul(realPow(intReal(size),3)+realPow(intReal(size),2),dens);
then (ops,allOpCosts);

else
equation
print("calculate costs failed!\n");
then (-1,-1.0);
end match;
end calculateCosts;

protected function getCommCostsOnly "function to compute the communicationCosts
author: Waurich TUD 2013-09"
Expand Down Expand Up @@ -4577,8 +4586,8 @@ algorithm
syst := arrayGet(compMapping,sccIndex);
reqTime := arrayGet(iRequiredTime, sccIndex);
//print("createExecCost0: Handling scc " + intString(sccIndex) + " with cost " + realString(reqTime) + "\n");
((costAdd,costMul,costTrig)) := countOperations(comp, syst, shared);
oCosts := (costAdd+costMul+costTrig + iCosts_op, realAdd(iCosts_cyc,reqTime));
//((costAdd,costMul,costTrig)) := countOperations(comp, syst, shared);
oCosts := (-100 + iCosts_op, realAdd(iCosts_cyc,reqTime));
end createExecCost0;

protected function createCommCosts "author: marcusw
Expand Down Expand Up @@ -4621,41 +4630,6 @@ algorithm
oComm := COMMUNICATION(numberOfVars,integerVars,floatVars,booleanVars,stringVars,childNode,requiredTime);
end createCommCosts0;

public function countOperations "author: marcusw
Count the operations of the given component."
input BackendDAE.StrongComponent icomp;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
output tuple<Integer,Integer,Integer> operations; //<add,mul,trig>
protected
DAE.ComponentRef cr;
Integer eqnIdx,varIdx;
Integer op1,op2,op3;
BackendDAE.Variables vars;
BackendDAE.Var v;
BackendDAE.EquationArray eqns;
DAE.ElementSource source;
DAE.Exp e1, e2, varexp, exp_;
String s;
algorithm
operations := matchcontinue(icomp,isyst,ishared)
case(BackendDAE.SINGLEEQUATION(eqn=eqnIdx,var=varIdx), BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns), _)
equation
BackendDAE.EQUATION(exp=e1, scalar=e2, source=source) = BackendEquation.equationNth1(eqns, eqnIdx);
(v as BackendDAE.VAR(varName = cr)) = BackendVariable.getVarAt(vars, varIdx);
varexp = Expression.crefExp(cr);
varexp = if BackendVariable.isStateVar(v) then Expression.expDer(varexp) else varexp;
(exp_, _) = ExpressionSolve.solveLin(e1, e2, varexp);
(_,(op1,op2,_,op3)) = BackendDAEOptimize.countOperationsExp(exp_,(0,0,0,0));
then ((op1,op2,op3));
else
equation
((op1,op2,_,op3)) = BackendDAEOptimize.countOperationstraverseComps({icomp},isyst,ishared,(0,0,0,0));
then ((op1,op2,op3));
end matchcontinue;
end countOperations;


//---------------------------------
// Functions to validate the graph
//---------------------------------
Expand Down

0 comments on commit d89adcd

Please sign in to comment.