Skip to content

Commit dd75640

Browse files
author
Marcus Walther
committed
- measureTime of CPP-Runtime produces a valid json-file now
- the hpcom json file reader will now exit correctly if the json file is invalid - fixed a bug in HPCOM-TaskGraph -- the execcosts of the nodes are correctly mapped to the json-file-values - moved execstat measure commands to the correct locations git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22285 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent ef99e6c commit dd75640

File tree

4 files changed

+67
-43
lines changed

4 files changed

+67
-43
lines changed

Compiler/BackEnd/HpcOmSimCodeMain.mo

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,40 +208,30 @@ algorithm
208208

209209
//dumpSimEqSCCMapping(simeqCompMapping);
210210
//dumpSccSimEqMapping(sccSimEqMapping);
211-
212-
213-
//Create TaskGraph for all strongly connected components
214-
//------------------------------------------------------
215-
(taskGraph,taskGraphData) = HpcOmTaskGraph.createTaskGraph(inBackendDAE,filenamePrefix);
216-
217-
218-
//Create Costs
219-
//------------
220-
taskGraphData = HpcOmTaskGraph.createCosts(inBackendDAE, filenamePrefix +& "_eqs_prof" , simeqCompMapping, taskGraphData);
221-
SimCodeUtil.execStat("hpcom create costs");
222-
223-
fileName = ("taskGraph"+&filenamePrefix+&".graphml");
224-
schedulerInfo = arrayCreate(arrayLength(taskGraph), (-1,-1,-1.0));
225-
HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraph, taskGraphData,inBackendDAE, fileName, "", {}, {}, sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,true,true));
226211
SimCodeUtil.execStat("hpcom setup");
227212

228-
229213
//print("DAE_onlySCCs\n");
230214
//HpcOmTaskGraph.printTaskGraph(taskGraph);
231215
//HpcOmTaskGraph.printTaskGraphMeta(taskGraphData);
232216

233217

234218
//Get complete DAE System
235219
//-----------------------
236-
taskGraphDAE = arrayCopy(taskGraph);
237-
taskGraphDataDAE = HpcOmTaskGraph.copyTaskGraphMeta(taskGraphData);
238-
(taskGraphDAE,taskGraphDataDAE) = HpcOmTaskGraph.appendRemovedEquations(inBackendDAE,taskGraphDAE,taskGraphDataDAE);
239-
240-
fileName = ("taskGraph"+&filenamePrefix+&"DAE.graphml");
241-
daeSccMapping = listArray(List.map(SimCodeUtil.getRemovedEquationSimEqSysIdxes(simCode),List.create));
242-
daeSccMapping = Util.arrayAppend(sccSimEqMapping,daeSccMapping);
243-
schedulerInfo = arrayCreate(arrayLength(taskGraphDAE), (-1,-1,-1.0));
244-
HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphDAE, taskGraphDataDAE,inBackendDAE, fileName, "", {}, {}, daeSccMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,true,true));
220+
(taskGraph,taskGraphData) = HpcOmTaskGraph.createTaskGraph(inBackendDAE,filenamePrefix);
221+
222+
fileName = ("taskGraph"+&filenamePrefix+&".graphml");
223+
schedulerInfo = arrayCreate(arrayLength(taskGraph), (-1,-1,-1.0));
224+
HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraph, taskGraphData,inBackendDAE, fileName, "", {}, {}, sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,true,true));
225+
226+
//taskGraphDAE = arrayCopy(taskGraph);
227+
//taskGraphDataDAE = HpcOmTaskGraph.copyTaskGraphMeta(taskGraphData);
228+
//(taskGraphDAE,taskGraphDataDAE) = HpcOmTaskGraph.appendRemovedEquations(inBackendDAE,taskGraphDAE,taskGraphDataDAE);
229+
230+
//fileName = ("taskGraph"+&filenamePrefix+&"DAE.graphml");
231+
//daeSccMapping = listArray(List.map(SimCodeUtil.getRemovedEquationSimEqSysIdxes(simCode),List.create));
232+
//daeSccMapping = Util.arrayAppend(sccSimEqMapping,daeSccMapping);
233+
//schedulerInfo = arrayCreate(arrayLength(taskGraphDAE), (-1,-1,-1.0));
234+
//HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphDAE, taskGraphDataDAE,inBackendDAE, fileName, "", {}, {}, daeSccMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,true,true));
245235
SimCodeUtil.execStat("hpcom create and dump DAE TaskGraph");
246236

247237
//print("DAE\n");
@@ -263,6 +253,10 @@ algorithm
263253
HpcOmSimCode.TASKDEPSCHEDULE(tasks=eventSystemTasks) = HpcOmScheduler.createTaskDepSchedule(taskGraphEvent, taskGraphDataEvent, sccSimEqMapping);
264254
eventSystemTaskList = List.map(eventSystemTasks, Util.tuple21);
265255

256+
//Create Costs
257+
//------------
258+
taskGraphData = HpcOmTaskGraph.createCosts(inBackendDAE, filenamePrefix +& "_eqs_prof" , simeqCompMapping, taskGraphData);
259+
SimCodeUtil.execStat("hpcom create costs");
266260

267261
//Get ODE System
268262
//--------------

Compiler/BackEnd/HpcOmTaskGraph.mo

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,7 +4086,7 @@ protected
40864086
tuple<Integer,Integer> reqTimeCom;
40874087
//These mappings are for simEqSystems
40884088
list<tuple<Integer,Integer,Real>> reqTimeOpLstSimCode; //<simEqIdx,numberOfCalcs,calcTimeSum>
4089-
array<tuple<Integer,Real>> reqTimeOpSimCode;
4089+
array<tuple<Integer,Real>> reqTimeOpSimCode; //<simEqIdx,calcTime>
40904090
TaskGraphMeta tmpTaskGraphMeta;
40914091
array<Real> reqTimeOp; //Calculation time for each scc
40924092
array<list<Integer>> inComps;
@@ -4099,10 +4099,13 @@ algorithm
40994099
compMapping = Util.arrayMap(compMapping_withIdx, Util.tuple21);
41004100
((_,reqTimeCom)) = HpcOmBenchmark.benchSystem();
41014101
reqTimeOpLstSimCode = HpcOmBenchmark.readCalcTimesFromFile(benchFilePrefix);
4102+
//print("createCosts: read files\n");
41024103
reqTimeOpSimCode = arrayCreate(listLength(reqTimeOpLstSimCode),(-1,-1.0));
41034104
reqTimeOpSimCode = List.fold(reqTimeOpLstSimCode, createCosts1, reqTimeOpSimCode);
4105+
//print("createCosts: reqTimeOpSimCode created\n");
41044106
reqTimeOp = arrayCreate(listLength(comps),-1.0);
41054107
reqTimeOp = convertSimEqToSccCosts(reqTimeOpSimCode, simeqCompMapping, reqTimeOp);
4108+
//print("createCosts: scc costs converted\n");
41064109
commCosts = createCommCosts(commCosts,1,reqTimeCom);
41074110
((_,tmpTaskGraphMeta)) = Util.arrayFold4(inComps,createCosts0,(comps,shared),compMapping, reqTimeOp, reqTimeCom, (1,iTaskGraphMeta));
41084111
then tmpTaskGraphMeta;
@@ -4301,35 +4304,35 @@ protected function convertSimEqToSccCosts
43014304
input array<Real> iReqTimeOp;
43024305
output array<Real> oReqTimeOp; //calcTime for each scc
43034306
algorithm
4304-
((_,oReqTimeOp)) := Util.arrayFold1(iReqTimeOpSimCode, convertSimEqToSccCosts1, iSimeqCompMapping, (0,iReqTimeOp));
4307+
((_,oReqTimeOp)) := Util.arrayFold1(iReqTimeOpSimCode, convertSimEqToSccCosts1, iSimeqCompMapping, (1,iReqTimeOp));
43054308
end convertSimEqToSccCosts;
43064309

