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
...@@ -108,7 +108,7 @@ public class EMADLGenerator { ...@@ -108,7 +108,7 @@ public class EMADLGenerator {
return emamGen; 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 ); setModelsPath( modelPath );
TaggingResolver symtab = EMADLAbstractSymtab.createSymTabAndTaggingResolver(getModelsPath()); TaggingResolver symtab = EMADLAbstractSymtab.createSymTabAndTaggingResolver(getModelsPath());
EMAComponentSymbol component = symtab.<EMAComponentSymbol>resolve(qualifiedName, EMAComponentSymbol.KIND).orElse(null); EMAComponentSymbol component = symtab.<EMAComponentSymbol>resolve(qualifiedName, EMAComponentSymbol.KIND).orElse(null);
...@@ -126,14 +126,13 @@ public class EMADLGenerator { ...@@ -126,14 +126,13 @@ public class EMADLGenerator {
generateFiles(symtab, instance, symtab, pythonPath, forced); generateFiles(symtab, instance, symtab, pythonPath, forced);
try{
executeCommands(); if (doCompile) {
}catch(Exception e){ compile();
System.out.println(e);
} }
} }
public void executeCommands() throws IOException { public void compile() throws IOException {
File tempScript = createTempScript(); File tempScript = createTempScript();
try { try {
ProcessBuilder pb = new ProcessBuilder("bash", tempScript.toString()); ProcessBuilder pb = new ProcessBuilder("bash", tempScript.toString());
...@@ -160,7 +159,7 @@ public class EMADLGenerator { ...@@ -160,7 +159,7 @@ public class EMADLGenerator {
PrintWriter printWriter = new PrintWriter(streamWriter); PrintWriter printWriter = new PrintWriter(streamWriter);
printWriter.println("#!/bin/bash"); printWriter.println("#!/bin/bash");
printWriter.println("csssd " + getGenerationTargetPath()); printWriter.println("cd " + getGenerationTargetPath());
printWriter.println("mkdir --parents build"); printWriter.println("mkdir --parents build");
printWriter.println("cd build"); printWriter.println("cd build");
printWriter.println("cmake .."); printWriter.println("cmake ..");
...@@ -255,15 +254,13 @@ public class EMADLGenerator { ...@@ -255,15 +254,13 @@ public class EMADLGenerator {
exitCode = p.waitFor(); exitCode = p.waitFor();
} }
catch(InterruptedException e) { catch(InterruptedException e) {
//throw new Exception("Error: Training aborted" + e.toString()); Log.error("Training aborted: exit code " + Integer.toString(exitCode));
System.out.println("Error: Training aborted" + e.toString()); System.exit(1);
continue;
} }
if(exitCode != 0) { if(exitCode != 0) {
//throw new Exception("Error: Training error"); Log.error("Training failed: exit code " + Integer.toString(exitCode));
System.out.println("Error: Training failed" + Integer.toString(exitCode)); System.exit(1);
continue;
} }
fileContentsTrainingHashes.add(new FileContent(trainingHash, componentConfigFilename + ".training_hash")); fileContentsTrainingHashes.add(new FileContent(trainingHash, componentConfigFilename + ".training_hash"));
......
...@@ -71,6 +71,13 @@ public class EMADLGeneratorCli { ...@@ -71,6 +71,13 @@ public class EMADLGeneratorCli {
.required(false) .required(false)
.build(); .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();
private EMADLGeneratorCli() { private EMADLGeneratorCli() {
} }
...@@ -92,6 +99,7 @@ public class EMADLGeneratorCli { ...@@ -92,6 +99,7 @@ public class EMADLGeneratorCli {
options.addOption(OPTION_BACKEND); options.addOption(OPTION_BACKEND);
options.addOption(OPTION_RESTRAINED_TRAINING); options.addOption(OPTION_RESTRAINED_TRAINING);
options.addOption(OPTION_TRAINING_PYTHON_PATH); options.addOption(OPTION_TRAINING_PYTHON_PATH);
options.addOption(OPTION_COMPILE);
return options; return options;
} }
...@@ -113,8 +121,10 @@ public class EMADLGeneratorCli { ...@@ -113,8 +121,10 @@ public class EMADLGeneratorCli {
String backendString = cliArgs.getOptionValue(OPTION_BACKEND.getOpt()); String backendString = cliArgs.getOptionValue(OPTION_BACKEND.getOpt());
String forced = cliArgs.getOptionValue(OPTION_RESTRAINED_TRAINING.getOpt()); String forced = cliArgs.getOptionValue(OPTION_RESTRAINED_TRAINING.getOpt());
String pythonPath = cliArgs.getOptionValue(OPTION_TRAINING_PYTHON_PATH.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_BACKEND = "MXNET";
final String DEFAULT_FORCED = "UNSET"; final String DEFAULT_FORCED = "UNSET";
final String DEFAULT_COMPILE = "y";
if (backendString == null) { if (backendString == null) {
Log.warn("backend not specified. backend set to default value " + DEFAULT_BACKEND); Log.warn("backend not specified. backend set to default value " + DEFAULT_BACKEND);
...@@ -138,13 +148,22 @@ public class EMADLGeneratorCli { ...@@ -138,13 +148,22 @@ public class EMADLGeneratorCli {
Log.error("specified setting ("+forced+") for forcing/preventing training not supported. set to default value " + DEFAULT_FORCED); Log.error("specified setting ("+forced+") for forcing/preventing training not supported. set to default value " + DEFAULT_FORCED);
forced = DEFAULT_FORCED; forced = DEFAULT_FORCED;
} }
EMADLGenerator generator = new EMADLGenerator(backend.get()); 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){ if (outputPath != null){
generator.setGenerationTargetPath(outputPath); generator.setGenerationTargetPath(outputPath);
} }
try{ 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){ catch (IOException e){
Log.error("io error during generation", e); Log.error("io error during generation", e);
......
...@@ -51,7 +51,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -51,7 +51,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testCifar10Generation() throws IOException, TemplateException { public void testCifar10Generation() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
...@@ -73,7 +73,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -73,7 +73,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testSimulatorGeneration() throws IOException, TemplateException { public void testSimulatorGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
} }
...@@ -81,7 +81,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -81,7 +81,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testAddGeneration() throws IOException, TemplateException { public void testAddGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
} }
...@@ -89,7 +89,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -89,7 +89,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testAlexnetGeneration() throws IOException, TemplateException { public void testAlexnetGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
} }
...@@ -97,7 +97,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -97,7 +97,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testResNeXtGeneration() throws IOException, TemplateException { public void testResNeXtGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
} }
...@@ -105,7 +105,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -105,7 +105,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testThreeInputGeneration() throws IOException, TemplateException { public void testThreeInputGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().size() == 1); assertTrue(Log.getFindings().size() == 1);
} }
...@@ -113,7 +113,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -113,7 +113,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testMultipleOutputsGeneration() throws IOException, TemplateException { public void testMultipleOutputsGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().size() == 1); assertTrue(Log.getFindings().size() == 1);
} }
...@@ -121,7 +121,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -121,7 +121,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testVGGGeneration() throws IOException, TemplateException { public void testVGGGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
} }
...@@ -130,7 +130,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -130,7 +130,7 @@ public class GenerationTest extends AbstractSymtabTest {
public void testMultipleInstances() throws IOException, TemplateException { public void testMultipleInstances() throws IOException, TemplateException {
try { try {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
} }
...@@ -142,7 +142,7 @@ public class GenerationTest extends AbstractSymtabTest { ...@@ -142,7 +142,7 @@ public class GenerationTest extends AbstractSymtabTest {
@Test @Test
public void testMnistClassifier() throws IOException, TemplateException { public void testMnistClassifier() throws IOException, TemplateException {
Log.getFindings().clear(); 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); EMADLGeneratorCli.main(args);
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment