Commit c995f497 authored by Carlos Alfredo Yeverino Rodriguez's avatar Carlos Alfredo Yeverino Rodriguez
Browse files

Merge branch 'master' into adapt_pending_predefined_layers

parents 1c2df21e 7a65ba70
...@@ -26,7 +26,8 @@ stages: ...@@ -26,7 +26,8 @@ stages:
masterJobLinux: masterJobLinux:
stage: linux stage: linux
image: maven:3-jdk-8 image: maven:3-jdk-8
script: script:
- apt-get update -q && apt-get install -y -q g++ libhdf5-serial-dev libhdf5-dev libopenblas-dev
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install deploy --settings settings.xml - mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install deploy --settings settings.xml
- cat target/site/jacoco/index.html - cat target/site/jacoco/index.html
- mvn package sonar:sonar -s settings.xml - mvn package sonar:sonar -s settings.xml
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<!-- .. SE-Libraries .................................................. --> <!-- .. SE-Libraries .................................................. -->
<CNNArch.version>0.2.7</CNNArch.version> <CNNArch.version>0.2.7</CNNArch.version>
<CNNTrain.version>0.2.5</CNNTrain.version> <CNNTrain.version>0.2.5</CNNTrain.version>
<embedded-montiarc-math-generator>0.0.25-20180812.120330-2</embedded-montiarc-math-generator> <embedded-montiarc-math-generator>0.1.2-SNAPSHOT</embedded-montiarc-math-generator>
<!-- .. Libraries .................................................. --> <!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version> <guava.version>18.0</guava.version>
...@@ -101,6 +101,11 @@ ...@@ -101,6 +101,11 @@
<version>${junit.version}</version> <version>${junit.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.3.0</version>
</dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
......
...@@ -24,6 +24,8 @@ import de.monticore.io.paths.ModelPath; ...@@ -24,6 +24,8 @@ 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.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.cnnarch._symboltable.CNNArchLanguage;
import de.monticore.lang.monticar.generator.FileContent; import de.monticore.lang.monticar.generator.FileContent;
...@@ -44,6 +46,16 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{ ...@@ -44,6 +46,16 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{
private String generationTargetPath; private String generationTargetPath;
private void supportCheck(ArchitectureSymbol architecture){
LayerSupportChecker layerChecker = new LayerSupportChecker();
for (ArchitectureElementSymbol element : ((CompositeElementSymbol)architecture.getBody()).getElements()){
if (!layerChecker.isSupported(element.toString())) {
Log.error("Unsupported layer " + "'" + element.getName() + "'" + " for the backend CAFFE2. Code generation aborted.");
System.exit(1);
}
}
}
public CNNArch2Caffe2() { public CNNArch2Caffe2() {
setGenerationTargetPath("./target/generated-sources-cnnarch/"); setGenerationTargetPath("./target/generated-sources-cnnarch/");
} }
...@@ -78,6 +90,7 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{ ...@@ -78,6 +90,7 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{
} }
CNNArchCocos.checkAll(compilationUnit.get()); CNNArchCocos.checkAll(compilationUnit.get());
supportCheck(compilationUnit.get().getArchitecture());
try{ try{
generateFiles(compilationUnit.get().getArchitecture()); generateFiles(compilationUnit.get().getArchitecture());
...@@ -157,6 +170,7 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{ ...@@ -157,6 +170,7 @@ public class CNNArch2Caffe2 implements CNNArchGenerator{
CMakeConfig cMakeConfig = new CMakeConfig(rootModelName); CMakeConfig cMakeConfig = new CMakeConfig(rootModelName);
cMakeConfig.addModuleDependency(new CMakeFindModule("Armadillo", true)); cMakeConfig.addModuleDependency(new CMakeFindModule("Armadillo", true));
cMakeConfig.addModuleDependency(new CMakeFindModule("Caffe2", true)); cMakeConfig.addModuleDependency(new CMakeFindModule("Caffe2", true));
cMakeConfig.addCMakeCommand("set(LIBS ${LIBS} -lprotobuf -lglog -lgflags)");
cMakeConfig.addCMakeCommand("find_package(CUDA)" + "\n" cMakeConfig.addCMakeCommand("find_package(CUDA)" + "\n"
+ "set(INCLUDE_DIRS ${INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS})" + "\n" + "set(INCLUDE_DIRS ${INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS})" + "\n"
+ "set(LIBS ${LIBS} ${CUDA_LIBRARIES} ${CUDA_curand_LIBRARY})" + "\n"); //Needed since CUDA cannot be found correctly (including CUDA_curand_LIBRARY) and as optional using CMakeFindModule + "set(LIBS ${LIBS} ${CUDA_LIBRARIES} ${CUDA_curand_LIBRARY})" + "\n"); //Needed since CUDA cannot be found correctly (including CUDA_curand_LIBRARY) and as optional using CMakeFindModule
......
package de.monticore.lang.monticar.cnnarch.caffe2generator;
import static de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedLayers.*;
import java.util.ArrayList;
import java.util.List;
public class LayerSupportChecker {
private List<String> unsupportedLayerList = new ArrayList();
public LayerSupportChecker() {
//Set the unsupported layers for the backend
this.unsupportedLayerList.add(ADD_NAME);
this.unsupportedLayerList.add(SPLIT_NAME);
this.unsupportedLayerList.add(GET_NAME);
this.unsupportedLayerList.add(CONCATENATE_NAME);
this.unsupportedLayerList.add(BATCHNORM_NAME);
}
public boolean isSupported(String element) {
return !this.unsupportedLayerList.contains(element);
}
}
...@@ -23,6 +23,7 @@ package de.monticore.lang.monticar.cnnarch.caffe2generator; ...@@ -23,6 +23,7 @@ package de.monticore.lang.monticar.cnnarch.caffe2generator;
import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Log;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
...@@ -30,9 +31,12 @@ import java.nio.file.Path; ...@@ -30,9 +31,12 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
public class GenerationTest extends AbstractSymtabTest{ public class GenerationTest extends AbstractSymtabTest{
@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();
@Before @Before
public void setUp() { public void setUp() {
...@@ -61,16 +65,8 @@ public class GenerationTest extends AbstractSymtabTest{ ...@@ -61,16 +65,8 @@ public class GenerationTest extends AbstractSymtabTest{
public void testAlexnetGeneration() throws IOException, TemplateException { public void testAlexnetGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); Log.getFindings().clear();
String[] args = {"-m", "src/test/resources/architectures", "-r", "Alexnet", "-o", "./target/generated-sources-cnnarch/"}; String[] args = {"-m", "src/test/resources/architectures", "-r", "Alexnet", "-o", "./target/generated-sources-cnnarch/"};
exit.expectSystemExit();
CNNArch2Caffe2Cli.main(args); CNNArch2Caffe2Cli.main(args);
assertTrue(Log.getFindings().isEmpty());
checkFilesAreEqual(
Paths.get("./target/generated-sources-cnnarch"),
Paths.get("./src/test/resources/target_code"),
Arrays.asList(
"CNNCreator_Alexnet.py",
"CNNPredictor_Alexnet.h",
"execute_Alexnet"));
} }
@Test @Test
...@@ -94,8 +90,8 @@ public class GenerationTest extends AbstractSymtabTest{ ...@@ -94,8 +90,8 @@ public class GenerationTest extends AbstractSymtabTest{
public void testThreeInputCNNGeneration() throws IOException, TemplateException { public void testThreeInputCNNGeneration() throws IOException, TemplateException {
Log.getFindings().clear(); Log.getFindings().clear();
String[] args = {"-m", "src/test/resources/architectures", "-r", "ThreeInputCNN_M14"}; String[] args = {"-m", "src/test/resources/architectures", "-r", "ThreeInputCNN_M14"};
exit.expectSystemExit();
CNNArch2Caffe2Cli.main(args); CNNArch2Caffe2Cli.main(args);
assertTrue(Log.getFindings().size() == 1);
} }
@Test @Test
......
...@@ -7,14 +7,15 @@ project(alexnet LANGUAGES CXX) ...@@ -7,14 +7,15 @@ project(alexnet LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# add dependencies # add dependencies
find_package(Caffe2 REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Caffe2_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Caffe2_LIBRARIES})
find_package(Armadillo REQUIRED) find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS}) set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES}) set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
find_package(Caffe2 REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Caffe2_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Caffe2_LIBRARIES})
# additional commands # additional commands
set(LIBS ${LIBS} -lprotobuf -lglog -lgflags)
find_package(CUDA) find_package(CUDA)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS}) set(INCLUDE_DIRS ${INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS})
set(LIBS ${LIBS} ${CUDA_LIBRARIES} ${CUDA_curand_LIBRARY}) set(LIBS ${LIBS} ${CUDA_LIBRARIES} ${CUDA_curand_LIBRARY})
...@@ -28,7 +29,7 @@ endif() ...@@ -28,7 +29,7 @@ endif()
# create static library # create static library
include_directories(${INCLUDE_DIRS}) include_directories(${INCLUDE_DIRS})
add_library(alexnet alexnet.h) add_library(alexnet alexnet.h)
target_include_directories(alexnet PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(alexnet PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})
target_link_libraries(alexnet PUBLIC ${LIBS}) target_link_libraries(alexnet PUBLIC ${LIBS})
set_target_properties(alexnet PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(alexnet PROPERTIES LINKER_LANGUAGE CXX)
......
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