Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
CNNArch2X
Commits
aac37a40
Commit
aac37a40
authored
Sep 28, 2020
by
Malte Heithoff
Browse files
CNNArchGenerator now implements the Generator interface
parent
16a10f1e
Pipeline
#335891
canceled with stage
in 29 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/cnnarch/generator/CNNArchGenerator.java
View file @
aac37a40
...
...
@@ -4,21 +4,25 @@ package de.monticore.lang.monticar.cnnarch.generator;
import
de.monticore.io.paths.ModelPath
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.CNNArchLanguage
;
import
de.monticore.lang.monticar.generator.cmake.CMakeConfig
;
import
de.monticore.lang.monticar.generator.cmake.CMakeFindModule
;
import
de.monticore.lang.monticar.generator.Generator
;
import
de.monticore.lang.monticar.generator.FileContent
;
import
de.monticore.lang.monticar.generator.cpp.GeneratorCPP
;
import
de.monticore.lang.tagging._symboltable.TaggingResolver
;
import
de.monticore.symboltable.GlobalScope
;
import
de.monticore.symboltable.Scope
;
import
de.se_rwth.commons.logging.Log
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Arrays
;
import
java.util.LinkedList
;
import
java.util.List
;
public
abstract
class
CNNArchGenerator
{
public
abstract
class
CNNArchGenerator
implements
Generator
<
ArchitectureSymbol
>
{
private
boolean
generateCMake
=
false
;
protected
ArchitectureSupportChecker
architectureSupportChecker
;
protected
LayerSupportChecker
layerSupportChecker
;
...
...
@@ -35,8 +39,14 @@ public abstract class CNNArchGenerator {
System
.
exit
(
1
);
}
public
boolean
isCMakeRequired
()
{
return
true
;
@Override
public
boolean
isGenerateCMake
()
{
return
generateCMake
;
}
@Override
public
void
setGenerateCMake
(
boolean
generateCMake
)
{
this
.
generateCMake
=
generateCMake
;
}
public
String
getGenerationTargetPath
(){
...
...
@@ -58,7 +68,8 @@ public abstract class CNNArchGenerator {
this
.
modelsDirPath
=
modelsDirPath
.
toString
();
final
ModelPath
mp
=
new
ModelPath
(
modelsDirPath
);
GlobalScope
scope
=
new
GlobalScope
(
mp
,
new
CNNArchLanguage
());
generate
(
scope
,
rootModelName
);
TaggingResolver
tagging
=
new
TaggingResolver
(
scope
,
Arrays
.
asList
(
rootModelName
));
generate
(
tagging
,
rootModelName
);
}
// TODO: Rewrite so that CNNArchSymbolCompiler is used in EMADL2CPP instead of this method
...
...
@@ -66,9 +77,9 @@ public abstract class CNNArchGenerator {
return
architectureSupportChecker
.
check
(
architecture
)
&&
layerSupportChecker
.
check
(
architecture
);
}
public
void
generate
(
Scope
scope
,
String
rootModelName
){
public
void
generate
(
TaggingResolver
taggingResolver
,
String
rootModelName
){
CNNArchSymbolCompiler
symbolCompiler
=
new
CNNArchSymbolCompiler
(
architectureSupportChecker
,
layerSupportChecker
);
ArchitectureSymbol
architectureSymbol
=
symbolCompiler
.
compileArchitectureSymbol
(
scope
,
rootModelName
);
ArchitectureSymbol
architectureSymbol
=
symbolCompiler
.
compileArchitectureSymbol
(
taggingResolver
,
rootModelName
);
try
{
String
dataConfPath
=
getModelsDirPath
()
+
"/data_paths.txt"
;
...
...
@@ -86,37 +97,41 @@ public abstract class CNNArchGenerator {
}
architectureSymbol
.
setWeightsPath
(
weightsPath
);
architectureSymbol
.
setComponentName
(
rootModelName
);
generateFiles
(
architectureSymbol
);
generateFiles
(
taggingResolver
,
architectureSymbol
);
}
catch
(
IOException
e
){
Log
.
error
(
e
.
toString
());
}
}
//check cocos with CNNArchCocos.checkAll(architecture) before calling this method.
public
abstract
Map
<
String
,
String
>
generateStrings
(
ArchitectureSymbol
architecture
);
public
abstract
List
<
FileContent
>
generateStrings
(
TaggingResolver
taggingResolver
,
ArchitectureSymbol
architecture
);
//check cocos with CNNArchCocos.checkAll(architecture) before calling this method.
public
void
generateFiles
(
ArchitectureSymbol
architecture
)
throws
IOException
{
Map
<
String
,
String
>
fileContent
Map
=
generateStrings
(
architecture
);
generateFromFilecontentsMap
(
fileContent
Map
);
public
List
<
File
>
generateFiles
(
TaggingResolver
taggingResolver
,
ArchitectureSymbol
architecture
)
throws
IOException
{
List
<
FileContent
>
fileContent
s
=
generateStrings
(
taggingResolver
,
architecture
);
return
generateFromFilecontentsMap
(
fileContent
s
);
}
public
void
generateFromFilecontentsMap
(
Map
<
String
,
String
>
fileContentMap
)
throws
IOException
{
public
List
<
File
>
generateFromFilecontentsMap
(
List
<
FileContent
>
fileContents
)
throws
IOException
{
List
<
File
>
res
=
new
LinkedList
<>();
GeneratorCPP
genCPP
=
new
GeneratorCPP
();
genCPP
.
setGenerationTargetPath
(
getGenerationTargetPath
());
for
(
String
fileName
:
fileContent
Map
.
keySet
())
{
genCPP
.
generateFile
(
new
FileContent
(
fileContentMap
.
get
(
fileName
),
fileName
));
for
(
FileContent
fileContent
:
fileContent
s
)
{
res
.
add
(
genCPP
.
generateFile
(
fileContent
));
}
return
res
;
}
public
void
generateCMake
(
String
rootModelName
){
Map
<
String
,
String
>
fileContent
Map
=
generateCMakeContent
(
rootModelName
);
List
<
FileContent
>
fileContent
s
=
generateCMakeContent
(
rootModelName
);
try
{
generateFromFilecontentsMap
(
fileContent
Map
);
generateFromFilecontentsMap
(
fileContent
s
);
}
catch
(
IOException
e
)
{
Log
.
error
(
"CMake file could not be generated"
+
e
.
getMessage
());
}
}
public
abstract
Map
<
String
,
String
>
generateCMakeContent
(
String
rootModelName
);
public
abstract
List
<
FileContent
>
generateCMakeContent
(
String
rootModelName
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment