Skip to content

Commit 7f20c6e

Browse files
author
Marcus Walther
committed
- level scheduling structure is now using the task-uniontype
- nodeMark-multiplicator will now be applied on dumping - added code generation and scheduler for OpenMP 4.0 task dependencies - remove comment-signs before "applyFilters..." git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19629 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 6037fc2 commit 7f20c6e

File tree

7 files changed

+486
-162
lines changed

7 files changed

+486
-162
lines changed

Compiler/BackEnd/HpcOmScheduler.mo

Lines changed: 184 additions & 68 deletions
Large diffs are not rendered by default.

Compiler/BackEnd/HpcOmSimCode.mo

Lines changed: 224 additions & 78 deletions
Large diffs are not rendered by default.

Compiler/BackEnd/HpcOmTaskGraph.mo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public uniontype TaskGraphMeta // stores all the metadata for the TaskGraph
6969
array<String> nodeDescs; // a description of the nodes for the graphml generation
7070
array<tuple<Integer,Real>> exeCosts; // the execution cost for the nodes <numberOfOperations, requiredCycles
7171
array<list<tuple<Integer,Integer,Integer>>> commCosts; // the communication cost tuple(_,numberOfVars,requiredCycles) for an edge from array[parentNode] to tuple(childNode,_)
72-
array<Integer> nodeMark; // put some additional stuff in here -> this is currently not a nodeMark, its a componentMark
72+
array<Integer> nodeMark; // used for level informations -> this is currently not a nodeMark, its a componentMark
7373
end TASKGRAPHMETA;
7474
end TaskGraphMeta; //TODO: Remove rootNodes from structure
7575

@@ -2428,7 +2428,7 @@ algorithm
24282428
((_,calcTime)) = arrayGet(exeCosts,primalComp);
24292429
((opCount,calcTime)) = arrayGet(exeCosts,primalComp);
24302430
calcTimeString = realString(calcTime);
2431-
yCoord = arrayGet(nodeMark,primalComp);
2431+
yCoord = arrayGet(nodeMark,primalComp)*80;
24322432
calcTimeString = realString(calcTime);
24332433
opCountString = intString(opCount);
24342434
yCoordString = intString(yCoord);
@@ -5367,10 +5367,11 @@ protected
53675367
Integer levelInterval;
53685368
tuple<Integer,Integer> coords;
53695369
algorithm
5370-
levelInterval := 80;
5370+
//levelInterval := 80;
53715371
parallelSetIdx := getParallelSetForComp(compIdx,1,parallelSets);
53725372
((xCoord,yCoord)) := arrayGet(nodeCoordsIn,compIdx);
5373-
coords := ((xCoord,parallelSetIdx*levelInterval));
5373+
//coords := ((xCoord,parallelSetIdx*levelInterval));
5374+
coords := ((xCoord,parallelSetIdx));
53745375
nodeCoordsOut := arrayUpdate(nodeCoordsIn,compIdx,coords);
53755376
end getYCoordForNode;
53765377

Compiler/Template/CodegenC.tpl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,9 +2136,10 @@ end functionXXX_systems_HPCOM;
21362136

