From 1d392645a3bbf00dfac4450d73f2b8db1aa880ad Mon Sep 17 00:00:00 2001 From: Carlos Alfredo Yeverino Rodriguez Date: Fri, 22 Feb 2019 19:38:54 +0100 Subject: [PATCH] change CNNArchGenerator to an abstract class --- pom.xml | 2 +- .../cnnarch/gluongenerator/CNNArch2Gluon.java | 71 +------------------ 2 files changed, 3 insertions(+), 70 deletions(-) diff --git a/pom.xml b/pom.xml index ba1e0ac4..b924852f 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ - 0.2.8 + 0.2.9 0.2.6 0.1.4 diff --git a/src/main/java/de/monticore/lang/monticar/cnnarch/gluongenerator/CNNArch2Gluon.java b/src/main/java/de/monticore/lang/monticar/cnnarch/gluongenerator/CNNArch2Gluon.java index d268f963..f8aad2ed 100644 --- a/src/main/java/de/monticore/lang/monticar/cnnarch/gluongenerator/CNNArch2Gluon.java +++ b/src/main/java/de/monticore/lang/monticar/cnnarch/gluongenerator/CNNArch2Gluon.java @@ -20,32 +20,26 @@ */ package de.monticore.lang.monticar.cnnarch.gluongenerator; -import de.monticore.io.paths.ModelPath; import de.monticore.lang.monticar.cnnarch.CNNArchGenerator; import de.monticore.lang.monticar.cnnarch._cocos.CNNArchCocos; import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol; import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureElementSymbol; import de.monticore.lang.monticar.cnnarch._symboltable.CompositeElementSymbol; 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.cmake.CMakeConfig; import de.monticore.lang.monticar.generator.cmake.CMakeFindModule; import de.monticore.lang.monticar.generator.cpp.GeneratorCPP; -import de.monticore.symboltable.GlobalScope; import de.monticore.symboltable.Scope; import de.se_rwth.commons.logging.Log; import java.io.IOException; -import java.nio.file.Path; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.List; -public class CNNArch2Gluon implements CNNArchGenerator { - - private String generationTargetPath; +public class CNNArch2Gluon extends CNNArchGenerator { private boolean isSupportedLayer(ArchitectureElementSymbol element, LayerSupportChecker layerChecker){ List constructLayerElemList; @@ -76,37 +70,10 @@ public class CNNArch2Gluon implements CNNArchGenerator { return true; } - private static void quitGeneration(){ - Log.error("Code generation is aborted"); - System.exit(1); - } - public CNNArch2Gluon() { 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){ Optional compilationUnit = scope.resolve(rootModelName, CNNArchCompilationUnitSymbol.KIND); if (!compilationUnit.isPresent()){ @@ -152,41 +119,7 @@ public class CNNArch2Gluon implements CNNArchGenerator { return fileContentMap; } - private void checkValidGeneration(ArchitectureSymbol architecture){ - if (architecture.getInputs().size() > 1){ - Log.error("This cnn architecture has multiple inputs, " + - "which is currently not supported by the mxnetgenerator. " - , architecture.getSourcePosition()); - } - if (architecture.getOutputs().size() > 1){ - Log.error("This cnn architecture has multiple outputs, " + - "which is currently not supported by the mxnetgenerator. " - , 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 mxnetgenerator." - , architecture.getSourcePosition()); - } - } - - //check cocos with CNNArchCocos.checkAll(architecture) before calling this method. - public void generateFiles(ArchitectureSymbol architecture) throws IOException{ - Map fileContentMap = generateStrings(architecture); - generateFromFilecontentsMap(fileContentMap); - } - - public void generateCMake(String rootModelName) { - Map fileContentMap = generateCMakeContent(rootModelName); - try { - generateFromFilecontentsMap(fileContentMap); - } catch (IOException e) { - Log.error("CMake file could not be generated" + e.getMessage()); - } - } - - private void generateFromFilecontentsMap(Map fileContentMap) throws IOException { + public void generateFromFilecontentsMap(Map fileContentMap) throws IOException { GeneratorCPP genCPP = new GeneratorCPP(); genCPP.setGenerationTargetPath(getGenerationTargetPath()); for (String fileName : fileContentMap.keySet()){ -- GitLab