Commit d337d40d authored by Svetlana Pavlitskaya's avatar Svetlana Pavlitskaya Committed by Evgeny Kusmenko

Implemented cmake support

parent 46929f12
......@@ -33,12 +33,12 @@ masterJobLinux:
only:
- master
#masterJobWindows:
# stage: windows
# script:
# - mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
# tags:
# - Windows10
masterJobWindows:
stage: windows
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
tags:
- Windows10
BranchJobLinux:
stage: linux
......
......@@ -8,15 +8,16 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>cnnarch-mxnet-generator</artifactId>
<version>0.2.3-SNAPSHOT</version>
<version>0.2.4-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
<properties>
<!-- .. SE-Libraries .................................................. -->
<CNNArch.version>0.2.4-SNAPSHOT</CNNArch.version>
<CNNArch.version>0.2.5-SNAPSHOT</CNNArch.version>
<CNNTrain.version>0.2.4-SNAPSHOT</CNNTrain.version>
<embedded-montiarc-math-generator>0.0.25-SNAPSHOT</embedded-montiarc-math-generator>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......@@ -86,6 +87,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>${embedded-montiarc-math-generator}</version>
</dependency>
<!-- .. Test Libraries ............................................... -->
<dependency>
......
......@@ -27,6 +27,9 @@ import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.CNNArchCompilationUnitSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.CNNArchLanguage;
import de.monticore.lang.monticar.cnntrain._symboltable.ConfigurationSymbol;
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.symboltable.GlobalScope;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
......@@ -45,6 +48,11 @@ public class CNNArch2MxNet implements CNNArchGenerator {
setGenerationTargetPath("./target/generated-sources-cnnarch/");
}
@Override
public boolean isCMakeRequired() {
return true;
}
public String getGenerationTargetPath() {
if (generationTargetPath.charAt(generationTargetPath.length() - 1) != '/') {
this.generationTargetPath = generationTargetPath + "/";
......@@ -141,9 +149,20 @@ public class CNNArch2MxNet implements CNNArchGenerator {
//check cocos with CNNArchCocos.checkAll(architecture) before calling this method.
public void generateFiles(ArchitectureSymbol architecture) throws IOException{
CNNArchTemplateController archTc = new CNNArchTemplateController(architecture);
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) {
e.printStackTrace();
}
}
private void generateFromFilecontentsMap(Map<String, String> fileContentMap) throws IOException {
for (String fileName : fileContentMap.keySet()){
File f = new File(getGenerationTargetPath() + fileName);
Log.info(f.getName(), "FileCreation:");
......@@ -159,4 +178,20 @@ public class CNNArch2MxNet implements CNNArchGenerator {
writer.close();
}
}
public Map<String, String> generateCMakeContent(String rootModelName) {
// model name should start with a lower case letter. If it is a component, replace dot . by _
rootModelName = rootModelName.replace('.', '_').replace('[', '_').replace(']', '_');
rootModelName = rootModelName.substring(0, 1).toLowerCase() + rootModelName.substring(1);
CMakeConfig cMakeConfig = new CMakeConfig(rootModelName);
cMakeConfig.addModuleDependency(new CMakeFindModule("Armadillo", true));
cMakeConfig.addCMakeCommandEnd("set(LIBS ${LIBS} mxnet)");
Map<String,String> fileContentMap = new HashMap<>();
for (FileContent fileContent : cMakeConfig.generateCMakeFiles()){
fileContentMap.put(fileContent.getFileName(), fileContent.getFileContent());
}
return fileContentMap;
}
}
......@@ -194,7 +194,7 @@ public class GenerationTest extends AbstractSymtabTest{
}
@Test
public void testSimpleCfgGeneration() throws IOException, TemplateException {
public void testSimpleCfgGeneration() throws IOException {
Log.getFindings().clear();
List<ConfigurationSymbol> configurations = new ArrayList<>();
List<String> instanceName = Arrays.asList("main_net1", "main_net2");
......@@ -230,7 +230,7 @@ public class GenerationTest extends AbstractSymtabTest{
}
@Test
public void testEmptyCfgGeneration() throws IOException, TemplateException {
public void testEmptyCfgGeneration() throws IOException {
Log.getFindings().clear();
List<ConfigurationSymbol> configurations = new ArrayList<>();
List<String> instanceName = Arrays.asList("main_net1");
......@@ -259,4 +259,29 @@ public class GenerationTest extends AbstractSymtabTest{
Arrays.asList(
"CNNTrainer_mainEmpty.py"));
}
@Test
public void testCMakeGeneration() {
Log.getFindings().clear();
String rootModelName = "alexnet";
CNNArch2MxNet generator = new CNNArch2MxNet();
generator.setGenerationTargetPath("./target/generated-sources-cnnarch");
generator.generateCMake(rootModelName);
assertTrue(Log.getFindings().isEmpty());
checkFilesAreEqual(
Paths.get("./target/generated-sources-cnnarch"),
Paths.get("./src/test/resources/target_code"),
Arrays.asList(
"CMakeLists.txt"));
checkFilesAreEqual(
Paths.get("./target/generated-sources-cnnarch/cmake"),
Paths.get("./src/test/resources/target_code/cmake"),
Arrays.asList(
"FindArmadillo.cmake"));
}
}
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
project(alexnet LANGUAGES CXX)
#set cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# add dependencies
find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional commands
# create static library
include_directories(${INCLUDE_DIRS})
add_library(alexnet alexnet.h)
target_include_directories(alexnet PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(alexnet PUBLIC ${LIBS})
set_target_properties(alexnet PROPERTIES LINKER_LANGUAGE CXX)
# export cmake project
export(TARGETS alexnet FILE alexnet.cmake)
# additional commands end
set(LIBS ${LIBS} mxnet)
# Automatically generated file
#
# - Try to find Armadillo
# Once done this will define
# Armadillo_FOUND - System has Armadillo
# Armadillo_INCLUDE_DIRS - The Armadillo include directories
# Armadillo_LIBRARY_DIRS - The library directories needed to use Armadillo
# Armadillo_LIBRARIES - The libraries needed to use Armadillo
find_path(Armadillo_INCLUDE_DIR
NAMES armadillo
PATH_SUFFIXES "include"
PATHS
HINTS $ENV{Armadillo_HOME}
)
find_library(Armadillo_LIBRARY
NAMES armadillo
PATH_SUFFIXES "lib" "lib64" "lib/x86_64-linux-gnu" "examples/lib_win64" "build" "Release"
PATHS
HINTS $ENV{Armadillo_HOME}
)
include(FindPackageHandleStandardArgs)
# if all listed variables are TRUE
find_package_handle_standard_args(
Armadillo
DEFAULT_MSG
Armadillo_INCLUDE_DIR
Armadillo_LIBRARY
)
mark_as_advanced(
Armadillo_INCLUDE_DIR
Armadillo_LIBRARY
)
set(Armadillo_INCLUDE_DIRS ${Armadillo_INCLUDE_DIR})
set(Armadillo_LIBRARIES ${Armadillo_LIBRARY})
\ No newline at end of file
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