43074310
protected function convertSimEqToSccCosts1
43084311
input tuple<Integer,Real> iReqTimeOpSimCode;
43094312
input array<Integer> iSimeqCompMapping; //Map each simEq to the scc
43104313
input tuple<Integer,array<Real>> iReqTimeOp;
4311-
output tuple<Integer,array<Real>> oReqTimeOp; //calcTime for each scc
4314+
output tuple<Integer,array<Real>> oReqTimeOp; //<simEqIdx, calcTime>
43124315
protected
43134316
Integer simEqCalcCount, simEqIdx;
43144317
Real simEqCalcTime, realSimEqCalcCount;
43154318
array<Real> reqTime;
43164319
algorithm
43174320
oReqTimeOp := matchcontinue(iReqTimeOpSimCode,iSimeqCompMapping,iReqTimeOp)
4318-
case(_,_,_)
4321+
case((simEqCalcCount, simEqCalcTime),_,(simEqIdx,reqTime))
43194322
equation
4320-
(simEqCalcCount, simEqCalcTime) = iReqTimeOpSimCode;
4321-
(simEqIdx,reqTime) = iReqTimeOp;
43224323
realSimEqCalcCount = intReal(simEqCalcCount);
43234324
true = realNe(realSimEqCalcCount,0.0);
43244325
reqTime = convertSimEqToSccCosts2(reqTime, realDiv(simEqCalcTime,realSimEqCalcCount), simEqIdx, iSimeqCompMapping);
43254326
then ((simEqIdx+1,reqTime));
4326-
else
4327+
case((simEqCalcCount, simEqCalcTime),_,(simEqIdx,reqTime))
43274328
equation
4328-
(simEqCalcCount, simEqCalcTime) = iReqTimeOpSimCode;
4329-
(simEqIdx,reqTime) = iReqTimeOp;
43304329
realSimEqCalcCount = intReal(simEqCalcCount);
43314330
reqTime = convertSimEqToSccCosts2(reqTime, 0.0, simEqIdx, iSimeqCompMapping);
43324331
then ((simEqIdx+1,reqTime));
4332+
else
4333+
equation
4334+
print("convertSimEqToSccCosts1 failed!\n");
4335+
then fail();
43334336
end matchcontinue;
43344337
end convertSimEqToSccCosts1;
43354338

@@ -4350,7 +4353,7 @@ algorithm
43504353
sccIdx = arrayGet(iSimeqCompMapping, iSimEqIdx);
43514354
true = intGt(sccIdx,0);
43524355
reqTime = arrayUpdate(reqTime,sccIdx, iSimEqCalcTime);
4353-
//print("convertSimEqToSccCosts2 sccIdx: " +& intString(sccIdx) +& " reqTime: " +& realString(iSimEqCalcTime) +& "\n");
4356+
//print("convertSimEqToSccCosts2 sccIdx: " +& intString(sccIdx) +& " simEqIdx: " +& intString(iSimEqIdx) +& " reqTime: " +& realString(iSimEqCalcTime) +& "\n");
43544357
then
43554358
reqTime;
43564359
else
@@ -4396,10 +4399,15 @@ protected
43964399
Integer simEqIdx,calcTimeCount;
43974400
Real calcTime;
43984401
algorithm
4399-
tmpArray := iReqTime;
4400-
(simEqIdx,calcTimeCount,calcTime) := iTuple;
4401-
tmpArray := arrayUpdate(iReqTime, simEqIdx+1,(calcTimeCount,calcTime));
4402-
oReqTime := tmpArray;
4402+
oReqTime := match(iTuple, iReqTime)
4403+
case((0,calcTimeCount,calcTime),_)
4404+
then iReqTime;
4405+
case((simEqIdx,calcTimeCount,calcTime),tmpArray)
4406+
equation
4407+
//print("createCosts1: simEqIdx: " +& intString(simEqIdx) +& " calc-time: " +& realString(calcTime) +& " array-length: " +& intString(arrayLength(iReqTime)) +& "\n");
4408+
tmpArray = arrayUpdate(iReqTime, simEqIdx,(calcTimeCount,calcTime));
4409+
then tmpArray;
4410+
end match;
44034411
end createCosts1;
44044412

