Commit e3dd6528 authored by Svetlana Pavlitskaya's avatar Svetlana Pavlitskaya
Browse files

Added backend option, edited tag. Tests are passing

parent 9d64c9e3
Pipeline #70368 passed with stage
in 3 minutes and 17 seconds
......@@ -3,6 +3,7 @@ package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema;
import de.monticore.lang.monticar.emadl.generator.EMADLAbstractSymtab;
import de.monticore.lang.monticar.emadl.generator.EMADLGeneratorCli;
import de.monticore.lang.monticar.generator.middleware.impls.CPPGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.EMADLGeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.ODVGenImpl;
......@@ -61,6 +62,8 @@ public final class DistributedTargetGeneratorCli {
.valueSeparator(',')
.build();
private static final Option OPTION_EMADL_BACKEND = EMADLGeneratorCli.OPTION_BACKEND;
public static final String GENERATOR_CPP = "cpp";
public static final String GENERATOR_EMADL = "emadlcpp";
public static final String GENERATOR_ROSCPP = "roscpp";
......@@ -85,6 +88,7 @@ public final class DistributedTargetGeneratorCli {
options.addOption(OPTION_ROOT_MODEL);
options.addOption(OPTION_OUTPUT_PATH);
options.addOption(OPTION_GENERATORS);
options.addOption(OPTION_EMADL_BACKEND);
return options;
}
......@@ -150,7 +154,8 @@ public final class DistributedTargetGeneratorCli {
}
if (generators.contains(GENERATOR_EMADL)) {
generator.add(new EMADLGeneratorImpl(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt())), "cpp");
String backendString = cliArgs.getOptionValue(OPTION_EMADL_BACKEND.getOpt());
generator.add(new EMADLGeneratorImpl(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()), backendString), "cpp");
}
if (generators.contains(GENERATOR_ROSCPP)) {
......
......@@ -7,18 +7,27 @@ import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.helpers.NameHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.TemplateHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class EMADLGeneratorImpl implements GeneratorImpl {
private String generationTargetPath;
private EMADLGenerator emadlGenerator;
final String DEFAULT_BACKEND = "MXNET";
public EMADLGeneratorImpl(String modelPath){
emadlGenerator = new EMADLGenerator(Backend.MXNET);
public EMADLGeneratorImpl(String modelPath, String backendString){
Optional<Backend> backend = Backend.getBackendFromString(backendString);
if (!backend.isPresent()){
Log.warn("specified backend " + backendString + " not supported. backend set to default value " + DEFAULT_BACKEND);
backend = Backend.getBackendFromString(DEFAULT_BACKEND);
}
emadlGenerator = new EMADLGenerator(backend.get());
emadlGenerator.setModelsPath(modelPath);
}
......
......@@ -21,6 +21,7 @@ public class CliTest{
private static final String INVALID_ROOT_MODEL_OPTION = "--root-model=invalid.invalid.addComp";
private static final String INVALID_GENERATOR_OPTION = "--generators=invalid";
private static final String INVALID_GENERATOR_EMPTY_OPTION = "--generators=";
public static final String RESNET_MODELNAME = "tests.emadlTests.resNet34";
@BeforeClass
public static void initLog(){
......@@ -99,50 +100,47 @@ public class CliTest{
@Test
public void testSingleEMADLGenerator(){
String targetDir = "target/cliTest/emadl_test/";
String modelName = "resNet34";
String targetDir = "target/cliTest/SingleEmadlTest/";
String[] args = {
"--models-dir=src/test/resources/tests/emadl_test/",
"--root-model="+modelName,
VALID_MODELS_DIR_OPTION,
"--root-model="+RESNET_MODELNAME,
"--generators=emadlcpp",
"--backend=MXNET",
"--output-dir=" + targetDir};
DistributedTargetGeneratorCli.main(args);
String[] positiveFileNames = getEMADLGeneratedFilesList(modelName, false);
String[] positiveFileNames = getEMADLGeneratedFilesList(false);
for (String positiveFileName : positiveFileNames) {
assertTrue(Files.exists(Paths.get(targetDir + positiveFileName)));
}
}
@Ignore
@Test
public void testEMADLAndRosGenerator(){
String targetDir = "target/cliTest/emadl_ros_test/";
String modelName = "resNet34";
String targetDir = "target/cliTest/EmadlRosTest/";
String[] args = {
"--models-dir=src/test/resources/tests/emadl_test/",
"--root-model="+modelName,
VALID_MODELS_DIR_OPTION,
"--root-model="+RESNET_MODELNAME,
"--generators=emadlcpp,roscpp",
"--backend=MXNET",
"--output-dir=" + targetDir};
DistributedTargetGeneratorCli.main(args);
String[] positiveFileNames = getEMADLGeneratedFilesList(true);
String[] positiveFileNames = getEMADLGeneratedFilesList(modelName, false);
assertTrue(LogConfig.getErrorCount() == 1);
for (String positiveFileName : positiveFileNames) {
assertTrue(Files.exists(Paths.get(targetDir + positiveFileName)));
}
}
private String[] getEMADLGeneratedFilesList(String modelName, boolean generateRosFiles) {
private String[] getEMADLGeneratedFilesList(boolean generateRosFiles) {
String modelName = RESNET_MODELNAME.replace('.', '_');
String[] generatedFiles = {
modelName + "/CMakeLists.txt",
modelName + "/cpp/CNNBufferFile.h",
modelName + "/cpp/CNNCreator_" + modelName + ".py",
modelName + "/cpp/CNNPredictor_" + modelName + ".h",
modelName + "/cpp/CNNTrainer_ResNet34.py",
modelName + "/cpp/CNNTrainer_tests_emadlTests_ResNet34.py",
modelName + "/cpp/CNNTranslator.h",
modelName + "/cpp/HelperA.h",
modelName + "/cpp/CMakeLists.txt",
......
......@@ -282,21 +282,19 @@ public class GenerationTest extends AbstractSymtabTest {
middlewareGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
public void testEMADLGeneration() throws IOException, TemplateException {
TaggingResolver taggingResolver = EMADLAbstractSymtab.createSymTabAndTaggingResolver(TEST_PATH + "tests/emadl_test/");
//register the middleware tag types
public void testEMADLMiddlewareGeneration() throws IOException, TemplateException {
TaggingResolver taggingResolver = EMADLAbstractSymtab.createSymTabAndTaggingResolver(TEST_PATH);
RosToEmamTagSchema.registerTagTypes(taggingResolver);
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("resNet34", ExpandedComponentInstanceSymbol.KIND).orElse(null);
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("tests.emadlTests.resNet34", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
// TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
MiddlewareGenerator middlewareGenerator = new MiddlewareGenerator();
middlewareGenerator.setGenerationTargetPath("./target/generated-sources-emadl-test/");
middlewareGenerator.add(new EMADLGeneratorImpl(TEST_PATH + "tests/emadl_test/"), "cpp");
// middlewareGenerator.add(new RosCppGenImpl(), "roscpp");
middlewareGenerator.setGenerationTargetPath("./target/generated-sources-emadl/");
middlewareGenerator.add(new EMADLGeneratorImpl(TEST_PATH, "MXNET"), "cpp");
middlewareGenerator.add(new RosCppGenImpl(), "roscpp");
middlewareGenerator.generate(componentInstanceSymbol, taggingResolver);
assertTrue(Log.getFindings().isEmpty());
......@@ -312,10 +310,11 @@ public class GenerationTest extends AbstractSymtabTest {
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
StarBridgeGenerator starBridgeGenerator = new StarBridgeGenerator();
starBridgeGenerator.setGenerationTargetPath("./target/generated-sources-emam/basicGeneration/src/");
starBridgeGenerator.add(new EMADLGeneratorImpl(TEST_PATH), "emadlcpp");
starBridgeGenerator.setGenerationTargetPath("./target/generated-sources-emadl-ros/");
starBridgeGenerator.add(new EMADLGeneratorImpl(TEST_PATH, "MXNET"), "cpp");
starBridgeGenerator.add(new RosCppGenImpl(), "roscpp");
starBridgeGenerator.generate(componentInstanceSymbol, taggingResolver);
assertTrue(Log.getFindings().isEmpty());
}
}
......@@ -8,4 +8,4 @@ configuration ResNet34{
learning_rate_decay:0.8
step_size:1000
}
}
}
\ No newline at end of file
package tests.emadlTests;
component ResNet34{
ports in Z(0:255)^{3, 224, 224} image,
out Q(0:1)^{1000} predictions;
......
package tests.emadlTests;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags ResNet34 {
tag resNet34.image with RosConnection = {topic=(/name1, std_msgs/Int32MultiArray)};
tag resNet34.predictions with RosConnection = {topic=(/name1, std_msgs/Float32MultiArray)};
tag resNet34.image with RosConnection = {topic=(/image, std_msgs/Int32MultiArray)};
tag resNet34.predictions with RosConnection = {topic=(/predictions, std_msgs/Float64MultiArray)};
}
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