21372137
template functionXXX_system_HPCOM(list<SimEqSystem> derivativEquations, String name, Integer n, Option<ScheduleSimCode> hpcOmScheduleOpt, String modelNamePrefixStr)
21382138
::=
2139+
let type = getConfigString(HPCOM_CODE)
21392140
match hpcOmScheduleOpt
21402141
case SOME(hpcOmSchedule as LEVELSCHEDULESC(__)) then
2141-
let odeEqs = hpcOmSchedule.eqsOfLevels |> eqs => functionXXX_system0_HPCOM_Level(derivativEquations,name,eqs,modelNamePrefixStr); separator="\n"
2142+
let odeEqs = hpcOmSchedule.tasksOfLevels |> tasks => functionXXX_system0_HPCOM_Level(derivativEquations,name,tasks,type,modelNamePrefixStr); separator="\n"
21422143
<<
21432144
void terminateHpcOmThreads()
21442145
{
@@ -2150,8 +2151,6 @@ template functionXXX_system_HPCOM(list<SimEqSystem> derivativEquations, String n
21502151
}
21512152
>>
21522153
case SOME(hpcOmSchedule as THREADSCHEDULESC(__)) then
2153-
let type = getConfigString(HPCOM_CODE)
2154-
21552154
let locks = hpcOmSchedule.lockIdc |> idx => function_HPCOM_createLock(idx, "lock", type); separator="\n"
21562155
let initlocks = hpcOmSchedule.lockIdc |> idx => function_HPCOM_initializeLock(idx, "lock", type); separator="\n"
21572156
let assignLocks = hpcOmSchedule.lockIdc |> idx => function_HPCOM_assignLock(idx, "lock", type); separator="\n"
@@ -2310,10 +2309,9 @@ template functionXXX_system_HPCOM(list<SimEqSystem> derivativEquations, String n
23102309

23112310
end functionXXX_system_HPCOM;
23122311

2313-
template functionXXX_system0_HPCOM_Level(list<SimEqSystem> derivativEquations, String name, list<Integer> eqsOfLevel, String modelNamePrefixStr)
2312+
template functionXXX_system0_HPCOM_Level(list<SimEqSystem> derivativEquations, String name, list<Task> tasksOfLevel, String iType, String modelNamePrefixStr)
23142313
::=
2315-
//let odeEqs = "#pragma omp parallel sections\n{"
2316-
let odeEqs = eqsOfLevel |> eq => equationNamesHPCOM_(eq,derivativEquations,contextSimulationNonDiscrete,modelNamePrefixStr); separator="\n"
2314+
let odeEqs = tasksOfLevel |> task => function_HPCOM_Task(derivativEquations,name,task,iType,modelNamePrefixStr); separator="\n"
23172315
<<
23182316
if (omp_get_dynamic())
23192317
omp_set_dynamic(0);
@@ -2379,6 +2377,11 @@ template function_HPCOM_Task(list<SimEqSystem> derivativEquations, String name,
23792377
<%odeEqs%>
23802378
// End Task <%task.index%>
23812379
>>
2380+
case (task as CALCTASK_LEVEL(__)) then
2381+
let odeEqs = task.eqIdc |> eq => equationNamesHPCOM_Thread_(eq,derivativEquations,contextSimulationNonDiscrete,modelNamePrefixStr); separator="\n"
2382+
<<
2383+
<%odeEqs%>
2384+
>>
23822385
case (task as ASSIGNLOCKTASK(__)) then
23832386
let assLck = function_HPCOM_assignLock(task.lockId, "lock", iType); separator="\n"
23842387
<<

Compiler/Template/CodegenCppHpcom.tpl

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,11 @@ template update2(list<SimEqSystem> allEquationsPlusWhen, Absyn.Path name, list<S
362362
let reinit = (whenClauses |> when hasindex i0 =>
363363
genreinits(when, &varDecls,i0,simCode,context)
364364
;separator="\n";empty)
365+
let type = getConfigString(HPCOM_CODE)
365366
366367
match hpcOmScheduleOpt
367368
case SOME(hpcOmSchedule as LEVELSCHEDULESC(__)) then
368-
let odeEqs = hpcOmSchedule.eqsOfLevels |> eqs => functionXXX_system0_HPCOM_Level(allEquationsPlusWhen, eqs, &varDecls, simCode); separator="\n"
369+
let odeEqs = hpcOmSchedule.tasksOfLevels |> tasks => functionXXX_system0_HPCOM_Level(allEquationsPlusWhen, tasks, type, &varDecls, simCode); separator="\n"
369370
<<
370371
bool <%lastIdentOfPath(name)%>::evaluate(const UPDATETYPE command)
371372
{
@@ -378,7 +379,6 @@ template update2(list<SimEqSystem> allEquationsPlusWhen, Absyn.Path name, list<S
378379
}
379380
>>
380381
case SOME(hpcOmSchedule as THREADSCHEDULESC(__)) then
381-
let type = getConfigString(HPCOM_CODE)
382382
383383
match type
384384
case ("openmp") then
@@ -418,11 +418,27 @@ template update2(list<SimEqSystem> allEquationsPlusWhen, Absyn.Path name, list<S
418418
return state_var_reinitialized;
419419
}
420420
>>
421+
case SOME(hpcOmSchedule as TASKDEPSCHEDULESC(__)) then
422+
let taskEqs = functionXXX_system0_HPCOM_TaskDep(hpcOmSchedule.tasks, allEquationsPlusWhen, type, &varDecls, simCode); separator="\n"
423+
<<
424+
//using type: <%type%>
425+
bool <%lastIdentOfPath(name)%>::evaluate(const UPDATETYPE command)
426+
{
427+
bool state_var_reinitialized = false;
428+
omp_set_dynamic(1);
429+
430+
<%&varDecls%>
431+
<%taskEqs%>
432+
<%reinit%>
433+
434+
return state_var_reinitialized;
435+
}
436+
>>
421437
end update2;
422438
423-
template functionXXX_system0_HPCOM_Level(list<SimEqSystem> allEquationsPlusWhen, list<Integer> eqsOfLevel, Text &varDecls, SimCode simCode)
439+
template functionXXX_system0_HPCOM_Level(list<SimEqSystem> allEquationsPlusWhen, list<Task> tasksOfLevel, String iType, Text &varDecls, SimCode simCode)
424440
::=
425-
let odeEqs = eqsOfLevel |> eq => equationNamesHPCOMLevel_(eq,allEquationsPlusWhen,contextSimulationNonDiscrete, &varDecls, simCode); separator="\n"
441+
let odeEqs = tasksOfLevel |> task => function_HPCOM_Task(allEquationsPlusWhen,task,iType, &varDecls, simCode); separator="\n"
426442
<<
427443
if (omp_get_dynamic())
428444
omp_set_dynamic(0);
@@ -433,6 +449,37 @@ template functionXXX_system0_HPCOM_Level(list<SimEqSystem> allEquationsPlusWhen,
433449
>>
434450
end functionXXX_system0_HPCOM_Level;
435451
452+
template functionXXX_system0_HPCOM_TaskDep(list<tuple<Task,list<Integer>>> tasks, list<SimEqSystem> allEquationsPlusWhen, String iType, Text &varDecls, SimCode simCode)
453+
::=
454+
let odeEqs = tasks |> t => functionXXX_system0_HPCOM_TaskDep0(t,allEquationsPlusWhen, iType, &varDecls, simCode); separator="\n"
455+
<<
456+
457+
int t[0];
458+
#pragma omp parallel
459+
{
460+
#pragma omp master
461+
{
462+
<%odeEqs%>
463+
}
464+
}
465+
>>
466+
end functionXXX_system0_HPCOM_TaskDep;
467+
468+
template functionXXX_system0_HPCOM_TaskDep0(tuple<Task,list<Integer>> taskIn, list<SimEqSystem> allEquationsPlusWhen, String iType, Text &varDecls, SimCode simCode)
469+
::=
470+
match taskIn
471+
case ((task as CALCTASK(__),parents)) then
472+
let taskEqs = function_HPCOM_Task(allEquationsPlusWhen,task,iType,&varDecls,simCode); separator="\n"
473+
let parentDependencies = parents |> p => 't[<%p%>]'; separator = ","
474+
let depIn = if intGt(listLength(parents),0) then 'depend(in:<%parentDependencies%>)' else ""
475+
<<
476+
#pragma omp task <%depIn%> depend(out:t[<%task.index%>])
477+
{
478+
<%taskEqs%>
479+
}
480+
>>
481+
end functionXXX_system0_HPCOM_TaskDep0;
482+
436483
template functionXXX_system0_HPCOM_Thread(list<SimEqSystem> allEquationsPlusWhen, list<list<Task>> threadTasks, String iType, Text &varDecls, SimCode simCode)
437484
::=
438485
match iType
@@ -508,6 +555,11 @@ template function_HPCOM_Task(list<SimEqSystem> allEquationsPlusWhen, Task iTask,
508555
<%odeEqs%>
509556
// End Task <%task.index%>
510557
>>
558+
case (task as CALCTASK_LEVEL(__)) then
559+
let odeEqs = task.eqIdc |> eq => equationNamesHPCOM_(eq,allEquationsPlusWhen,contextSimulationNonDiscrete,&varDecls, simCode); separator="\n"
560+
<<
561+
<%odeEqs%>
562+
>>
511563
case (task as ASSIGNLOCKTASK(__)) then
512564
let assLck = function_HPCOM_assignLock(task.lockId, "lock", iType); separator="\n"
513565
<<

Compiler/Template/SimCodeTV.mo

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,9 @@ package HpcOmScheduler
29932993
Integer threadIdx;
29942994
list<Integer> eqIdc;
29952995
end CALCTASK;
2996+
record CALCTASK_LEVEL
2997+
list<Integer> eqIdc;
2998+
end CALCTASK_LEVEL;
29962999
record ASSIGNLOCKTASK //Task which assignes a lock
29973000
String lockId;
29983001
end ASSIGNLOCKTASK;
@@ -3005,12 +3008,15 @@ package HpcOmScheduler
30053008

30063009
uniontype ScheduleSimCode
30073010
record LEVELSCHEDULESC
3008-
list<list<Integer>> eqsOfLevels;
3011+
list<list<Task>> tasksOfLevels;
30093012
end LEVELSCHEDULESC;
30103013
record THREADSCHEDULESC
30113014
list<list<Task>> threadTasks;
30123015
list<String> lockIdc;
30133016
end THREADSCHEDULESC;
3017+
record TASKDEPSCHEDULESC
3018+
list<tuple<Task,list<Integer>>> tasks;
3019+
end TASKDEPSCHEDULESC;
30143020
end ScheduleSimCode;
30153021
end HpcOmScheduler;
30163022

Compiler/Util/Flags.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ constant ConfigFlag CORBA_OBJECT_REFERENCE_FILE_PATH = CONFIG_FLAG(49, "corbaObj
823823

824824
constant ConfigFlag HPCOM_SCHEDULER = CONFIG_FLAG(50, "hpcomScheduler",
825825
NONE(), EXTERNAL(), STRING_FLAG(""), NONE(),
826-
Util.gettext("Sets the scheduler for task graph scheduling (list | level | levelr | ext | mcp). Default: list."));
826+
Util.gettext("Sets the scheduler for task graph scheduling (list | level | levelr | ext | mcp | taskdep). Default: list."));
827827

828828
constant ConfigFlag TEARING_HEURISTIC = CONFIG_FLAG(51, "tearingHeuristic",
829829
NONE(), EXTERNAL(), STRING_FLAG("cellier"),

0 commit comments

Comments
 (0)