44054413
protected function createExecCost "author: marcusw
@@ -4416,6 +4424,7 @@ algorithm
44164424
tuple<Integer,Real> execCost;
44174425
case(_,_,_,_,_,_)
44184426
equation
4427+
//print("\tcreateExecCost: sccs: " +& stringDelimitList(List.map(iNodeSccs, intString), ",") +& "\n");
44194428
execCost = List.fold3(iNodeSccs, createExecCost0, icomps_shared, compMapping, iRequiredTime, (0,0.0));
44204429
_ = arrayUpdate(iExecCosts,iNodeIdx,execCost);
44214430
then ();
@@ -4447,6 +4456,7 @@ algorithm
44474456
comp := listGet(comps,sccIndex);
44484457
syst := arrayGet(compMapping,sccIndex);
44494458
reqTime := arrayGet(iRequiredTime, sccIndex);
4459+
//print("createExecCost0: Handling scc " +& intString(sccIndex) +& " with cost " +& realString(reqTime) +& "\n");
44504460
((costAdd,costMul,costTrig)) := countOperations(comp, syst, shared);
44514461
oCosts := (costAdd+costMul+costTrig + iCosts_op, realAdd(iCosts_cyc,reqTime));
44524462
end createExecCost0;

Compiler/runtime/HpcOmBenchmarkExt.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,36 @@ std::list<std::list<double> > ReadJsonBenchFileEquations(std::string filePath)
354354

355355
/* allocate memory for entire content */
356356
buffer = (char*)calloc( 1, lSize+1 );
357-
if( !buffer ) fclose(fp),fputs("memory alloc fails",stderr),exit(1);
357+
if( !buffer )
358+
{
359+
fclose(fp),fputs("memory alloc fails\n",stderr);
360+
return resultList;
361+
}
358362

359363
/* copy the file into the buffer */
360364
if( 1!=fread( buffer , lSize, 1 , fp) )
361-
fclose(fp),free(buffer),fputs("entire read fails",stderr),exit(1);
362-
365+
{
366+
fclose(fp),free(buffer),fputs("entire read fails\n",stderr);
367+
return resultList;
368+
}
363369
/* do your work here, buffer is a string contains the whole text */
364370
root = cJSON_Parse(buffer);
371+
372+
if(root == 0)
373+
{
374+
fclose(fp),free(buffer),fputs("no root object defined in json-file - maybe the json file is corrupt\n",stderr);
375+
return resultList;
376+
}
377+
365378
profileBlocks = cJSON_GetObjectItem(root,"profileBlocks");
379+
if(profileBlocks == 0)
380+
{
381+
fclose(fp),free(buffer),fputs("no profile blocks defined in json-file\n",stderr);
382+
return resultList;
383+
}
384+
366385
arraySize = cJSON_GetArraySize(profileBlocks);
386+
367387
for(i = 0; i < arraySize; i++)
368388
{
369389
cJSON *item = cJSON_GetArrayItem(profileBlocks, i);

SimulationRuntime/cpp/Core/Utils/extension/measure_time.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void MeasureTime::writeTimeToJason(std::string model_name, std::vector<MeasureTi
9696

9797
for (unsigned i = 0; i < data.size(); ++i)
9898
{
99-
os << "{\"id\":" << i+1 << ",\"ncall\":" << data[i].numCalcs << "," << data[i].sumMeasuredValues->serializeToJson() << "},\n";
99+
os << "{\"id\":" << (i+1) << ",\"ncall\":" << data[i].numCalcs << "," << data[i].sumMeasuredValues->serializeToJson() << "}" << ((i+1) == data.size() ? "" : ",") << "\n";
100100
}
101101
os << "]\n}";
102102
os.close();

0 commit comments

Comments
 (0)