Skip to content

Commit

Permalink
Add debug flag reportSerializedSize
Browse files Browse the repository at this point in the history
The debug flag will serialize data structures and report their sizes
via compiler notifications.
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 9, 2016
1 parent 86e3c04 commit 312e5a4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
50 changes: 50 additions & 0 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -81,7 +81,9 @@ import HpcOmTaskGraph;
import SerializeModelInfo;
import SimCodeDump;
import TaskSystemDump;
import Serializer;
import SimCodeUtil;
import StringUtil;
import System;
import Util;
import BackendDump;
Expand Down Expand Up @@ -421,6 +423,11 @@ algorithm
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");

if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(simCode, filenamePrefix, "simCode");
ExecStat.execStat("Serialize simCode");
end if;

System.realtimeTick(ClockIndexes.RT_CLOCK_TEMPLATES);
callTargetTemplates(simCode, Config.simCodeTarget());
timeTemplates := System.realtimeTock(ClockIndexes.RT_CLOCK_TEMPLATES);
Expand Down Expand Up @@ -773,28 +780,59 @@ algorithm
list<BackendDAE.Equation> removedInitialEquationLst;
list<BackendDAE.Var> primaryParameters "already sorted";
list<BackendDAE.Var> allPrimaryParameters "already sorted";
Real fsize;

case (cache, graph, _, (st as GlobalScript.SYMBOLTABLE(ast=p)), filenameprefix, _, _, _) equation
// calculate stuff that we need to create SimCode data structure
System.realtimeTick(ClockIndexes.RT_CLOCK_FRONTEND);
ExecStat.execStatReset();
(cache, graph, dae, st) = CevalScriptBackend.runFrontEnd(cache, graph, className, st, false);
ExecStat.execStat("FrontEnd");

if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(dae, filenameprefix, "dae");
serializeNotify(graph, filenameprefix, "graph");
serializeNotify(cache, filenameprefix, "cache");
serializeNotify(st, filenameprefix, "st");
ExecStat.execStat("Serialize FrontEnd");
end if;

timeFrontend = System.realtimeTock(ClockIndexes.RT_CLOCK_FRONTEND);

System.realtimeTick(ClockIndexes.RT_CLOCK_BACKEND);
dae = DAEUtil.transformationsBeforeBackend(cache, graph, dae);
ExecStat.execStat("Transformations before backend");

if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(dae, filenameprefix, "dae2");
ExecStat.execStat("Serialize DAE (2)");
end if;

description = DAEUtil.daeDescription(dae);
dlow = BackendDAECreate.lower(dae, cache, graph, BackendDAE.EXTRA_INFO(description,filenameprefix));

GC.free(dae);
graph = FCore.EG("<EMPTY>");

if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(dlow, filenameprefix, "dlow");
ExecStat.execStat("Serialize dlow");
end if;

//BackendDump.printBackendDAE(dlow);
(dlow, initDAE, useHomotopy, initDAE_lambda0, removedInitialEquationLst, primaryParameters, allPrimaryParameters) = BackendDAEUtil.getSolvedSystem(dlow,inFileNamePrefix);
timeBackend = System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND);

if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(dlow, filenameprefix, "simDAE");
serializeNotify(initDAE, filenameprefix, "initDAE");
serializeNotify(initDAE_lambda0, filenameprefix, "initDAE_lambda0");
serializeNotify(removedInitialEquationLst, filenameprefix, "removedInitialEquationLst");
serializeNotify(primaryParameters, filenameprefix, "primaryParameters");
serializeNotify(allPrimaryParameters, filenameprefix, "allPrimaryParameters");
ExecStat.execStat("Serialize solved system");
end if;

(libs, file_dir, timeSimCode, timeTemplates) =
generateModelCode(dlow, initDAE, useHomotopy, initDAE_lambda0, removedInitialEquationLst, primaryParameters, allPrimaryParameters, p, className, filenameprefix, inSimSettingsOpt, args);

Expand All @@ -813,5 +851,17 @@ algorithm
end matchcontinue;
end translateModel;

protected function serializeNotify<T>
input T data;
input String prefix;
input String name;
protected
Real fsize;
algorithm
Serializer.outputFile(data, prefix + "_"+name+".bin");
(,fsize,) := System.stat(prefix + "_"+name+".bin");
Error.addMessage(Error.SERIALIZED_SIZE, {name, StringUtil.bytesToReadableUnit(fsize)});
end serializeNotify;

annotation(__OpenModelica_Interface="backend");
end SimCodeMain;
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -925,6 +925,8 @@ public constant Message UNIONTYPE_MISSING_TYPEVARS = MESSAGE(5044, TRANSLATION()
Util.gettext("Uniontype %s has type variables, but they were not given in the declaration."));
public constant Message UNIONTYPE_WRONG_NUM_TYPEVARS = MESSAGE(5045, TRANSLATION(), ERROR(),
Util.gettext("Uniontype %s has %s type variables, but got %s."));
public constant Message SERIALIZED_SIZE = MESSAGE(5046, TRANSLATION(), NOTIFICATION(),
Util.gettext("%s has serialized size %s."));

public constant Message COMPILER_ERROR = MESSAGE(5999, TRANSLATION(), ERROR(),
Util.notrans("%s"));
Expand Down
5 changes: 4 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -497,6 +497,8 @@ constant DebugFlag TOTAL_TEARING_DUMPVERBOSE = DEBUG_FLAG(161, "totaltearingdump
Util.gettext("Dumps verbose total tearing information."));
constant DebugFlag PARALLEL_CODEGEN = DEBUG_FLAG(162, "parallelCodegen", true,
Util.gettext("Enables code generation in parallel (disable this if compiling a model causes you to run out of RAM)."));
constant DebugFlag SERIALIZED_SIZE = DEBUG_FLAG(163, "reportSerializedSize", false,
Util.gettext("Reports serialized sizes of various data structures used in the compiler."));

// This is a list of all debug flags, to keep track of which flags are used. A
// flag can not be used unless it's in this list, and the list is checked at
Expand Down Expand Up @@ -665,7 +667,8 @@ constant list<DebugFlag> allDebugFlags = {
OMC_RECORD_ALLOC_WORDS,
TOTAL_TEARING_DUMP,
TOTAL_TEARING_DUMPVERBOSE,
PARALLEL_CODEGEN
PARALLEL_CODEGEN,
SERIALIZED_SIZE
};

public
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Util/StringUtil.mo
Expand Up @@ -318,7 +318,7 @@ algorithm
end equalIgnoreSpace;

function bytesToReadableUnit
input Integer bytes;
input Real bytes;
input Integer significantDigits=4;
input Real maxSizeInUnit=500 "If it is 1000, we print up to 1000GB before changing to X TB";
output String str;
Expand All @@ -334,7 +334,7 @@ algorithm
elseif bytes > maxSizeInUnit then
str := String(bytes/kB, significantDigits=significantDigits)+" kB";
else
str := String(bytes);
str := String(integer(bytes));
end if;
end bytesToReadableUnit;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/boot/LoadCompilerSources.mos
Expand Up @@ -195,7 +195,6 @@ if true then /* Suppress output */
"../Util/ModelicaExternalC.mo",
"../Util/Print.mo",
"../Util/PriorityQueue.mo",
// "../Util/Serializer.mo",
"../Util/Settings.mo",
"../Util/StackOverflow.mo",
"../Util/StringUtil.mo",
Expand Down Expand Up @@ -341,7 +340,8 @@ if true then /* Suppress output */
"../Util/HashTableCrToUnit.mo",
"../Util/HashTableStringToUnit.mo",
"../Util/HashTableUnitToString.mo",
"../Util/SimulationResults.mo",
"../Util/Serializer.mo",
"../Util/SimulationResults.mo",
"../Util/TaskGraphResults.mo"

};
Expand Down

0 comments on commit 312e5a4

Please sign in to comment.