Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
monticore
EmbeddedMontiArc
generators
EMADL2CPP
Commits
73f14641
Commit
73f14641
authored
Mar 09, 2019
by
Christopher Jan-Steffen Brix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added command line option to avoid compilation of generated code, needed eg. for Windows
parent
f509c7c1
Pipeline
#110323
failed with stages
in 4 minutes and 59 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
28 deletions
+44
-28
src/main/java/de/monticore/lang/monticar/emadl/generator/EMADLGenerator.java
...nticore/lang/monticar/emadl/generator/EMADLGenerator.java
+10
-13
src/main/java/de/monticore/lang/monticar/emadl/generator/EMADLGeneratorCli.java
...core/lang/monticar/emadl/generator/EMADLGeneratorCli.java
+24
-5
src/test/java/de/monticore/lang/monticar/emadl/GenerationTest.java
...java/de/monticore/lang/monticar/emadl/GenerationTest.java
+10
-10
No files found.
src/main/java/de/monticore/lang/monticar/emadl/generator/EMADLGenerator.java
View file @
73f14641
...
...
@@ -108,7 +108,7 @@ public class EMADLGenerator {
return
emamGen
;
}
public
void
generate
(
String
modelPath
,
String
qualifiedName
,
String
pythonPath
,
String
forced
)
throws
IOException
,
TemplateException
{
public
void
generate
(
String
modelPath
,
String
qualifiedName
,
String
pythonPath
,
String
forced
,
boolean
doCompile
)
throws
IOException
,
TemplateException
{
setModelsPath
(
modelPath
);
TaggingResolver
symtab
=
EMADLAbstractSymtab
.
createSymTabAndTaggingResolver
(
getModelsPath
());
EMAComponentSymbol
component
=
symtab
.<
EMAComponentSymbol
>
resolve
(
qualifiedName
,
EMAComponentSymbol
.
KIND
).
orElse
(
null
);
...
...
@@ -126,14 +126,13 @@ public class EMADLGenerator {
generateFiles
(
symtab
,
instance
,
symtab
,
pythonPath
,
forced
);
try
{
executeCommands
();
}
catch
(
Exception
e
){
System
.
out
.
println
(
e
);
if
(
doCompile
)
{
compile
();
}
}
public
void
executeCommands
()
throws
IOException
{
public
void
compile
()
throws
IOException
{
File
tempScript
=
createTempScript
();
try
{
ProcessBuilder
pb
=
new
ProcessBuilder
(
"bash"
,
tempScript
.
toString
());
...
...
@@ -160,7 +159,7 @@ public class EMADLGenerator {
PrintWriter
printWriter
=
new
PrintWriter
(
streamWriter
);
printWriter
.
println
(
"#!/bin/bash"
);
printWriter
.
println
(
"c
sss
d "
+
getGenerationTargetPath
());
printWriter
.
println
(
"cd "
+
getGenerationTargetPath
());
printWriter
.
println
(
"mkdir --parents build"
);
printWriter
.
println
(
"cd build"
);
printWriter
.
println
(
"cmake .."
);
...
...
@@ -255,15 +254,13 @@ public class EMADLGenerator {
exitCode
=
p
.
waitFor
();
}
catch
(
InterruptedException
e
)
{
//throw new Exception("Error: Training aborted" + e.toString());
System
.
out
.
println
(
"Error: Training aborted"
+
e
.
toString
());
continue
;
Log
.
error
(
"Training aborted: exit code "
+
Integer
.
toString
(
exitCode
));
System
.
exit
(
1
);
}
if
(
exitCode
!=
0
)
{
//throw new Exception("Error: Training error");
System
.
out
.
println
(
"Error: Training failed"
+
Integer
.
toString
(
exitCode
));
continue
;
Log
.
error
(
"Training failed: exit code "
+
Integer
.
toString
(
exitCode
));
System
.
exit
(
1
);
}
fileContentsTrainingHashes
.
add
(
new
FileContent
(
trainingHash
,
componentConfigFilename
+
".training_hash"
));
...
...
src/main/java/de/monticore/lang/monticar/emadl/generator/EMADLGeneratorCli.java
View file @
73f14641
...
...
@@ -65,10 +65,17 @@ public class EMADLGeneratorCli {
.
build
();
public
static
final
Option
OPTION_RESTRAINED_TRAINING
=
Option
.
builder
(
"f"
)
.
longOpt
(
"forced"
)
.
desc
(
"no training or a forced training. Options: y (a forced training), n (no training)"
)
.
hasArg
(
true
)
.
required
(
false
)
.
longOpt
(
"forced"
)
.
desc
(
"no training or a forced training. Options: y (a forced training), n (no training)"
)
.
hasArg
(
true
)
.
required
(
false
)
.
build
();
public
static
final
Option
OPTION_COMPILE
=
Option
.
builder
(
"c"
)
.
longOpt
(
"compile"
)
.
desc
(
"Compile the generated c code. Needs to be disabled eg. on Windows. Options: y (compile), n (don't compile). Default is y"
)
.
hasArg
(
true
)
.
required
(
false
)
.
build
();
...
...
@@ -92,6 +99,7 @@ public class EMADLGeneratorCli {
options
.
addOption
(
OPTION_BACKEND
);
options
.
addOption
(
OPTION_RESTRAINED_TRAINING
);
options
.
addOption
(
OPTION_TRAINING_PYTHON_PATH
);
options
.
addOption
(
OPTION_COMPILE
);
return
options
;
}
...
...
@@ -113,8 +121,10 @@ public class EMADLGeneratorCli {
String
backendString
=
cliArgs
.
getOptionValue
(
OPTION_BACKEND
.
getOpt
());
String
forced
=
cliArgs
.
getOptionValue
(
OPTION_RESTRAINED_TRAINING
.
getOpt
());
String
pythonPath
=
cliArgs
.
getOptionValue
(
OPTION_TRAINING_PYTHON_PATH
.
getOpt
());
String
compile
=
cliArgs
.
getOptionValue
(
OPTION_COMPILE
.
getOpt
());
final
String
DEFAULT_BACKEND
=
"MXNET"
;
final
String
DEFAULT_FORCED
=
"UNSET"
;
final
String
DEFAULT_COMPILE
=
"y"
;
if
(
backendString
==
null
)
{
Log
.
warn
(
"backend not specified. backend set to default value "
+
DEFAULT_BACKEND
);
...
...
@@ -138,13 +148,22 @@ public class EMADLGeneratorCli {
Log
.
error
(
"specified setting ("
+
forced
+
") for forcing/preventing training not supported. set to default value "
+
DEFAULT_FORCED
);
forced
=
DEFAULT_FORCED
;
}
EMADLGenerator
generator
=
new
EMADLGenerator
(
backend
.
get
());
if
(
compile
==
null
)
{
compile
=
DEFAULT_COMPILE
;
}
else
if
(!
compile
.
equals
(
"y"
)
&&
!
compile
.
equals
(
"n"
))
{
Log
.
error
(
"specified setting ("
+
compile
+
") for skipping the compilation not supported. set to default value "
+
DEFAULT_COMPILE
);
compile
=
DEFAULT_COMPILE
;
}
if
(
outputPath
!=
null
){
generator
.
setGenerationTargetPath
(
outputPath
);
}
try
{
generator
.
generate
(
cliArgs
.
getOptionValue
(
OPTION_MODELS_PATH
.
getOpt
()),
rootModelName
,
pythonPath
,
forced
);
generator
.
generate
(
cliArgs
.
getOptionValue
(
OPTION_MODELS_PATH
.
getOpt
()),
rootModelName
,
pythonPath
,
forced
,
compile
.
equals
(
"y"
)
);
}
catch
(
IOException
e
){
Log
.
error
(
"io error during generation"
,
e
);
...
...
src/test/java/de/monticore/lang/monticar/emadl/GenerationTest.java
View file @
73f14641
...
...
@@ -51,7 +51,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testCifar10Generation
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"cifar10.Cifar10Classifier"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"cifar10.Cifar10Classifier"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
...
...
@@ -73,7 +73,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testSimulatorGeneration
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"simulator.MainController"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"simulator.MainController"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
}
...
...
@@ -81,7 +81,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testAddGeneration
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"Add"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"Add"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
}
...
...
@@ -89,7 +89,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testAlexnetGeneration
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"Alexnet"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"Alexnet"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
}
...
...
@@ -97,7 +97,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testResNeXtGeneration
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"ResNeXt50"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"ResNeXt50"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
}
...
...
@@ -105,7 +105,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testThreeInputGeneration
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"ThreeInputCNN_M14"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"ThreeInputCNN_M14"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
size
()
==
1
);
}
...
...
@@ -113,7 +113,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testMultipleOutputsGeneration
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"MultipleOutputs"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"MultipleOutputs"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
size
()
==
1
);
}
...
...
@@ -121,7 +121,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testVGGGeneration
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"VGG16"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"VGG16"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
}
...
...
@@ -130,7 +130,7 @@ public class GenerationTest extends AbstractSymtabTest {
public
void
testMultipleInstances
()
throws
IOException
,
TemplateException
{
try
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"InstanceTest.MainB"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"InstanceTest.MainB"
,
"-b"
,
"MXNET"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
}
...
...
@@ -142,7 +142,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test
public
void
testMnistClassifier
()
throws
IOException
,
TemplateException
{
Log
.
getFindings
().
clear
();
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"mnist.MnistClassifier"
,
"-b"
,
"CAFFE2"
,
"-f"
,
"n"
};
String
[]
args
=
{
"-m"
,
"src/test/resources/models/"
,
"-r"
,
"mnist.MnistClassifier"
,
"-b"
,
"CAFFE2"
,
"-f"
,
"n"
,
"-c"
,
"n"
};
EMADLGeneratorCli
.
main
(
args
);
assertTrue
(
Log
.
getFindings
().
isEmpty
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment