Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 54.7% 479 / 0 / 876
Functions: -% 0 / 1 / 1
Branches: 42.6% 174 / 0 / 408

OMCompiler/Compiler/BackEnd/HpcOmMemory.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package HpcOmMemory
37
38 import BackendDAE;
39 import DAE;
40 import HashTableCrIListArray;
41 import HashTableCrILst;
42 import HpcOmSimCode;
43 import HpcOmTaskGraph;
44 import SimCode;
45 import SimCodeVar;
46
47 protected
48
49 import Array;
50 import BackendDAEUtil;
51 import BackendDump;
52 import BackendEquation;
53 import BackendVariable;
54 import BaseHashTable;
55 import ComponentReference;
56 protected import ComponentReferenceBasics;
57 import Config;
58 import Error;
59 import ExpandableArray;
60 import Expression;
61 import Flags;
62 import GraphML;
63 import HpcOmScheduler;
64 import List;
65 import SimCodeUtil;
66 import SimCodeUtilShared;
67 import Util;
68
69 // -------------------------------------------
70 // STRUCTURES
71 // -------------------------------------------
72
73 public constant Integer VARDATATYPE_FLOAT = 1;
74 public constant Integer VARDATATYPE_INTEGER = 2;
75 public constant Integer VARDATATYPE_BOOLEAN = 3;
76 public constant Integer VARDATATYPE_STRING = 4;
77
78 public constant Integer VARTYPE_STATE = 1;
79 public constant Integer VARTYPE_STATEDER = 2;
80 public constant Integer VARTYPE_PARAM = 3;
81 public constant Integer VARTYPE_ALIAS = 4;
82 public constant Integer VARTYPE_OTHER = 5;
83
84 protected uniontype CacheMap
85 //CacheMap that stores variables of same type in the same array (different arrays for bool, float and int vars)
86 record CACHEMAP
87 Integer cacheLineSize; //cache line size in bytes
88 list<SimCodeVar.SimVar> cacheVariables; //all variables that are stored in the cache
89 list<CacheLineMap> cacheLinesFloat;
90 list<CacheLineMap> cacheLinesInt;
91 list<CacheLineMap> cacheLinesBool;
92 end CACHEMAP;
93 //CacheMap that stores variables of different types in the same array -- just used for default cache map
94 record UNIFORM_CACHEMAP
95 Integer cacheLineSize; //cache line size in bytes
96 list<SimCodeVar.SimVar> cacheVariables; //all variables that are stored in the cache
97 list<CacheLineMap> cacheLines;
98 end UNIFORM_CACHEMAP;
99 end CacheMap;
100
101 protected uniontype CacheLineMap
102 record CACHELINEMAP
103 Integer idx;
104 Integer numBytesFree;
105 list<CacheLineEntry> entries;
106 end CACHELINEMAP;
107 end CacheLineMap;
108
109 protected uniontype CacheLineEntry
110 record CACHELINEENTRY
111 Integer start; //starting with 0
112 Integer dataType; //1 = float, 2 = int, 3 = bool
113 Integer size;
114 Integer scVarIdx; //see CacheMap.cacheVariables
115 Integer threadOwner; //TODO: check if necessary
116 end CACHELINEENTRY;
117 end CacheLineEntry;
118
119 protected uniontype CacheMapMeta
120 record CACHEMAPMETA
121 array<Option<SimCodeVar.SimVar>> allSCVarsMapping;
122 array<tuple<Integer, Integer, Integer>> simCodeVarTypes; //<dataType, numberOfBytesRequired, varType>
123 array<tuple<Integer, Integer>> scVarCLMapping; //mapping for each scVar -> <CLIdx,varType>
124 end CACHEMAPMETA;
125 end CacheMapMeta;
126
127 protected uniontype PartlyFilledCacheLine
128 record PARTLYFILLEDCACHELINE_LEVEL
129 CacheLineMap cacheLineMap;
130 list<Integer> prefetchLevel;
131 list<tuple<Integer,Integer>> writeLevel; //(LevelIdx, ThreadIdx)
132 end PARTLYFILLEDCACHELINE_LEVEL;
133 record PARTLYFILLEDCACHELINE_THREAD
134 CacheLineMap cacheLineMap;
135 end PARTLYFILLEDCACHELINE_THREAD;
136 end PartlyFilledCacheLine;
137
138 protected uniontype ScVarInfo
139 record SCVARINFO //an onwer of -1 and isShared = true indicates that the variable is unused
140 Integer ownerThread; //the thread that writes the variable or the only thread that reads the variable
141 Boolean isShared;
142 end SCVARINFO;
143 end ScVarInfo;
144
145 protected type PartlyFilledCacheLines = tuple<list<PartlyFilledCacheLine>, list<PartlyFilledCacheLine>, list<PartlyFilledCacheLine>>;
146 protected type CacheLines = tuple<list<CacheLineMap>, list<CacheLineMap>, list<CacheLineMap>>;
147
148 // -------------------------------------------
149 // FUNCTIONS
150 // -------------------------------------------
151
152 public function createMemoryMap
153 "author: marcusw
154 Creates a MemoryMap which contains information about an optimized memory alignment and append the information to the given TaskGraph."
155 input SimCode.ModelInfo iModelInfo;
156 input HashTableCrIListArray.HashTable iVarToArrayIndexMapping;
157 input HashTableCrILst.HashTable iVarToIndexMapping;
158 input HpcOmTaskGraph.TaskGraph iTaskGraph;
159 input HpcOmTaskGraph.TaskGraph iTaskGraphT;
160 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
161 input BackendDAE.EqSystems iEqSystems;
162 input String iFileNamePrefix;
163 input array<tuple<Integer,Integer,Real>> iSchedulerInfo; //maps each Task to <threadId, orderId, startCalcTime>
164 input HpcOmSimCode.Schedule iSchedule;
165 input array<list<Integer>> iSccSimEqMapping; //Maps each scc to a list of simEqs
166 input list<list<Integer>> iCriticalPaths;
167 input list<list<Integer>> iCriticalPathsWoC;
168 input String iCriticalPathInfo;
169 input Integer iNumberOfThreads;
170 input BackendDAE.StrongComponents iAllComponents;
171 input Boolean isInitial;
172 output Option<HpcOmSimCode.MemoryMap> oMemoryMap;
173 output HashTableCrIListArray.HashTable oVarToArrayIndexMapping;
174 output HashTableCrILst.HashTable oVarToIndexMapping;
175 protected
176 SimCodeVar.SimVars simCodeVars;
177 list<SimCodeVar.SimVar> stateVars, derivativeVars, algVars, discreteAlgVars, intAlgVars, boolAlgVars, stringAlgVars, inputVars, outputVars, aliasVars, paramVars, intParamVars, boolParamVars, stringParamVars, intAliasVars, boolAliasVars, stringAliasVars;
178 list<Option<SimCodeVar.SimVar>> notOptimizedVarsFloatOpt, notOptimizedVarsIntOpt, notOptimizedVarsBoolOpt, notOptimizedVarsStringOpt;
179 list<SimCodeVar.SimVar> notOptimizedVarsFloat, notOptimizedVarsInt, notOptimizedVarsBool, notOptimizedVarsString;
180 tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>> notOptimizedVars;
181 array<Option<SimCodeVar.SimVar>> allVarsMapping;
182 HashTableCrILst.HashTable simVarIdxMappingHashTable;
183 Integer numCL, threadAttIdx;
184 array<list<Integer>> clTaskMapping;
185 array<Integer> scVarSolvedTaskMapping, sccNodeMapping;
186 array<list<Integer>> scVarUnsolvedTaskMapping;
187 array<String> annotInfo;
188 array<tuple<Integer,Integer>> scVarCLMapping;
189 CacheMap cacheMap;
190 Integer graphIdx;
191 GraphML.GraphInfo graphInfo;
192 String fileName;
193 array<array<list<Integer>>> eqSimCodeVarMapping; //eqSystem -> eqIdx -> varIdx
194 array<tuple<Integer,Integer,Integer>> eqCompMapping, varCompMapping;
195 BackendDAE.AdjacencyMatrix adjacencyMatrix;
196 Option<HpcOmSimCode.MemoryMap> tmpMemoryMapOpt;
197 Integer varCount;
198 Integer stateVarsCnt, derivativeVarsCnt, algVarsCnt, discreteAlgVarsCnt, intAlgVarsCnt, boolAlgVarsCnt, stringAlgVarsCnt, inputVarsCnt, outputVarsCnt, aliasVarsCnt, intAliasVarsCnt, boolAliasVarsCnt, stringAliasVarsCnt, paramVarsCnt, intParamVarsCnt, boolParamVarsCnt, stringParamVarsCnt;
199 Integer VARSIZE_FLOAT, VARSIZE_INTEGER, VARSIZE_BOOLEAN, VARSIZE_STRING, CACHELINE_SIZE;
200 array<tuple<Integer,Integer, Integer>> simCodeVarTypes; //<varDataType, varSize, varType>
201
202 array<list<Integer>> taskSolvedVarsMapping;
203 array<list<Integer>> taskUnsolvedVarsMapping;
204 array<list<Integer>> nodeSccMapping;
205 array<tuple<Integer,list<Integer>>> flatEqSimCodeVarMapping; //eqIdx -> (eqSysIdx, list of simVars)
206 array<list<tuple<Integer,Integer,Integer>>> sccEqMapping; //maps each scc to a list of <equationIdx, eqSystemIdx, offset>
207 array<ScVarInfo> scVarInfos;
208 HashTableCrIListArray.HashTable varToArrayIndexMapping;
209 HashTableCrILst.HashTable varToIndexMapping;
210 algorithm
211 (oMemoryMap, oVarToArrayIndexMapping, oVarToIndexMapping) := matchcontinue(iVarToArrayIndexMapping, iVarToIndexMapping, iTaskGraphMeta)
212 case(varToArrayIndexMapping, varToIndexMapping, HpcOmTaskGraph.TASKGRAPHMETA(eqCompMapping=eqCompMapping,varCompMapping=varCompMapping))
213 algorithm
214 VARSIZE_FLOAT := 8;
215 VARSIZE_INTEGER := 4;
216 VARSIZE_BOOLEAN := 1;
217 VARSIZE_STRING := 4; //32 bit pointer
218 CACHELINE_SIZE := 64;
219 //HpcOmTaskGraph.printTaskGraphMeta(iTaskGraphMeta);
220 //Create var hash table
221 8 SimCode.MODELINFO(vars=simCodeVars) := iModelInfo;
222 8 SimCodeVar.SIMVARS(stateVars=stateVars, derivativeVars=derivativeVars, algVars=algVars, discreteAlgVars=discreteAlgVars, intAlgVars=intAlgVars, boolAlgVars=boolAlgVars, stringAlgVars=stringAlgVars, inputVars=inputVars,
223 outputVars=outputVars, aliasVars=aliasVars, intAliasVars=intAliasVars, boolAliasVars=boolAliasVars, stringAliasVars=stringAliasVars, paramVars=paramVars, intParamVars=intParamVars, boolParamVars=boolParamVars, stringParamVars=stringParamVars) := simCodeVars;
224 8 allVarsMapping := SimCodeUtil.createIdxSCVarMapping(simCodeVars);
225 //SimCodeUtil.dumpIdxScVarMapping(allVarsMapping);
226
227 //print("--------------------------------\n");
228 8 simVarIdxMappingHashTable := HashTableCrILst.emptyHashTableSized(BaseHashTable.biggerBucketSize);
229 varCount := 0;
230 //simVarIdxMappingHashTable = fillSimVarHashTable(stateVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
231 8 stateVarsCnt := listLength(stateVars);
232 varCount := varCount + stateVarsCnt;
233 //simVarIdxMappingHashTable = fillSimVarHashTable(derivativeVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
234 8 derivativeVarsCnt := listLength(derivativeVars);
235 8 varCount := varCount + derivativeVarsCnt;
236 8 simVarIdxMappingHashTable := fillSimVarHashTable(algVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
237 8 algVarsCnt := listLength(algVars);
238 8 varCount := varCount + algVarsCnt;
239 8 simVarIdxMappingHashTable := fillSimVarHashTable(discreteAlgVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
240 8 discreteAlgVarsCnt := listLength(discreteAlgVars);
241 8 varCount := varCount + discreteAlgVarsCnt;
242 8 simVarIdxMappingHashTable := fillSimVarHashTable(intAlgVars,varCount,VARDATATYPE_INTEGER,simVarIdxMappingHashTable);
243 8 intAlgVarsCnt := listLength(intAlgVars);
244 8 varCount := varCount + intAlgVarsCnt;
245 8 simVarIdxMappingHashTable := fillSimVarHashTable(boolAlgVars,varCount,VARDATATYPE_BOOLEAN,simVarIdxMappingHashTable);
246 8 boolAlgVarsCnt := listLength(boolAlgVars);
247 8 varCount := varCount + boolAlgVarsCnt;
248 8 simVarIdxMappingHashTable := fillSimVarHashTable(stringAlgVars,varCount,VARDATATYPE_STRING,simVarIdxMappingHashTable);
249 8 stringAlgVarsCnt := listLength(stringAlgVars);
250 8 varCount := varCount + stringAlgVarsCnt;
251 8 simVarIdxMappingHashTable := fillSimVarHashTable(inputVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
252 8 inputVarsCnt := listLength(inputVars);
253 8 varCount := varCount + inputVarsCnt;
254 8 simVarIdxMappingHashTable := fillSimVarHashTable(outputVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
255 8 outputVarsCnt := listLength(outputVars);
256 8 varCount := varCount + outputVarsCnt;
257 //simVarIdxMappingHashTable = fillSimVarHashTable(aliasVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
258 8 aliasVarsCnt := listLength(aliasVars);
259 8 varCount := varCount + aliasVarsCnt;
260 //simVarIdxMappingHashTable = fillSimVarHashTable(intAliasVars,varCount,VARDATATYPE_INTEGER,simVarIdxMappingHashTable);
261 8 intAliasVarsCnt := listLength(intAliasVars);
262 8 varCount := varCount + intAliasVarsCnt;
263 //simVarIdxMappingHashTable = fillSimVarHashTable(boolAliasVars,varCount,VARDATATYPE_BOOLEAN,simVarIdxMappingHashTable);
264 8 boolAliasVarsCnt := listLength(boolAliasVars);
265 8 varCount := varCount + boolAliasVarsCnt;
266 8 simVarIdxMappingHashTable := fillSimVarHashTable(stringAliasVars,varCount,VARDATATYPE_STRING,simVarIdxMappingHashTable);
267 8 stringAliasVarsCnt := listLength(stringAliasVars);
268 8 varCount := varCount + stringAliasVarsCnt;
269 8 simVarIdxMappingHashTable := fillSimVarHashTable(paramVars,varCount,VARDATATYPE_FLOAT,simVarIdxMappingHashTable);
270 8 paramVarsCnt := listLength(paramVars);
271 8 varCount := varCount + paramVarsCnt;
272 8 simVarIdxMappingHashTable := fillSimVarHashTable(intParamVars,varCount,VARDATATYPE_INTEGER,simVarIdxMappingHashTable);
273 8 intParamVarsCnt := listLength(intParamVars);
274 8 varCount := varCount + intParamVarsCnt;
275 8 simVarIdxMappingHashTable := fillSimVarHashTable(boolParamVars,varCount,VARDATATYPE_BOOLEAN,simVarIdxMappingHashTable);
276 8 boolParamVarsCnt := listLength(boolParamVars);
277 8 varCount := varCount + boolParamVarsCnt;
278 8 simVarIdxMappingHashTable := fillSimVarHashTable(stringParamVars,varCount,VARDATATYPE_STRING,simVarIdxMappingHashTable);
279 8 stringParamVarsCnt := listLength(stringParamVars);
280 8 varCount := varCount + stringParamVarsCnt;
281
282 8 simCodeVarTypes := arrayCreate(varCount, (-1,-1,-1));
283 varCount := 0;
284
285 /* if stateVarsCnt > 0 then
286 List.map_0(List.intRange2(varCount+1, varCount+stateVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_STATE), inArray=simCodeVarTypes));
287 end if; */
288 varCount := varCount + stateVarsCnt;
289 /* if derivativeVarsCnt > 0 then
290 List.map_0(List.intRange2(varCount+1, varCount+derivativeVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_STATEDER), inArray=simCodeVarTypes));
291 end if; */
292 varCount := varCount + derivativeVarsCnt;
293
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if algVarsCnt > 0 then
294 8 List.map_0(List.intRange2(varCount+1, varCount+algVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_OTHER), inArray=simCodeVarTypes));
295 end if;
296 varCount := varCount + algVarsCnt;
297
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
8 if discreteAlgVarsCnt > 0 then
298 3 List.map_0(List.intRange2(varCount+1, varCount+discreteAlgVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_OTHER), inArray=simCodeVarTypes));
299 end if;
300 varCount := varCount + discreteAlgVarsCnt;
301
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if intAlgVarsCnt > 0 then
302 2 List.map_0(List.intRange2(varCount+1, varCount+intAlgVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_INTEGER,VARSIZE_INTEGER,VARTYPE_OTHER), inArray=simCodeVarTypes));
303 end if;
304 varCount := varCount + intAlgVarsCnt;
305
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if boolAlgVarsCnt > 0 then
306 4 List.map_0(List.intRange2(varCount+1, varCount+boolAlgVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_BOOLEAN,VARSIZE_BOOLEAN,VARTYPE_OTHER), inArray=simCodeVarTypes));
307 end if;
308 varCount := varCount + boolAlgVarsCnt;
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if stringAlgVarsCnt > 0 then
310 ✗ List.map_0(List.intRange2(varCount+1, varCount+stringAlgVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_STRING,VARSIZE_STRING,VARTYPE_OTHER), inArray=simCodeVarTypes));
311 end if;
312 varCount := varCount + stringAlgVarsCnt;
313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if inputVarsCnt > 0 then
314 ✗ List.map_0(List.intRange2(varCount+1, varCount+inputVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_OTHER), inArray=simCodeVarTypes));
315 end if;
316 varCount := varCount + inputVarsCnt;
317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if outputVarsCnt > 0 then
318 ✗ List.map_0(List.intRange2(varCount+1, varCount+outputVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_OTHER), inArray=simCodeVarTypes));
319 end if;
320 varCount := varCount + outputVarsCnt;
321 /*if aliasVarsCnt > 0 then
322 List.map_0(List.intRange2(varCount+1, varCount+aliasVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_ALIAS), inArray=simCodeVarTypes));
323 end if;*/
324 varCount := varCount + aliasVarsCnt;
325 /*if intAliasVarsCnt > 0 then
326 List.map_0(List.intRange2(varCount+1, varCount+intAliasVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_INTEGER,VARSIZE_INTEGER,VARTYPE_ALIAS), inArray=simCodeVarTypes));
327 end if;*/
328 varCount := varCount + intAliasVarsCnt;
329 /*if boolAliasVarsCnt > 0 then
330 List.map_0(List.intRange2(varCount+1, varCount+boolAliasVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_BOOLEAN,VARSIZE_BOOLEAN,VARTYPE_ALIAS), inArray=simCodeVarTypes));
331 end if;*/
332 varCount := varCount + boolAliasVarsCnt;
333 varCount := varCount + stringAliasVarsCnt;
334
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if paramVarsCnt > 0 then
335 8 List.map_0(List.intRange2(varCount+1, varCount+paramVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_FLOAT,VARSIZE_FLOAT,VARTYPE_PARAM), inArray=simCodeVarTypes));
336 end if;
337 varCount := varCount + paramVarsCnt;
338
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
8 if intParamVarsCnt > 0 then
339 3 List.map_0(List.intRange2(varCount+1, varCount+intParamVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_INTEGER,VARSIZE_INTEGER,VARTYPE_PARAM), inArray=simCodeVarTypes));
340 end if;
341 varCount := varCount + intParamVarsCnt;
342
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if boolParamVarsCnt > 0 then
343 8 List.map_0(List.intRange2(varCount+1, varCount+boolParamVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_BOOLEAN,VARSIZE_BOOLEAN,VARTYPE_PARAM), inArray=simCodeVarTypes));
344 end if;
345 varCount := varCount + boolParamVarsCnt;
346
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 7 times.
8 if stringParamVarsCnt > 0 then
347 1 List.map_0(List.intRange2(varCount+1, varCount+stringParamVarsCnt), function Array.updateIndexFirst(inValue = (VARDATATYPE_STRING,VARSIZE_STRING,VARTYPE_PARAM), inArray=simCodeVarTypes));
348 end if;
349 varCount := varCount + stringParamVarsCnt;
350 //printSimCodeVarTypes(simCodeVarTypes);
351
352 //print("-------------------------------------\n");
353 //BaseHashTable.dumpHashTable(simVarIdxMappingHashTable);
354 //Create CacheMap
355 8 sccNodeMapping := HpcOmTaskGraph.getSccNodeMapping(arrayLength(iSccSimEqMapping), iTaskGraphMeta);
356 //printSccNodeMapping(sccNodeMapping);
357 8 scVarSolvedTaskMapping := getSimCodeVarNodeMapping(iTaskGraphMeta,iEqSystems,varCount,sccNodeMapping,simVarIdxMappingHashTable);
358 //printScVarTaskMapping(scVarSolvedTaskMapping);
359 //print("-------------------------------------\n");
360
361 8 eqSimCodeVarMapping := getEqSCVarMapping(iEqSystems,simVarIdxMappingHashTable);
362 //printEqSimCodeVarMapping(eqSimCodeVarMapping);
363
364 8 sccEqMapping := invertEqCompMapping(eqCompMapping, arrayLength(sccNodeMapping));
365 8 nodeSccMapping := invertSccNodeMapping(sccNodeMapping, arrayLength(iTaskGraph));
366 8 flatEqSimCodeVarMapping := flattenEqSimCodeVarMapping(eqSimCodeVarMapping);
367 8 (taskSolvedVarsMapping, taskUnsolvedVarsMapping) := getTaskSimVarMapping(sccEqMapping, nodeSccMapping, flatEqSimCodeVarMapping, scVarSolvedTaskMapping, simCodeVarTypes);
368 8 scVarUnsolvedTaskMapping := transposeTasksScVarsMapping(taskUnsolvedVarsMapping, varCount);
369 8 scVarInfos := createVarInfos(scVarSolvedTaskMapping, scVarUnsolvedTaskMapping, iSchedulerInfo);
370 //printScVarInfos(scVarInfos);
371
372 //print("\nSolved variables\n==============\n");
373 //printNodeSimCodeVarMapping(taskSolvedVarsMapping);
374 //print("Unsolved variables\n==============\n");
375 //printNodeSimCodeVarMapping(taskUnsolvedVarsMapping);
376
377
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 7 times.
8 if(Flags.isSet(Flags.HPCOM_MEMORY_OPT)) then
378 1 (cacheMap,scVarCLMapping,numCL) := createCacheMapOptimized(iTaskGraph, iTaskGraphMeta, simCodeVars, allVarsMapping,simCodeVarTypes,scVarSolvedTaskMapping,scVarUnsolvedTaskMapping,CACHELINE_SIZE,iAllComponents,iSchedule,iSchedulerInfo,iNumberOfThreads,taskSolvedVarsMapping, taskUnsolvedVarsMapping, scVarInfos);
379 else
380 7 (cacheMap,scVarCLMapping,numCL) := createCacheMapDefault(allVarsMapping, CACHELINE_SIZE, simCodeVars, scVarSolvedTaskMapping, iSchedulerInfo, simCodeVarTypes);
381 end if;
382
383 8 (clTaskMapping,_) := getCacheLineTaskMapping(iTaskGraphMeta,iEqSystems,simVarIdxMappingHashTable,numCL,scVarCLMapping);
384
385 //Get not optimized variables (e.g. paramters that are not part of the task graph)
386 //--------------------------------------------------------------------------------
387 8 notOptimizedVars := getNotOptimizedVarsByCacheLineMapping(scVarCLMapping, allVarsMapping, simCodeVarTypes);
388 8 notOptimizedVarsFloatOpt := List.map(Util.tuple41(notOptimizedVars), function arrayGet(arr = allVarsMapping));
389 8 notOptimizedVarsIntOpt := List.map(Util.tuple42(notOptimizedVars), function arrayGet(arr = allVarsMapping));
390 8 notOptimizedVarsBoolOpt := List.map(Util.tuple43(notOptimizedVars), function arrayGet(arr = allVarsMapping));
391 8 notOptimizedVarsStringOpt := List.map(Util.tuple44(notOptimizedVars), function arrayGet(arr = allVarsMapping));
392
393 8 notOptimizedVarsFloat := List.map(notOptimizedVarsFloatOpt, Util.getOption);
394 8 notOptimizedVarsInt := List.map(notOptimizedVarsIntOpt, Util.getOption);
395 8 notOptimizedVarsBool := List.map(notOptimizedVarsBoolOpt, Util.getOption);
396 8 notOptimizedVarsString := List.map(notOptimizedVarsStringOpt, Util.getOption);
397 //Append cache line nodes to graph
398 //--------------------------------
399 8 graphInfo := GraphML.createGraphInfo();
400 8 (graphInfo, (_,graphIdx)) := GraphML.addGraph("TasksGroupGraph", true, graphInfo);
401
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 (graphInfo, _,(_,graphIdx)) := GraphML.addGroupNode("TasksGroup", graphIdx, false, "TG", graphInfo);
402 8 annotInfo := arrayCreate(arrayLength(iTaskGraph),"nothing");
403 8 graphInfo := HpcOmTaskGraph.convertToGraphMLSccLevelSubgraph(iTaskGraph, iTaskGraphMeta, iCriticalPathInfo, HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(iCriticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(iCriticalPathsWoC)), iSccSimEqMapping, iSchedulerInfo, annotInfo, graphIdx, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,true,true), graphInfo);
404
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
8 SOME((_,threadAttIdx)) := GraphML.getAttributeByNameAndTarget("ThreadId", GraphML.TARGET_NODE(), graphInfo);
405 8 (_,adjacencyMatrix,_) := BackendDAEUtil.getAdjacencyMatrix(listHead(iEqSystems), BackendDAE.ABSOLUTE(), NONE(), isInitial);
406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
16 graphInfo := appendCacheLinesToGraph(cacheMap, arrayLength(iTaskGraph), eqSimCodeVarMapping, iEqSystems, simVarIdxMappingHashTable, eqCompMapping, scVarSolvedTaskMapping, iSchedulerInfo, threadAttIdx, sccNodeMapping, taskSolvedVarsMapping, taskUnsolvedVarsMapping, scVarCLMapping, scVarInfos, graphInfo);
407 8 fileName := ("taskGraph"+iFileNamePrefix+"ODE_schedule_CL.graphml");
408 8 GraphML.dumpGraph(graphInfo, fileName);
409 //printCacheMap(cacheMap);
410
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 7 times.
8 if(Flags.isSet(Flags.HPCOM_MEMORY_OPT)) then
411 1 (varToArrayIndexMapping, varToIndexMapping, tmpMemoryMapOpt) := convertCacheToVarArrayMapping(cacheMap,CACHELINE_SIZE,stateVars,derivativeVars,aliasVars,intAliasVars,boolAliasVars,stringAliasVars,(VARSIZE_FLOAT,VARSIZE_INTEGER,VARSIZE_BOOLEAN),(notOptimizedVarsFloat,notOptimizedVarsInt,notOptimizedVarsBool,notOptimizedVarsString));
412 else
413 7 tmpMemoryMapOpt := NONE();
414 end if;
415
416 //print cache map
417 //printCacheMap(cacheMap);
418 evaluateCacheBehaviour(varToIndexMapping, simVarIdxMappingHashTable, taskSolvedVarsMapping, taskUnsolvedVarsMapping, iTaskGraph, iTaskGraphT, iNumberOfThreads, CACHELINE_SIZE, simCodeVarTypes, iSchedulerInfo);
419
420 //Create bipartite graph
421 //----------------------
422 8 graphInfo := GraphML.createGraphInfo();
423
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 (graphInfo, (_,graphIdx)) := GraphML.addGraph("TasksGroupGraph", true, graphInfo);
424 8 annotInfo := arrayCreate(arrayLength(iTaskGraph),"nothing");
425 8 graphInfo := HpcOmTaskGraph.convertToGraphMLSccLevelSubgraph(iTaskGraph, iTaskGraphMeta, iCriticalPathInfo, HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(iCriticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(iCriticalPathsWoC)), iSccSimEqMapping, iSchedulerInfo, annotInfo, graphIdx, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,true,true), graphInfo);
426
3/6
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
8 SOME((_,threadAttIdx)) := GraphML.getAttributeByNameAndTarget("ThreadId", GraphML.TARGET_NODE(), graphInfo);
427 8 graphInfo := appendVariablesToGraph(taskSolvedVarsMapping, taskUnsolvedVarsMapping, arrayLength(scVarSolvedTaskMapping), graphIdx, threadAttIdx, simVarIdxMappingHashTable, allVarsMapping, scVarInfos, graphInfo);
428 8 fileName := ("taskGraph"+iFileNamePrefix+"ODE_schedule_vars.graphml");
429 8 GraphML.dumpGraph(graphInfo, fileName);
430 8 then(tmpMemoryMapOpt, varToArrayIndexMapping, varToIndexMapping);
431 else
432 algorithm
433 ✗ Error.addInternalError("CreateMemoryMap failed!", sourceInfo());
434 then (NONE(), iVarToArrayIndexMapping, iVarToIndexMapping);
435 end matchcontinue;
436 end createMemoryMap;
437
438 protected function createCacheMapOptimized "author: marcusw
439 Creates a CacheMap optimized for the selected scheduler. All variables that are part of the created cache map are marked with 1 in the iVarMark-array."
440 input HpcOmTaskGraph.TaskGraph iTaskGraph;
441 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
442 input SimCodeVar.SimVars iSimCodeVars;
443 input array<Option<SimCodeVar.SimVar>> iAllSCVarsMapping;
444 input array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes; //<varDataType, varSize, varType>
445 input array<Integer> iScVarSolvedTaskMapping;
446 input array<list<Integer>> iScVarUnsolvedTaskMapping;
447 input Integer iCacheLineSize;
448 input BackendDAE.StrongComponents iAllComponents;
449 input HpcOmSimCode.Schedule iSchedule;
450 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
451 input Integer iNumberOfThreads;
452 input array<list<Integer>> iTaskSolvedVarsMapping;
453 input array<list<Integer>> iTaskUnsolvedVarsMapping;
454 input array<ScVarInfo> iScVarInfos;
455 output CacheMap oCacheMap;
456 output array<tuple<Integer,Integer>> oScVarCLMapping; //mapping for each scVar -> CLIdx
457 output Integer oNumCL;
458 protected
459 CacheMap cacheMap;
460 array<tuple<Integer,Integer>> scVarCLMapping;
461 Integer numCL;
462 list<HpcOmSimCode.TaskList> tasksOfLevels;
463 array<tuple<Integer,Integer,Real>> scheduleInfo;
464 array<list<HpcOmSimCode.Task>> threadTasks;
465 list<HpcOmSimCode.Task> allTasks;
466 algorithm
467 (oCacheMap,oScVarCLMapping,oNumCL) := match iSchedule
468 /* case(_,_,_,_,_,_,_,HpcOmSimCode.LEVELSCHEDULE(tasksOfLevels=tasksOfLevels, useFixedAssignments=false),_,_)
469 algorithm
470 (cacheMap,scVarCLMapping,numCL) = createCacheMapLevelOptimized(iAllSCVarsMapping,iSimCodeVarTypes,iScVarTaskMapping,iCacheLineSize,iAllComponents,tasksOfLevels,iNodeSimCodeVarMapping);
471 then (cacheMap,scVarCLMapping,numCL); */
472 case HpcOmSimCode.LEVELSCHEDULE(tasksOfLevels=tasksOfLevels, useFixedAssignments=true)
473 algorithm
474 1 print("Creating optimized cache map for fixed level scheduler\n");
475 1 scheduleInfo := HpcOmScheduler.convertScheduleStrucToInfo(iSchedule, arrayLength(iTaskGraph));
476 1 (cacheMap,scVarCLMapping,numCL) := createCacheMapLevelFixedOptimized(iTaskGraph,iTaskGraphMeta,iAllSCVarsMapping,iSimCodeVarTypes,iScVarSolvedTaskMapping,
477 iScVarUnsolvedTaskMapping,iCacheLineSize,iAllComponents,tasksOfLevels,iNumberOfThreads,
478 scheduleInfo,iTaskSolvedVarsMapping,iTaskUnsolvedVarsMapping,iScVarInfos);
479 then (cacheMap,scVarCLMapping,numCL);
480 case HpcOmSimCode.THREADSCHEDULE(threadTasks=threadTasks)
481 algorithm
482 ✗ print("Creating optimized cache map for thread scheduler\n");
483 ✗ scheduleInfo := HpcOmScheduler.convertScheduleStrucToInfo(iSchedule, arrayLength(iTaskGraph));
484 ✗ (cacheMap,scVarCLMapping,numCL) := createCacheMapThreadOptimized(iTaskGraph,iTaskGraphMeta,iAllSCVarsMapping,iSimCodeVarTypes,iScVarSolvedTaskMapping,
485 iScVarUnsolvedTaskMapping,iCacheLineSize,iAllComponents,threadTasks,iNumberOfThreads,
486 scheduleInfo,iTaskSolvedVarsMapping,iTaskUnsolvedVarsMapping,iScVarInfos);
487 then (cacheMap,scVarCLMapping,numCL);
488 case HpcOmSimCode.EMPTYSCHEDULE(tasks=HpcOmSimCode.SERIALTASKLIST(tasks=allTasks))
489 algorithm
490 ✗ print("Creating optimized cache map for empty scheduler\n");
491 ✗ threadTasks:=arrayCreate(1, allTasks);
492 ✗ scheduleInfo := HpcOmScheduler.convertScheduleStrucToInfo(iSchedule, arrayLength(iTaskGraph));
493 ✗ (cacheMap,scVarCLMapping,numCL) := createCacheMapThreadOptimized(iTaskGraph,iTaskGraphMeta,iAllSCVarsMapping,iSimCodeVarTypes,iScVarSolvedTaskMapping,
494 iScVarUnsolvedTaskMapping,iCacheLineSize,iAllComponents,threadTasks,1,
495 scheduleInfo,iTaskSolvedVarsMapping,iTaskUnsolvedVarsMapping,iScVarInfos);
496 then (cacheMap,scVarCLMapping,numCL);
497 else
498 algorithm
499 ✗ print("No optimized cache map for the selected scheduler avaiable. Using default cacheMap!\n");
500 ✗ (cacheMap,scVarCLMapping,numCL) := createCacheMapDefault(iAllSCVarsMapping, iCacheLineSize, iSimCodeVars, iScVarSolvedTaskMapping, iSchedulerInfo, iSimCodeVarTypes);
501 then (cacheMap,scVarCLMapping,numCL);
502 end match;
503 end createCacheMapOptimized;
504
505 protected function createCacheMapLevelOptimized "author: marcusw
506 Create the optimized cache map for the level-scheduler."
507 input array<Option<SimCodeVar.SimVar>> iAllSCVarsMapping;
508 input array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes; //<varDataType, numberOfBytesRequired, varType>
509 input array<Integer> iScVarTaskMapping;
510 input Integer iCacheLineSize;
511 input BackendDAE.StrongComponents iAllComponents;
512 input list<HpcOmSimCode.TaskList> iTasksOfLevels; //Schedule
513 input array<list<Integer>> iNodeSimCodeVarMapping;
514 output CacheMap oCacheMap;
515 output array<tuple<Integer,Integer>> oScVarCLMapping; //mapping for each scVar -> <CLIdx,varType>
516 output Integer oNumCL;
517 protected
518 CacheMap cacheMap;
519 CacheMapMeta cacheMapMeta;
520 Integer numCL;
521 array<tuple<Integer,Integer>> scVarCLMapping;
522 //cache lines of the threads (arrayIdx)
523 algorithm
524 ✗ cacheMap := CACHEMAP(iCacheLineSize,{},{},{},{});
525 ✗ scVarCLMapping := arrayCreate(arrayLength(iAllSCVarsMapping),(-1,-1));
526 numCL := 0;
527 ✗ cacheMapMeta := CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, scVarCLMapping);
528 //Iterate over levels
529 ✗ (_,cacheMap,cacheMapMeta,numCL) := List.fold1(iTasksOfLevels, createCacheMapLevelOptimized0, iNodeSimCodeVarMapping, ({},cacheMap,cacheMapMeta,numCL));
530 oCacheMap := cacheMap;
531 ✗ CACHEMAPMETA(scVarCLMapping=oScVarCLMapping) := cacheMapMeta;
532 oNumCL := numCL;
533 end createCacheMapLevelOptimized;
534
535 protected function createCacheMapLevelOptimized0 "author: marcusw
536 Appends the variables which are written by the task list (iLevelTasks) to the info-structure. Only cachelines are used that
537 are not written by the previous layer."
538 input HpcOmSimCode.TaskList iLevelTasks;
539 input array<list<Integer>> iNodeSimCodeVarMapping;
540 input tuple<list<Integer>,CacheMap,CacheMapMeta,Integer> iInfo; //<cacheLinesUsedByPreviousLayer,CacheMap,numCL>
541 output tuple<list<Integer>,CacheMap,CacheMapMeta,Integer> oInfo;
542 protected
543 Integer createdCL, numCL, cacheLineSize; //number of CL created for this level
544 list<Integer> allCL;
545 list<Integer> availableCL, availableCLold, writtenCL; //all cacheLines that can be used for writing
546 list<Integer> cacheLinesPrevLevel; //all cache lines written in previous level
547 list<tuple<Integer,Integer>> detailedCacheLineInfo;
548 CacheMap cacheMap;
549 CacheMapMeta cacheMapMeta;
550 list<CacheLineMap> cacheLinesFloat;
551 algorithm
552 ✗ (cacheLinesPrevLevel, cacheMap, cacheMapMeta, numCL) := iInfo;
553 ✗ allCL := List.intRange(numCL);
554 ✗ CACHEMAP(cacheLinesFloat=cacheLinesFloat,cacheLineSize=cacheLineSize) := cacheMap;
555 //print("createCacheMapLevelOptimized0: Handling new level. CL used by previous layer: " + stringDelimitList(List.map(cacheLinesPrevLevel,intString), ",") + " Number of CL: " + intString(numCL) + "\n");
556 ✗ availableCLold := List.setDifferenceIntN(allCL,cacheLinesPrevLevel,numCL);
557 //append free space to available cache lines and remove full cache lines
558 ✗ detailedCacheLineInfo := createDetailedCacheMapInformation(availableCLold, cacheLinesFloat, cacheLineSize);
559 ✗ detailedCacheLineInfo := listReverse(detailedCacheLineInfo);
560 //print("createCacheMapLevelOptimized0: clCandidates: " + stringDelimitList(List.map(List.map(detailedCacheLineInfo,Util.tuple21),intString), ",") + "\n");
561 ✗ (cacheMap,cacheMapMeta,createdCL,detailedCacheLineInfo) := List.fold1(getTaskListTasks(iLevelTasks), createCacheMapLevelOptimizedForTask, iNodeSimCodeVarMapping, (cacheMap,cacheMapMeta, 0,detailedCacheLineInfo));
562 ✗ availableCL := List.map(detailedCacheLineInfo, Util.tuple21);
563 //append the used cachelines to the writtenCL-list
564 //print("createCacheMapLevelOptimized0: New cacheLines created: " + intString(createdCL) + "\n");
565 ✗ writtenCL := List.setDifferenceIntN(availableCLold,availableCL,numCL);
566 //print("createCacheMapLevelOptimized0: Written CL_0: " + stringDelimitList(List.map(writtenCL,intString), ",") + " -- numCL: " + intString(numCL) + "\n");
567 ✗ writtenCL := listAppend(writtenCL, if intLe(numCL+1, numCL+createdCL) then List.intRange2(numCL+1, numCL+createdCL) else {}) annotation(__OpenModelica_DisableListAppendWarning=true);
568 //print("createCacheMapLevelOptimized0: Written CL_1: " + stringDelimitList(List.map(writtenCL,intString), ",") + "\n");
569 //print("======================================\n");
570 //printCacheMap(cacheMap);
571 //print("======================================\n");
572 ✗ oInfo := (writtenCL,cacheMap,cacheMapMeta,numCL+createdCL);
573 end createCacheMapLevelOptimized0;
574
575 protected function createCacheMapLevelOptimizedForTask "author: marcusw
576 Append the variables that are solved by the given task to the cachelines."
577 input HpcOmSimCode.Task iTask;
578 input array<list<Integer>> iNodeSimCodeVarMapping;
579 input tuple<CacheMap,CacheMapMeta,Integer,list<tuple<Integer,Integer>>> iInfo; //<CacheMap,CacheMapMeta,numNewCL,clCandidates>
580 output tuple<CacheMap,CacheMapMeta,Integer,list<tuple<Integer,Integer>>> oInfo;
581 protected
582 list<Integer> nodeIdc;
583 tuple<CacheMap,CacheMapMeta,Integer,list<tuple<Integer,Integer>>> tmpInfo;
584 algorithm
585 oInfo := match iTask
586 case HpcOmSimCode.CALCTASK_LEVEL(nodeIdc=nodeIdc)
587 algorithm
588 ✗ tmpInfo := List.fold(nodeIdc, function appendNodeVarsToCacheMap(iNodeSimCodeVarMapping=iNodeSimCodeVarMapping,iOwnerThread=-1), iInfo);
589 then tmpInfo;
590 else
591 algorithm
592 ✗ print("createCacheMapLevelOptimized1: Unsupported task type\n");
593 ✗ then fail();
594 end match;
595 end createCacheMapLevelOptimizedForTask;
596
597 protected function createCacheMapLevelFixedOptimized "author: marcusw
598 Create the optimized cache map for the levelfixed-scheduler."
599 input HpcOmTaskGraph.TaskGraph iTaskGraph;
600 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
601 input array<Option<SimCodeVar.SimVar>> iAllSCVarsMapping;
602 input array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes; //<varDataType, numberOfBytesRequired, varType>
603 input array<Integer> iScVarSolvedTaskMapping;
604 input array<list<Integer>> iScVarUnsolvedTaskMapping;
605 input Integer iCacheLineSize;
606 input BackendDAE.StrongComponents iAllComponents;
607 input list<HpcOmSimCode.TaskList> iTasksOfLevels; //Schedule
608 input Integer iNumberOfThreads;
609 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
610 input array<list<Integer>> iTaskSolvedVarsMapping;
611 input array<list<Integer>> iTaskUnsolvedVarsMapping;
612 input array<ScVarInfo> iScVarInfos;
613 output CacheMap oCacheMap;
614 output array<tuple<Integer,Integer>> oScVarCLMapping; //mapping for each scVar -> <CLIdx,varType>
615 output Integer oNumCL;
616 protected
617 CacheMap cacheMap;
618 CacheMapMeta cacheMapMeta;
619 array<Boolean> handledVariables;
620 array<tuple<Integer,Integer>> scVarCLMapping;
621 array<CacheLines> threadCacheLines; //cache lines of the threads (arrayIdx) -- CALC_ONLY and THREAD_ONLY variables
622 array<tuple<PartlyFilledCacheLines, CacheLines>> sharedCacheLines;
623 algorithm
624 1 cacheMap := CACHEMAP(iCacheLineSize,{},{},{},{});
625 1 scVarCLMapping := arrayCreate(arrayLength(iAllSCVarsMapping),(-1,-1));
626 1 handledVariables := arrayCreate(arrayLength(iSimCodeVarTypes), false);
627 oNumCL := 0;
628 1 threadCacheLines := arrayCreate(iNumberOfThreads, ({},{},{}));
629 1 sharedCacheLines := arrayCreate(iNumberOfThreads, (({},{},{}), ({},{},{})));
630 1 cacheMapMeta := CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, scVarCLMapping);
631 //Iterate over levels
632 1 (cacheMap,cacheMapMeta,oNumCL,_) := List.fold(iTasksOfLevels, function createCacheMapLevelFixedOptimizedForLevel(iTaskGraph=iTaskGraph, iTaskGraphMeta=iTaskGraphMeta,
633 iNumberOfThreads=iNumberOfThreads, iScVarInfos=iScVarInfos, iTaskSolvedVarsMapping=iTaskSolvedVarsMapping,
634 iTaskUnsolvedVarsMapping=iTaskUnsolvedVarsMapping, iHandledVariables=handledVariables, iSchedulerInfo=iSchedulerInfo,
635 iThreadCacheLines=threadCacheLines, iSharedCacheLines=sharedCacheLines), (cacheMap,cacheMapMeta,oNumCL,1));
636
637
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
2 for threadIdx in 1:iNumberOfThreads loop
638 1 cacheMap := createCacheMapFromThreadAndSharedCLs(arrayGet(threadCacheLines, threadIdx), arrayGet(sharedCacheLines, threadIdx), cacheMap);
639 end for;
640
641 oCacheMap := cacheMap;
642
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 CACHEMAPMETA(scVarCLMapping=oScVarCLMapping) := cacheMapMeta;
643 end createCacheMapLevelFixedOptimized;
644
645 protected function createCacheMapLevelFixedOptimizedForLevel "author: marcusw
646 Appends the variables which are written by the task list (iLevelTasks) to the info-structure."
647 input HpcOmSimCode.TaskList iLevelTasks;
648 input HpcOmTaskGraph.TaskGraph iTaskGraph;
649 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
650 input Integer iNumberOfThreads;
651 input array<ScVarInfo> iScVarInfos;
652 input array<list<Integer>> iTaskSolvedVarsMapping;
653 input array<list<Integer>> iTaskUnsolvedVarsMapping;
654 input array<Boolean> iHandledVariables; //true if the variable was already added to a cache line
655 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
656 input array<CacheLines> iThreadCacheLines; //Thread CacheLines for float, int and bool -- is updated!
657 input array<tuple<PartlyFilledCacheLines, CacheLines>> iSharedCacheLines;
658 input tuple<CacheMap,CacheMapMeta,Integer,Integer> iInfo; //<CacheMap,CacheMapMeta,numCL,level>
659 output tuple<CacheMap,CacheMapMeta,Integer,Integer> oInfo;
660 protected
661 Integer createdCL, numCL, cacheLineSize, level; //number of CL created for this level
662 list<Integer> allCL;
663 //all cacheLines that can be used for writing
664 //all cache lines written in previous level
665 CacheMap cacheMap;
666 CacheMapMeta cacheMapMeta;
667 list<CacheLineMap> cacheLinesFloat;
668 list<SimCodeVar.SimVar> cacheVariables;
669 algorithm
670 2 (cacheMap, cacheMapMeta, numCL, level) := iInfo;
671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 CACHEMAP(cacheVariables=cacheVariables) := cacheMap;
672 //print("\tcreateCacheMapLevelFixedOptimized0: handling level " + intString(level) + "\n");
673 2 allCL := List.intRange(numCL);
674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 CACHEMAP(cacheLinesFloat=cacheLinesFloat,cacheLineSize=cacheLineSize) := cacheMap;
675 2 (cacheMap,cacheMapMeta,createdCL) := List.fold(getTaskListTasks(iLevelTasks),
676 function createCacheMapLevelFixedOptimizedForTask(iTaskGraph=iTaskGraph, iTaskGraphMeta=iTaskGraphMeta, iSchedulerInfo=iSchedulerInfo,
677 iNumberOfThreads=iNumberOfThreads, iLevel=level, iScVarInfos=iScVarInfos, iTaskSolvedVarsMapping=iTaskSolvedVarsMapping,
678 iTaskUnsolvedVarsMapping=iTaskUnsolvedVarsMapping, iHandledVariables=iHandledVariables,
679 iThreadCacheLines=iThreadCacheLines, iSharedCacheLines=iSharedCacheLines), (cacheMap,cacheMapMeta,numCL));
680 //printCacheMap(cacheMap);
681 //print("===================================================\n===================================================\n===================================================\n");
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 CACHEMAP(cacheVariables=cacheVariables) := cacheMap;
683 2 oInfo := (cacheMap,cacheMapMeta,createdCL,level+1);
684 end createCacheMapLevelFixedOptimizedForLevel;
685
686 protected function createCacheMapLevelFixedOptimizedForTask "author: marcusw
687 Append the variables that are solved by the given task to the cachelines."
688 input HpcOmSimCode.Task iTask;
689 input HpcOmTaskGraph.TaskGraph iTaskGraph;
690 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
691 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
692 input Integer iNumberOfThreads;
693 input Integer iLevel;
694 input array<ScVarInfo> iScVarInfos;
695 input array<list<Integer>> iTaskSolvedVarsMapping;
696 input array<list<Integer>> iTaskUnsolvedVarsMapping;
697 input array<Boolean> iHandledVariables; //true if the variable was already added to a cache line
698 input array<CacheLines> iThreadCacheLines; //Thread CacheLines for float, int and bool
699 input array<tuple<PartlyFilledCacheLines, CacheLines>> iSharedCacheLines;
700 input tuple<CacheMap,CacheMapMeta,Integer> iInfo; //<CacheMap,CacheMapMeta,numNewCL>
701 output tuple<CacheMap,CacheMapMeta,Integer> oInfo;
702 protected
703 list<Integer> nodeIdc, solvedVars, unsolvedVars;
704 CacheMap cacheMap;
705 CacheMapMeta cacheMapMeta;
706 tuple<CacheMap,CacheMapMeta,Integer> tmpInfo;
707 Integer threadIdx, numNewCL;
708 array<Option<SimCodeVar.SimVar>> allSCVarsMapping;
709
710 list<SimCodeVar.SimVar> cacheVariables;
711 algorithm
712 oInfo := match(iTask, iInfo)
713 case(HpcOmSimCode.CALCTASK_LEVEL(nodeIdc=nodeIdc,threadIdx=SOME(threadIdx)), (cacheMap,cacheMapMeta as CACHEMAPMETA(allSCVarsMapping=allSCVarsMapping),numNewCL))
714 algorithm
715 36 solvedVars := List.flatten(List.map(nodeIdc, function arrayGet(arr=iTaskSolvedVarsMapping))); //there should be no duplicates
716 36 unsolvedVars := getUnsolvedVarsByNodeList(nodeIdc, arrayLength(iScVarInfos), iTaskUnsolvedVarsMapping);
717 36 tmpInfo := List.fold(listAppend(solvedVars,unsolvedVars), function createCacheMapOptimizedForTask1(iThreadIdx=threadIdx,iScVarInfos=iScVarInfos,
718 iHandledVariables=iHandledVariables,iSharedClSelectFunction=findMatchingSharedCLLevelfix,iCompareFuncArgument=(iLevel,threadIdx),
719 iFactoryMethod=createSharedClLevelFix,iThreadCacheLines=iThreadCacheLines,iSharedCacheLines=iSharedCacheLines),
720 (cacheMap, cacheMapMeta, numNewCL));
721
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
36 CACHEMAP(cacheVariables=cacheVariables) := Util.tuple31(tmpInfo);
722 then tmpInfo;
723 case(HpcOmSimCode.CALCTASK_LEVEL(nodeIdc=nodeIdc,threadIdx=NONE()), _)
724 algorithm
725 ✗ print("createCacheMapLevelOptimized1: Calctask without threadIdx given\n");
726 ✗ then fail();
727 else
728 algorithm
729 ✗ print("createCacheMapLevelOptimized1: Unsupported task type\n");
730 ✗ then fail();
731 end match;
732 end createCacheMapLevelFixedOptimizedForTask;
733
734 protected function getUnsolvedVarsByNodeList
735 input list<Integer> iNodeList;
736 input Integer iVarCount;
737 input array<list<Integer>> iTaskUnsolvedVarsMapping;
738 output list<Integer> oUnsolvedVars;
739 protected
740 array<Boolean> varMarks;
741 Integer nodeIdx, varIdx;
742 list<Integer> nodeUnsolvedVars;
743 list<Integer> tmpUnsolvedVars = {};
744 algorithm
745 36 varMarks := arrayCreate(iVarCount, false);
746
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
72 for nodeIdx in iNodeList loop
747 36 nodeUnsolvedVars := arrayGet(iTaskUnsolvedVarsMapping, nodeIdx);
748
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 36 times.
180 for varIdx in nodeUnsolvedVars loop
749
1/2
✓ Branch 1 taken 144 times.
✗ Branch 2 not taken.
144 if(boolNot(arrayGet(varMarks, varIdx))) then
750 tmpUnsolvedVars := varIdx::tmpUnsolvedVars;
751 144 varMarks := arrayUpdate(varMarks, varIdx, true);
752 end if;
753 end for;
754 end for;
755 oUnsolvedVars := tmpUnsolvedVars;
756 end getUnsolvedVarsByNodeList;
757
758 protected function createCacheMapThreadOptimized "author: marcusw
759 Create the optimized cache map for the thread-scheduler."
760 input HpcOmTaskGraph.TaskGraph iTaskGraph;
761 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
762 input array<Option<SimCodeVar.SimVar>> iAllSCVarsMapping;
763 input array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes; //<type, numberOfBytesRequired>
764 input array<Integer> iScVarSolvedTaskMapping;
765 input array<list<Integer>> iScVarUnsolvedTaskMapping;
766 input Integer iCacheLineSize;
767 input BackendDAE.StrongComponents iAllComponents;
768 input array<list<HpcOmSimCode.Task>> iThreadTasks; //Schedule
769 input Integer iNumberOfThreads;
770 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
771 input array<list<Integer>> iTaskSolvedVarsMapping;
772 input array<list<Integer>> iTaskUnsolvedVarsMapping;
773 input array<ScVarInfo> iScVarInfos;
774 output CacheMap oCacheMap;
775 output array<tuple<Integer,Integer>> oScVarCLMapping; //mapping for each scVar -> <CLIdx,varType>
776 output Integer oNumCL;
777 protected
778 array<CacheLines> threadCacheLines;
779 array<tuple<PartlyFilledCacheLines, CacheLines>> sharedCacheLines;
780 tuple<CacheMap,CacheMapMeta,Integer> tmpCacheInfo;
781 CacheMap cacheMap;
782 CacheMapMeta cacheMapMeta;
783 array<tuple<Integer,Integer>> scVarCLMapping;
784 array<Boolean> handledVariables;
785 algorithm
786 //Initialize variables
787 ✗ threadCacheLines := arrayCreate(iNumberOfThreads, ({},{},{}));
788 ✗ sharedCacheLines := arrayCreate(iNumberOfThreads, (({},{},{}), ({},{},{})));
789 ✗ handledVariables := arrayCreate(arrayLength(iSimCodeVarTypes), false);
790
791 ✗ cacheMap := CACHEMAP(iCacheLineSize,{},{},{},{});
792 ✗ scVarCLMapping := arrayCreate(arrayLength(iAllSCVarsMapping),(-1,-1));
793 oNumCL := 0;
794 ✗ cacheMapMeta := CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, scVarCLMapping);
795 ✗ tmpCacheInfo := (cacheMap, cacheMapMeta, oNumCL);
796
797 ✗ for threadIdx in 1:iNumberOfThreads loop
798 //print("======================================================================\n");
799 //print("createCacheMapThreadOptimized: Handling thread " + intString(threadIdx) + " with " + intString(oNumCL) + " cache lines\n");
800 //print("======================================================================\n");
801 ✗ (cacheMap, cacheMapMeta, oNumCL) := List.fold(arrayGet(iThreadTasks, threadIdx), function createCacheMapOptimizedForTask(
802 iTaskGraph=iTaskGraph, iTaskGraphMeta=iTaskGraphMeta, iSchedulerInfo=iSchedulerInfo, iTaskSolvedVarsMapping=iTaskSolvedVarsMapping,
803 iTaskUnsolvedVarsMapping=iTaskUnsolvedVarsMapping, iHandledVariables=handledVariables, iNumberOfThreads=iNumberOfThreads,
804 iSharedClSelectFunction=findMatchingSharedCLThread, iCompareFuncArgument=0, iFactoryMethod=createSharedClThread, iScVarInfos=iScVarInfos,
805 iThreadCacheLines=threadCacheLines, iSharedCacheLines=sharedCacheLines), tmpCacheInfo);
806
807 ✗ cacheMap := createCacheMapFromThreadAndSharedCLs(arrayGet(threadCacheLines, threadIdx), arrayGet(sharedCacheLines, threadIdx), cacheMap);
808
809 ✗ tmpCacheInfo := (cacheMap, cacheMapMeta, oNumCL);
810 end for;
811
812 ✗ oCacheMap := Util.tuple31(tmpCacheInfo);
813 ✗ CACHEMAPMETA(scVarCLMapping=oScVarCLMapping) := cacheMapMeta;
814 end createCacheMapThreadOptimized;
815
816 protected function createCacheMapOptimizedForTask<T> "author: marcusw
817 Append the variables that are solved by the given task to the cachelines."
818 input HpcOmSimCode.Task iTask;
819 input HpcOmTaskGraph.TaskGraph iTaskGraph;
820 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
821 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
822 input array<list<Integer>> iTaskSolvedVarsMapping;
823 input array<list<Integer>> iTaskUnsolvedVarsMapping;
824 input array<Boolean> iHandledVariables; //true if the variable was already added to a cache line
825 input Integer iNumberOfThreads;
826 input HeuristicFunction iSharedClSelectFunction; //the function that will search for the ideal cache line to store a given variable
827 input T iCompareFuncArgument;
828 input FactoryMethod iFactoryMethod; //function to create a partly filled cache line object
829 input array<CacheLines> iThreadCacheLines; //Thread exclusive CacheLines for float, int and bool
830 input array<tuple<PartlyFilledCacheLines, CacheLines> > iSharedCacheLines; //Thread shared CacheLines for float, int and bool
831 input array<ScVarInfo> iScVarInfos;
832 input tuple<CacheMap,CacheMapMeta,Integer> iInfo; //<CacheMap,CacheMapMeta,numOfCLs>
833 output tuple<CacheMap,CacheMapMeta,Integer> oInfo;
834
835 partial function HeuristicFunction
836 input Integer iNodeVar;
837 input Integer iVarSize; //number of required bytes
838 input Integer iVarType;
839 input Integer iThreadIdx;
840 input T inElement;
841 input array<tuple<PartlyFilledCacheLines, CacheLines> > iSharedCacheLines;
842 output Option<tuple<PartlyFilledCacheLine, Integer>> oMatchedCacheLine; //<CL, listIndex>
843 end HeuristicFunction;
844
845 partial function FactoryMethod
846 input Option<PartlyFilledCacheLine> iOldPartlyFilledCacheLine;
847 input CacheLineMap iCacheLineMap;
848 input T iAdditionalArguments;
849 output PartlyFilledCacheLine oCreatedCacheLine;
850 end FactoryMethod;
851 protected
852 Integer threadIdx, taskIdx;
853 list<Integer> solvedVars, unsolvedVars, vars;
854 CacheMap cacheMap;
855 CacheMapMeta cacheMapMeta;
856 Integer numOfCLs;
857 tuple<CacheMap,CacheMapMeta,Integer> tmpInfo;
858 array<Option<SimCodeVar.SimVar>> allSCVarsMapping;
859 algorithm
860 oInfo := match(iTask, iInfo)
861 case(HpcOmSimCode.CALCTASK(index=taskIdx, threadIdx=threadIdx), (cacheMap, cacheMapMeta as CACHEMAPMETA(allSCVarsMapping=allSCVarsMapping), numOfCLs))
862 algorithm
863 ✗ solvedVars := arrayGet(iTaskSolvedVarsMapping, taskIdx);
864 ✗ unsolvedVars := arrayGet(iTaskUnsolvedVarsMapping, taskIdx);
865 ✗ vars := List.sort(listAppend(solvedVars,unsolvedVars), intGt);
866 //print("createCacheMapOptimizedForTask: Vars for task " + stringDelimitList(List.map(vars, intString), ",") + "\n");
867 ✗ tmpInfo := List.fold(vars, function createCacheMapOptimizedForTask1(iThreadIdx=threadIdx, iScVarInfos=iScVarInfos, iHandledVariables=iHandledVariables,
868 iSharedClSelectFunction=iSharedClSelectFunction, iCompareFuncArgument=iCompareFuncArgument, iFactoryMethod=iFactoryMethod, iThreadCacheLines=iThreadCacheLines,
869 iSharedCacheLines=iSharedCacheLines), (cacheMap, cacheMapMeta, numOfCLs));
870 then tmpInfo;
871 case(HpcOmSimCode.DEPTASK(_), (cacheMap, cacheMapMeta as CACHEMAPMETA(allSCVarsMapping=allSCVarsMapping), numOfCLs))
872 then iInfo;
873 else
874 algorithm
875 ✗ print("createCacheMapThreadOptimizedForTask failed!\n");
876 then iInfo;
877 end match;
878 end createCacheMapOptimizedForTask;
879
880 protected function createCacheMapOptimizedForTask1<T>
881 input Integer iScVar;
882 input Integer iThreadIdx;
883 input array<ScVarInfo> iScVarInfos;
884 input array<Boolean> iHandledVariables;
885 input HeuristicFunction iSharedClSelectFunction; //the function that will search for the ideal cache line to store a given variable
886 input T iCompareFuncArgument;
887 input FactoryMethod iFactoryMethod; //function to create a partly filled cache line object
888 input array<CacheLines> iThreadCacheLines; //Thread exclusive CacheLines for float, int and bool
889 input array<tuple<PartlyFilledCacheLines, CacheLines> > iSharedCacheLines; //Thread shared CacheLines for float, int and bool (partly and fully filled)
890 input tuple<CacheMap,CacheMapMeta,Integer> iInfo; //<CacheMap,CacheMapMeta,numOfCLs>
891 output tuple<CacheMap,CacheMapMeta,Integer> oInfo;
892
893 partial function HeuristicFunction
894 input Integer iNodeVar;
895 input Integer iVarSize; //number of required bytes
896 input Integer iVarType;
897 input Integer iThreadIdx;
898 input T inElement;
899 input array<tuple<PartlyFilledCacheLines, CacheLines> > iSharedCacheLines;
900 output Option<tuple<PartlyFilledCacheLine, Integer>> oMatchedCacheLine; //<CL, listIndex>
901 end HeuristicFunction;
902
903 partial function FactoryMethod
904 input Option<PartlyFilledCacheLine> iOldPartlyFilledCacheLine;
905 input CacheLineMap iCacheLineMap;
906 input T iAdditionalArguments;
907 output PartlyFilledCacheLine oCreatedCacheLine;
908 end FactoryMethod;
909 protected
910 Boolean isShared;
911 CacheMap cacheMap;
912 CacheMapMeta cacheMapMeta;
913 Integer numOfCLs;
914 Integer ownerThread;
915 algorithm
916 308 (cacheMap, cacheMapMeta, numOfCLs) := iInfo;
917 308 SCVARINFO(ownerThread,isShared) := arrayGet(iScVarInfos, iScVar);
918 //print("createCacheMapThreadOptimizedForTask1: Handling sc-var " + intString(iScVar) + ". Owner thread is " + intString(ownerThread) + " Number of cache lines is " + intString(numOfCLs) + "\n");
919
3/4
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 286 times.
✓ Branch 4 taken 22 times.
308 if(boolAnd(boolNot(boolAnd(intEq(ownerThread,-1), isShared)), boolNot(arrayGet(iHandledVariables, iScVar)))) then
920 //print("Variable " + intString(iScVar) + " was not already handled\n");
921
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 264 times.
286 if(isShared) then
922 //print("--> Handling as shared variable\n");
923 22 (cacheMap,cacheMapMeta,numOfCLs) := addVarsToSharedCL({iScVar}, iSharedClSelectFunction, iFactoryMethod, iThreadIdx, iCompareFuncArgument, iSharedCacheLines, (cacheMap,cacheMapMeta,numOfCLs));
924 else
925 //print("--> Handling as thread variable\n");
926 264 (cacheMap,cacheMapMeta,numOfCLs) := addVarsToThreadCL({iScVar},iThreadIdx,iThreadCacheLines,(cacheMap,cacheMapMeta,numOfCLs));
927 end if;
928 else
929 //print("createCacheMapOptimizedForTask1: Skipping variable '" + intString(iScVar) + "'\n");
930 end if;
931 308 arrayUpdate(iHandledVariables, iScVar, true);
932 308 oInfo := (cacheMap,cacheMapMeta,numOfCLs);
933 end createCacheMapOptimizedForTask1;
934
935 protected function createVarInfos
936 input array<Integer> iScVarSolvedTaskMapping;
937 input array<list<Integer>> iScVarUnsolvedTaskMapping;
938 input array<tuple<Integer,Integer,Real>> iSchedulerInfo; //maps each Task to <threadId, orderId, startCalcTime>
939 output array<ScVarInfo> oVarInfos;
940 protected
941 array<ScVarInfo> tmpVarInfos;
942 Integer scVarIdx, numberOfScVars;
943 algorithm
944 numberOfScVars := arrayLength(iScVarSolvedTaskMapping);
945 8 tmpVarInfos := arrayCreate(numberOfScVars, SCVARINFO(-1,false));
946
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
5614 for scVarIdx in 1:numberOfScVars loop
947 5606 tmpVarInfos := arrayUpdate(tmpVarInfos, scVarIdx, getVarInfoByScVarIdx(scVarIdx, iScVarSolvedTaskMapping, iScVarUnsolvedTaskMapping, iSchedulerInfo));
948 end for;
949 oVarInfos := tmpVarInfos;
950 end createVarInfos;
951
952 protected function getVarInfoByScVarIdx
953 input Integer iScVarIdx;
954 input array<Integer> iScVarSolvedTaskMapping;
955 input array<list<Integer>> iScVarUnsolvedTaskMapping;
956 input array<tuple<Integer,Integer,Real>> iSchedulerInfo; //maps each Task to <threadId, orderId, startCalcTime>
957 output ScVarInfo oVarInfo;
958 protected
959 Integer solvingThreadIdx, solvingTaskIdx, listLen;
960 Integer owner = -1;
961 Boolean isShared = false;
962 list<Integer> threads = {};
963 list<Integer> unsolvingThreadIdc, unsolvingTaskIdc;
964 algorithm
965 5606 solvingTaskIdx := arrayGet(iScVarSolvedTaskMapping, iScVarIdx);
966 5606 unsolvingTaskIdc := arrayGet(iScVarUnsolvedTaskMapping, iScVarIdx);
967 //print("getVarInfoByScVarIdx: Handling variable '" + intString(iScVarIdx) + "' with unsolving tasks " + stringDelimitList(List.map(unsolvingTaskIdc, intString), ",") + "\n");
968
2/2
✓ Branch 0 taken 1355 times.
✓ Branch 1 taken 4251 times.
5606 if(intGt(solvingTaskIdx, 0)) then
969 1355 solvingThreadIdx := Util.tuple31(arrayGet(iSchedulerInfo, solvingTaskIdx));
970 owner := solvingThreadIdx;
971 threads := owner::threads;
972 end if;
973 5606 listLen := listLength(unsolvingTaskIdc);
974 5606 unsolvingThreadIdc := List.map(List.map(unsolvingTaskIdc, function arrayGet(arr=iSchedulerInfo)), Util.tuple31);
975 //print("getVarInfoByScVarIdx: --> unsolving threads are " + stringDelimitList(List.map(unsolvingThreadIdc, intString), ",") + "\n");
976
2/2
✓ Branch 0 taken 467 times.
✓ Branch 1 taken 5139 times.
5606 if(intEq(listLen, 1)) then
977
2/2
✓ Branch 0 taken 409 times.
✓ Branch 1 taken 58 times.
467 if(intLt(owner, 0)) then
978 409 owner := listHead(unsolvingThreadIdc);
979 threads := owner::threads;
980 else
981 isShared := true;
982 end if;
983 end if;
984
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 5239 times.
5606 if(intGt(listLen, 1)) then
985 367 threads := List.unique(listAppend(unsolvingThreadIdc, threads));
986 isShared := true;
987 end if;
988
2/2
✓ Branch 0 taken 5181 times.
✓ Branch 1 taken 58 times.
10787 oVarInfo := SCVARINFO(owner, isShared);
989 end getVarInfoByScVarIdx;
990
991 protected function addVarsToThreadCL "author: marcusw
992 Add the given variables as thread-only variable to the cache lines."
993 input list<Integer> iNodeVars;
994 input Integer iThreadIdx;
995 input array<CacheLines> iThreadCacheLines; //Thread CacheLines for float, int and bool
996 input tuple<CacheMap,CacheMapMeta,Integer> iInfo; //<CacheMap,CacheMapMeta,numCLs>
997 output tuple<CacheMap,CacheMapMeta,Integer> oInfo;
998 protected
999 CacheLineMap lastCL;
1000 SimCodeVar.SimVar cacheVariable;
1001 array<Option<SimCodeVar.SimVar>> allSCVarsMapping;
1002 Integer varIdx, varDataType, varNumBytesRequired, numCLs, cacheLineSize;
1003 array<tuple<Integer,Integer,Integer>> simCodeVarTypes; //<varDataType, numberOfBytesRequired, varType>
1004 array<tuple<Integer, Integer>> scVarCLMapping;
1005 list<CacheLineMap> fullCLs, threadCacheLines;
1006 list<SimCodeVar.SimVar> cacheVariables;
1007 list<CacheLineMap> cacheLinesFloat, cacheLinesInt, cacheLinesBool;
1008
1009 Integer lastCLidx;
1010 Integer lastCLnumBytesFree;
1011 list<CacheLineEntry> lastCLentries;
1012 CacheLineEntry varEntry;
1013 DAE.ComponentRef cacheVarName;
1014
1015 list<CacheLineMap> threadCacheLinesFloat, threadCacheLinesInt, threadCacheLinesBool;
1016 algorithm
1017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 (CACHEMAP(cacheLineSize=cacheLineSize,cacheVariables=cacheVariables,cacheLinesFloat=cacheLinesFloat, cacheLinesInt=cacheLinesInt, cacheLinesBool=cacheLinesBool),CACHEMAPMETA(allSCVarsMapping=allSCVarsMapping,simCodeVarTypes=simCodeVarTypes,scVarCLMapping=scVarCLMapping),numCLs) := iInfo;
1018
1019 //only the first CL has enough space to store another variable
1020
2/2
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 264 times.
528 for varIdx in iNodeVars loop
1021 264 (varDataType,varNumBytesRequired,_) := arrayGet(simCodeVarTypes, varIdx);
1022 264 (threadCacheLinesFloat,threadCacheLinesInt,threadCacheLinesBool,threadCacheLines) := getCacheLineForVarType(varDataType, arrayGet(iThreadCacheLines, iThreadIdx));
1023
1024
2/2
✓ Branch 0 taken 262 times.
✓ Branch 1 taken 2 times.
264 if not listEmpty(threadCacheLines) then
1025 262 lastCL::fullCLs := threadCacheLines;
1026 else
1027 2 lastCLidx := numCLs + 1;
1028 lastCLnumBytesFree := cacheLineSize;
1029 lastCLentries := {};
1030 2 lastCL := CACHELINEMAP(idx=lastCLidx, numBytesFree=lastCLnumBytesFree, entries=lastCLentries);
1031 numCLs := numCLs + 1;
1032 fullCLs := {};
1033 end if;
1034
1035 264 CACHELINEMAP(idx=lastCLidx,numBytesFree=lastCLnumBytesFree,entries=lastCLentries) := lastCL;
1036
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 237 times.
264 if(intLt(lastCLnumBytesFree,varNumBytesRequired)) then //variable does not fit into CL --> create a new CL
1037 //print("\t\t\t\taddVarsToThreadCL: variable " + intString(varIdx) + " does not fit into lastCL.\n");
1038 fullCLs := lastCL::fullCLs;
1039 27 lastCLidx := numCLs + 1;
1040 //print("\t\t\t\taddVarsToThreadCL: lastCLidx " + intString(listLength(cacheLinesFloat)) + " + " + intString(numCLs) + " + 1\n");
1041 lastCLnumBytesFree := cacheLineSize;
1042 lastCLentries := {};
1043 27 lastCL := CACHELINEMAP(idx=lastCLidx, numBytesFree=lastCLnumBytesFree, entries=lastCLentries);
1044 numCLs := numCLs + 1;
1045 end if;
1046 // print("addVarsToThreadCL: adding variable '" + intString(listLength(cacheVariables)) + "'\n");
1047
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 264 times.
264 SOME(cacheVariable as SimCodeVar.SIMVAR(name=cacheVarName)) := arrayGet(allSCVarsMapping, varIdx);
1048 //print("addVarsToThreadCL: Variable " + ComponentReferenceBasics.printComponentRefStr(cacheVarName) + " has type " + intString(varDataType) + "\n");
1049
1050 //print("addVarsToThreadCL: adding variable '" + intString(listLength(cacheVariables)) + "' [" + dumpSimCodeVar(cacheVariable) + "] to cache line map '" + intString(lastCLidx) + "'\n");
1051 //print("\t\t\t\taddVarsToThreadCL: cacheVariable found.\n");
1052 cacheVariables := cacheVariable::cacheVariables;
1053 264 scVarCLMapping := arrayUpdate(scVarCLMapping, varIdx, (lastCLidx,varDataType));
1054 //print("\t\t\tCache variables: " + intString(listLength(cacheVariables)) + " to thread " + intString(iThreadIdx) + "\n");
1055 264 varEntry := CACHELINEENTRY(start=cacheLineSize-lastCLnumBytesFree,dataType=varDataType,size=varNumBytesRequired,scVarIdx=listLength(cacheVariables),threadOwner=iThreadIdx);
1056 264 lastCL := CACHELINEMAP(idx=lastCLidx,numBytesFree=lastCLnumBytesFree-varNumBytesRequired,entries=varEntry::lastCLentries);
1057
1058 264 arrayUpdate(iThreadCacheLines, iThreadIdx, contractCacheLineForVarType(varDataType, threadCacheLinesFloat, threadCacheLinesInt, threadCacheLinesBool, lastCL::fullCLs));
1059 end for;
1060
1061 264 oInfo := (CACHEMAP(cacheLineSize,cacheVariables,cacheLinesFloat,cacheLinesInt,cacheLinesBool),CACHEMAPMETA(allSCVarsMapping,simCodeVarTypes,scVarCLMapping),numCLs);
1062 end addVarsToThreadCL;
1063
1064 protected function getCacheLineForVarType "author: marcusw
1065 Get all cache lines of the given array, separated by their types. The cache lines that should be used to store the given data type, are
1066 additionally returned as last argument."
1067 input Integer iVarDataType;
1068 input CacheLines iCacheLinesForTypes;
1069 output list<CacheLineMap> oCacheLinesFloat;
1070 output list<CacheLineMap> oCacheLinesInt;
1071 output list<CacheLineMap> oCacheLinesBool;
1072 output list<CacheLineMap> oVarCacheLines = {}; //one of the 3 types above
1073 algorithm
1074 264 (oCacheLinesFloat,oCacheLinesInt,oCacheLinesBool) := iCacheLinesForTypes;
1075
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 220 times.
264 if(intEq(iVarDataType, VARDATATYPE_FLOAT)) then
1076 //print("addVarsToThreadCL: Found REAL-VARIABLE!\n");
1077 (oVarCacheLines,_,_) := iCacheLinesForTypes;
1078 else
1079
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(intEq(iVarDataType, VARDATATYPE_INTEGER)) then
1080 //print("addVarsToThreadCL: Found INT-VARIABLE!\n");
1081 (_,oVarCacheLines,_) := iCacheLinesForTypes;
1082 else
1083
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if(intEq(iVarDataType, VARDATATYPE_BOOLEAN)) then
1084 //print("addVarsToThreadCL: Found BOOL-VARIABLE!\n");
1085 (_,_,oVarCacheLines) := iCacheLinesForTypes;
1086 else
1087 ✗ print("getCacheLineForVarType: Found Variable with unknown type ( " + intString(iVarDataType) + ")!\n");
1088 end if;
1089 end if;
1090 end if;
1091 end getCacheLineForVarType;
1092
1093 protected function contractCacheLineForVarType "author: marcusw
1094 Get all cache lines of the given array, separated by their types. The cache lines that should be used to store the given data type, are
1095 additionally returned as last argument."
1096 input Integer iVarDataType;
1097 input list<CacheLineMap> iCacheLinesFloat;
1098 input list<CacheLineMap> iCacheLinesInt;
1099 input list<CacheLineMap> iCacheLinesBool;
1100 input list<CacheLineMap> iVarCacheLines;
1101 output CacheLines oContractedCacheLines = (iCacheLinesFloat, iCacheLinesInt, iCacheLinesBool);
1102 algorithm
1103
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 44 times.
264 if(intEq(iVarDataType, VARDATATYPE_FLOAT)) then
1104 220 oContractedCacheLines := (iVarCacheLines, iCacheLinesInt, iCacheLinesBool);
1105 else
1106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if(intEq(iVarDataType, VARDATATYPE_INTEGER)) then
1107 ✗ oContractedCacheLines := (iCacheLinesFloat, iVarCacheLines, iCacheLinesBool);
1108 else
1109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if(intEq(iVarDataType, VARDATATYPE_BOOLEAN)) then
1110 44 oContractedCacheLines := (iCacheLinesFloat, iCacheLinesInt, iVarCacheLines);
1111 end if;
1112 end if;
1113 end if;
1114 end contractCacheLineForVarType;
1115
1116 protected function addVarsToSharedCL<T> "author: marcusw
1117 Append the given variables to shared cache lines. If a matching partly filled cache line is found,
1118 the partly filled cache line object is updates. Otherwise a new cache line object is created. If a cacheline
1119 is filled completely, it is appended to the CacheLines-structure of iSharedCacheLines."
1120 input list<Integer> iNodeVars;
1121 input HeuristicFunction iSharedClSelectFunction; //the function that will search for the ideal cache line to store a given variable
1122 input FactoryMethod iFactoryMethod; //function to create a partly filled cache line object
1123 input Integer iThreadIdx;
1124 input T iCompareFuncArgument;
1125 input array<tuple<PartlyFilledCacheLines, CacheLines> > iSharedCacheLines; //partly filled cache lines and fully shared cache lines
1126 input tuple<CacheMap,CacheMapMeta,Integer> iInfo; //<CacheMapMeta,NumOfCLs>
1127 output tuple<CacheMap,CacheMapMeta,Integer> oInfo;
1128
1129 partial function HeuristicFunction
1130 input Integer iNodeVar;
1131 input Integer iVarSize; //number of required bytes
1132 input Integer iVarType;
1133 input Integer iThreadIdx;
1134 input T inElement;
1135 input array<tuple<PartlyFilledCacheLines, CacheLines> > iSharedCacheLines;
1136 output Option<tuple<PartlyFilledCacheLine, Integer>> oMatchedCacheLine; //<CL, listIndex>
1137 end HeuristicFunction;
1138
1139 partial function FactoryMethod
1140 input Option<PartlyFilledCacheLine> iOldPartlyFilledCacheLine;
1141 input CacheLineMap iCacheLineMap;
1142 input T iAdditionalArguments;
1143 output PartlyFilledCacheLine oCreatedCacheLine;
1144 end FactoryMethod;
1145
1146 protected
1147 array<Option<SimCodeVar.SimVar>> allSCVarsMapping;
1148 Integer varIdx, varDataType, numOfCLs, cacheLineSize, varSize;
1149 array<tuple<Integer,Integer,Integer>> simCodeVarTypes; //<varDataType, numberOfBytesRequired,varType>
1150 array<tuple<Integer, Integer>> scVarCLMapping;
1151 list<SimCodeVar.SimVar> cacheVariables;
1152 list<CacheLineMap> cacheLinesFloat;
1153 CacheMap cacheMap;
1154 CacheMapMeta cacheMapMeta;
1155 Option<tuple<PartlyFilledCacheLine,Integer>> matchedCacheLine;
1156 algorithm
1157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 (cacheMap as CACHEMAP(cacheLineSize=cacheLineSize,cacheVariables=cacheVariables,cacheLinesFloat=cacheLinesFloat),cacheMapMeta as CACHEMAPMETA(allSCVarsMapping=allSCVarsMapping,simCodeVarTypes=simCodeVarTypes,scVarCLMapping=scVarCLMapping),numOfCLs) := iInfo;
1158
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 22 times.
44 for varIdx in iNodeVars loop
1159 22 (varDataType,varSize,_) := arrayGet(simCodeVarTypes, varIdx);
1160 //print("addVarsToSharedCL: varIdx=" + intString(varIdx) + " varType=" + intString(varDataType) + "\n");
1161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 matchedCacheLine := iSharedClSelectFunction(varIdx, varSize, varDataType, iThreadIdx, iCompareFuncArgument, iSharedCacheLines);
1162 22 (cacheMap,cacheMapMeta,numOfCLs) := addVarsToSharedCL0(matchedCacheLine, varIdx, iFactoryMethod, iCompareFuncArgument, iThreadIdx, iSharedCacheLines, (cacheMap,cacheMapMeta,numOfCLs));
1163 end for;
1164 22 oInfo := (cacheMap,cacheMapMeta,numOfCLs);
1165 end addVarsToSharedCL;
1166
1167 protected function addVarsToSharedCL0<T> "author: marcusw
1168 Add the given variable to the iMatchedCacheLine if the object is not NONE() and if there is enough space.
1169 Otherwise add a new CL."
1170 input Option<tuple<PartlyFilledCacheLine,Integer>> iMatchedCacheLine; //<CL, listIndex>
1171 input Integer iVarIdx;
1172 input FactoryMethod iFactoryMethod; //method to create a new shared cache line object
1173 input T iAdditionalArgument;
1174 input Integer iThreadIdx;
1175 input array<tuple<PartlyFilledCacheLines, CacheLines> > iSharedCacheLines; //partly filled cache lines and fully shared cache lines
1176 input tuple<CacheMap,CacheMapMeta,Integer> iInfo; //<CacheMapMeta,NumOfCLs>
1177 output tuple<CacheMap,CacheMapMeta,Integer> oInfo;
1178
1179 partial function FactoryMethod
1180 input Option<PartlyFilledCacheLine> iOldPartlyFilledCacheLine;
1181 input CacheLineMap iCacheLineMap;
1182 input T iAdditionalArguments;
1183 output PartlyFilledCacheLine oCreatedCacheLine;
1184 end FactoryMethod;
1185
1186 protected
1187 PartlyFilledCacheLines threadPartlyFilledCacheLines;
1188 list<PartlyFilledCacheLine> partlyFilledClFloat, partlyFilledClInt, partlyFilledClBool;
1189 CacheLines threadFullyFilledCacheLines;
1190 list<CacheLineMap> fullyFilledClFloat, fullyFilledClInt, fullyFilledClBool;
1191 array<Option<SimCodeVar.SimVar>> allSCVarsMapping;
1192 array<tuple<Integer,Integer,Integer>> simCodeVarTypes; //<varDataType, numberOfBytesRequired, varType>
1193 array<tuple<Integer, Integer>> scVarCLMapping; //mapping for each scVar -> <CLIdx,varType>
1194 PartlyFilledCacheLine partlyFilledCacheLine;
1195 Option<PartlyFilledCacheLine> partlyFilledCacheLineOption;
1196 Integer matchedClIndex, numOfCLs, clMapIdx, clMapNumBytesFree, varDataType, varSize, cacheLineSize;
1197 list<SimCodeVar.SimVar> cacheVariables;
1198 list<CacheLineMap> cacheLinesFloat, cacheLinesInt, cacheLinesBool;
1199 list<CacheLineEntry> clMapEntries;
1200 CacheLineEntry entry;
1201 CacheLineMap cacheLineMap;
1202 SimCodeVar.SimVar cacheVariable;
1203 algorithm
1204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 (CACHEMAP(cacheLineSize=cacheLineSize,cacheVariables=cacheVariables,cacheLinesFloat=cacheLinesFloat,cacheLinesInt=cacheLinesInt,cacheLinesBool=cacheLinesBool),CACHEMAPMETA(allSCVarsMapping=allSCVarsMapping,simCodeVarTypes=simCodeVarTypes,scVarCLMapping=scVarCLMapping),numOfCLs) := iInfo;
1205 22 (varDataType,varSize,_) := arrayGet(simCodeVarTypes, iVarIdx);
1206 22 (threadPartlyFilledCacheLines,threadFullyFilledCacheLines) := arrayGet(iSharedCacheLines, iThreadIdx);
1207 22 (partlyFilledClFloat, partlyFilledClInt, partlyFilledClBool) := threadPartlyFilledCacheLines;
1208 22 (fullyFilledClFloat, fullyFilledClInt, fullyFilledClBool) := threadFullyFilledCacheLines;
1209
1210
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 19 times.
22 if(isSome(iMatchedCacheLine)) then //advice was given, to which CL the variable should be added
1211 clMapIdx := numOfCLs;
1212 19 SOME((partlyFilledCacheLine, matchedClIndex)) := iMatchedCacheLine;
1213 partlyFilledCacheLineOption := SOME(partlyFilledCacheLine);
1214 19 CACHELINEMAP(clMapIdx,clMapNumBytesFree,clMapEntries) := getCacheLineMapOfPartlyFilledCacheLine(partlyFilledCacheLine);
1215 else
1216 //print("addVarsToSharedCL0: no advice was given\n");
1217 3 numOfCLs := numOfCLs + 1;
1218 partlyFilledCacheLineOption := NONE();
1219 clMapIdx := numOfCLs;
1220 clMapNumBytesFree := cacheLineSize;
1221 clMapEntries := {};
1222 matchedClIndex := -1;
1223 end if;
1224 22 clMapNumBytesFree := clMapNumBytesFree - varSize;
1225
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
22 SOME(cacheVariable) := arrayGet(allSCVarsMapping, iVarIdx);
1226 cacheVariables := cacheVariable::cacheVariables;
1227 22 entry := CACHELINEENTRY(cacheLineSize - clMapNumBytesFree - varSize, varDataType, varSize, listLength(cacheVariables), iThreadIdx);
1228
1229 //print("addVarsToSharedCL0: adding variable '" + intString(listLength(cacheVariables) - 1) + "' [" + dumpSimCodeVar(cacheVariable) + "] to cache line map '" + intString(clMapIdx) + "'\n");
1230 22 cacheLineMap := CACHELINEMAP(clMapIdx,clMapNumBytesFree,entry::clMapEntries);
1231
1232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 partlyFilledCacheLine := iFactoryMethod(partlyFilledCacheLineOption, cacheLineMap, iAdditionalArgument);
1233 22 scVarCLMapping := arrayUpdate(scVarCLMapping, iVarIdx, (clMapIdx,varDataType));
1234
1235
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
22 if(intEq(clMapNumBytesFree, 0)) then //CL is now full - remove it from partly filled CL list and add it to cachemap
1236
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(intEq(varDataType, VARDATATYPE_FLOAT)) then
1237 2 partlyFilledClFloat := listDelete(partlyFilledClFloat, matchedClIndex);
1238 fullyFilledClFloat := cacheLineMap::fullyFilledClFloat;
1239 else
1240 ✗ if(intEq(varDataType, VARDATATYPE_INTEGER)) then
1241 ✗ partlyFilledClInt := listDelete(partlyFilledClInt, matchedClIndex);
1242 fullyFilledClInt := cacheLineMap::fullyFilledClInt;
1243 else
1244 ✗ partlyFilledClBool := listDelete(partlyFilledClBool, matchedClIndex);
1245 fullyFilledClBool := cacheLineMap::fullyFilledClBool;
1246 end if;
1247 end if;
1248 else
1249
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 3 times.
20 if(intNe(matchedClIndex, -1)) then
1250
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(intEq(varDataType, VARDATATYPE_FLOAT)) then
1251 17 partlyFilledClFloat := List.set(partlyFilledClFloat, matchedClIndex, partlyFilledCacheLine);
1252 else
1253 ✗ if(intEq(varDataType, VARDATATYPE_INTEGER)) then
1254 ✗ partlyFilledClInt := List.set(partlyFilledClInt, matchedClIndex, partlyFilledCacheLine);
1255 else
1256 ✗ partlyFilledClBool := List.set(partlyFilledClBool, matchedClIndex, partlyFilledCacheLine);
1257 end if;
1258 end if;
1259 else
1260
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(intEq(varDataType, VARDATATYPE_FLOAT)) then
1261 partlyFilledClFloat := partlyFilledCacheLine::partlyFilledClFloat;
1262 else
1263 ✗ if(intEq(varDataType, VARDATATYPE_INTEGER)) then
1264 partlyFilledClInt := partlyFilledCacheLine::partlyFilledClInt;
1265 else
1266 partlyFilledClBool := partlyFilledCacheLine::partlyFilledClBool;
1267 end if;
1268 end if;
1269 end if;
1270 end if;
1271
1272 22 arrayUpdate(iSharedCacheLines, iThreadIdx, ((partlyFilledClFloat, partlyFilledClInt, partlyFilledClBool), (fullyFilledClFloat, fullyFilledClInt, fullyFilledClBool)));
1273 22 oInfo := (CACHEMAP(cacheLineSize=cacheLineSize,cacheVariables=cacheVariables,cacheLinesFloat=cacheLinesFloat,cacheLinesInt=cacheLinesInt,cacheLinesBool=cacheLinesBool),CACHEMAPMETA(allSCVarsMapping=allSCVarsMapping,simCodeVarTypes=simCodeVarTypes,scVarCLMapping=scVarCLMapping),numOfCLs);
1274 end addVarsToSharedCL0;
1275
1276 protected function getPartlyFilledCLByVarType
1277 input Integer iVarType;
1278 input PartlyFilledCacheLines iSharedCacheLines;
1279 output list<PartlyFilledCacheLine> oSharedCacheLinesForType;
1280 algorithm
1281
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(intEq(iVarType, VARDATATYPE_FLOAT)) then
1282 22 oSharedCacheLinesForType := Util.tuple31(iSharedCacheLines);
1283 else
1284 ✗ if(intEq(iVarType, VARDATATYPE_INTEGER)) then
1285 ✗ oSharedCacheLinesForType := Util.tuple32(iSharedCacheLines);
1286 else
1287 ✗ oSharedCacheLinesForType := Util.tuple33(iSharedCacheLines);
1288 end if;
1289 end if;
1290 end getPartlyFilledCLByVarType;
1291
1292 protected function findMatchingSharedCLLevelfix "author: marcusw
1293 Iterate over the given shared cache line list and return the first entry that can be used to store the shared variable iNodeVar."
1294 input Integer iNodeVar;
1295 input Integer iVarSize; //number of required bytes
1296 input Integer iVarType;
1297 input Integer iThreadIdx;
1298 input tuple<Integer,Integer> iLevelThreadIdx;
1299 input array<tuple<PartlyFilledCacheLines, CacheLines>> iSharedCacheLines;
1300 output Option<tuple<PartlyFilledCacheLine,Integer>> oMatchedCacheLine; //<CL, listIndex>
1301 protected
1302 list<PartlyFilledCacheLine> partlyFilledCacheLines;
1303 PartlyFilledCacheLines sharedCacheLines;
1304 Integer levelIdx;
1305 algorithm
1306 22 (levelIdx,_) := iLevelThreadIdx;
1307 22 sharedCacheLines := Util.tuple21(arrayGet(iSharedCacheLines, iThreadIdx));
1308 oMatchedCacheLine := NONE();
1309 22 partlyFilledCacheLines := getPartlyFilledCLByVarType(iVarType, sharedCacheLines);
1310 22 oMatchedCacheLine := findMatchingSharedCLLevelfix0(iNodeVar, iVarSize, levelIdx, iThreadIdx, 1, partlyFilledCacheLines);
1311 end findMatchingSharedCLLevelfix;
1312
1313 protected function findMatchingSharedCLLevelfix0 "author: marcusw
1314 Iterate over the given shared cache line list and return the first entry that can be used to store the shared variable iNodeVar."
1315 input Integer iNodeVar;
1316 input Integer iVarSize; //number of required bytes
1317 input Integer iLevelIdx;
1318 input Integer iThreadIdx;
1319 input Integer iCurrentListIdx;
1320 input list<PartlyFilledCacheLine> iSharedCacheLines;
1321 output Option<tuple<PartlyFilledCacheLine,Integer>> oMatchedCacheLine; //<CL, listIndex>
1322 protected
1323 PartlyFilledCacheLine head;
1324 list<PartlyFilledCacheLine> rest;
1325 Option<tuple<PartlyFilledCacheLine,Integer>> tmpMatchedCacheLine;
1326
1327 CacheLineMap cacheLineMap;
1328 Integer numBytesFree;
1329 list<Integer> prefetchLevel;
1330 list<tuple<Integer,Integer>> writeLevel; //(LevelIdx, ThreadIdx)
1331 algorithm
1332 oMatchedCacheLine := match iSharedCacheLines
1333 case (head as PARTLYFILLEDCACHELINE_LEVEL(cacheLineMap=(cacheLineMap as CACHELINEMAP(numBytesFree=numBytesFree)),prefetchLevel=prefetchLevel,writeLevel=writeLevel))::rest
1334 algorithm
1335
2/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
19 if(boolOr(intLt(numBytesFree, iVarSize), List.exist1(prefetchLevel,intEq, iLevelIdx))) then //The CL has not enough space or is used for prefetching -- can not be used for writing
1336 ✗ tmpMatchedCacheLine := findMatchingSharedCLLevelfix0(iNodeVar, iVarSize, iLevelIdx, iThreadIdx, iCurrentListIdx+1, rest);
1337 else
1338
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
19 if(List.any(writeLevel, function isCLWrittenByOtherThread(iLevelIdx=iLevelIdx, iThreadIdx=iThreadIdx))) then //The CL is written by another thread in the same level -- can not be used for writing
1339 ✗ tmpMatchedCacheLine := findMatchingSharedCLLevelfix0(iNodeVar, iVarSize, iLevelIdx, iThreadIdx, iCurrentListIdx+1, rest);
1340 else
1341
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
19 if(List.any(writeLevel, function isCLWrittenByOtherThread(iLevelIdx=iLevelIdx-1, iThreadIdx=iThreadIdx))) then //The CL is written by another thread in the previous level -- can not be used for writing
1342 ✗ tmpMatchedCacheLine := findMatchingSharedCLLevelfix0(iNodeVar, iVarSize, iLevelIdx, iThreadIdx, iCurrentListIdx+1, rest);
1343 else //CL matches
1344 19 tmpMatchedCacheLine := SOME((head, iCurrentListIdx));
1345 end if;
1346 end if;
1347 end if;
1348 then tmpMatchedCacheLine;
1349 case {}
1350 then NONE();
1351 else
1352 algorithm
1353 ✗ print("findMatchingSharedCLLevelfix0: Unknown partly filled cache line type given.\n");
1354 then NONE();
1355 end match;
1356 end findMatchingSharedCLLevelfix0;
1357
1358 protected function findMatchingSharedCLThread "author: marcusw
1359 Iterate over the given shared cache line list and return the first entry that can be used to store the shared variable iNodeVar."
1360 input Integer iNodeVar;
1361 input Integer iVarSize; //number of required bytes
1362 input Integer iVarType;
1363 input Integer iThreadIdx;
1364 input Integer iAdditionalArgument; //unused
1365 input array<tuple<PartlyFilledCacheLines, CacheLines>> iSharedCacheLines;
1366 output Option<tuple<PartlyFilledCacheLine,Integer>> oMatchedCacheLine; //<CL, listIndex>
1367 protected
1368 list<PartlyFilledCacheLine> partlyFilledCacheLines;
1369 PartlyFilledCacheLine partlyFilledCL;
1370 Integer numBytesFree, listIdx;
1371 algorithm
1372 oMatchedCacheLine := NONE();
1373 ✗ partlyFilledCacheLines := getPartlyFilledCLByVarType(iVarType, Util.tuple21(arrayGet(iSharedCacheLines, iThreadIdx)));
1374 listIdx := 1;
1375 ✗ for partlyFilledCL in partlyFilledCacheLines loop
1376 ✗ CACHELINEMAP(numBytesFree=numBytesFree) := getCacheLineMapOfPartlyFilledCacheLine(partlyFilledCL);
1377 ✗ if(intGe(numBytesFree, iVarSize)) then
1378 ✗ oMatchedCacheLine := (SOME((partlyFilledCL, listIdx)));
1379 ✗ break;
1380 end if;
1381 ✗ listIdx := listIdx + 1;
1382 end for;
1383 end findMatchingSharedCLThread;
1384
1385 protected function createSharedClThread
1386 input Option<PartlyFilledCacheLine> iOldPartlyFilledCacheLine;
1387 input CacheLineMap iCacheLineMap;
1388 input Integer iAdditionalArgument; //unused
1389 output PartlyFilledCacheLine oCreatedCacheLine;
1390 algorithm
1391 ✗ oCreatedCacheLine := PARTLYFILLEDCACHELINE_THREAD(iCacheLineMap);
1392 end createSharedClThread;
1393
1394 protected function createSharedClLevelFix
1395 input Option<PartlyFilledCacheLine> iOldPartlyFilledCacheLine;
1396 input CacheLineMap iCacheLineMap;
1397 input tuple<Integer,Integer> iLevelThreadIdx;
1398 output PartlyFilledCacheLine oCreatedCacheLine;
1399 protected
1400 list<Integer> prefetchLevel;
1401 list<tuple<Integer, Integer>> writeLevel;
1402 Integer levelIdx, threadIdx;
1403 algorithm
1404 22 (levelIdx, threadIdx) := iLevelThreadIdx;
1405
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 3 times.
22 if(isSome(iOldPartlyFilledCacheLine)) then
1406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 SOME(PARTLYFILLEDCACHELINE_LEVEL(prefetchLevel=prefetchLevel,writeLevel=writeLevel)) := iOldPartlyFilledCacheLine;
1407 else
1408 prefetchLevel := {};
1409 writeLevel := {};
1410 end if;
1411
1412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if(intGt(levelIdx - 1, 0)) then
1413 ✗ prefetchLevel := (levelIdx-1)::prefetchLevel;
1414 end if;
1415 22 writeLevel := (levelIdx, threadIdx)::writeLevel;
1416
1417 22 oCreatedCacheLine := PARTLYFILLEDCACHELINE_LEVEL(iCacheLineMap,prefetchLevel,writeLevel);
1418 end createSharedClLevelFix;
1419
1420 protected function isCLWrittenByOtherThread "author: marcusw
1421 Return 'true' if the given entry has levelidx == iLevelIdx and is handled by a thread != iThreadIdx."
1422 input tuple<Integer,Integer> iLevelInfo; //(LevelIdx, ThreadIdx)
1423 input Integer iLevelIdx;
1424 input Integer iThreadIdx;
1425 output Boolean oWrittenByOtherThread;
1426 protected
1427 Integer levelIdx, threadIdx;
1428 Boolean ret;
1429 algorithm
1430 142 (levelIdx, threadIdx) := iLevelInfo;
1431 142 ret := boolAnd(intEq(levelIdx, iLevelIdx), intNe(threadIdx, iThreadIdx));
1432 oWrittenByOtherThread := ret;
1433 end isCLWrittenByOtherThread;
1434
1435 protected function createCacheMapFromThreadAndSharedCLs "author: marcusw
1436 Create a cachemap-object out of the given thread and shared cache lines by appending them to the cache lines of the iCacheMap-object."
1437 input CacheLines iThreadCacheLines;
1438 input tuple<PartlyFilledCacheLines, CacheLines> iSharedCacheLines;
1439 input CacheMap iCacheMap;
1440 output CacheMap oCacheMap;
1441 protected
1442 Integer cacheLineSize;
1443 list<CacheLineMap> cacheLinesFloat, cacheLinesInt, cacheLinesBool;
1444 CacheLines fullyFilledSharedCacheLines;
1445 PartlyFilledCacheLines partlyFilledCacheLines;
1446 list<SimCodeVar.SimVar> cacheVariables;
1447 algorithm
1448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 CACHEMAP(cacheLineSize, cacheVariables, cacheLinesFloat, cacheLinesInt, cacheLinesBool) := iCacheMap;
1449
1450 1 (partlyFilledCacheLines,fullyFilledSharedCacheLines) := iSharedCacheLines;
1451 1 cacheLinesFloat := listAppend(cacheLinesFloat, listAppend(Util.tuple31(iThreadCacheLines), Util.tuple31(fullyFilledSharedCacheLines))) annotation(__OpenModelica_DisableListAppendWarning=true);
1452 //print("HpcOmMemory.createCacheMapFromThreadAndSharedCLs: Thread float cache lines\n");
1453 //List.map_0(cacheLinesFloat, function printCacheLineMap(iCacheVariables = cacheVariables));
1454 //print("\n");
1455 1 cacheLinesInt := listAppend(cacheLinesInt, listAppend(Util.tuple32(iThreadCacheLines), Util.tuple32(fullyFilledSharedCacheLines))) annotation(__OpenModelica_DisableListAppendWarning=true);
1456 //print("HpcOmMemory.createCacheMapFromThreadAndSharedCLs: Thread int cache lines\n");
1457 //List.map_0(cacheLinesInt, function printCacheLineMap(iCacheVariables = cacheVariables));
1458 //print("\n");
1459 1 cacheLinesBool := listAppend(cacheLinesBool, listAppend(Util.tuple33(iThreadCacheLines), Util.tuple33(fullyFilledSharedCacheLines))) annotation(__OpenModelica_DisableListAppendWarning=true);
1460 //print("HpcOmMemory.createCacheMapFromThreadAndSharedCLs: Thread bool cache lines\n");
1461 //List.map_0(cacheLinesBool, function printCacheLineMap(iCacheVariables = cacheVariables));
1462 //print("\n");
1463
1464 1 cacheLinesFloat := listAppend(cacheLinesFloat, List.map(Util.tuple31(partlyFilledCacheLines), getCacheLineMapOfPartlyFilledCacheLine)) annotation(__OpenModelica_DisableListAppendWarning=true);
1465 //print("HpcOmMemory.createCacheMapFromThreadAndSharedCLs: Partly float cache lines\n");
1466 //List.map_0(List.map(Util.tuple31(partlyFilledCacheLines), getCacheLineMapOfPartlyFilledCacheLine), function printCacheLineMap(iCacheVariables = cacheVariables));
1467 //print("\n");
1468 1 cacheLinesInt := listAppend(cacheLinesInt, List.map(Util.tuple32(partlyFilledCacheLines), getCacheLineMapOfPartlyFilledCacheLine)) annotation(__OpenModelica_DisableListAppendWarning=true);
1469 1 cacheLinesBool := listAppend(cacheLinesBool, List.map(Util.tuple33(partlyFilledCacheLines), getCacheLineMapOfPartlyFilledCacheLine)) annotation(__OpenModelica_DisableListAppendWarning=true);
1470
1471 1 oCacheMap := CACHEMAP(cacheLineSize, cacheVariables, cacheLinesFloat, cacheLinesInt, cacheLinesBool);
1472 end createCacheMapFromThreadAndSharedCLs;
1473
1474 protected function createCacheMapDefault "author: marcusw
1475 Create a default cacheMap without optimization."
1476 input array<Option<SimCodeVar.SimVar>> iAllSCVars;
1477 input Integer iCacheLineSize;
1478 input SimCodeVar.SimVars iSimCodeVars;
1479 input array<Integer> iScVarTaskMapping;
1480 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
1481 input array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes; //<varDataType, varSize, varType>
1482 output CacheMap oCacheMap;
1483 output array<tuple<Integer,Integer>> oScVarCLMapping; //mapping for each scVar -> CLIdx
1484 output Integer oNumCL;
1485 protected
1486 algorithm
1487
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
7 if((stringEqual(Config.simCodeTarget(), "Cpp") )) then
1488 ✗ (oCacheMap, oScVarCLMapping, oNumCL) := createCacheMapDefaultCppRuntime(iAllSCVars, iCacheLineSize, iSimCodeVars, iScVarTaskMapping, iSchedulerInfo, iSimCodeVarTypes);
1489 else
1490 7 oCacheMap := UNIFORM_CACHEMAP(iCacheLineSize,{},{});
1491 7 oNumCL := 0;
1492 7 oScVarCLMapping := arrayCreate(0, (-1,-1));
1493 end if;
1494 end createCacheMapDefault;
1495
1496 protected function createCacheMapDefaultCppRuntime "author: marcusw
1497 Create a default cacheMap without optimization."
1498 input array<Option<SimCodeVar.SimVar>> iAllSCVars;
1499 input Integer iCacheLineSize;
1500 input SimCodeVar.SimVars iSimCodeVars;
1501 input array<Integer> iScVarTaskMapping;
1502 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
1503 input array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes; //<varDataType, varSize, varType>
1504 output CacheMap oCacheMap;
1505 output array<tuple<Integer,Integer>> oScVarCLMapping; //mapping for each scVar -> CLIdx
1506 output Integer oNumCL;
1507 protected
1508 list<SimCodeVar.SimVar> stateVars, derivativeVars, algVars, discreteAlgVars, paramVars, aliasVars, intAlgVars, intParamVars, intAliasVars, boolAlgVars, boolParamVars, boolAliasVars;
1509 list<SimCodeVar.SimVar> inputVars, outputVars;
1510 CacheMap cacheMap;
1511 CacheLineMap lastCacheLine;
1512 array<tuple<Integer,Integer>> scVarCLMapping; //mapping for each scVar -> CLIdx
1513 Integer currentScVarIdx;
1514 Integer paramVarsStart, aliasVarsStart, stateDerVarsStart, algVarsStart, discreteAlgVarsStart, intAlgVarsStart, intParamVarsStart;
1515 list<CacheLineMap> filledCacheLines;
1516 list<SimCodeVar.SimVar> allVars;
1517 algorithm
1518 (oCacheMap, oScVarCLMapping, oNumCL) := match iSimCodeVars
1519 case SimCodeVar.SIMVARS(stateVars=stateVars, derivativeVars=derivativeVars, algVars=algVars, discreteAlgVars=discreteAlgVars,
1520 paramVars=paramVars, aliasVars=aliasVars, intAlgVars=intAlgVars, intParamVars=intParamVars, intAliasVars=intAliasVars,
1521 boolAlgVars=boolAlgVars, boolParamVars=boolParamVars, boolAliasVars=boolAliasVars, inputVars=inputVars, outputVars=outputVars)
1522 algorithm
1523 //add stateDer - variables to seperate cache lines
1524 ✗ currentScVarIdx := 1;
1525 ✗ stateDerVarsStart := listLength(stateVars) + 1;
1526 ✗ scVarCLMapping := arrayCreate(arrayLength(iAllSCVars),(-1,-1));
1527 filledCacheLines := {};
1528 ✗ lastCacheLine := CACHELINEMAP(1, iCacheLineSize, {});
1529 ✗ (filledCacheLines, lastCacheLine, currentScVarIdx) := createCacheMapDefaultCppRuntime0(derivativeVars, currentScVarIdx, stateDerVarsStart, scVarCLMapping, filledCacheLines, iScVarTaskMapping, iSchedulerInfo, lastCacheLine, iCacheLineSize, iSimCodeVarTypes);
1530 ✗ filledCacheLines := lastCacheLine::filledCacheLines;
1531 ✗ lastCacheLine := CACHELINEMAP(listLength(filledCacheLines) + 1, iCacheLineSize, {});
1532 ✗ allVars := listReverse(derivativeVars);
1533 //print("StateDer-Vars finished\n");
1534
1535 //add all other variables to uniform cache map
1536 ✗ algVarsStart := stateDerVarsStart + listLength(derivativeVars);
1537 ✗ discreteAlgVarsStart := algVarsStart + listLength(algVars);
1538 ✗ intAlgVarsStart := discreteAlgVarsStart + listLength(discreteAlgVars);
1539 ✗ aliasVarsStart := intAlgVarsStart + listLength(boolAlgVars) + listLength(inputVars) + listLength(outputVars);
1540 ✗ paramVarsStart := aliasVarsStart + listLength(aliasVars) + listLength(intAliasVars) + listLength(boolAliasVars);
1541 ✗ intParamVarsStart := paramVarsStart + listLength(paramVars);
1542
1543 ✗ (filledCacheLines, lastCacheLine, currentScVarIdx) := createCacheMapDefaultCppRuntime0(algVars, currentScVarIdx, algVarsStart, scVarCLMapping, filledCacheLines, iScVarTaskMapping, iSchedulerInfo, lastCacheLine, iCacheLineSize, iSimCodeVarTypes);
1544 ✗ allVars := List.append_reverse(algVars, allVars);
1545 //print("algVars finished\n");
1546
1547 ✗ (filledCacheLines, lastCacheLine, currentScVarIdx) := createCacheMapDefaultCppRuntime0(discreteAlgVars, currentScVarIdx, discreteAlgVarsStart, scVarCLMapping, filledCacheLines, iScVarTaskMapping, iSchedulerInfo, lastCacheLine, iCacheLineSize, iSimCodeVarTypes);
1548 ✗ allVars := List.append_reverse(discreteAlgVars, allVars);
1549 //print("discreteAlgVars finished\n");
1550
1551 //print("\n\nParamVarsStart: " + intString(paramVarsStart) + "\n");
1552 ✗ (filledCacheLines, lastCacheLine, currentScVarIdx) := createCacheMapDefaultCppRuntime0(paramVars, currentScVarIdx, paramVarsStart, scVarCLMapping, filledCacheLines, iScVarTaskMapping, iSchedulerInfo, lastCacheLine, iCacheLineSize, iSimCodeVarTypes);
1553 ✗ allVars := List.append_reverse(paramVars, allVars);
1554 //print("paramVars finished\n");
1555
1556 ✗ (filledCacheLines, lastCacheLine, currentScVarIdx) := createCacheMapDefaultCppRuntime0(aliasVars, currentScVarIdx, aliasVarsStart, scVarCLMapping, filledCacheLines, iScVarTaskMapping, iSchedulerInfo, lastCacheLine, iCacheLineSize, iSimCodeVarTypes);
1557 ✗ allVars := List.append_reverse(aliasVars, allVars);
1558
1559 //print("\n\nIntAlgVarsStart: " + intString(intAlgVarsStart) + "\n");
1560 ✗ (filledCacheLines, lastCacheLine, currentScVarIdx) := createCacheMapDefaultCppRuntime0(intAlgVars, currentScVarIdx, intAlgVarsStart, scVarCLMapping, filledCacheLines, iScVarTaskMapping, iSchedulerInfo, lastCacheLine, iCacheLineSize, iSimCodeVarTypes);
1561 ✗ allVars := List.append_reverse(intAlgVars, allVars);
1562 //print("intAlgVars finished\n");
1563
1564 //print("\n\nIntParamVarsStart: " + intString(intParamVarsStart) + "\n");
1565 ✗ (filledCacheLines, lastCacheLine, currentScVarIdx) := createCacheMapDefaultCppRuntime0(intParamVars, currentScVarIdx, intAlgVarsStart, scVarCLMapping, filledCacheLines, iScVarTaskMapping, iSchedulerInfo, lastCacheLine, iCacheLineSize, iSimCodeVarTypes);
1566 ✗ allVars := List.append_reverse(intParamVars, allVars);
1567 //print("intAlgVars finished\n");
1568
1569 ✗ cacheMap := UNIFORM_CACHEMAP(iCacheLineSize, allVars, lastCacheLine::filledCacheLines);
1570 ✗ then (cacheMap, scVarCLMapping, listLength(filledCacheLines) + 1);
1571 end match;
1572 end createCacheMapDefaultCppRuntime;
1573
1574 protected function createCacheMapDefaultCppRuntime0 "author: marcusw
1575 Add the given variables to cache lines."
1576 input list<SimCodeVar.SimVar> iVariables; //all variables that should be added to cache lines
1577 input Integer iScVarIdxStart; //index of the first variable of the iVariable-list
1578 input Integer iRealScVarIdxStart;
1579 input array<tuple<Integer,Integer>> iScVarCLMapping; //updated
1580 input list<CacheLineMap> iFilledCacheLines; //all cache lines that are already filled
1581 input array<Integer> iScVarTaskMapping;
1582 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
1583 input CacheLineMap iLastCacheLine;
1584 input Integer iCacheLineSize;
1585 input array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes;
1586 output list<CacheLineMap> oFilledCacheLines;
1587 output CacheLineMap oLastCacheLine;
1588 output Integer oScVarIdx;
1589 protected
1590 Integer currentScVarIdx, varSize, varDataType, varTask, threadIdx, varCLIdx;
1591 SimCodeVar.SimVar var;
1592 CacheLineEntry entry;
1593 Boolean newCacheLineCreated;
1594 CacheLineMap lastCacheLine, lastCacheLineNew;
1595 list<CacheLineMap> filledCacheLines;
1596 list<CacheLineEntry> cachelineEntries;
1597 DAE.ComponentRef name;
1598 String nameStr;
1599 algorithm
1600 currentScVarIdx := 0;
1601 lastCacheLine := iLastCacheLine;
1602 filledCacheLines := iFilledCacheLines;
1603 ✗ for var in iVariables loop
1604 ✗ SimCodeVar.SIMVAR(name=name) := var;
1605 ✗ nameStr := ComponentReferenceBasics.printComponentRefStr(name);
1606 ✗ if(boolAnd(intLt(currentScVarIdx, arrayLength(iSimCodeVarTypes)), intLt(currentScVarIdx, arrayLength(iScVarCLMapping)))) then
1607 ✗ (varDataType, varSize, _) := arrayGet(iSimCodeVarTypes, currentScVarIdx + iRealScVarIdxStart);
1608
1609 //print("createCacheMapDefaultCppRuntime0: iScVarIdxStart=" + intString(iScVarIdxStart) + " iRealScVarIdxStart=" + intString(iRealScVarIdxStart) + "\n");
1610 //print("Try to get variable: " + intString(currentScVarIdx + iRealScVarIdxStart) + " out of array with length: " + intString(arrayLength(iScVarTaskMapping)) + "\n");
1611 //print("Try to get variable: " + intString(currentScVarIdx + iRealScVarIdxStart) + " out of array with length: " + intString(arrayLength(iSimCodeVarTypes)) + "\n");
1612 //print("iScVarCLMapping-length: " + intString(arrayLength(iScVarCLMapping)) + "\n");
1613
1614 ✗ if(intLe(currentScVarIdx + iRealScVarIdxStart, arrayLength(iScVarTaskMapping))) then
1615 ✗ varTask := arrayGet(iScVarTaskMapping, currentScVarIdx + iRealScVarIdxStart);
1616 else
1617 varTask := -1;
1618 end if;
1619 //print("createCacheMapDefaultCppRuntime0: Handling SC-Var '" + intString(currentScVarIdx + iScVarIdxStart) + "' [" + nameStr + "] by task '" + intString(varTask) + "'\n");
1620 ✗ if(boolAnd(intGe(varTask, 1), intGe(arrayLength(iSchedulerInfo), varTask))) then
1621 ✗ threadIdx := Util.tuple31(arrayGet(iSchedulerInfo, varTask));
1622 else
1623 threadIdx := -1;
1624 end if;
1625 //print("threadIdx: " + intString(threadIdx) + "\n");
1626 ✗ entry := CACHELINEENTRY(-1, varDataType, varSize, currentScVarIdx + iScVarIdxStart, threadIdx);
1627
1628 ✗ (entry, lastCacheLineNew, newCacheLineCreated) := createCacheMapDefaultCppRuntime1(entry, iCacheLineSize, lastCacheLine);
1629 ✗ CACHELINEMAP(idx=varCLIdx, entries=cachelineEntries) := lastCacheLineNew;
1630 //print("Number of elements in cacheline: " + intString(listLength(cachelineEntries)) + "\n");
1631 ✗ arrayUpdate(iScVarCLMapping, currentScVarIdx + iRealScVarIdxStart, (varCLIdx, varDataType));
1632
1633 ✗ if(newCacheLineCreated) then
1634 filledCacheLines := lastCacheLine::filledCacheLines;
1635 end if;
1636 lastCacheLine := lastCacheLineNew;
1637 end if;
1638 ✗ currentScVarIdx := currentScVarIdx + 1;
1639 end for;
1640 oFilledCacheLines := filledCacheLines;
1641 oLastCacheLine := lastCacheLine;
1642 ✗ oScVarIdx := currentScVarIdx + iScVarIdxStart;
1643 end createCacheMapDefaultCppRuntime0;
1644
1645 protected function createCacheMapDefaultCppRuntime1 "author: marcusw
1646 Add the given variable to the given cache line. If the variable does not fit into the cache line, create a new one."
1647 input CacheLineEntry iCacheLineEntry;
1648 input Integer iCacheLineSize;
1649 input CacheLineMap iLastCacheLine; //check if the variable fits into this cache line
1650 output CacheLineEntry oCacheLineEntry; //start is modified
1651 output CacheLineMap oLastCacheLine; //either the given iLastCacheLine with the new entry or a new cache line.
1652 output Boolean oNewOneCreated; //true if a new cache line was created
1653 protected
1654 Integer numberOfFreeBytesLastCacheLine;
1655 list<CacheLineEntry> lastCacheLineEntries;
1656 CacheLineMap cacheLine;
1657 CacheLineEntry cacheLineEntry;
1658 Integer entrySize, entryStart, entryType, entryVarIdx, entryThreadOwner, lastCacheLineIdx;
1659 algorithm
1660 ✗ CACHELINEENTRY(entryStart, entryType, entrySize, entryVarIdx, entryThreadOwner) := iCacheLineEntry;
1661 ✗ CACHELINEMAP(lastCacheLineIdx, numberOfFreeBytesLastCacheLine, lastCacheLineEntries) := iLastCacheLine;
1662 ✗ if(intGt(entrySize, numberOfFreeBytesLastCacheLine)) then
1663 //create a new cache line
1664 ✗ cacheLineEntry := CACHELINEENTRY(0, entryType, entrySize, entryVarIdx, entryThreadOwner);
1665 ✗ cacheLine := CACHELINEMAP(lastCacheLineIdx + 1, iCacheLineSize - entrySize, {cacheLineEntry});
1666 oNewOneCreated := true;
1667 else
1668 //add the entry to the last cache line
1669 ✗ cacheLineEntry := CACHELINEENTRY(iCacheLineSize - numberOfFreeBytesLastCacheLine, entryType, entrySize, entryVarIdx, entryThreadOwner);
1670 ✗ cacheLine := CACHELINEMAP(lastCacheLineIdx, numberOfFreeBytesLastCacheLine - entrySize, cacheLineEntry::lastCacheLineEntries);
1671 oNewOneCreated := false;
1672 end if;
1673 oCacheLineEntry := cacheLineEntry;
1674 oLastCacheLine := cacheLine;
1675 end createCacheMapDefaultCppRuntime1;
1676
1677 protected function appendNodeVarsToCacheMap "author: marcusw
1678 Append the variables that are solved by the given node to the cachelines. The used CL are removed from the candidate list."
1679 input Integer iNodeIdx;
1680 input Integer iOwnerThread; //-1 if none
1681 input array<list<Integer>> iNodeSimCodeVarMapping;
1682 input tuple<CacheMap, CacheMapMeta, Integer, list<tuple<Integer,Integer>>> iInfo; //<CacheMap,numNewCL, clCandidates <ClIdx,freeBytes>>
1683 output tuple<CacheMap, CacheMapMeta, Integer, list<tuple<Integer,Integer>>> oInfo;
1684 protected
1685 list<Integer> simCodeVars, writtenCL;
1686 CacheMap iCacheMap;
1687 CacheMapMeta iCacheMapMeta;
1688 Integer iNumNewCL;
1689 String varsString;
1690 list<tuple<Integer,Integer>> clCandidates;
1691 algorithm
1692 ✗ simCodeVars := arrayGet(iNodeSimCodeVarMapping, iNodeIdx);
1693 ✗ (iCacheMap,iCacheMapMeta,iNumNewCL,clCandidates) := iInfo;
1694 ✗ varsString := stringDelimitList(List.map(simCodeVars, intString), ",");
1695 //print("appendNodeVarsToCacheMap: Handling node " + intString(iNodeIdx) + " clCandidates: " + intString(listLength(clCandidates)) + " simCodeVars: " + varsString + "\n");
1696 ✗ (iCacheMap, iCacheMapMeta, iNumNewCL,clCandidates,writtenCL,_) := List.fold(simCodeVars, function appendSCVarToCacheMap(iOwnerThread=iOwnerThread), (iCacheMap, iCacheMapMeta, iNumNewCL,clCandidates,{},1));
1697 ✗ clCandidates := List.removeOnTrue(writtenCL, appendNodeVarsToCacheMap0, clCandidates);
1698 ✗ oInfo := (iCacheMap,iCacheMapMeta,iNumNewCL,clCandidates);
1699 end appendNodeVarsToCacheMap;
1700
1701 protected function appendNodeVarsToCacheMap0 "author: marcusw
1702 Mark the cachelines with 'false' that are already full or part of the iWrittenCLs-list."
1703 input list<Integer> iWrittenCLs;
1704 input tuple<Integer,Integer> iDetailedCLInfo; //<ClIdx,freeBytes>
1705 output Boolean oRemove;
1706 protected
1707 Integer clIdx, freeBytes;
1708 Boolean res;
1709 algorithm
1710 oRemove := matchcontinue iDetailedCLInfo
1711 case (clIdx,freeBytes)
1712 algorithm //CacheLine is full
1713 ✗ true := intEq(freeBytes,0);
1714 then true;
1715 case (clIdx,freeBytes)
1716 algorithm
1717 ✗ res := List.isMemberOnTrue(clIdx,iWrittenCLs, intEq);
1718 then res;
1719 else
1720 algorithm
1721 ✗ print("appendNodeVarsToCacheMap0 failed!\n");
1722 ✗ then fail();
1723 end matchcontinue;
1724 end appendNodeVarsToCacheMap0;
1725
1726 protected function appendSCVarToCacheMap "author: marcusw
1727 Add the given sc-var to the cacheMap and update the information of cacheMapMeta. If the currentCLCandidate-index is not in range [1,len(cacheLineCandidates)], a new cacheline is added."
1728 input Integer iSCVarIdx;
1729 input Integer iOwnerThread;
1730 input tuple<CacheMap, CacheMapMeta, Integer, list<tuple<Integer,Integer>>, list<Integer>, Integer> iInfo; //<CacheMap, CacheMapMeta, numNewCL, cacheLineCandidates <ClIdx,freeBytes>, writtenCL, currentCLCandidate>
1731 output tuple<CacheMap, CacheMapMeta, Integer, list<tuple<Integer,Integer>>, list<Integer>, Integer> oInfo;
1732 protected
1733 array<Option<SimCodeVar.SimVar>> iAllSCVarsMapping;
1734 array<tuple<Integer,Integer,Integer>> iSimCodeVarTypes; //<type, numberOfBytesRequired>
1735 array<tuple<Integer,Integer>> iScVarCLMapping; //will be updated: mapping scVar (arrayIdx) -> <clIdx,varType>
1736 Integer currentCLCandidateIdx, currentCLCandidateCLIdx, clIdx, currentCLCandidateFreeBytes, cacheLineSize, numNewCL, varDataType, numBytesRequired, entryStart;
1737 tuple<Integer,Integer> currentCLCandidate;
1738 list<tuple<Integer,Integer>> cacheLineCandidates;
1739 list<CacheLineMap> cacheLinesFloat, cacheLinesInt, cacheLinesBool;
1740 list<SimCodeVar.SimVar> cacheVariables;
1741 CacheLineMap cacheLine;
1742 list<CacheLineEntry> CLentries;
1743 SimCodeVar.SimVar scVar;
1744 Integer numCacheVars, freeSpace, numBytesFree;
1745 CacheMap cacheMap;
1746 CacheMapMeta cacheMapMeta;
1747 list<Integer> writtenCL;
1748 tuple<CacheMap, CacheMapMeta, Integer, list<tuple<Integer,Integer>>, list<Integer>, Integer> tmpInfo;
1749 algorithm
1750 oInfo := matchcontinue iInfo
1751 case (cacheMap as CACHEMAP(cacheLineSize=cacheLineSize,cacheVariables=cacheVariables,cacheLinesFloat=cacheLinesFloat, cacheLinesInt=cacheLinesInt, cacheLinesBool=cacheLinesBool), cacheMapMeta as CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, iScVarCLMapping), numNewCL, cacheLineCandidates, writtenCL, currentCLCandidateIdx)
1752 algorithm //case 1: current CL-candidate has enough space to store variable
1753 ✗ true := intGe(listLength(cacheLineCandidates), currentCLCandidateIdx);
1754 ✗ currentCLCandidate := listGet(cacheLineCandidates, currentCLCandidateIdx);
1755 ✗ (varDataType,numBytesRequired,_) := arrayGet(iSimCodeVarTypes,iSCVarIdx);
1756 ✗ true := doesSCVarFitIntoCL(currentCLCandidate, numBytesRequired);
1757 //print(" -- candidateCL has enough space\n");
1758 ✗ (currentCLCandidateCLIdx,currentCLCandidateFreeBytes) := currentCLCandidate;
1759 //print("appendSCVarToCacheMap scVarIdx: " + intString(iSCVarIdx) + "\n");
1760 //print(" -- CachelineCandidates: " + intString(listLength(cacheLineCandidates)) + " currentCLCandidateidx: " + intString(currentCLCandidateIdx) + " with " + intString(currentCLCandidateFreeBytes) + "free bytes\n");
1761 ✗ cacheLine := listGet(cacheLinesFloat, listLength(cacheLinesFloat) - currentCLCandidateCLIdx + 1);
1762 ✗ CACHELINEMAP(idx=clIdx,numBytesFree=numBytesFree,entries=CLentries) := cacheLine;
1763 //print(" -- writing to CL " + intString(clIdx) + " (free bytes: " + intString(currentCLCandidateFreeBytes) + ")\n");
1764 //write new cache lines
1765 ✗ entryStart := cacheLineSize-currentCLCandidateFreeBytes;
1766 ✗ numCacheVars := listLength(cacheVariables)+1;
1767 ✗ CLentries := CACHELINEENTRY(entryStart,varDataType, numBytesRequired, numCacheVars, iOwnerThread)::CLentries;
1768 ✗ cacheLine := CACHELINEMAP(clIdx,numBytesFree+numBytesRequired,CLentries);
1769 ✗ cacheLinesFloat := List.set(cacheLinesFloat, listLength(cacheLinesFloat) - currentCLCandidateCLIdx + 1, cacheLine);
1770 //update scVarCL-Mapping
1771 ✗ iScVarCLMapping := arrayUpdate(iScVarCLMapping,iSCVarIdx,(clIdx,varDataType));
1772 //append variable
1773 ✗ SOME(scVar) := arrayGet(iAllSCVarsMapping,iSCVarIdx);
1774
1775 //varText = Tpl.textString(SimCodeDump.dumpVars(Tpl.emptyTxt, {scVar}, false));
1776 //print(" appendSCVarToCacheMap: Handling variable " + intString(iSCVarIdx) + " | " + varText + "\n");
1777
1778 cacheVariables := scVar::cacheVariables;
1779 writtenCL := clIdx::writtenCL;
1780 //write candidate list
1781 ✗ currentCLCandidate := (currentCLCandidateCLIdx,currentCLCandidateFreeBytes-numBytesRequired);
1782 ✗ cacheLineCandidates := List.set(cacheLineCandidates, currentCLCandidateIdx, currentCLCandidate);
1783 ✗ cacheMap := CACHEMAP(cacheLineSize,cacheVariables,cacheLinesFloat, cacheLinesInt, cacheLinesBool);
1784 ✗ cacheMapMeta := CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, iScVarCLMapping);
1785 //printCacheMap(cacheMap);
1786 //print(" appendSCVarToCacheMap: Done\n");
1787 ✗ then ((cacheMap, cacheMapMeta, numNewCL, cacheLineCandidates, writtenCL, currentCLCandidateIdx));
1788 case (cacheMap as CACHEMAP(cacheLineSize=cacheLineSize,cacheVariables=cacheVariables,cacheLinesFloat=cacheLinesFloat, cacheLinesInt=cacheLinesInt, cacheLinesBool=cacheLinesBool), cacheMapMeta as CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, iScVarCLMapping), numNewCL, cacheLineCandidates, writtenCL, currentCLCandidateIdx)
1789 algorithm //case 2: current CL-candidate has not enough space to store variable
1790 ✗ true := intGe(listLength(cacheLineCandidates), currentCLCandidateIdx);
1791 ✗ (varDataType,numBytesRequired,_) := arrayGet(iSimCodeVarTypes,iSCVarIdx);
1792 ✗ tmpInfo := appendSCVarToCacheMap(iSCVarIdx, iOwnerThread, (cacheMap, cacheMapMeta, numNewCL,cacheLineCandidates,writtenCL,currentCLCandidateIdx+1));
1793 then tmpInfo;
1794 case (cacheMap as CACHEMAP(cacheLineSize=cacheLineSize,cacheVariables=cacheVariables,cacheLinesFloat=cacheLinesFloat, cacheLinesInt=cacheLinesInt, cacheLinesBool=cacheLinesBool), CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, iScVarCLMapping), numNewCL, cacheLineCandidates, writtenCL, currentCLCandidateIdx)
1795 algorithm //case 3: no CL-candidates available
1796 //print("--appendSCVarToCacheMap: Handling variable " + intString(iSCVarIdx) + "\n");
1797
1798 ✗ (varDataType,numBytesRequired,_) := arrayGet(iSimCodeVarTypes,iSCVarIdx);
1799 entryStart := 0;
1800 ✗ numCacheVars := listLength(cacheVariables)+1;
1801 ✗ CLentries := {CACHELINEENTRY(entryStart,varDataType, numBytesRequired, numCacheVars, iOwnerThread)};
1802 ✗ clIdx := listLength(cacheLinesFloat) + 1;
1803 ✗ cacheLine := CACHELINEMAP(clIdx,numBytesRequired,CLentries);
1804 cacheLinesFloat := cacheLine::cacheLinesFloat;
1805 //update scVarCL-Mapping
1806 ✗ iScVarCLMapping := arrayUpdate(iScVarCLMapping,iSCVarIdx,(clIdx,varDataType));
1807 //append variable
1808 ✗ SOME(scVar) := arrayGet(iAllSCVarsMapping,iSCVarIdx);
1809 cacheVariables := scVar::cacheVariables;
1810 writtenCL := clIdx::writtenCL;
1811 ✗ freeSpace := cacheLineSize-numBytesRequired;
1812 //print(" -- writing new CL (idx: " + intString(clIdx) + "; freeSpace: " + intString(freeSpace) + ")\n");
1813 ✗ cacheLineCandidates := List.appendElt((clIdx,freeSpace), cacheLineCandidates);
1814 ✗ cacheMap := CACHEMAP(cacheLineSize,cacheVariables,cacheLinesFloat, cacheLinesInt, cacheLinesBool);
1815 ✗ cacheMapMeta := CACHEMAPMETA(iAllSCVarsMapping, iSimCodeVarTypes, iScVarCLMapping);
1816 //printCacheMap(cacheMap);
1817 ✗ then ((cacheMap, cacheMapMeta, numNewCL+1, cacheLineCandidates, writtenCL, currentCLCandidateIdx));
1818 else
1819 algorithm
1820 ✗ print("appendSCVarToCacheMap failed! Variable skipped.\n");
1821 then iInfo;
1822 end matchcontinue;
1823 end appendSCVarToCacheMap;
1824
1825 protected function doesSCVarFitIntoCL "author: marcusw
1826 Check that at least the iNumBytes are free in the given cacheline candidate."
1827 input tuple<Integer,Integer> iCacheLineCandidate;
1828 input Integer iNumBytes;
1829 output Boolean oResult;
1830 protected
1831 Integer freeSpace;
1832 algorithm
1833 ✗ (_,freeSpace) := iCacheLineCandidate;
1834 ✗ oResult := intGe(freeSpace, iNumBytes);
1835 end doesSCVarFitIntoCL;
1836
1837 protected function createDetailedCacheMapInformation "author: marcusw
1838 This method will create more detailed information about the given cachelines. It will return a list
1839 of tuples, containing the cacheLineIndex and the number of bytes that are free in the cache line."
1840 input list<Integer> iCacheLinesIdc; //cache line indices
1841 input list<CacheLineMap> iCacheLines; //input cache lines
1842 input Integer iCacheLineSize;
1843 output list<tuple<Integer,Integer>> oCacheLines; //list of cache lines <CLIdx,NumBytesFree>
1844 protected
1845 array<CacheLineMap> iCacheLinesArray;
1846 algorithm
1847 ✗ iCacheLinesArray := listArray(iCacheLines);
1848 ✗ oCacheLines := List.fold2(iCacheLinesIdc, createDetailedCacheMapInformation0, iCacheLinesArray, iCacheLineSize, {});
1849 end createDetailedCacheMapInformation;
1850
1851 protected function createDetailedCacheMapInformation0 "author: marcusw
1852 Append more detailed information about the cacheline with index 'iCacheLineIdx' to the iCacheLines-list."
1853 input Integer iCacheLineIdx;
1854 input array<CacheLineMap> iCacheLinesArray;
1855 input Integer iCacheLineSize;
1856 input list<tuple<Integer,Integer>> iCacheLines; //list of cache lines <CLIdx,NumBytesFree>
1857 output list<tuple<Integer,Integer>> oCacheLines;
1858 protected
1859 CacheLineMap cacheLineEntry;
1860 Integer numBytesFree;
1861 list<tuple<Integer,Integer>> cacheLines;
1862 algorithm
1863 oCacheLines := matchcontinue iCacheLines
1864 case _
1865 algorithm
1866 //print("createDetailedCacheMapInformation0: CacheLineIdx: " + intString(iCacheLineIdx) + "\n");
1867 ✗ cacheLineEntry := arrayGet(iCacheLinesArray, arrayLength(iCacheLinesArray) - iCacheLineIdx + 1);
1868 ✗ numBytesFree := iCacheLineSize-getNumOfUsedBytesByCacheLine(cacheLineEntry);
1869 //print("\tNumber of free bytes: " + intString(numBytesFree) + "\n");
1870 ✗ true := intGt(numBytesFree,0);
1871 ✗ cacheLines := (iCacheLineIdx,numBytesFree)::iCacheLines;
1872 then cacheLines;
1873 else
1874 then iCacheLines;
1875 end matchcontinue;
1876 end createDetailedCacheMapInformation0;
1877
1878 protected function getNumOfUsedBytesByCacheLine "author: marcusw
1879 Get the number of bytes that are already blocked in the cacheline."
1880 input CacheLineMap iCacheLineMap;
1881 output Integer oNumBytes;
1882 protected
1883 list<CacheLineEntry> entries;
1884 Integer firstEntryStart, firstEntrySize;
1885 algorithm
1886 ✗ CACHELINEMAP(entries=entries) := iCacheLineMap;
1887 ✗ entries := List.sort(entries, sortCacheLineEntriesByPos);
1888 //print("getNumOfUsedBytesByCacheLine:\n");
1889 //printCacheLineMapClean(iCacheLineMap);
1890 ✗ CACHELINEENTRY(start=firstEntryStart,size=firstEntrySize) := List.last(entries);
1891 ✗ oNumBytes := firstEntryStart + firstEntrySize;
1892 end getNumOfUsedBytesByCacheLine;
1893
1894 protected function sortCacheLineEntriesByPos "author: marcusw
1895 Helper function to sort various cachelines by their memory position."
1896 input CacheLineEntry iCacheLineEntry1;
1897 input CacheLineEntry iCacheLineEntry2;
1898 output Boolean oIsGreater;
1899 protected
1900 Integer start1, start2;
1901 algorithm
1902 ✗ CACHELINEENTRY(start=start1) := iCacheLineEntry1;
1903 ✗ CACHELINEENTRY(start=start2) := iCacheLineEntry2;
1904 ✗ oIsGreater := intGt(start1,start2);
1905 end sortCacheLineEntriesByPos;
1906
1907 protected function reverseCacheLineMapEntries "author: marcusw
1908 Reverse the entry-list of the given cacheline-map."
1909 input CacheLineMap iCacheLineMap;
1910 output CacheLineMap oCacheLineMap;
1911 protected
1912 Integer idx,numBytesFree;
1913 list<CacheLineEntry> entries;
1914 algorithm
1915 ✗ CACHELINEMAP(idx=idx,numBytesFree=numBytesFree,entries=entries) := iCacheLineMap;
1916 ✗ entries := listReverse(entries);
1917 ✗ oCacheLineMap := CACHELINEMAP(idx,numBytesFree,entries);
1918 end reverseCacheLineMapEntries;
1919
1920 protected function compareCacheLineMapByIdx "author: marcusw
1921 Reverse the entry-list of the given cacheline-map."
1922 input CacheLineMap iCacheLineMap;
1923 input CacheLineMap iCacheLineMap2;
1924 output Boolean oIsGreater;
1925 protected
1926 Integer idx1, idx2;
1927 algorithm
1928 95 CACHELINEMAP(idx=idx1) := iCacheLineMap;
1929 95 CACHELINEMAP(idx=idx2) := iCacheLineMap2;
1930 95 oIsGreater := intGt(idx1, idx2);
1931 end compareCacheLineMapByIdx;
1932
1933 protected function convertCacheToVarArrayMapping "author: marcusw
1934 Convert the information of the given cache-map to variable-array mapping used for the code generation."
1935 input CacheMap iCacheMap;
1936 input Integer iCacheLineSize;
1937 input list<SimCodeVar.SimVar> iStateVars;
1938 input list<SimCodeVar.SimVar> iDerivativeVars;
1939 input list<SimCodeVar.SimVar> iAliasVars;
1940 input list<SimCodeVar.SimVar> iIntAliasVars;
1941 input list<SimCodeVar.SimVar> iBoolAliasVars;
1942 input list<SimCodeVar.SimVar> iStringAliasVars;
1943 input tuple<Integer,Integer,Integer> iVarSizes; //size of float, int and bool variables (in bytes)
1944 input tuple<list<SimCodeVar.SimVar>, list<SimCodeVar.SimVar>, list<SimCodeVar.SimVar>, list<SimCodeVar.SimVar>> iNotOptimizedVars;
1945 output HashTableCrIListArray.HashTable oVarToArrayIndexMapping;
1946 output HashTableCrILst.HashTable oVarToIndexMapping;
1947 output Option<HpcOmSimCode.MemoryMap> oMemoryMap;
1948 protected
1949 Integer cacheLineSize, maxNumElemsFloat, maxNumElemsInt, maxNumElemsBool, stateAndStateDerSize;
1950 list<SimCodeVar.SimVar> cacheVariables;
1951 array<SimCodeVar.SimVar> cacheVariablesArray;
1952 list<CacheLineMap> cacheLinesFloat, cacheLinesInt, cacheLinesBool, allCacheLines;
1953 HashTableCrIListArray.HashTable varArrayIndexMappingHashTable;
1954 HashTableCrILst.HashTable varIndexMappingHashTable; //maps each variable to a memory "slot"
1955 Integer varSizeFloat, varSizeInt, varSizeBool, varSizeString;
1956 //<scVarIdx, arrayPosition, arrayIdx>
1957 array<Integer> varIdxOffsets;
1958 list<SimCodeVar.SimVar> notOptimizedVarsFloat, notOptimizedVarsInt, notOptimizedVarsBool, notOptimizedVarsString;
1959 array<Integer> currentVarIndices;
1960 algorithm
1961 (oVarToArrayIndexMapping,oVarToIndexMapping,oMemoryMap) := match(iCacheMap, iVarSizes, iNotOptimizedVars)
1962 case(CACHEMAP(cacheLineSize=cacheLineSize, cacheVariables=cacheVariables, cacheLinesFloat=cacheLinesFloat, cacheLinesInt=cacheLinesInt, cacheLinesBool=cacheLinesBool), (varSizeFloat, varSizeInt, varSizeBool), (notOptimizedVarsFloat,notOptimizedVarsInt,notOptimizedVarsBool,notOptimizedVarsString))
1963 algorithm
1964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 maxNumElemsFloat := intDiv(iCacheLineSize, varSizeFloat);
1965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 maxNumElemsInt := intDiv(iCacheLineSize, varSizeInt);
1966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 maxNumElemsBool := intDiv(iCacheLineSize, varSizeBool);
1967
1968 1 cacheVariablesArray := listArray(cacheVariables);
1969 1 varArrayIndexMappingHashTable := HashTableCrIListArray.emptyHashTable();
1970 1 varIndexMappingHashTable := HashTableCrILst.emptyHashTable();
1971
1972 1 currentVarIndices := arrayCreate(4,1);
1973 //The first array elements are reserved for state and state derivative variables
1974 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(iStateVars, VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
1975 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) :=SimCodeUtilShared.addVarToArrayIndexMappings(iDerivativeVars, VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
1976
1977
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 stateAndStateDerSize := intAdd(listLength(iStateVars), listLength(iDerivativeVars));
1978
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if(intEq(intMod(stateAndStateDerSize, maxNumElemsFloat), 0)) then
1979 1 arrayUpdate(currentVarIndices,1,(stateAndStateDerSize + 1));
1980 1 arrayUpdate(currentVarIndices,2,1);
1981 1 arrayUpdate(currentVarIndices,3,1);
1982 1 arrayUpdate(currentVarIndices,4,1);
1983 else
1984 ✗ arrayUpdate(currentVarIndices,1,stateAndStateDerSize + (maxNumElemsFloat - intMod(stateAndStateDerSize, maxNumElemsFloat)) + 1);
1985 ✗ arrayUpdate(currentVarIndices,2,1);
1986 ✗ arrayUpdate(currentVarIndices,3,1);
1987 ✗ arrayUpdate(currentVarIndices,4,1);
1988 end if;
1989
1990 //print("convertCacheToVarArrayMapping: The first " + intString(arrayGet(currentVarIndices,1)) + " elements are reserved for states and state derivatives\n");
1991 1 varSizeFloat := arrayGet(currentVarIndices,1);
1992
1993 1 varIdxOffsets := arrayCreate(3,1);
1994 1 varIdxOffsets := arrayUpdate(varIdxOffsets, 1, arrayGet(currentVarIndices,1) + 1);
1995 1 allCacheLines := List.sort(getAllCacheLinesOfCacheMap(iCacheMap), compareCacheLineMapByIdx);
1996
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
1 (varArrayIndexMappingHashTable,varIndexMappingHashTable) := List.fold(allCacheLines, function addCacheLineMapToVarArrayMapping(iCacheLineSize=cacheLineSize, iVarIdxOffsets=varIdxOffsets, iCacheVariables=cacheVariablesArray), (varArrayIndexMappingHashTable,varIndexMappingHashTable));
1997
1998 1 arrayUpdate(currentVarIndices, 1, arrayGet(currentVarIndices,1) + intMul(listLength(cacheLinesFloat), maxNumElemsFloat));
1999 1 arrayUpdate(currentVarIndices, 2, intMul(listLength(cacheLinesInt), maxNumElemsInt) + 1);
2000 1 arrayUpdate(currentVarIndices, 3, intMul(listLength(cacheLinesBool), maxNumElemsBool) + 1);
2001 1 arrayUpdate(currentVarIndices, 4, 1);
2002
2003 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(listReverse(notOptimizedVarsFloat), VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2004 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(listReverse(notOptimizedVarsInt), VARDATATYPE_INTEGER, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2005 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(listReverse(notOptimizedVarsBool), VARDATATYPE_BOOLEAN, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2006 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(listReverse(notOptimizedVarsString), VARDATATYPE_STRING, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2007
2008 //BaseHashTable.dumpHashTable(varArrayIndexMappingHashTable);
2009 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(iAliasVars, VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2010 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(iIntAliasVars, VARDATATYPE_INTEGER, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2011 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(iBoolAliasVars, VARDATATYPE_BOOLEAN, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2012 1 (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMappings(iStringAliasVars, VARDATATYPE_STRING, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2013
2014 1 varSizeFloat := varSizeFloat + intMul(listLength(cacheLinesFloat), maxNumElemsFloat) + listLength(notOptimizedVarsFloat);
2015 //SimCodeUtil.dumpVarLst(notOptimizedVarsFloat, "convertCacheToVarArrayMapping: Not optimized float vars");
2016 //print("\n");
2017 //SimCodeUtil.dumpVarLst(notOptimizedVarsInt, "convertCacheToVarArrayMapping: Not optimized int vars");
2018 //print("\n");
2019 //SimCodeUtil.dumpVarLst(notOptimizedVarsBool, "convertCacheToVarArrayMapping: Not optimized bool vars");
2020 //print("\n");
2021 //print("convertCacheToVarArrayMapping: " + intString(intMul(listLength(cacheLinesFloat), maxNumElemsFloat)) + " elements are reserved optimized variables. " + intString(varSizeFloat) + " variables at all.\n");
2022 1 varSizeInt := intMul(listLength(cacheLinesInt), maxNumElemsInt) + listLength(notOptimizedVarsInt);
2023 //print("convertCacheToVarArrayMapping: " + intString(intMul(listLength(cacheLinesBool), maxNumElemsBool)) + " elements are reserved for optimized variables [bool]\n");
2024 1 varSizeBool := intMul(listLength(cacheLinesBool), maxNumElemsBool) + listLength(notOptimizedVarsBool);
2025 1 varSizeString := listLength(notOptimizedVarsString);
2026
2027 1 then (varArrayIndexMappingHashTable, varIndexMappingHashTable, SOME(HpcOmSimCode.MEMORYMAP_ARRAY(varSizeFloat,varSizeInt,varSizeBool,varSizeString)));
2028 case(UNIFORM_CACHEMAP(), _, _)
2029 algorithm
2030 ✗ Error.addMessage(Error.INTERNAL_ERROR, {"ConvertCacheToVarArrayMapping: Uniform-CacheMap not supported!"});
2031 ✗ then fail();
2032 else
2033 algorithm
2034 ✗ Error.addMessage(Error.INTERNAL_ERROR, {"ConvertCacheToVarArrayMapping: CacheMap-Type not supported!"});
2035 ✗ then fail();
2036 end match;
2037 end convertCacheToVarArrayMapping;
2038
2039 protected function addCacheLineMapToVarArrayMapping "author: marcusw
2040 Append the information of the given cachline-map to the position-mapping-structure."
2041 input CacheLineMap iCacheLineMap;
2042 input Integer iCacheLineSize;
2043 input array<Integer> iVarIdxOffsets; //an offset that is substracted from the arrayPosition (for float, int and bool variables -> taken from iArrayIdx)
2044 input array<SimCodeVar.SimVar> iCacheVariables;
2045 input tuple<HashTableCrIListArray.HashTable, HashTableCrILst.HashTable> iPositionMapping; //<varArrayIndexMappingHashTable, varIndexMappingHashTable, currentVarIndices>
2046 output tuple<HashTableCrIListArray.HashTable, HashTableCrILst.HashTable> oPositionMapping; //<varArrayIndexMappingHashTable, varIndexMappingHashTable, currentVarIndices>
2047 protected
2048 HashTableCrIListArray.HashTable varArrayIndexMappingHashTable;
2049 HashTableCrILst.HashTable varIndexMappingHashTable;
2050
2051 Integer idx; //the arrayIdx is derived from the variable type of the first cacheline entry
2052 list<CacheLineEntry> entries;
2053 Integer dataType, size;
2054 algorithm
2055 oPositionMapping := match(iCacheLineMap, iPositionMapping)
2056 case(CACHELINEMAP(idx=idx,entries=entries), (varArrayIndexMappingHashTable, varIndexMappingHashTable))
2057 algorithm
2058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 CACHELINEENTRY(dataType=dataType, size=size)::_ := entries;
2059 //print("addCacheLineMapToVarArrayMapping: Adding cache line '" + intString(idx) + "' with '" + intString(listLength(entries)) + "' entries\n");
2060 32 (varArrayIndexMappingHashTable, varIndexMappingHashTable) := List.fold(entries, function addCacheLineEntryToVarArrayMapping(iArrayIdx=dataType, iClIdxSize=(idx, iCacheLineSize), iVarIdxOffsets=iVarIdxOffsets, iCacheVariables=iCacheVariables), iPositionMapping);
2061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 arrayUpdate(iVarIdxOffsets, dataType, intAdd(arrayGet(iVarIdxOffsets, dataType), intDiv(iCacheLineSize, size)));
2062 //_ = convertCacheToVarArrayMapping2Helper(iVarIdxOffsets, 1, dataType);
2063 32 then ((varArrayIndexMappingHashTable, varIndexMappingHashTable));
2064 else
2065 algorithm
2066 ✗ Error.addMessage(Error.INTERNAL_ERROR, {"addCacheLineMapToVarArrayMapping failed! CacheLineMap-Type not supported!"});
2067 ✗ then fail();
2068 end match;
2069 end addCacheLineMapToVarArrayMapping;
2070
2071 protected function addCacheLineEntryToVarArrayMapping "author: marcusw
2072 Append the information of the given cachline-entry to the position-mapping-structure."
2073 input CacheLineEntry iCacheLineEntry;
2074 input Integer iArrayIdx;
2075 input tuple<Integer,Integer> iClIdxSize; //<CLIdx, CLSize>>
2076 input array<Integer> iVarIdxOffsets; //an offset that is substracted from the arrayPosition (for float, int and bool variables -> taken from iArrayIdx)
2077 input array<SimCodeVar.SimVar> iCacheVariables;
2078 input tuple<HashTableCrIListArray.HashTable, HashTableCrILst.HashTable> iPositionMapping; //<varArrayIndexMappingHashTable, varIndexMappingHashTable, currentVarIndices>
2079 output tuple<HashTableCrIListArray.HashTable, HashTableCrILst.HashTable> oPositionMapping; //<varArrayIndexMappingHashTable, varIndexMappingHashTable, currentVarIndices>
2080 protected
2081 HashTableCrIListArray.HashTable varArrayIndexMappingHashTable;
2082 HashTableCrILst.HashTable varIndexMappingHashTable;
2083
2084 Integer scVarIdx, start, size, arrayPosition, offset;
2085 array<Integer> currentVarIndices;
2086 algorithm
2087 oPositionMapping := match(iCacheLineEntry, iPositionMapping)
2088 case(CACHELINEENTRY(scVarIdx=scVarIdx, start=start, size=size), (varArrayIndexMappingHashTable, varIndexMappingHashTable))
2089 algorithm
2090 286 offset := arrayGet(iVarIdxOffsets, iArrayIdx);
2091 //arrayPosition = intDiv(start, size) + (clIdx - 1)*intDiv(clSize, size) + offset;
2092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 286 times.
286 arrayPosition := intDiv(start, size) + offset;
2093 //print("convertCacheMapToMemoryMap2: offset=" + intString(offset) + " array-index=" + intString(iArrayIdx) + " array-position=" + intString(arrayPosition) + "\n");
2094 286 currentVarIndices := arrayCreate(4,arrayPosition);
2095 //print("convertCacheMapToMemoryMap2: number of variables=" + intString(arrayLength(iCacheVariables)) + " arrayPosition=" + intString(arrayPosition) + "\n");
2096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 286 times.
572 (_, varArrayIndexMappingHashTable, varIndexMappingHashTable) := SimCodeUtilShared.addVarToArrayIndexMapping(arrayGet(iCacheVariables, arrayLength(iCacheVariables) - scVarIdx + 1), iArrayIdx, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
2097 //iPositionMappingList = (realScVarIdx,arrayPosition,iArrayIdx)::iPositionMappingList;
2098 //for arridx in listRange(arrayLength(iVarIdxOffsets)) loop
2099 // _ = arrayUpdate(iVarIdxOffset, intDiv(clSize, size));
2100 //end for;
2101 //print("convertCacheMapToMemoryMap2: " + ComponentReference.debugPrintComponentRefTypeStr(name) + " [" + intString(arrayPosition) + "] with array-pos: " + intString(arrayPosition) + " | array-index: " + intString(iArrayIdx) + " | start: " + intString(start) + "\n");
2102 286 then ((varArrayIndexMappingHashTable, varIndexMappingHashTable));
2103 else
2104 algorithm
2105 ✗ Error.addMessage(Error.INTERNAL_ERROR, {"addCacheLineEntryToVarArrayMapping failed! Unsupported entry-type\n"});
2106 ✗ then fail();
2107 end match;
2108 end addCacheLineEntryToVarArrayMapping;
2109
2110 protected function convertCacheToVarArrayMapping2Helper "author: marcusw
2111 Add the given offset to all array-positions with a index != iIndex."
2112 input array<Integer> iArray;
2113 input Integer iOffset;
2114 input Integer iIndex;
2115 output array<Integer> oArray;
2116 protected
2117 array<Integer> tmpArray;
2118 Integer i;
2119 algorithm
2120 tmpArray := iArray;
2121 ✗ for i in 1:arrayLength(tmpArray) loop
2122 ✗ if(intNe(i, iIndex)) then
2123 ✗ tmpArray := arrayUpdate(tmpArray, i, arrayGet(tmpArray, i) + iOffset);
2124 end if;
2125 end for;
2126 oArray := tmpArray;
2127 end convertCacheToVarArrayMapping2Helper;
2128
2129 protected function getNotOptimizedVarsByCacheLineMapping "author: marcusw
2130 Get all sim code variables that have no valid cl-mapping."
2131 input array<tuple<Integer,Integer>> iScVarCLMapping;
2132 input array<Option<SimCodeVar.SimVar>> iAllVarsMapping;
2133 input array<tuple<Integer,Integer, Integer>> iSimCodeVarTypes; //<varDataType, varSize, varType>
2134 output tuple<list<Integer>, list<Integer>, list<Integer>, list<Integer>> oNotOptimizedVars;
2135 algorithm
2136 8 (oNotOptimizedVars,_) := Array.fold(iScVarCLMapping, function getNotOptimizedVarsByCacheLineMapping0(iAllVarsMapping=iAllVarsMapping,iSimCodeVarTypes=iSimCodeVarTypes), (({},{},{},{}),1));
2137 end getNotOptimizedVarsByCacheLineMapping;
2138
2139 protected function getNotOptimizedVarsByCacheLineMapping0 "author: marcusw
2140 Add the sc-variable to the output list if it has no valid mapping."
2141 input tuple<Integer,Integer> iScVarCLMapping;
2142 input array<Option<SimCodeVar.SimVar>> iAllVarsMapping;
2143 input array<tuple<Integer,Integer, Integer>> iSimCodeVarTypes; //<varDataType, varSize, varType>
2144 input tuple<tuple<list<Integer>, list<Integer>, list<Integer>, list<Integer>>, Integer> iEntries; //<input-list,scVarindex>
2145 output tuple<tuple<list<Integer>, list<Integer>, list<Integer>, list<Integer>>, Integer> oEntries; //<input-list,scVarindex>
2146 protected
2147 list<Integer> tmpSimVarsFloat, tmpSimVarsInt, tmpSimVarsBool, tmpSimVarsString;
2148 Integer scVarIdx, dataType;
2149 algorithm
2150 oEntries := matchcontinue(iScVarCLMapping, iEntries)
2151 case((-1,_), ((tmpSimVarsFloat, tmpSimVarsInt, tmpSimVarsBool, tmpSimVarsString), scVarIdx))
2152 algorithm
2153 597 dataType := Util.tuple31(arrayGet(iSimCodeVarTypes, scVarIdx));
2154
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 432 times.
597 if(intEq(dataType, VARDATATYPE_FLOAT)) then
2155 tmpSimVarsFloat := scVarIdx::tmpSimVarsFloat;
2156 else
2157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 432 times.
432 if(intEq(dataType, VARDATATYPE_INTEGER)) then
2158 tmpSimVarsInt := scVarIdx::tmpSimVarsInt;
2159 else
2160
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 410 times.
432 if(intEq(dataType, VARDATATYPE_BOOLEAN)) then
2161 tmpSimVarsBool := scVarIdx::tmpSimVarsBool;
2162 else
2163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 410 times.
410 if(intEq(dataType, VARDATATYPE_STRING)) then
2164 tmpSimVarsString := scVarIdx::tmpSimVarsString;
2165 end if;
2166 end if;
2167 end if;
2168 end if;
2169 597 then (((tmpSimVarsFloat, tmpSimVarsInt, tmpSimVarsBool, tmpSimVarsString), scVarIdx+1));
2170 case(_, ((tmpSimVarsFloat, tmpSimVarsInt, tmpSimVarsBool, tmpSimVarsString), scVarIdx))
2171 286 then (((tmpSimVarsFloat, tmpSimVarsInt, tmpSimVarsBool, tmpSimVarsString), scVarIdx+1));
2172 end matchcontinue;
2173 end getNotOptimizedVarsByCacheLineMapping0;
2174
2175 // -------------------------------------------
2176 // ANALYSIS
2177 // -------------------------------------------
2178
2179 protected function evaluateCacheBehaviour
2180 input HashTableCrILst.HashTable iVarToIndexMappingHashTable; //maps each sim var to a memory slot
2181 input HashTableCrILst.HashTable iSimVarIdxMappingHashTable; //maps each sim var to an ID
2182 input array<list<Integer>> taskSolvedVarsMapping;
2183 input array<list<Integer>> taskUnsolvedVarsMapping;
2184 input HpcOmTaskGraph.TaskGraph iTaskGraph;
2185 input HpcOmTaskGraph.TaskGraph iTaskGraphT;
2186 input Integer iNumberOfThreads;
2187 input Integer iCacheLineSize;
2188 input array<tuple<Integer,Integer, Integer>> iSimCodeVarTypes; //<varDataType, varSize, varType>
2189 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
2190 protected
2191 //bool, int and float cache lines are starting with index 1 each
2192 //offset of cache lines (e.g. int-offset = number of float cache lines)
2193 algorithm
2194 //(varTypeCLOffset, varToCLMapping) := createVarCLMappingFromVarArrayIndexHashTable(iVarToIndexMappingHashTable, iSimVarIdxMappingHashTable, iSimCodeVarTypes);
2195 /*
2196 cacheLineSize := getCacheLineSizeOfCacheMap(iCacheMap);
2197 cacheLines := getAllCacheLinesOfCacheMap(iCacheMap);
2198 cacheLineThreadProperties := arrayCreate(iNumberOfCLs, arrayCreate(iNumberOfThreads, 0.0));
2199 for cacheLine in cacheLines loop
2200 createCacheLineThreadProperties(cacheLine, iNumberOfThreads, cacheLineSize, cacheLineThreadProperties);
2201 end for;
2202 locCoWrite := calculateLocCoWrite(iNodeSimCodeVarMapping, iScVarCLMapping, cacheLineThreadProperties, iSchedulerInfo);
2203 locCoRead := calculateLocCoRead(iTaskGraphT, iNodeSimCodeVarMapping, iScVarCLMapping, cacheLineThreadProperties, iSchedulerInfo);
2204 locCo := locCoWrite * 0.6 + locCoRead * 0.4;
2205 print("LocCo-Write for Graph is " + realString(locCoWrite) + "\n");
2206 print("LocCo-Read for Graph is " + realString(locCoRead) + "\n");
2207 print("LocCo for Graph is " + realString(locCo) + "\n");
2208 */
2209 end evaluateCacheBehaviour;
2210
2211 protected function createVarCLMappingFromVarArrayIndexHashTable
2212 input HashTableCrILst.HashTable iVarToIndexMappingHashTable;
2213 input HashTableCrILst.HashTable iSimVarIdxMappingHashTable;
2214 input Integer iCacheLineSize;
2215 input array<tuple<Integer,Integer, Integer>> iSimCodeVarTypes; //<varDataType, varSize, varType>
2216 output array<Integer> oNumberOfVars; //number of variables stored in flaot, bool and int array
2217 output array<Integer> oVarToCLMapping;
2218 protected
2219 list<tuple<DAE.ComponentRef, list<Integer>>> hashTableElements;
2220 tuple<DAE.ComponentRef, list<Integer>> hashTableElement;
2221 array<Integer> varToCLMapping;
2222 array<Integer> numberOfVars;
2223 Integer pos;
2224 DAE.ComponentRef cref;
2225 algorithm
2226
2227 ✗ varToCLMapping := arrayCreate(arrayLength(iSimCodeVarTypes), -1);
2228 ✗ numberOfVars := arrayCreate(3, 0);
2229 ✗ hashTableElements := BaseHashTable.hashTableList(iVarToIndexMappingHashTable);
2230 ✗ for hashTableElement in hashTableElements loop
2231 ✗ (cref, pos::_) := hashTableElement;
2232 //(id::_) := BaseHashTable.get(iSimVarIdxMappingHashTable, cref);
2233 //arrayUpdate(varToCLMapping, id, pos);
2234 end for;
2235 oNumberOfVars := numberOfVars;
2236 oVarToCLMapping := varToCLMapping;
2237 end createVarCLMappingFromVarArrayIndexHashTable;
2238
2239 protected function createCacheLineThreadProperties
2240 input CacheLineMap iCacheLine;
2241 input Integer iNumberOfThreads;
2242 input Integer iCacheLineSize;
2243 input array<array<Real>> iCacheLineThreadProperties; //updated
2244 protected
2245 array<Integer> bytesPerThread;
2246 array<Real> threadProperties;
2247 Integer cacheLineIdx, threadOwner, size, threadIdx, numBytesFree, numBytesUnassigned;
2248 list<CacheLineEntry> entries;
2249 CacheLineEntry entry;
2250 Real sizeReal;
2251 algorithm
2252 ✗ CACHELINEMAP(idx=cacheLineIdx,entries=entries,numBytesFree=numBytesFree) := iCacheLine;
2253 numBytesUnassigned := 0;
2254 //print("createCacheLineThreadProperties: Handling CL " + intString(cacheLineIdx) + "\n");
2255 ✗ threadProperties := arrayCreate(iNumberOfThreads, 0.0);
2256 ✗ bytesPerThread := arrayCreate(iNumberOfThreads, 0);
2257 ✗ for entry in entries loop
2258 ✗ CACHELINEENTRY(threadOwner=threadOwner,size=size) := entry;
2259 ✗ if(intLt(threadOwner, 0)) then
2260 ✗ numBytesUnassigned := numBytesUnassigned + size;
2261 else
2262 ✗ bytesPerThread := arrayUpdate(bytesPerThread, threadOwner, arrayGet(bytesPerThread, threadOwner) + size);
2263 end if;
2264 end for;
2265 ✗ sizeReal := intReal(iCacheLineSize - numBytesFree - numBytesUnassigned);
2266 ✗ if(realGt(sizeReal, 0)) then
2267 ✗ for threadIdx in 1:iNumberOfThreads loop
2268 //print("createCacheLineThreadProperties: Thread " + intString(threadIdx) + " has " + intString(arrayGet(bytesPerThread, threadIdx)) + " bytes \n");
2269 //print("createCacheLineThreadProperties: ThreadProperties-length=" + intString(arrayLength(threadProperties)) + " index=" + intString(threadIdx) + "\n");
2270 ✗ arrayUpdate(threadProperties, threadIdx, realDiv(intReal(arrayGet(bytesPerThread, threadIdx)),sizeReal));
2271 end for;
2272 end if;
2273 //print("createCacheLineThreadProperties: iCacheLineThreadProperties-length=" + intString(arrayLength(iCacheLineThreadProperties)) + " index=" + intString(cacheLineIdx) + "\n");
2274 ✗ arrayUpdate(iCacheLineThreadProperties, cacheLineIdx, threadProperties);
2275 end createCacheLineThreadProperties;
2276
2277 protected function calculateLocCoRead
2278 input HpcOmTaskGraph.TaskGraph iTaskGraphT;
2279 input array<list<Integer>> iNodeSimCodeVarMapping;
2280 input array<tuple<Integer,Integer>> iScVarCLMapping;
2281 input array<array<Real>> cacheLineThreadProperties;
2282 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
2283 output Real oLocCoRead;
2284 protected
2285 Integer nodeIdx, numberOfNodes, threadIdx;
2286 Real sum, locCoRead;
2287 algorithm
2288 numberOfNodes := arrayLength(iNodeSimCodeVarMapping);
2289 sum := 0.0;
2290 ✗ for nodeIdx in 1:numberOfNodes loop
2291 ✗ threadIdx := Util.tuple31(arrayGet(iSchedulerInfo, nodeIdx));
2292 ✗ locCoRead := calculateLocCoReadForTask(nodeIdx, threadIdx, iTaskGraphT, iNodeSimCodeVarMapping, iScVarCLMapping, cacheLineThreadProperties);
2293 ✗ sum := sum + locCoRead;
2294 //print("LocCo-Read for Calc-Task " + intString(nodeIdx) + " handled by thread " + intString(threadIdx) + " is " + realString(locCoRead) + "\n");
2295 end for;
2296 ✗ if(intGt(numberOfNodes, 0)) then
2297 ✗ oLocCoRead := realDiv(sum, numberOfNodes);
2298 else
2299 oLocCoRead := 1.0;
2300 end if;
2301 end calculateLocCoRead;
2302
2303 protected function calculateLocCoReadForTask
2304 input Integer iNodeIdx;
2305 input Integer iThreadIdx;
2306 input HpcOmTaskGraph.TaskGraph iTaskGraphT;
2307 input array<list<Integer>> iNodeSimCodeVarMapping;
2308 input array<tuple<Integer,Integer>> iScVarCLMapping;
2309 input array<array<Real>> iCacheLineThreadProperties;
2310 output Real oLocCoRead;
2311 protected
2312 Integer predecessor, numberOfPredecessors;
2313 list<Integer> predecessors;
2314 Real sum;
2315 algorithm
2316 sum := 0.0;
2317 ✗ predecessors := arrayGet(iTaskGraphT, iNodeIdx);
2318 ✗ numberOfPredecessors := listLength(predecessors);
2319 ✗ for predecessor in predecessors loop
2320 ✗ sum := sum + calculateLocCoForTask(predecessor, iThreadIdx, arrayGet(iNodeSimCodeVarMapping, predecessor), iScVarCLMapping, iCacheLineThreadProperties);
2321 end for;
2322 ✗ if(intGt(numberOfPredecessors, 0)) then
2323 ✗ oLocCoRead := realDiv(sum, numberOfPredecessors);
2324 else
2325 oLocCoRead := 1.0;
2326 end if;
2327 end calculateLocCoReadForTask;
2328
2329 protected function calculateLocCoWrite
2330 input array<list<Integer>> iNodeSimCodeVarMapping;
2331 input array<tuple<Integer,Integer>> iScVarCLMapping;
2332 input array<array<Real>> cacheLineThreadProperties;
2333 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
2334 output Real oLocCoWrite;
2335 protected
2336 Integer nodeIdx, numberOfNodes, threadIdx;
2337 Real sum, locCoWrite;
2338 algorithm
2339 numberOfNodes := arrayLength(iNodeSimCodeVarMapping);
2340 sum := 0.0;
2341 ✗ for nodeIdx in 1:numberOfNodes loop
2342 ✗ threadIdx := Util.tuple31(arrayGet(iSchedulerInfo, nodeIdx));
2343 //print("calculateLocCoWrite: nodeIdx='" + intString(nodeIdx) + "' threadIdx='" + intString(threadIdx) + "'\n");
2344 ✗ locCoWrite := calculateLocCoForTask(nodeIdx, threadIdx, arrayGet(iNodeSimCodeVarMapping, nodeIdx), iScVarCLMapping, cacheLineThreadProperties);
2345 ✗ sum := sum + locCoWrite;
2346 //print("LocCo-Write for Calc-Task " + intString(nodeIdx) + " handled by thread " + intString(threadIdx) + " is " + realString(locCoWrite) + "\n");
2347 end for;
2348 ✗ if(intGt(numberOfNodes, 0)) then
2349 ✗ oLocCoWrite := realDiv(sum, numberOfNodes);
2350 else
2351 oLocCoWrite := 1.0;
2352 end if;
2353 end calculateLocCoWrite;
2354
2355 protected function calculateLocCoForTask
2356 input Integer iTaskIdx;
2357 input Integer iThreadIdx;
2358 input list<Integer> iNodeSimCodeVarMapping;
2359 input array<tuple<Integer,Integer>> iScVarCLMapping;
2360 input array<array<Real>> iCacheLineThreadProperties;
2361 output Real oLocCo;
2362 protected
2363 Integer simCodeVar, clIdx;
2364 Real sum;
2365 algorithm
2366 sum := 0.0;
2367 ✗ for simCodeVar in iNodeSimCodeVarMapping loop
2368 //print("calculateLocCoForTask: handling simCodeVar" + intString(simCodeVar) + "\n");
2369 ✗ clIdx := Util.tuple21(arrayGet(iScVarCLMapping, simCodeVar));
2370 //print("calculateLocCoForTask: clIdx=" + intString(clIdx) + "\n");
2371 ✗ sum := sum + arrayGet(arrayGet(iCacheLineThreadProperties,clIdx), iThreadIdx);
2372 end for;
2373 ✗ oLocCo := realDiv(sum, intReal(listLength(iNodeSimCodeVarMapping)));
2374 end calculateLocCoForTask;
2375
2376 // -------------------------------------------
2377 // MAPPINGS
2378 // -------------------------------------------
2379
2380 protected function fillSimVarHashTable "author: marcusw
2381 Function to create a mapping for each simVar-name to the simVar-Index+Offset."
2382 input list<SimCodeVar.SimVar> iSimVars;
2383 input Integer iOffset;
2384 input Integer iType; //1 = real; 2 = int; 3 = bool
2385 input HashTableCrILst.HashTable iHt; //contains a list of type Integer for each simVar. List.First: Index, List.Secons: Offset, List.Third: Type
2386 output HashTableCrILst.HashTable oHt;
2387 protected
2388 HashTableCrILst.HashTable tmpHashTable;
2389 SimCodeVar.SimVar simVar;
2390 Integer index;
2391 DAE.ComponentRef name;
2392 algorithm
2393 tmpHashTable := iHt;
2394
2/2
✓ Branch 0 taken 3375 times.
✓ Branch 1 taken 96 times.
3471 for simVar in iSimVars loop
2395 3375 SimCodeVar.SIMVAR(name=name,index=index) := simVar;
2396 3375 index := index + 1;
2397 //print("fillSimVarHashTableTraverse: " + ComponentReference.debugPrintComponentRefTypeStr(name) + " with index: " + intString(index+ iOffset) + "\n");
2398 3375 tmpHashTable := BaseHashTable.add((name,{index,iOffset,iType}),tmpHashTable);
2399 end for;
2400 oHt := tmpHashTable;
2401 end fillSimVarHashTable;
2402
2403 protected function transposeScVarTaskMapping
2404 input array<Integer> iScVarTaskMapping;
2405 input HpcOmTaskGraph.TaskGraph iTaskGraph;
2406 output array<list<Integer>> oNodeSimCodeVarMapping;
2407 protected
2408 array<list<Integer>> tmpNodeSimCodeVarMapping;
2409 Integer scVarIdx, taskIdx;
2410 list<Integer> oldList;
2411 algorithm
2412 ✗ tmpNodeSimCodeVarMapping := arrayCreate(arrayLength(iTaskGraph), {});
2413 ✗ for scVarIdx in 1:arrayLength(iScVarTaskMapping) loop
2414 ✗ taskIdx := arrayGet(iScVarTaskMapping, scVarIdx);
2415 //print("Handling sc-var with index: " + intString(scVarIdx) + "\n");
2416 ✗ if(intGt(taskIdx, 0)) then
2417 //print("Has task index " + intString(taskIdx) + "\n");
2418 ✗ oldList := arrayGet(tmpNodeSimCodeVarMapping, taskIdx);
2419 oldList := scVarIdx::oldList;
2420 ✗ arrayUpdate(tmpNodeSimCodeVarMapping, taskIdx, oldList);
2421 end if;
2422 end for;
2423 oNodeSimCodeVarMapping := tmpNodeSimCodeVarMapping;
2424 end transposeScVarTaskMapping;
2425
2426 protected function transposeTasksScVarsMapping
2427 input array<list<Integer>> iTasksScVarMapping;
2428 input Integer iNumberOfScVars;
2429 output array<list<Integer>> oScVarTasksMapping;
2430 protected
2431 array<list<Integer>> tmpScVarTasksMapping;
2432 Integer scVarIdx, taskIdx;
2433 list<Integer> oldList, scVarIdc;
2434 algorithm
2435 8 tmpScVarTasksMapping := arrayCreate(iNumberOfScVars, {});
2436
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 time.
506 for taskIdx in 1:arrayLength(iTasksScVarMapping) loop
2437 498 scVarIdc := arrayGet(iTasksScVarMapping, taskIdx);
2438
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 498 times.
2128 for scVarIdx in scVarIdc loop
2439
1/2
✓ Branch 0 taken 1630 times.
✗ Branch 1 not taken.
1630 if(intGt(scVarIdx, 0)) then
2440 1630 oldList := arrayGet(tmpScVarTasksMapping, scVarIdx);
2441 oldList := taskIdx::oldList;
2442 1630 arrayUpdate(tmpScVarTasksMapping, scVarIdx, oldList);
2443 end if;
2444 end for;
2445 end for;
2446 oScVarTasksMapping := tmpScVarTasksMapping;
2447 end transposeTasksScVarsMapping;
2448
2449 protected function getEqSCVarMapping "author: marcusw
2450 Create a mapping for all eqSystems to the solved equations to a list of variables that are part of the equation."
2451 input BackendDAE.EqSystems iEqSystems;
2452 input HashTableCrILst.HashTable iHt; //Mapping varName -> varIdx
2453 output array<array<list<Integer>>> oMapping; //eqSysIdx -> eqIdx -> list<scVarIdx>
2454 protected
2455 list<array<list<Integer>>> tmpMapping;
2456 algorithm
2457 8 tmpMapping := List.map1(iEqSystems, getEqSCVarMappingByEqSystem, iHt);
2458 8 oMapping := listArray(tmpMapping);
2459 end getEqSCVarMapping;
2460
2461 protected function getEqSCVarMappingByEqSystem "author: marcusw
2462 Function to create a mapping for each equation in the equationSystem to a list of simCode-Variables that are part of the equation-expressions."
2463 input BackendDAE.EqSystem iEqSystem;
2464 input HashTableCrILst.HashTable iHt; //Mapping varName -> varIdx
2465 output array<list<Integer>> oMapping; //eqIdx -> list<scVarIdx>
2466 protected
2467 BackendDAE.EquationArray orderedEqs;
2468 list<Option<BackendDAE.Equation>> equOptList;
2469 algorithm
2470 17 BackendDAE.EQSYSTEM(orderedEqs=orderedEqs) := iEqSystem;
2471 17 equOptList := arrayList(ExpandableArray.getData(orderedEqs));
2472 17 oMapping := listArray(List.map1Option(equOptList, getEqSCVarMapping0, iHt));
2473 end getEqSCVarMappingByEqSystem;
2474
2475 protected function getEqSCVarMapping0 "author: marcusw
2476 Create a list of simcode-variables that are part of the given equation."
2477 input BackendDAE.Equation iEquation;
2478 input HashTableCrILst.HashTable iHt; //Mapping varName -> varIdx
2479 output list<Integer> oMapping;
2480 algorithm
2481 //print("getEqSCVarMapping0: Handling equation:\n" + BackendDump.equationString(iEquation) + "\n");
2482 1980 (_,(_,(_,oMapping))) := BackendEquation.traverseExpsOfEquation(iEquation,Expression.traverseSubexpressionsHelper, (createMemoryMapTraverse0, (iHt,{})));
2483 //((_,(_,oMapping))) := Expression.traverseExpBottomUp(exp,createMemoryMapTraverse, (iHt,{}));
2484 end getEqSCVarMapping0;
2485
2486 protected function createMemoryMapTraverse0 "author: marcusw
2487 Extend the variable list if the given expression is a cref."
2488 input DAE.Exp inExp;
2489 input tuple<HashTableCrILst.HashTable, list<Integer>> inTpl; // <hashTable, variableList, nextVarIsDerived>
2490 output DAE.Exp outExp;
2491 output tuple<HashTableCrILst.HashTable, list<Integer>> oTpl;
2492 protected
2493 list<Integer> iVarList, oVarList, varInfo;
2494 Integer varIdx, varHead;
2495 HashTableCrILst.HashTable iHashTable;
2496 DAE.Exp iExp;
2497 DAE.ComponentRef componentRef;
2498 algorithm
2499 (outExp,oTpl) := matchcontinue(inExp,inTpl)
2500 case (iExp as DAE.CALL(path = Absyn.IDENT("der"), expLst = {DAE.CREF(componentRef = componentRef)}), (iHashTable,iVarList))
2501 algorithm
2502 //print("HpcOmSimCode.createMemoryMapTraverse: found der-call\n");
2503 361 varInfo := BaseHashTable.get(componentRef, iHashTable);
2504 ✗ varIdx := listHead(varInfo) + List.second(varInfo);
2505 //Delete state variable first
2506 ✗ if(boolNot(listEmpty(iVarList))) then
2507 ✗ varHead := listHead(iVarList);
2508 ✗ if(intEq(varHead, varIdx)) then
2509 ✗ iVarList := listRest(iVarList);
2510 //print("createMemoryMapTraverse0: Removed variable " + intString(varIdx) + "\n");
2511 end if;
2512 end if;
2513 //Add der state variable
2514 ✗ varInfo := BaseHashTable.get(ComponentReference.crefPrefixDer(componentRef), iHashTable);
2515 ✗ varIdx := listHead(varInfo) + List.second(varInfo);
2516 //print("createMemoryMapTraverse0: Added variable " + intString(varIdx) + "\n");
2517 oVarList := varIdx :: iVarList;
2518 ✗ then (iExp,(iHashTable,oVarList));
2519 case(iExp as DAE.CREF(componentRef=componentRef), (iHashTable,iVarList))
2520 algorithm
2521 //print("HpcOmSimCode.createMemoryMapTraverse: try to find componentRef '" + ComponentReference.crefStr(componentRef) + "\n");
2522 8792 varInfo := BaseHashTable.get(componentRef, iHashTable);
2523 6845 varIdx := listHead(varInfo) + List.second(varInfo);
2524 //print("createMemoryMapTraverse0 " + intString(varIdx) + "\n");
2525 //print("HpcOmSimCode.createMemoryMapTraverse: Found ref " + ComponentReferenceBasics.printComponentRefStr(componentRef) + " with Index: " + intString(varIdx) + "\n");
2526 //ExpressionDump.dumpExp(iExp);
2527 oVarList := varIdx :: iVarList;
2528 6845 then (iExp,(iHashTable,oVarList));
2529 else (inExp,inTpl);
2530 end matchcontinue;
2531 end createMemoryMapTraverse0;
2532
2533 protected function getSimCodeVarNodeMapping "author: marcusw
2534 Create a mapping for all simcode-variables to the task that calculates it."
2535 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
2536 input BackendDAE.EqSystems iEqSystems;
2537 input Integer iNumScVars;
2538 input array<Integer> iCompNodeMapping;
2539 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
2540 output array<Integer> oScVarTaskMapping; //mapping scVarIdx (arrayIdx) to the taskIdx
2541 protected
2542 array<tuple<Integer,Integer,Integer>> varCompMapping;
2543 array<Integer> scVarTaskMapping;
2544 algorithm
2545 8 scVarTaskMapping := arrayCreate(iNumScVars,-1);
2546 8 HpcOmTaskGraph.TASKGRAPHMETA(varCompMapping=varCompMapping) := iTaskGraphMeta;
2547 //iterate over all variables
2548 8 (oScVarTaskMapping,_) := Array.fold(varCompMapping, function getSimCodeVarNodeMapping0(iEqSystems = iEqSystems, iVarNameSCVarIdxMapping = iVarNameSCVarIdxMapping, iCompNodeMapping = iCompNodeMapping), (scVarTaskMapping,1));
2549 end getSimCodeVarNodeMapping;
2550
2551 protected function getSimCodeVarNodeMapping0 "author: marcusw
2552 Add the given mapping between varIdx and nodeIdx to the mapping-array."
2553 input tuple<Integer,Integer,Integer> iCompIdx; //<compIdx,eqSysIdx,varOffset>
2554 input BackendDAE.EqSystems iEqSystems;
2555 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
2556 input array<Integer> iCompNodeMapping;
2557 input tuple<array<Integer>, Integer> iScVarTaskMappingVarIdx; //<mapping scVarIdx -> task, varIdx>
2558 output tuple<array<Integer>, Integer> oScVarTaskMappingVarIdx;
2559 protected
2560 array<Integer> iScVarTaskMapping;
2561 Integer varIdx,eqSysIdx,varOffset,scVarIdx, compIdx, nodeIdx, scVarOffset;
2562 BackendDAE.EqSystem eqSystem;
2563 BackendDAE.Variables orderedVars;
2564 BackendDAE.Var var;
2565 DAE.ComponentRef varName;
2566 list<Integer> scVarValues;
2567 String varNameString;
2568 algorithm
2569 oScVarTaskMappingVarIdx := matchcontinue(iCompIdx, iScVarTaskMappingVarIdx)
2570 case((compIdx,eqSysIdx,varOffset), (iScVarTaskMapping,varIdx))
2571 algorithm
2572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1983 times.
1983 true := intGt(compIdx,0);
2573 1983 eqSystem := listGet(iEqSystems,eqSysIdx);
2574 1983 BackendDAE.EQSYSTEM(orderedVars=orderedVars) := eqSystem;
2575 1983 var := BackendVariable.getVarAt(orderedVars, varIdx - varOffset);
2576 BackendDAE.VAR(varName=varName) := var;
2577 1980 varName := getModifiedVarName(var);
2578 1980 scVarValues := BaseHashTable.get(varName,iVarNameSCVarIdxMapping);
2579 1847 varNameString := ComponentReferenceBasics.printComponentRefStr(varName);
2580 //print("getSimCodeVarNodeMapping0: SCC-Idx: " + intString(compIdx) + " name: " + varNameString + "\n");
2581 1847 scVarIdx := listHead(scVarValues);
2582 1847 scVarOffset := List.second(scVarValues);
2583 1847 scVarIdx := scVarIdx + scVarOffset;
2584 1847 nodeIdx := arrayGet(iCompNodeMapping, compIdx);
2585 //oldVal = arrayGet(iClTaskMapping,clIdx);
2586 //print("getCacheLineTaskMadumpComponentReferencepping0 scVarIdx: " + intString(scVarIdx) + "\n");
2587 1847 iScVarTaskMapping := arrayUpdate(iScVarTaskMapping,scVarIdx,nodeIdx);
2588 //print("Variable " + intString(varIdx) + " (" + ComponentReferenceBasics.printComponentRefStr(varName) + ") [SC-Var " + intString(scVarIdx) + "]: Node " + intString(nodeIdx) + "\n---------------------\n");
2589 //print("Part of CL " + intString(clIdx) + " solved by node " + intString(nodeIdx) + "\n\n");
2590 1847 then ((iScVarTaskMapping,varIdx+1));
2591 case(_, (iScVarTaskMapping,varIdx))
2592 136 then ((iScVarTaskMapping,varIdx+1));
2593 end matchcontinue;
2594 end getSimCodeVarNodeMapping0;
2595
2596 protected function invertEqCompMapping "author: marcusw
2597 Convert a equation-component-mapping to a component-equation-mapping."
2598 input array<tuple<Integer,Integer,Integer>> iEqCompMapping; // maps each equation to <compIdx, eqSystemIdx, offset>
2599 input Integer iNumOfComps;
2600 output array<list<tuple<Integer,Integer,Integer>>> oCompEqMapping; //maps each scc to a list of <equationIdx, eqSystemIdx, offset>
2601 protected
2602 array<list<tuple<Integer,Integer,Integer>>> tmpCompEqMapping;
2603 Integer eqIdx, compIdx, eqSystemIdx, offset;
2604 list<tuple<Integer,Integer,Integer>> compEqEntry;
2605 algorithm
2606 8 tmpCompEqMapping := arrayCreate(iNumOfComps, {});
2607
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
1988 for eqIdx in 1:arrayLength(iEqCompMapping) loop
2608 1980 (compIdx, eqSystemIdx, offset) := arrayGet(iEqCompMapping, eqIdx);
2609 1980 compEqEntry := arrayGet(tmpCompEqMapping, compIdx);
2610 3960 tmpCompEqMapping := arrayUpdate(tmpCompEqMapping, compIdx, (eqIdx, eqSystemIdx, offset)::compEqEntry);
2611 end for;
2612 oCompEqMapping := tmpCompEqMapping;
2613 end invertEqCompMapping;
2614
2615 protected function invertSccNodeMapping
2616 input array<Integer> iSccNodeMapping;
2617 input Integer iNumberOfNodes;
2618 output array<list<Integer>> oNodeSccMapping;
2619 protected
2620 array<list<Integer>> tmpNodeSccMapping;
2621 Integer sccIdx, nodeIdx;
2622 list<Integer> nodeSccEntry;
2623 algorithm
2624 8 tmpNodeSccMapping := arrayCreate(iNumberOfNodes, {});
2625 //print("invertSccNodeMapping: Creating scc node mapping with " + intString(iNumberOfNodes) + " nodes\n");
2626
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
1641 for sccIdx in 1:arrayLength(iSccNodeMapping) loop
2627 1633 nodeIdx := arrayGet(iSccNodeMapping, sccIdx);
2628
2/2
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 574 times.
1633 if intGt(nodeIdx, 0) then
2629 //print("invertSccNodeMapping: Adding node " + intString(nodeIdx) + " with scc " + intString(sccIdx) + " to mapping\n");
2630 1059 nodeSccEntry := arrayGet(tmpNodeSccMapping, nodeIdx);
2631 1059 tmpNodeSccMapping := arrayUpdate(tmpNodeSccMapping, nodeIdx, sccIdx::nodeSccEntry);
2632 end if;
2633 end for;
2634 oNodeSccMapping := tmpNodeSccMapping;
2635 end invertSccNodeMapping;
2636
2637 protected function flattenEqSimCodeVarMapping
2638 input array<array<list<Integer>>> iEqSimCodeVarMapping; //eqSystem -> eqIdx -> varIdx
2639 output array<tuple<Integer,list<Integer>>> oFlatEqSimCodeVarMapping; //maps each equation to the eqSystem and a list of varIdc
2640 protected
2641 list<Integer> simCodeVarList;
2642 array<tuple<Integer,list<Integer>>> tmpFlatEqSimCodeVarMapping;
2643 Integer eqCount, eqIdx, eqSysIdx, eqSimCodeVarIdx;
2644 array<list<Integer>> eqSimCodeVarMappingEntry;
2645 algorithm
2646 //Calculate the number of equations first
2647 eqCount := 0;
2648
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 for eqSysIdx in 1:arrayLength(iEqSimCodeVarMapping) loop
2649 17 eqSimCodeVarMappingEntry := arrayGet(iEqSimCodeVarMapping, eqSysIdx);
2650 17 eqCount := eqCount + arrayLength(eqSimCodeVarMappingEntry);
2651 end for;
2652
2653 eqIdx := 1;
2654 8 tmpFlatEqSimCodeVarMapping := arrayCreate(eqCount, (-1, {}));
2655
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
25 for eqSysIdx in 1:arrayLength(iEqSimCodeVarMapping) loop
2656 17 eqSimCodeVarMappingEntry := arrayGet(iEqSimCodeVarMapping, eqSysIdx);
2657
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 for eqSimCodeVarIdx in 1:arrayLength(eqSimCodeVarMappingEntry) loop
2658 1980 simCodeVarList := arrayGet(eqSimCodeVarMappingEntry, eqSimCodeVarIdx);
2659 1980 tmpFlatEqSimCodeVarMapping := arrayUpdate(tmpFlatEqSimCodeVarMapping, eqIdx, (eqSysIdx,simCodeVarList));
2660 1980 eqIdx := eqIdx + 1;
2661 end for;
2662 end for;
2663
2664 oFlatEqSimCodeVarMapping := tmpFlatEqSimCodeVarMapping;
2665 end flattenEqSimCodeVarMapping;
2666
2667 protected function getModifiedVarName "author: marcusw
2668 Get the correct varName (if the variable is derived, the $DER-Prefix is added."
2669 input BackendDAE.Var iVar;
2670 output DAE.ComponentRef oVarName;
2671 protected
2672 DAE.ComponentRef iVarName, tmpVarName;
2673 BackendDAE.VarKind varKind;
2674 algorithm
2675 oVarName := match iVar
2676 case BackendDAE.VAR(varName=iVarName, varKind=BackendDAE.STATE(index=1))
2677 algorithm
2678 266 tmpVarName := DAE.CREF_QUAL(DAE.derivativeNamePrefix,DAE.T_REAL({}),{},iVarName);
2679 then tmpVarName;
2680 case BackendDAE.VAR(varName=iVarName,varKind=varKind)
2681 algorithm
2682 //BackendDump.dumpKind(varKind);
2683 tmpVarName := iVarName;
2684 then tmpVarName;
2685 end match;
2686 end getModifiedVarName;
2687
2688 protected function getCacheLineTaskMapping "author: marcusw
2689 This method will create an array, which contains all tasks that are writing to the cacheline (arrayIndex)."
2690 input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
2691 input BackendDAE.EqSystems iEqSystems;
2692 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
2693 input Integer iNumCacheLines; //number of cache lines
2694 input array<tuple<Integer,Integer>> iSCVarCLMapping; //mapping for each SimCode.Var (arrayIndex) to the cache line index and cache line type
2695 output array<list<Integer>> oCLTaskMapping;
2696 output array<Integer> oScVarTaskMapping;
2697 protected
2698 array<tuple<Integer,Integer,Integer>> varCompMapping;
2699 array<list<Integer>> tmpCLTaskMapping;
2700 array<Integer> scVarTaskMapping;
2701 algorithm
2702 8 tmpCLTaskMapping := arrayCreate(iNumCacheLines,{});
2703 8 scVarTaskMapping := arrayCreate(arrayLength(iSCVarCLMapping),-1);
2704 8 HpcOmTaskGraph.TASKGRAPHMETA(varCompMapping=varCompMapping) := iTaskGraphMeta;
2705 //iterate over all variables
2706 8 (tmpCLTaskMapping,oScVarTaskMapping,_) := Array.fold(varCompMapping, function getCacheLineTaskMapping0( iEqSystems = iEqSystems, iVarNameSCVarIdxMapping = iVarNameSCVarIdxMapping, iSCVarCLMapping = iSCVarCLMapping), (tmpCLTaskMapping,scVarTaskMapping,1));
2707 8 tmpCLTaskMapping := Array.map1(tmpCLTaskMapping, List.sort, intLt);
2708 8 oCLTaskMapping := Array.map1(tmpCLTaskMapping, List.sortedUnique, intEq);
2709 end getCacheLineTaskMapping;
2710
2711 protected function getCacheLineTaskMapping0 "author: marcusw
2712 This method will extend the mapping with the information of the given node."
2713 input tuple<Integer,Integer,Integer> iNodeIdx; //<nodeIdx,eqSysIdx,varOffset>
2714 input BackendDAE.EqSystems iEqSystems;
2715 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
2716 input array<tuple<Integer,Integer>> iSCVarCLMapping; //mapping for each SimCode.Var (arrayIndex) to the cache line index
2717 input tuple<array<list<Integer>>, array<Integer>, Integer> iCLTaskMappingVarIdx; //<mapping clIdx -> task, mapping scVarIdx -> task, varIdx>
2718 output tuple<array<list<Integer>>, array<Integer>, Integer> oCLTaskMappingVarIdx;
2719 protected
2720 array<list<Integer>> iClTaskMapping;
2721 array<Integer> iScVarTaskMapping;
2722 Integer varIdx,eqSysIdx,varOffset,scVarIdx,clIdx,nodeIdx, scVarOffset;
2723 BackendDAE.EqSystem eqSystem;
2724 BackendDAE.Variables orderedVars;
2725 BackendDAE.Var var;
2726 DAE.ComponentRef varName;
2727 list<Integer> oldVal, scVarValues;
2728 algorithm
2729 oCLTaskMappingVarIdx := matchcontinue(iNodeIdx, iCLTaskMappingVarIdx)
2730 case((nodeIdx,eqSysIdx,varOffset), (iClTaskMapping,iScVarTaskMapping,varIdx))
2731 algorithm
2732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1983 times.
1983 true := intGt(nodeIdx,0);
2733 1983 eqSystem := listGet(iEqSystems,eqSysIdx);
2734 1983 BackendDAE.EQSYSTEM(orderedVars=orderedVars) := eqSystem;
2735 1983 var := BackendVariable.getVarAt(orderedVars, varIdx - varOffset);
2736 BackendDAE.VAR(varName=varName) := var;
2737 1980 varName := getModifiedVarName(var);
2738 1980 scVarValues := BaseHashTable.get(varName,iVarNameSCVarIdxMapping);
2739 1847 scVarIdx := listHead(scVarValues);
2740 1847 scVarOffset := List.second(scVarValues);
2741 1847 scVarIdx := scVarIdx + scVarOffset;
2742 1847 (clIdx,_) := arrayGet(iSCVarCLMapping,scVarIdx);
2743 202 oldVal := arrayGet(iClTaskMapping,clIdx);
2744 175 iClTaskMapping := arrayUpdate(iClTaskMapping,clIdx,nodeIdx::oldVal);
2745 //print("getCacheLineTaskMapping0 scVarIdx: " + intString(scVarIdx) + "\n");
2746 175 iScVarTaskMapping := arrayUpdate(iScVarTaskMapping,scVarIdx,nodeIdx);
2747 //print("Variable " + intString(varIdx) + " (" + ComponentReferenceBasics.printComponentRefStr(varName) + ") [SC-Var " + intString(scVarIdx) + "]\n---------------------\n");
2748 //print("Part of CL " + intString(clIdx) + " solved by node " + intString(nodeIdx) + "\n\n");
2749 175 then ((iClTaskMapping,iScVarTaskMapping,varIdx+1));
2750 case(_, (iClTaskMapping,iScVarTaskMapping,varIdx))
2751 1808 then ((iClTaskMapping,iScVarTaskMapping,varIdx+1));
2752 end matchcontinue;
2753 end getCacheLineTaskMapping0;
2754
2755 protected function getTaskSimVarMapping "author: marcusw
2756 Get a mapping for each task to all solved and all required variables."
2757 input array<list<tuple<Integer,Integer,Integer>>> iSccEqMapping; //maps each scc to a list of <equationIdx, eqSystemIdx, offset>
2758 input array<list<Integer>> iNodeSccMapping; //maps each node to a list of sccs that are solved in the node
2759 input array<tuple<Integer,list<Integer>>> iEqSimCodeVarMapping; //maps each equation to the eqSystem and a list of varIdc
2760 input array<Integer> iScVarTaskMapping; //maps each sc-var to the task that solves it
2761 input array<tuple<Integer,Integer, Integer>> iSimCodeVarTypes; //if the var-type is -1, than the variable is skipped
2762 output array<list<Integer>> oSolvedVars; //mapping for each task to a list of solved variables
2763 output array<list<Integer>> oNotSolvedVars; //mapping for each task to a list of required variables that are not solved
2764 protected
2765 array<list<Integer>> tmpSolvedVars, tmpNotSolvedVars;
2766 array<Integer> scVarMarks, scSolvedVarMarks; //mark the last task that read this variable to detect duplications
2767 list<Integer> nodeSccs, eqVars;
2768 Integer nodeIdx, sccIdx, eqIdx, var, varTask, varMark, varType, nvar, var;
2769 list<tuple<Integer,Integer,Integer>> sccEqs;
2770 tuple<Integer,Integer,Integer> sccEq;
2771 algorithm
2772 try
2773 8 tmpSolvedVars := arrayCreate(arrayLength(iNodeSccMapping), {});
2774 8 tmpNotSolvedVars := arrayCreate(arrayLength(iNodeSccMapping), {});
2775 8 scVarMarks := arrayCreate(arrayLength(iScVarTaskMapping), -1);
2776 8 scSolvedVarMarks := arrayCreate(arrayLength(iScVarTaskMapping), -1);
2777 nvar := arrayLength(iScVarTaskMapping);
2778
2779
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 time.
506 for nodeIdx in 1:arrayLength(iNodeSccMapping) loop
2780 498 nodeSccs := arrayGet(iNodeSccMapping, nodeIdx);
2781 //print("getTaskSimVarMapping: Node '" + intString(nodeIdx) + "' has sccs {" + stringDelimitList(List.map(nodeSccs, intString), ",") + "}\n");
2782
2/2
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 498 times.
1557 for sccIdx in nodeSccs loop
2783 1059 sccEqs := arrayGet(iSccEqMapping, sccIdx);
2784 //print(" - Scc '" + intString(sccIdx) + "' has equations {" + stringDelimitList(List.map(List.map(sccEqs, Util.tuple31), intString), ",") + "}\n");
2785
2/2
✓ Branch 0 taken 1508 times.
✓ Branch 1 taken 1059 times.
2567 for sccEq in sccEqs loop
2786 1508 (eqIdx,_,_) := sccEq;
2787 1508 (_,eqVars) := arrayGet(iEqSimCodeVarMapping, eqIdx);
2788 //print(" - Equation '" + intString(eqIdx) + "' has variables {" + stringDelimitList(List.map(eqVars, intString), ",") + "}\n");
2789
2/2
✓ Branch 0 taken 5638 times.
✓ Branch 1 taken 1508 times.
7146 for v2 in eqVars loop
2790
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5638 times.
5638 var := if v2>nvar then v2-nvar /* states */ else v2;
2791 5638 varTask := arrayGet(iScVarTaskMapping, var);
2792 //print(" - Variable '" + intString(var) + "' is solved by task " + intString(varTask) + "\n");
2793 5638 varType := Util.tuple31(arrayGet(iSimCodeVarTypes, var));
2794
2/2
✓ Branch 0 taken 5189 times.
✓ Branch 1 taken 449 times.
5638 if(intGt(varType, 0)) then
2795
2/2
✓ Branch 0 taken 2795 times.
✓ Branch 1 taken 2394 times.
5189 if(intEq(nodeIdx, varTask)) then
2796 //variable is solved by the task
2797 2795 varMark := arrayGet(scSolvedVarMarks, var);
2798
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 1535 times.
2795 if(intNe(varMark, nodeIdx)) then
2799 2520 tmpSolvedVars := arrayUpdate(tmpSolvedVars, nodeIdx, var::arrayGet(tmpSolvedVars, nodeIdx));
2800 1260 scSolvedVarMarks := arrayUpdate(scSolvedVarMarks, var, nodeIdx);
2801 end if;
2802 else
2803 2394 varMark := arrayGet(scVarMarks, var);
2804 //print(" - Variable '" + intString(var) + "' has mark " + intString(varMark) + "\n");
2805
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 764 times.
2394 if(intNe(varMark, nodeIdx)) then
2806 //variable is read by the task and was not already handled
2807 3260 tmpNotSolvedVars := arrayUpdate(tmpNotSolvedVars, nodeIdx, var::arrayGet(tmpNotSolvedVars, nodeIdx));
2808 1630 scVarMarks := arrayUpdate(scVarMarks, var, nodeIdx);
2809 end if;
2810 end if;
2811 else
2812 //print(" - Variable '" + intString(var) + "' skipped because of negative type\n");
2813 end if;
2814 end for;
2815 end for;
2816 end for;
2817 end for;
2818
2819 oSolvedVars := tmpSolvedVars;
2820 oNotSolvedVars := tmpNotSolvedVars;
2821 else
2822 ✗ Error.addInternalError(getInstanceName() + " failed", sourceInfo());
2823 ✗ fail();
2824 end try;
2825 end getTaskSimVarMapping;
2826
2827
2828 // -------------------------------------------
2829 // GRAPH
2830 // -------------------------------------------
2831
2832 protected function appendCacheLinesToGraph "author: marcusw
2833 This method will extend the given graph-info with a new subgraph containing all cache lines.
2834 Dependencies between the tasks and the cache lines will be inserted as edges."
2835 input CacheMap iCacheMap;
2836 input Integer iNumberOfNodes; //number of nodes in the task graph
2837 input array<array<list<Integer>>> iEqSimCodeVarMapping;
2838 input BackendDAE.EqSystems iEqSystems; //the eqSystem of the adjacency matrix
2839 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
2840 input array<tuple<Integer,Integer,Integer>> ieqCompMapping; //a mapping from eqIdx (arrayIdx) to the scc idx
2841 input array<Integer> iScVarTaskMapping; //maps each scVar (arrayIdx) to the task that solves it
2842 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
2843 input Integer iThreadIdAttributeIdx; //index for attribute "threadId"
2844 input array<Integer> iCompNodeMapping;
2845 input array<list<Integer>> iTaskSolvedVarsMapping;
2846 input array<list<Integer>> iTaskUnsolvedVarsMapping;
2847 input array<tuple<Integer,Integer>> iScVarCLMapping;
2848 input array<ScVarInfo> iScVarInfos;
2849 input GraphML.GraphInfo iGraphInfo;
2850 output GraphML.GraphInfo oGraphInfo;
2851 protected
2852 Integer clGroupNodeIdx, graphCount;
2853 GraphML.GraphInfo tmpGraphInfo;
2854 array<list<Integer>> knownEdges; //edges from task to variables
2855 array<Boolean> addedVariables;
2856 array<SimCodeVar.SimVar> cacheVariables;
2857 list<CacheLineMap> cacheLines;
2858 algorithm
2859 oGraphInfo := matchcontinue iGraphInfo
2860 case GraphML.GRAPHINFO(graphCount=graphCount)
2861 algorithm
2862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 true := intLe(1, graphCount);
2863 8 knownEdges := arrayCreate(iNumberOfNodes,{});
2864 8 addedVariables := arrayCreate(arrayLength(iScVarTaskMapping), false);
2865 8 (tmpGraphInfo,_,(_,clGroupNodeIdx)) := GraphML.addGroupNode("CL_GoupNode", 1, false, "CL", iGraphInfo);
2866 8 cacheLines := getAllCacheLinesOfCacheMap(iCacheMap);
2867 8 cacheVariables := listArray(getCacheVariablesOfCacheMap(iCacheMap));
2868 8 tmpGraphInfo := List.fold(cacheLines, function appendCacheLineMapToGraph(iCacheVariables=cacheVariables, iAddedVariables=addedVariables, iSchedulerInfo=iSchedulerInfo, iTopGraphAttThreadIdIdx=(clGroupNodeIdx,iThreadIdAttributeIdx), iScVarTaskMapping=iScVarTaskMapping, iVarNameSCVarIdxMapping=iVarNameSCVarIdxMapping, iScVarInfos=iScVarInfos), tmpGraphInfo);
2869 //tmpGraphInfo = appendUnmappedVariablesToGraph(iScVarCLMapping, tmpGraphInfo);
2870 8 tmpGraphInfo := appendTaskVarEdgesToGraph(iTaskSolvedVarsMapping, iTaskUnsolvedVarsMapping, tmpGraphInfo);
2871 then tmpGraphInfo;
2872 case GraphML.GRAPHINFO(graphCount=graphCount)
2873 algorithm
2874 ✗ true := intEq(graphCount,0);
2875 then iGraphInfo;
2876 else
2877 algorithm
2878 ✗ print("HpcOmSimCode.appendCacheLinesToGraph failed!\n");
2879 ✗ then fail();
2880 end matchcontinue;
2881 end appendCacheLinesToGraph;
2882
2883 protected function appendVariablesToGraph "author: marcusw
2884 Add all variables to the task graph as nodes with a round shape."
2885 input array<list<Integer>> iTaskSolvedVarsMapping;
2886 input array<list<Integer>> iTaskUnsolvedVarsMapping;
2887 input Integer iNumberOfScVars;
2888 input Integer iGraphIdx;
2889 input Integer iThreadIdAttributeIdx; //index for attribute "threadId"
2890 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
2891 input array<Option<SimCodeVar.SimVar>> iAllVarsMapping;
2892 input array<ScVarInfo> iScVarInfos;
2893 input GraphML.GraphInfo iGraphInfo;
2894 output GraphML.GraphInfo oGraphInfo;
2895 protected
2896 GraphML.GraphInfo tmpGraphInfo = iGraphInfo;
2897 String description, threadText;
2898 Option<SimCodeVar.SimVar> simVarOpt;
2899 SimCodeVar.SimVar simVar;
2900 DAE.ComponentRef varCompRef;
2901 GraphML.NodeLabel nodeLabel;
2902 Boolean isValidVar;
2903 list<Integer> realScVarIdxOffset;
2904 Integer realScVarIdx, realScVarOffset, threadOwner;
2905 algorithm
2906 //add all variables as a node first
2907
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
5614 for varIdx in 1:iNumberOfScVars loop
2908 isValidVar := true;
2909 //print("Handling variable " + intString(varIdx) + " out of var-mapping with size " + intString(arrayLength(iAllVarsMapping)) + "\n");
2910 5606 simVarOpt := arrayGet(iAllVarsMapping, varIdx);
2911 description := "unknown";
2912 threadText := "Th -1";
2913
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5606 times.
✓ Branch 2 taken 5369 times.
✓ Branch 3 taken 237 times.
5606 if(isSome(simVarOpt)) then
2914 5369 simVar := Util.getOption(simVarOpt);
2915 5369 varCompRef := simVar.name;
2916 5369 description := ComponentReferenceBasics.printComponentRefStr(varCompRef);
2917 5369 isValidVar := BaseHashTable.hasKey(varCompRef, iVarNameSCVarIdxMapping);
2918
2919
2/2
✓ Branch 1 taken 3327 times.
✓ Branch 2 taken 2042 times.
5369 if(BaseHashTable.hasKey(varCompRef, iVarNameSCVarIdxMapping)) then
2920 3327 realScVarIdxOffset := BaseHashTable.get(varCompRef, iVarNameSCVarIdxMapping);
2921 3327 realScVarIdx := listGet(realScVarIdxOffset,1);
2922 3327 realScVarOffset := listGet(realScVarIdxOffset,2);
2923 3327 realScVarIdx := realScVarIdx + realScVarOffset;
2924 3327 SCVARINFO(ownerThread=threadOwner) := arrayGet(iScVarInfos, realScVarIdx);
2925 3327 threadText := "Th " + intString(threadOwner);
2926 end if;
2927 end if;
2928 //print("appendVariablesToGraph: Appending variable " + description + " to graph with index " + intString(iGraphIdx) + "\n");
2929
2/2
✓ Branch 0 taken 3564 times.
✓ Branch 1 taken 2042 times.
5606 if(isValidVar) then
2930 3564 nodeLabel := GraphML.NODELABEL_INTERNAL(intString(varIdx), NONE(), GraphML.FONTPLAIN());
2931 10692 tmpGraphInfo := GraphML.addNode("var" + intString(varIdx), GraphML.COLOR_GREEN2,GraphML.BORDERWIDTH_STANDARD, {nodeLabel}, GraphML.ELLIPSE(), SOME(description), {(iThreadIdAttributeIdx,threadText)}, iGraphIdx, tmpGraphInfo);
2932 end if;
2933 end for;
2934 8 tmpGraphInfo := appendTaskVarEdgesToGraph(iTaskSolvedVarsMapping, iTaskUnsolvedVarsMapping, tmpGraphInfo);
2935 oGraphInfo := tmpGraphInfo;
2936 end appendVariablesToGraph;
2937
2938 protected function appendTaskVarEdgesToGraph
2939 input array<list<Integer>> iTaskSolvedVarsMapping;
2940 input array<list<Integer>> iTaskUnsolvedVarsMapping;
2941 input GraphML.GraphInfo iGraphInfo;
2942 output GraphML.GraphInfo oGraphInfo;
2943 protected
2944 GraphML.GraphInfo tmpGraphInfo = iGraphInfo;
2945 Integer taskIdx, varIdx;
2946 list<Integer> taskVarList;
2947 algorithm
2948 //add edges to solved variables
2949
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
1012 for taskIdx in 1:arrayLength(iTaskSolvedVarsMapping) loop
2950 996 taskVarList := arrayGet(iTaskSolvedVarsMapping, taskIdx);
2951
2/2
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 996 times.
3516 for varIdx in taskVarList loop
2952 2520 tmpGraphInfo := GraphML.addEdge("varEdge_" + intString(taskIdx) + "_" + intString(varIdx), "var" + intString(varIdx), "Node" + intString(taskIdx), GraphML.COLOR_BLACK, GraphML.LINE(), GraphML.LINEWIDTH_STANDARD, false, {}, (GraphML.ARROWNONE(), GraphML.ARROWSTANDART()), {}, tmpGraphInfo);
2953 end for;
2954 end for;
2955 //add edges to unsolved variables
2956
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
1012 for taskIdx in 1:arrayLength(iTaskUnsolvedVarsMapping) loop
2957 996 taskVarList := arrayGet(iTaskUnsolvedVarsMapping, taskIdx);
2958
2/2
✓ Branch 0 taken 3260 times.
✓ Branch 1 taken 996 times.
4256 for varIdx in taskVarList loop
2959 3260 tmpGraphInfo := GraphML.addEdge("varEdge_" + intString(taskIdx) + "_" + intString(varIdx), "Node" + intString(taskIdx), "var" + intString(varIdx), GraphML.COLOR_BLACK, GraphML.LINE(), GraphML.LINEWIDTH_STANDARD, false, {}, (GraphML.ARROWNONE(), GraphML.ARROWSTANDART()), {}, tmpGraphInfo);
2960 end for;
2961 end for;
2962 oGraphInfo := tmpGraphInfo;
2963 end appendTaskVarEdgesToGraph;
2964
2965 protected function appendUnmappedVariablesToGraph
2966 input array<tuple<Integer,Integer>> iScVarCLMapping;
2967 input GraphML.GraphInfo iGraphInfo;
2968 output GraphML.GraphInfo oGraphInfo;
2969 protected
2970 GraphML.GraphInfo tmpGraphInfo = iGraphInfo;
2971 Integer scVarIdx, clIdx;
2972 algorithm
2973 ✗ for scVarIdx in 1:arrayLength(iScVarCLMapping) loop
2974 ✗ (clIdx,_) := arrayGet(iScVarCLMapping, scVarIdx);
2975 if(intLt(clIdx, 1)) then
2976 //print("appendUnmappedVariablesToGraph: Found unmapped sc-var with index '" + intString(scVarIdx) + "'\n");
2977 //tmpGraphInfo := GraphML.addNode("var" + intString(varIdx), GraphML.COLOR_GREEN2, {nodeLabel}, GraphML.ELLIPSE(), SOME(description), {}, iGraphIdx, tmpGraphInfo);
2978 end if;
2979 end for;
2980 oGraphInfo := tmpGraphInfo;
2981 end appendUnmappedVariablesToGraph;
2982
2983 protected function appendCacheLineMapToGraph "author: marcusw
2984 This method will extend the given graph-info with a new subgraph containing the entry of the given cache line."
2985 input CacheLineMap iCacheLineMap;
2986 input array<SimCodeVar.SimVar> iCacheVariables;
2987 input array<Boolean> iAddedVariables;
2988 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
2989 input tuple<Integer,Integer> iTopGraphAttThreadIdIdx; //<topGraphIdx,threadIdAttIdx>
2990 input array<Integer> iScVarTaskMapping; //maps each scVar (arrayIdx) to the task that solves her
2991 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
2992 input array<ScVarInfo> iScVarInfos;
2993 input GraphML.GraphInfo iGraphInfo;
2994 output GraphML.GraphInfo oGraphInfo;
2995 protected
2996 Integer idx, graphIdx, iTopGraphIdx, iAttThreadIdIdx;
2997 list<CacheLineEntry> entries;
2998 CacheLineEntry entry;
2999 GraphML.GraphInfo tmpGraphInfo;
3000 Integer entryThreadOwner;
3001 Boolean notOnlyParamters;
3002 algorithm
3003 32 CACHELINEMAP(idx=idx,entries=entries) := iCacheLineMap;
3004 //print("appendCacheLineMapToGraph: handling cache line map '" + intString(idx) + "' with " + intString(listLength(entries)) + " entries\n");
3005 //printCacheLineMap(iCacheLineMap, arrayList(iCacheVariables));
3006 //check if the cache line contains only parameters
3007 notOnlyParamters := false;
3008
2/2
✓ Branch 0 taken 286 times.
✓ Branch 1 taken 32 times.
318 for entry in entries loop
3009 286 CACHELINEENTRY(threadOwner=entryThreadOwner) := entry;
3010 286 notOnlyParamters := boolOr(notOnlyParamters, intNe(entryThreadOwner, -1));
3011 end for;
3012
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if(notOnlyParamters) then
3013 32 (iTopGraphIdx, iAttThreadIdIdx) := iTopGraphAttThreadIdIdx;
3014 32 (tmpGraphInfo, _,(_,graphIdx)) := GraphML.addGroupNode("CL_Meta_" + intString(idx), iTopGraphIdx, true, "CL" + intString(idx), iGraphInfo);
3015 32 oGraphInfo := List.fold(entries, function appendCacheLineEntryToGraph(iCacheVariables=iCacheVariables, iAddedVariables=iAddedVariables, iSchedulerInfo=iSchedulerInfo, iTopGraphAttThreadIdIdx=(graphIdx,iAttThreadIdIdx), iScVarTaskMapping=iScVarTaskMapping, iVarNameSCVarIdxMapping=iVarNameSCVarIdxMapping, iScVarInfos=iScVarInfos), tmpGraphInfo);
3016 else
3017 oGraphInfo := iGraphInfo;
3018 end if;
3019 end appendCacheLineMapToGraph;
3020
3021 protected function appendCacheLineEntryToGraph
3022 input CacheLineEntry iCacheLineEntry;
3023 input array<SimCodeVar.SimVar> iCacheVariables;
3024 input array<Boolean> iAddedVariables;
3025 input array<tuple<Integer,Integer,Real>> iSchedulerInfo;
3026 input tuple<Integer,Integer> iTopGraphAttThreadIdIdx; //<topGraphIdx,threadIdAttIdx>
3027 input array<Integer> iScVarTaskMapping; //maps each scVar (arrayIdx) to the task that solves her
3028 input HashTableCrILst.HashTable iVarNameSCVarIdxMapping;
3029 input array<ScVarInfo> iScVarInfos;
3030 input GraphML.GraphInfo iGraphInfo;
3031 output GraphML.GraphInfo oGraphInfo;
3032 protected
3033 list<Integer> realScVarIdxOffset;
3034 Integer scVarIdx, realScVarIdx, realScVarOffset, taskIdx, iTopGraphIdx, iAttThreadIdIdx, threadOwner;
3035 String varString, threadText, nodeLabelText, nodeId;
3036 GraphML.NodeLabel nodeLabel;
3037 SimCodeVar.SimVar iVar;
3038 DAE.ComponentRef name;
3039 algorithm
3040 286 CACHELINEENTRY(scVarIdx=scVarIdx,threadOwner=threadOwner) := iCacheLineEntry;
3041
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 286 times.
286 (iTopGraphIdx, iAttThreadIdIdx) := iTopGraphAttThreadIdIdx;
3042 //print("HpcOmSimCode.appendCacheLineNodesToGraphTraverse scVarIdx: " + intString(scVarIdx) + " list length of iCacheVariables: " + intString(arrayLength(iCacheVariables)) + "\n");
3043
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
286 if(intGe(arrayLength(iCacheVariables) - scVarIdx + 1, 1)) then
3044 286 iVar := arrayGet(iCacheVariables, arrayLength(iCacheVariables) - scVarIdx + 1);
3045 286 SimCodeVar.SIMVAR(name=name) := iVar;
3046 //print("Var with name " + ComponentReferenceBasics.printComponentRefStr(name) + " found. ScVar-Idx: " + intString(scVarIdx) + "\n");
3047
1/2
✓ Branch 1 taken 286 times.
✗ Branch 2 not taken.
286 if(BaseHashTable.hasKey(name, iVarNameSCVarIdxMapping)) then
3048 286 realScVarIdxOffset := BaseHashTable.get(name, iVarNameSCVarIdxMapping);
3049 286 realScVarIdx := listGet(realScVarIdxOffset,1);
3050 286 realScVarOffset := listGet(realScVarIdxOffset,2);
3051 286 realScVarIdx := realScVarIdx + realScVarOffset;
3052 286 varString := ComponentReferenceBasics.printComponentRefStr(name);
3053 286 taskIdx := arrayGet(iScVarTaskMapping,realScVarIdx);
3054 //print("HpcOmSimCode.appendCacheLineNodesToGraphTraverse SCVarNode: " + intString(realScVarIdx) + " [" + varString + "] sccIdx: " + intString(taskIdx) + "\n");
3055 //print("HpcOmSimCode.appendCacheLineNodesToGraphTraverse ThreadOwner: " + intString(threadOwner) + "\n");
3056 286 SCVARINFO(ownerThread=threadOwner) := arrayGet(iScVarInfos, realScVarIdx);
3057 //print("HpcOmSimCode.appendCacheLineNodesToGraphTraverse ThreadOwner: " + intString(threadOwner) + "\n");
3058 286 nodeId := "var" + intString(realScVarIdx);
3059
3060 286 arrayUpdate(iAddedVariables, realScVarIdx, true);
3061 286 threadText := "Th " + intString(threadOwner);
3062 286 nodeLabelText := intString(realScVarIdx);
3063 286 nodeLabel := GraphML.NODELABEL_INTERNAL(nodeLabelText, NONE(), GraphML.FONTPLAIN());
3064 572 (oGraphInfo,_) := GraphML.addNode(nodeId, GraphML.COLOR_GREEN2,GraphML.BORDERWIDTH_STANDARD, {nodeLabel}, GraphML.ELLIPSE(), SOME(varString), {(iAttThreadIdIdx,threadText)}, iTopGraphIdx, iGraphInfo);
3065 //print("--handled with realScVarIdx '" + intString(realScVarIdx) + "'\n");
3066 else
3067 oGraphInfo := iGraphInfo;
3068 end if;
3069 else
3070 oGraphInfo := iGraphInfo;
3071 end if;
3072 end appendCacheLineEntryToGraph;
3073
3074
3075 // -------------------------------------------
3076 // PRINT
3077 // -------------------------------------------
3078
3079 protected function printCacheMap
3080 input CacheMap iCacheMap;
3081 protected
3082 Integer cacheLineSize;
3083 list<CacheLineMap> cacheLinesFloat;
3084 list<CacheLineMap> cacheLinesInt;
3085 list<CacheLineMap> cacheLinesBool;
3086 list<CacheLineMap> cacheLines;
3087 list<SimCodeVar.SimVar> cacheVariables;
3088 algorithm
3089 () := match iCacheMap
3090 case CACHEMAP(cacheLineSize=cacheLineSize, cacheVariables=cacheVariables, cacheLinesFloat=cacheLinesFloat, cacheLinesInt=cacheLinesInt, cacheLinesBool=cacheLinesBool)
3091 algorithm
3092 ✗ print("\n\nCacheMap\n---------------\n");
3093 ✗ print(" Variables\n");
3094 ✗ List.fold(cacheVariables, printCacheVariable, listLength(cacheVariables));
3095 ✗ print(" Float Cache Lines\n");
3096 ✗ List.map1_0(cacheLinesFloat, printCacheLineMap, cacheVariables);
3097 ✗ print(" Int Cache Lines\n");
3098 ✗ List.map1_0(cacheLinesInt, printCacheLineMap, cacheVariables);
3099 ✗ print(" Bool Cache Lines\n");
3100 ✗ List.map1_0(cacheLinesBool, printCacheLineMap, cacheVariables);
3101 then ();
3102 case UNIFORM_CACHEMAP(cacheLineSize=cacheLineSize, cacheVariables=cacheVariables, cacheLines=cacheLines)
3103 algorithm
3104 ✗ print("\n\nUniform CacheMap\n---------------\n");
3105 ✗ print(" Variables.\n");
3106 ✗ List.map1_0(cacheLines, printCacheLineMap, cacheVariables);
3107 then ();
3108 else
3109 algorithm
3110 ✗ print("printCacheMap: Unsupported cache map type!\n");
3111 then ();
3112 end match;
3113 end printCacheMap;
3114
3115 protected function printCacheVariable
3116 input SimCodeVar.SimVar iCacheVariable;
3117 input Integer iIdx;
3118 output Integer oIdx;
3119 algorithm
3120 ✗ print(" " + intString(iIdx) + ": " + dumpSimCodeVar(iCacheVariable) + "\n");
3121 ✗ oIdx := iIdx - 1;
3122 end printCacheVariable;
3123
3124 protected function printCacheLineMap
3125 input CacheLineMap iCacheLineMap;
3126 input list<SimCodeVar.SimVar> iCacheVariables;
3127 protected
3128 Integer idx;
3129 list<CacheLineEntry> entries;
3130 String iVarsString, iBytesString;
3131 algorithm
3132 ✗ CACHELINEMAP(idx=idx, entries=entries) := iCacheLineMap;
3133 ✗ print(" CacheLineMap " + intString(idx) + " (" + intString(listLength(entries)) + " entries)\n");
3134 ✗ (iVarsString, iBytesString) := List.fold1(entries, cacheLineEntryToString, iCacheVariables, ("",""));
3135 ✗ print(" " + iVarsString + "\n");
3136 ✗ print(" " + iBytesString + "\n");
3137 ✗ print("\n");
3138 end printCacheLineMap;
3139
3140 protected function printCacheLineMapClean
3141 input CacheLineMap iCacheLineMap;
3142 protected
3143 Integer idx;
3144 list<CacheLineEntry> entries;
3145 String iVarsString, iBytesString;
3146 algorithm
3147 ✗ CACHELINEMAP(idx=idx, entries=entries) := iCacheLineMap;
3148 ✗ print(" CacheLineMap " + intString(idx) + " (" + intString(listLength(entries)) + " entries)\n");
3149 ✗ (iVarsString, iBytesString) := List.fold(entries, cacheLineEntryToStringClean, ("",""));
3150 ✗ print(" " + iVarsString + "\n");
3151 ✗ print(" " + iBytesString + "\n");
3152 ✗ print("\n");
3153 end printCacheLineMapClean;
3154
3155 protected function cacheLineEntryToString
3156 input CacheLineEntry iCacheLineEntry;
3157 input list<SimCodeVar.SimVar> iCacheVariables;
3158 input tuple<String,String> iString; //<variable names seperated by |, byte positions string>
3159 output tuple<String,String> oString;
3160 protected
3161 Integer start;
3162 Integer dataType;
3163 Integer size;
3164 Integer scVarIdx;
3165 String scVarStr;
3166 SimCodeVar.SimVar iVar;
3167 String iVarsString, iBytesString, iBytesStringNew;
3168 algorithm
3169 ✗ (iVarsString, iBytesString) := iString;
3170 ✗ CACHELINEENTRY(start=start,dataType=dataType,size=size,scVarIdx=scVarIdx) := iCacheLineEntry;
3171 //print("cacheLineEntryToString: try to create entry for variable '" + intString(scVarIdx) + "' out of cache-variable list with '" + intString(listLength(iCacheVariables)) + "' entries \n");
3172 ✗ iVar := listGet(iCacheVariables, listLength(iCacheVariables) - scVarIdx + 1);
3173 ✗ scVarStr := dumpSimCodeVar(iVar) + " [" + intString(scVarIdx) + "]";
3174 ✗ iVarsString := iVarsString + " " + scVarStr;
3175 ✗ if(intGt(start, 0)) then
3176 ✗ iVarsString := iVarsString + " | ";
3177 ✗ iBytesStringNew := intString(start);
3178 else
3179 iBytesStringNew := "";
3180 end if;
3181 ✗ iBytesStringNew := Util.stringPadLeft(iBytesStringNew, 2 + stringLength(scVarStr) + stringLength(iBytesStringNew), " ");
3182 ✗ iBytesString := iBytesString + iBytesStringNew;
3183 ✗ oString := (iVarsString,iBytesString);
3184 end cacheLineEntryToString;
3185
3186 protected function cacheLineEntryToStringClean
3187 input CacheLineEntry iCacheLineEntry;
3188 input tuple<String,String> iString; //<variable names seperated by |, byte positions string>
3189 output tuple<String,String> oString;
3190 protected
3191 Integer start;
3192 Integer dataType;
3193 Integer size;
3194 Integer scVarIdx;
3195 String scVarStr;
3196 String iVarsString, iBytesString, iBytesStringNew;
3197 algorithm
3198 ✗ (iVarsString, iBytesString) := iString;
3199 ✗ CACHELINEENTRY(start=start,dataType=dataType,size=size,scVarIdx=scVarIdx) := iCacheLineEntry;
3200 ✗ scVarStr := intString(scVarIdx);
3201 ✗ iVarsString := iVarsString + "| " + scVarStr + " ";
3202 ✗ iBytesStringNew := intString(start);
3203 ✗ iBytesStringNew := Util.stringPadRight(iBytesStringNew, 3 + stringLength(scVarStr), " ");
3204 ✗ iBytesString := iBytesString + iBytesStringNew;
3205 ✗ oString := (iVarsString,iBytesString);
3206 end cacheLineEntryToStringClean;
3207
3208 protected function dumpSimCodeVar
3209 input SimCodeVar.SimVar iVar;
3210 output String oString;
3211 protected
3212 DAE.ComponentRef name;
3213 algorithm
3214 ✗ SimCodeVar.SIMVAR(name=name) := iVar;
3215 ✗ oString := ComponentReferenceBasics.printComponentRefStr(name);
3216 end dumpSimCodeVar;
3217
3218 protected function printNodeSimCodeVarMapping
3219 input array<list<Integer>> iMapping;
3220 algorithm
3221 ✗ print("Node - SimCodeVar - Mapping\n------------------\n");
3222 ✗ Array.fold(iMapping, printNodeSimCodeVarMapping0,1);
3223 ✗ print("\n");
3224 end printNodeSimCodeVarMapping;
3225
3226 protected function printNodeSimCodeVarMapping0
3227 input list<Integer> iMappingEntry;
3228 input Integer iNodeIdx;
3229 output Integer oNodeIdx;
3230 algorithm
3231 ✗ print("Node " + intString(iNodeIdx) + " uses sc-vars: " + stringDelimitList(List.map(iMappingEntry, intString), ",") + "\n");
3232 ✗ oNodeIdx := iNodeIdx + 1;
3233 end printNodeSimCodeVarMapping0;
3234
3235 protected function printScVarTaskMapping
3236 input array<Integer> iMapping;
3237 algorithm
3238 ✗ print("----------------------\nSCVar - Task - Mapping\n----------------------\n");
3239 ✗ Array.fold(iMapping, printScVarTaskMapping0, 1);
3240 ✗ print("\n");
3241 end printScVarTaskMapping;
3242
3243 protected function printScVarTaskMapping0
3244 input Integer iMappingEntry;
3245 input Integer iScVarIdx;
3246 output Integer oScVarIdx;
3247 algorithm
3248 ✗ print("SCVar " + intString(iScVarIdx) + " is solved in task: " + intString(iMappingEntry) + "\n");
3249 ✗ oScVarIdx := iScVarIdx + 1;
3250 end printScVarTaskMapping0;
3251
3252 protected function printCacheLineTaskMapping
3253 input array<list<Integer>> iCacheLineTaskMapping;
3254 algorithm
3255 ✗ Array.fold(iCacheLineTaskMapping, printCacheLineTaskMapping0, 1);
3256 end printCacheLineTaskMapping;
3257
3258 protected function printCacheLineTaskMapping0
3259 input list<Integer> iTasks;
3260 input Integer iCacheLineIdx;
3261 output Integer oCacheLineIdx;
3262 algorithm
3263 ✗ print("Tasks that are writing to cacheline " + intString(iCacheLineIdx) + ": " + stringDelimitList(List.map(iTasks, intString), ",") + "\n");
3264 ✗ oCacheLineIdx := iCacheLineIdx + 1;
3265 end printCacheLineTaskMapping0;
3266
3267 protected function printEqSimCodeVarMapping
3268 input array<array<list<Integer>>> iMapping; //eqSysIdx -> eqIdx -> list<scVarIdx>
3269 protected
3270 array<list<Integer>> sysInformation;
3271 Integer sysIdx;
3272 list<Integer> vars;
3273 algorithm
3274 ✗ for sysIdx in 1:arrayLength(iMapping) loop
3275 ✗ print("System " + intString(sysIdx) + "\n");
3276 ✗ sysInformation := arrayGet(iMapping, sysIdx);
3277 ✗ for eqIdx in 1:arrayLength(sysInformation) loop
3278 ✗ vars := arrayGet(sysInformation, eqIdx);
3279 //print(" Equation " + intString(eqIdx) + " needs variables " + stringDelimitList(List.map(vars, intString), ",") + "\n");
3280 end for;
3281 end for;
3282 end printEqSimCodeVarMapping;
3283
3284 protected function printSccNodeMapping
3285 input array<Integer> iMapping;
3286 algorithm
3287 ✗ print("--------------------\nScc - Node - Mapping\n--------------------\n");
3288 ✗ Array.fold(iMapping, printSccNodeMapping0, 1);
3289 end printSccNodeMapping;
3290
3291 protected function printSccNodeMapping0
3292 input Integer iMappingEntry;
3293 input Integer iIdx;
3294 output Integer oIdx;
3295 algorithm
3296 ✗ print("Scc " + intString(iIdx) + " is solved by node " + intString(iMappingEntry) + "\n");
3297 ✗ oIdx := iIdx + 1;
3298 end printSccNodeMapping0;
3299
3300 protected function printScVarInfos
3301 input array<ScVarInfo> iScVarInfos;
3302 protected
3303 Integer scVarIdx;
3304 Integer ownerThread;
3305 Boolean isShared;
3306 algorithm
3307 ✗ print("--------------------\nScVar - Infos\n--------------------\n");
3308 ✗ for scVarIdx in 1:arrayLength(iScVarInfos) loop
3309 ✗ SCVARINFO(ownerThread=ownerThread, isShared=isShared) := arrayGet(iScVarInfos, scVarIdx);
3310 ✗ print("ScVar " + intString(scVarIdx) + " has thread owner " + intString(ownerThread) + " and shared state " + boolString(isShared) + "\n");
3311 end for;
3312 end printScVarInfos;
3313
3314 protected function dumpScVarsByIdx
3315 input Integer iSimCodeVarIdx;
3316 input array<Option<SimCodeVar.SimVar>> iAllSCVarsMapping;
3317 output String oString;
3318 protected
3319 String tmpString;
3320 SimCodeVar.SimVar simVar;
3321 algorithm
3322 oString := matchcontinue iAllSCVarsMapping
3323 case _
3324 algorithm
3325 ✗ SOME(simVar) := arrayGet(iAllSCVarsMapping, iSimCodeVarIdx);
3326 ✗ tmpString := dumpSimCodeVar(simVar);
3327 then tmpString;
3328 else
3329 algorithm
3330 ✗ print("dumpScVarsByIdx: Failed to find simcode-variable with index " + intString(iSimCodeVarIdx) + "\n");
3331 then "NONE";
3332 end matchcontinue;
3333 end dumpScVarsByIdx;
3334
3335 protected function printSimCodeVarTypes
3336 input array<tuple<Integer,Integer, Integer>> iSimCodeVarTypes;
3337 protected
3338 Integer varIdx, varDataType, varSize, varType;
3339 algorithm
3340 ✗ for varIdx in 1:arrayLength(iSimCodeVarTypes) loop
3341 ✗ (varDataType, varSize, varType) := arrayGet(iSimCodeVarTypes, varIdx);
3342 ✗ print("Variable " + intString(varIdx) + " has data type " + intString(varDataType) + " and size " + intString(varSize) + " and type " + intString(varType) + "\n");
3343 end for;
3344 end printSimCodeVarTypes;
3345
3346 // -------------------------------------------
3347 // SUSAN
3348 // -------------------------------------------
3349
3350 public function getSubscriptListOfArrayCref
3351 input DAE.ComponentRef iCref;
3352 input list<String> iNumArrayElems;
3353 output list<list<DAE.Subscript>> oSubscriptList;
3354 protected
3355 list<DAE.ComponentRef> tmpCrefs;
3356 algorithm
3357 //print("getSubscriptListOfArrayCref: iNumArrayElems=" + stringDelimitList(iNumArrayElems, ",") + "\n");
3358 //print("============================================\n");
3359 ✗ tmpCrefs := expandCref(iCref, iNumArrayElems);
3360 //for cref in tmpCrefs loop
3361 // print(ComponentReferenceBasics.printComponentRefStr(cref) + "\n");
3362 //end for;
3363 ✗ oSubscriptList := List.map(tmpCrefs, ComponentReference.crefLastSubs);
3364 end getSubscriptListOfArrayCref;
3365
3366 public function expandCref
3367 input DAE.ComponentRef iCref;
3368 input list<String> iNumArrayElems;
3369 output list<DAE.ComponentRef> oCrefs;
3370 protected
3371 Integer elems, dims;
3372 list<Integer> dimElemCount;
3373 DAE.ComponentRef cref;
3374 algorithm
3375 ✗ cref := removeSubscripts(iCref);
3376 //print("expandCref: " + ComponentReferenceBasics.printComponentRefStr(cref) + "\n");
3377 ✗ dims := getCrefDims(iCref);
3378 //print("expandCref: iNumArrayElems=" + stringDelimitList(iNumArrayElems, ",") + "\n");
3379 ✗ dimElemCount := getDimElemCount(listReverse(iNumArrayElems),dims);
3380 //print("expandCref: numArrayElems " + intString(getNumArrayElems(iNumArrayElems, getCrefDims(iCref))) + "\n");
3381 ✗ elems := List.reduce(dimElemCount, intMul);
3382 //print("expandCref: " + ComponentReferenceBasics.printComponentRefStr(iCref) + " dims: " + intString(dims) + " elems: " + intString(elems) + "\n");
3383 ✗ dims := listLength(iNumArrayElems);
3384 //print("expandCref: " + ComponentReferenceBasics.printComponentRefStr(iCref) + " dims: " + intString(dims) + "[" + intString(getCrefDims(iCref)) + "] elems: " + intString(elems) + "\n");
3385 ✗ oCrefs := expandCref1(cref, elems, dimElemCount);
3386 end expandCref;
3387
3388 public function expandCrefWithDims
3389 input DAE.ComponentRef iCref;
3390 input DAE.Dimensions iDims;
3391 output list<DAE.ComponentRef> oCrefs;
3392 protected
3393 DAE.Dimension dim;
3394 list<String> numArrayElems;
3395 algorithm
3396 numArrayElems := {};
3397 ✗ for dim in iDims loop
3398 ✗ numArrayElems := getDimStringOfDimElement(dim)::numArrayElems;
3399 end for;
3400 ✗ oCrefs := expandCref(iCref, numArrayElems);
3401 end expandCrefWithDims;
3402
3403 protected function getDimStringOfDimElement
3404 input DAE.Dimension iDim;
3405 output String oDimString;
3406 protected
3407 Integer integer;
3408 algorithm
3409 oDimString := match iDim
3410 case DAE.DIM_INTEGER(integer)
3411 ✗ then intString(integer);
3412 else
3413 algorithm
3414 ✗ print("getDimStringOfDimElement: unsupported Dimension-type given!\n");
3415 then "";
3416 end match;
3417 end getDimStringOfDimElement;
3418
3419 protected function removeSubscripts
3420 input DAE.ComponentRef iCref;
3421 output DAE.ComponentRef oCref;
3422 protected
3423 DAE.Ident ident;
3424 DAE.Type identType "type of the identifier, without considering the subscripts";
3425 list<DAE.Subscript> subscriptLst;
3426 DAE.ComponentRef componentRef;
3427 algorithm
3428 oCref := match iCref
3429 case DAE.CREF_QUAL(ident,identType,subscriptLst,componentRef)
3430 algorithm
3431 ✗ componentRef := removeSubscripts(componentRef);
3432 ✗ then DAE.CREF_QUAL(ident,identType,subscriptLst,componentRef);
3433 case DAE.CREF_IDENT(ident,identType,subscriptLst)
3434 ✗ then DAE.CREF_IDENT(ident,identType,{});
3435 else iCref;
3436 end match;
3437 end removeSubscripts;
3438
3439 protected function getDimElemCount
3440 input list<String> iNumArrayElems;
3441 input Integer iDims;
3442 output list<Integer> oNumArrayElems;
3443 protected
3444 list<Integer> dimList, intNumArrayElems;
3445 Integer dims;
3446 algorithm
3447 ✗ dims := if intLe(iDims,0) then listLength(iNumArrayElems) else iDims;
3448 ✗ dimList := List.intRange(dims);
3449 ✗ intNumArrayElems := List.map(iNumArrayElems,stringInt);
3450 //print("getDimElemCount: dims=" + intString(dims) + " elems=" + intString(listLength(iNumArrayElems)) + "\n");
3451 ✗ oNumArrayElems := List.map1(dimList, List.getIndexFirst, intNumArrayElems);
3452 end getDimElemCount;
3453
3454 protected function getCrefDims
3455 input DAE.ComponentRef iCref;
3456 output Integer oDims;
3457 protected
3458 DAE.ComponentRef componentRef;
3459 list<DAE.Subscript> subscriptLst;
3460 Integer tmpDims;
3461 algorithm
3462 oDims := match iCref
3463 case DAE.CREF_QUAL(componentRef=componentRef)
3464 ✗ then getCrefDims(componentRef);
3465 case DAE.CREF_IDENT(subscriptLst=subscriptLst)
3466 algorithm
3467 ✗ tmpDims := listLength(subscriptLst);
3468 then tmpDims;
3469 else
3470 algorithm
3471 ✗ print("HpcOmMemory.getCrefDims failed!\n");
3472 then 0;
3473 end match;
3474 end getCrefDims;
3475
3476 protected function expandCref1
3477 input DAE.ComponentRef iCref;
3478 input Integer iElems;
3479 input list<Integer> iDimElemCount;
3480 output list<DAE.ComponentRef> oCrefs;
3481 protected
3482 list<DAE.ComponentRef> tmpCrefs;
3483 list<Integer> idxList;
3484 algorithm
3485 oCrefs := matchcontinue iDimElemCount
3486 case _
3487 algorithm
3488 ✗ tmpCrefs := ComponentReference.expandCref(iCref, false);
3489 ✗ true := intEq(listLength(tmpCrefs), iElems);
3490 then tmpCrefs;
3491 else
3492 algorithm
3493 //print("expandCref1: " + ComponentReferenceBasics.printComponentRefStr(iCref) + " elems: " + intString(iElems) + " dims: " + intString(listLength(iDimElemCount)) + "\n");
3494 ✗ idxList := List.intRange(List.reduce(iDimElemCount, intMul));
3495 //print("expandCref1 idxList-count: " + intString(listLength(idxList)) + "\n");
3496 //ComponentReference.printComponentRefList(List.map2(idxList, createArrayIndexCref, iDimElemCount, iCref));
3497 ✗ tmpCrefs := List.map2(idxList, createArrayIndexCref, iDimElemCount, iCref);
3498 //ComponentReference.printComponentRefList(tmpCrefs);
3499 then tmpCrefs;
3500 end matchcontinue;
3501 end expandCref1;
3502
3503 protected function createArrayIndexCref
3504 input Integer iIdx;
3505 input list<Integer> iDimElemCount;
3506 input DAE.ComponentRef iCref;
3507 output DAE.ComponentRef oCref;
3508 algorithm
3509 ✗ (oCref,_) := createArrayIndexCref_impl(iIdx, iDimElemCount, (iCref,1));
3510 end createArrayIndexCref;
3511
3512 protected function createArrayIndexCref_impl
3513 input Integer iIdx;
3514 input list<Integer> iDimElemCount;
3515 input tuple<DAE.ComponentRef, Integer> iRefCurrentDim; //<ref, currentDim>
3516 output tuple<DAE.ComponentRef, Integer> oRefCurrentDim;
3517 protected
3518 DAE.Ident ident;
3519 DAE.Type identType;
3520 list<DAE.Subscript> subscriptLst;
3521 DAE.ComponentRef componentRef;
3522 Integer currentDim, idxValue, dimElemsPre, dimElems;
3523 algorithm
3524 oRefCurrentDim := matchcontinue iRefCurrentDim
3525 case (DAE.CREF_QUAL(ident,identType,subscriptLst,componentRef),1) //the first dimension represents the last c-array-index
3526 algorithm
3527 ✗ true := intLe(1, listLength(iDimElemCount));
3528 //print("createArrayIndexCref_impl case1 " + ComponentReferenceBasics.printComponentRefStr(Util.tuple21(iRefCurrentDim)) + " currentDim " + intString(1) + "\n");
3529 ✗ (componentRef,_) := createArrayIndexCref_impl(iIdx, iDimElemCount, (componentRef,1));
3530 ✗ then ((DAE.CREF_QUAL(ident,identType,subscriptLst,componentRef),2));
3531
3532 case (DAE.CREF_QUAL(ident,identType,subscriptLst,componentRef),currentDim)
3533 algorithm
3534 ✗ true := intLe(currentDim, listLength(iDimElemCount));
3535 //print("createArrayIndexCref_impl case2 " + ComponentReferenceBasics.printComponentRefStr(Util.tuple21(iRefCurrentDim)) + " currentDim " + intString(currentDim) + "\n");
3536 ✗ (componentRef,_) := createArrayIndexCref_impl(iIdx, iDimElemCount, (componentRef,currentDim));
3537 ✗ then ((DAE.CREF_QUAL(ident,identType,subscriptLst,componentRef),currentDim+1));
3538
3539 case (DAE.CREF_IDENT(ident,identType,subscriptLst),1)
3540 algorithm
3541 ✗ true := intLe(1, listLength(iDimElemCount));
3542 //print("createArrayIndexCref_impl case3 | len(subscriptList)= " + intString(listLength(subscriptLst)) + " " + ComponentReferenceBasics.printComponentRefStr(Util.tuple21(iRefCurrentDim)) + " currentDim " + intString(1) + "\n");
3543 ✗ idxValue := intMod(iIdx-1,listHead(iDimElemCount)) + 1;
3544 ✗ subscriptLst := DAE.INDEX(DAE.ICONST(idxValue))::subscriptLst;
3545 ✗ then createArrayIndexCref_impl(iIdx, iDimElemCount, (DAE.CREF_IDENT(ident,identType,subscriptLst),2));
3546
3547 case (DAE.CREF_IDENT(ident,identType,subscriptLst),currentDim)
3548 algorithm
3549 ✗ true := intLe(currentDim, listLength(iDimElemCount));
3550 //dimElemsPre = List.reduce(List.sublist(iDimElemCount, listLength(iDimElemCount) - currentDim + 2, currentDim - 1), intMul);
3551 //print("createArrayIndexCref_impl case4: listLen=" + intString(listLength(iDimElemCount)) + " currentDim= " + intString(currentDim) + "\n");
3552 ✗ dimElemsPre := List.reduce(List.sublist(iDimElemCount, 1, listLength(iDimElemCount) - currentDim + 1), intMul);
3553 //print("createArrayIndexCref_impl case4 | len(subscriptList)= " + intString(listLength(subscriptLst)) + " " + ComponentReferenceBasics.printComponentRefStr(Util.tuple21(iRefCurrentDim)) + " currentDim " + intString(currentDim) + " dimElemsPre: " + intString(dimElemsPre) + "\n");
3554 ✗ dimElems := listGet(iDimElemCount, currentDim);
3555 ✗ idxValue := intMod(intDiv(iIdx - 1, dimElemsPre),dimElems) + 1;
3556 //print("createArrayIndexCref_impl case4 idxValue=" + intString(idxValue) + "\n");
3557 ✗ subscriptLst := DAE.INDEX(DAE.ICONST(idxValue))::subscriptLst;
3558 ✗ then createArrayIndexCref_impl(iIdx, iDimElemCount, (DAE.CREF_IDENT(ident,identType,subscriptLst),currentDim+1));
3559 case (DAE.CREF_IDENT(ident,identType,subscriptLst),currentDim)
3560 algorithm
3561 ✗ false := intLe(currentDim, listLength(iDimElemCount));
3562 //print("createArrayIndexCref_impl case5: listLen=" + intString(listLength(iDimElemCount)) + " currentDim= " + intString(currentDim) + "\n");
3563 then iRefCurrentDim;
3564 else
3565 algorithm
3566 ✗ print("createArrayIndexCref_impl failed!\n");
3567 then iRefCurrentDim;
3568 end matchcontinue;
3569 end createArrayIndexCref_impl;
3570
3571 // -------------------------------------------
3572 // UTIL
3573 // -------------------------------------------
3574
3575 protected function getTaskListTasks
3576 input HpcOmSimCode.TaskList iTaskList;
3577 output list<HpcOmSimCode.Task> oTasks;
3578 protected
3579 list<HpcOmSimCode.Task> tasks;
3580 algorithm
3581 oTasks := match iTaskList
3582 case HpcOmSimCode.PARALLELTASKLIST(tasks=tasks)
3583 then tasks;
3584 case HpcOmSimCode.PARALLELTASKLIST(tasks=tasks)
3585 then tasks;
3586 else
3587 algorithm
3588 ✗ print("getTaskListTasks failed!\n");
3589 then {};
3590 end match;
3591 end getTaskListTasks;
3592
3593 protected function getCacheLineMapOfPartlyFilledCacheLine
3594 input PartlyFilledCacheLine iPartlyFilledCacheLine;
3595 output CacheLineMap oCacheLineMap;
3596 protected
3597 CacheLineMap cacheLineMap;
3598 algorithm
3599 oCacheLineMap := match iPartlyFilledCacheLine
3600 case PARTLYFILLEDCACHELINE_LEVEL(cacheLineMap=cacheLineMap)
3601 then cacheLineMap;
3602 case PARTLYFILLEDCACHELINE_THREAD(cacheLineMap=cacheLineMap)
3603 then cacheLineMap;
3604 end match;
3605 end getCacheLineMapOfPartlyFilledCacheLine;
3606
3607 protected function getAllCacheLinesOfCacheMap "author: marcusw
3608 Get all cache lines that are stored in the given cache map."
3609 input CacheMap iCacheMap;
3610 output list<CacheLineMap> oCacheLines;
3611 protected
3612 list<CacheLineMap> cacheLinesFloat, cacheLinesInt, cacheLinesBool, allCacheLines;
3613 algorithm
3614 oCacheLines := match iCacheMap
3615 case CACHEMAP(cacheLinesFloat=cacheLinesFloat, cacheLinesInt=cacheLinesInt, cacheLinesBool=cacheLinesBool)
3616 algorithm
3617 2 allCacheLines := listAppend(cacheLinesFloat, listAppend(cacheLinesInt, cacheLinesBool));
3618 then allCacheLines;
3619 case UNIFORM_CACHEMAP(cacheLines=allCacheLines)
3620 then allCacheLines;
3621 end match;
3622 end getAllCacheLinesOfCacheMap;
3623
3624 protected function getCacheVariablesOfCacheMap "author: marcusw
3625 Get all cache variables that are stored in the given cache map."
3626 input CacheMap iCacheMap;
3627 output list<SimCodeVar.SimVar> oCacheVariables;
3628 protected
3629 list<SimCodeVar.SimVar> cacheVariables;
3630 algorithm
3631 oCacheVariables := match iCacheMap
3632 case CACHEMAP(cacheVariables=cacheVariables)
3633 then cacheVariables;
3634 case UNIFORM_CACHEMAP(cacheVariables=cacheVariables)
3635 then cacheVariables;
3636 end match;
3637 end getCacheVariablesOfCacheMap;
3638
3639 protected function getCacheLineSizeOfCacheMap "author: marcusw
3640 Get the cache line size of the given cache map."
3641 input CacheMap iCacheMap;
3642 output Integer oCacheLineSize;
3643 protected
3644 Integer cacheLineSize;
3645 algorithm
3646 oCacheLineSize := match iCacheMap
3647 case CACHEMAP(cacheLineSize=cacheLineSize)
3648 then cacheLineSize;
3649 case UNIFORM_CACHEMAP(cacheLineSize=cacheLineSize)
3650 then cacheLineSize;
3651 end match;
3652 end getCacheLineSizeOfCacheMap;
3653
3654 annotation(__OpenModelica_Interface="backend");
3655 end HpcOmMemory;
3656