change CNNArchGenerator to an abstract class

parent 9f055caa
Pipeline #107035 passed with stages
in 3 minutes and 37 seconds
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<properties> <properties>
<!-- .. SE-Libraries .................................................. --> <!-- .. SE-Libraries .................................................. -->
<CNNArch.version>0.2.8</CNNArch.version> <CNNArch.version>0.2.9</CNNArch.version>
<CNNTrain.version>0.2.6</CNNTrain.version> <CNNTrain.version>0.2.6</CNNTrain.version>
<embedded-montiarc-math-opt-generator>0.1.4</embedded-montiarc-math-opt-generator> <embedded-montiarc-math-opt-generator>0.1.4</embedded-montiarc-math-opt-generator>
......
...@@ -20,32 +20,26 @@ ...@@ -20,32 +20,26 @@
*/ */
package de.monticore.lang.monticar.cnnarch.caffe2generator; package de.monticore.lang.monticar.cnnarch.caffe2generator;
import de.monticore.io.paths.ModelPath;
import de.monticore.lang.monticar.cnnarch.CNNArchGenerator; import de.monticore.lang.monticar.cnnarch.CNNArchGenerator;
import de.monticore.lang.monticar.cnnarch._cocos.CNNArchCocos; import de.monticore.lang.monticar.cnnarch._cocos.CNNArchCocos;
import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol; import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureElementSymbol; import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureElementSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.CompositeElementSymbol; import de.monticore.lang.monticar.cnnarch._symboltable.CompositeElementSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.CNNArchCompilationUnitSymbol; import de.monticore.lang.monticar.cnnarch._symboltable.CNNArchCompilationUnitSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.CNNArchLanguage;
import de.monticore.lang.monticar.generator.FileContent; import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cmake.CMakeConfig; import de.monticore.lang.monticar.generator.cmake.CMakeConfig;
import de.monticore.lang.monticar.generator.cmake.CMakeFindModule; import de.monticore.lang.monticar.generator.cmake.CMakeFindModule;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP; import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.Scope; import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Log;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.List; import java.util.List;
public class CNNArch2Caffe2 implements CNNArchGenerator{ public class CNNArch2Caffe2 extends CNNArchGenerator{
private String generationTargetPath;
private boolean isSupportedLayer(ArchitectureElementSymbol element, LayerSupportChecker layerChecker){ private boolean isSupportedLayer(ArchitectureElementSymbol element, LayerSupportChecker layerChecker){
List<ArchitectureElementSymbol> constructLayerElemList; List<ArchitectureElementSymbol> constructLayerElemList;
...@@ -76,37 +70,10 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{ ...@@ -76,37 +70,10 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{
return true; return true;
} }
private static void quitGeneration(){
Log.error("Code generation is aborted");
System.exit(1);
}
public CNNArch2Caffe2() { public CNNArch2Caffe2() {
setGenerationTargetPath("./target/generated-sources-cnnarch/"); setGenerationTargetPath("./target/generated-sources-cnnarch/");
} }
@Override
public boolean isCMakeRequired() {
return true;
}
public String getGenerationTargetPath() {
if (generationTargetPath.charAt(generationTargetPath.length() - 1) != '/') {
this.generationTargetPath = generationTargetPath + "/";
}
return generationTargetPath;
}
public void setGenerationTargetPath(String generationTargetPath) {
this.generationTargetPath = generationTargetPath;
}
public void generate(Path modelsDirPath, String rootModelName){
final ModelPath mp = new ModelPath(modelsDirPath);
GlobalScope scope = new GlobalScope(mp, new CNNArchLanguage());
generate(scope, rootModelName);
}
public void generate(Scope scope, String rootModelName){ public void generate(Scope scope, String rootModelName){
Optional<CNNArchCompilationUnitSymbol> compilationUnit = scope.resolve(rootModelName, CNNArchCompilationUnitSymbol.KIND); Optional<CNNArchCompilationUnitSymbol> compilationUnit = scope.resolve(rootModelName, CNNArchCompilationUnitSymbol.KIND);
if (!compilationUnit.isPresent()){ if (!compilationUnit.isPresent()){
...@@ -146,41 +113,7 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{ ...@@ -146,41 +113,7 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{
return fileContentMap; return fileContentMap;
} }
private void checkValidGeneration(ArchitectureSymbol architecture){ public void generateFromFilecontentsMap(Map<String, String> fileContentMap) throws IOException {
if (architecture.getInputs().size() > 1){
Log.error("This cnn architecture has multiple inputs, " +
"which is currently not supported by the caffe2generator. "
, architecture.getSourcePosition());
}
if (architecture.getOutputs().size() > 1){
Log.error("This cnn architecture has multiple outputs, " +
"which is currently not supported by the caffe2generator. "
, architecture.getSourcePosition());
}
if (architecture.getOutputs().get(0).getDefinition().getType().getWidth() != 1 ||
architecture.getOutputs().get(0).getDefinition().getType().getHeight() != 1){
Log.error("This cnn architecture has a multi-dimensional output, " +
"which is currently not supported by the caffe2generator."
, architecture.getSourcePosition());
}
}
//check cocos with CNNArchCocos.checkAll(architecture) before calling this method.
public void generateFiles(ArchitectureSymbol architecture) throws IOException{
Map<String, String> fileContentMap = generateStrings(architecture);
generateFromFilecontentsMap(fileContentMap);
}
public void generateCMake(String rootModelName) {
Map<String, String> fileContentMap = generateCMakeContent(rootModelName);
try {
generateFromFilecontentsMap(fileContentMap);
} catch (IOException e) {
Log.error("CMake file could not be generated" + e.getMessage());
}
}
private void generateFromFilecontentsMap(Map<String, String> fileContentMap) throws IOException {
GeneratorCPP genCPP = new GeneratorCPP(); GeneratorCPP genCPP = new GeneratorCPP();
genCPP.setGenerationTargetPath(getGenerationTargetPath()); genCPP.setGenerationTargetPath(getGenerationTargetPath());
for (String fileName : fileContentMap.keySet()){ for (String fileName : fileContentMap.keySet()){
......
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