Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
CNNArch2Gluon
Commits
100af92f
Commit
100af92f
authored
Feb 22, 2019
by
Carlos Alfredo Yeverino Rodriguez
Browse files
Merge branch 'change_cnnarchinterface_to_abstractclass' into 'master'
change CNNArchGenerator to an abstract class See merge request
!7
parents
b285e4eb
1d392645
Pipeline
#107489
passed with stages
in 3 minutes and 53 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
100af92f
...
...
@@ -15,7 +15,7 @@
<properties>
<!-- .. SE-Libraries .................................................. -->
<CNNArch.version>
0.2.
8
</CNNArch.version>
<CNNArch.version>
0.2.
9
</CNNArch.version>
<CNNTrain.version>
0.2.6
</CNNTrain.version>
<embedded-montiarc-math-opt-generator>
0.1.4
</embedded-montiarc-math-opt-generator>
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/gluongenerator/CNNArch2Gluon.java
View file @
100af92f
...
...
@@ -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
<
ArchitectureElementSymbol
>
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
<
CNNArchCompilationUnitSymbol
>
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
<
String
,
String
>
fileContentMap
=
generateStrings
(
architecture
);
generateFromFilecontentsMap
(
fileContentMap
);
}
public
void
generateCMake
(
String
rootModelName
)
{
Map
<
String
,
String
>
fileContentMap
=
generateCMakeContent
(
rootModelName
);
try
{
generateFromFilecontentsMap
(
fileContentMap
);
}
catch
(
IOException
e
)
{
Log
.
error
(
"CMake file could not be generated"
+
e
.
getMessage
());
}
}
private
void
generateFromFilecontentsMap
(
Map
<
String
,
String
>
fileContentMap
)
throws
IOException
{
public
void
generateFromFilecontentsMap
(
Map
<
String
,
String
>
fileContentMap
)
throws
IOException
{
GeneratorCPP
genCPP
=
new
GeneratorCPP
();
genCPP
.
setGenerationTargetPath
(
getGenerationTargetPath
());
for
(
String
fileName
:
fileContentMap
.
keySet
()){
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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