Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

CNNArch.mc4 7.94 KB
Newer Older
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
1
package de.monticore.lang.monticar;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
2

3
grammar CNNArch extends de.monticore.lang.monticar.Common2 {
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
4

5
    symbol scope CNNArchCompilationUnit = "architecture" Name& "{" Architecture "}";
6

7
    Architecture = defs:VarDef* inputStructure:InputStructure elements:ArchitectureElement*;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
8

9 10 11
    interface VarDef;
    symbol InputDef implements VarDef = "def" "input" Name& (ArrayDeclaration)?;
    symbol OutputDef implements VarDef = "def" "output" Name& (ArrayDeclaration)?;
12

13 14
    interface ArchitectureElement extends GroupElement;
    interface GroupElement;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
15
    interface Method;
16 17 18 19 20 21
    interface GroupMethod extends Method,GroupElement;
    interface MergeMethod extends Method;
    interface LayerMethod extends Method,ArchitectureElement;
    interface InputStructure;
    interface InputElement;
    interface ArgumentListing;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
22
    interface ArgumentAssignment;
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    interface GroupStructure;
    interface Group;

    SingleInput implements InputStructure,InputElement = input:Name@InputDef "->";
    ArrayInput implements InputElement = input:Name@InputDef "[" (index:UnitNumberResolution)? "]" "->";

    InputGroupStructure implements GroupStructure,InputStructure = groups:InputGroup+
                                                                   MergeStructure;


    OutputStructure implements ArchitectureElement = "output" (GroupOrdinalRange)? "{"
                                                     elements:ArchitectureElement* "}" "->"
                                                     output:Name@OutputDef;

    RepeatStructure implements ArchitectureElement = "repeat"
                                                     intLiteral:UnitNumberResolution "{"
                                                     ArchitectureElement* "}";

    StandardGroupStructure implements ArchitectureElement,GroupStructure = groups:StandardGroup+
                                                                           MergeStructure;



    MergeStructure = "merge" method:MergeMethod;

    StandardGroup implements Group = declaration:GroupDeclaration "{"
                                     body:GroupBody "}";

    InputGroup implements Group = declaration:GroupDeclaration "{"
                                  input:InputElement
                                  body:GroupBody "}";

    GroupDeclaration = "group" (GroupOrdinalRange|GroupOrdinal);
    GroupOrdinal = intLiteral:UnitNumberResolution;
    GroupOrdinalRange = startInt:UnitNumberResolution".."endInt:UnitNumberResolution;

    GroupBody = elements:GroupElement*;


Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
62

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
63
    ArgumentRhs = number:Number
64
                | tuple:Tuple
65 66 67
                | booleanVal:BooleanLiteral;
                //| type:ArgumentKeyword;

68
    Tuple = "(" values:Number "," values:(Number || ",")+ ")";
69 70 71 72 73
    //interface ArgumentKeyword;
    //ast ArgumentKeyword = method Optional<String> getName(){};



Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
74

75 76 77 78 79 80 81 82 83
    ast Method = method ASTArgumentListing getArgumentListing(){}
                 method Enum getType(){};
    ast ArgumentAssignment = method Enum getLhs(){}
                             method ASTArgumentRhs getRhs(){};
    //ast ArgumentListing = method java.util.List<? extends ASTArgumentAssignment> getArguments(){};
    ast InputElement = method String getInput(){}
                       method Optional<de.monticore.lang.monticar.cnnarch._symboltable.InputDefSymbol> getInputSymbol(){};
    ast Group = method ASTGroupDeclaration getDeclaration(){}
                method ASTGroupBody getBody(){};
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
84 85 86 87




88 89 90 91 92
    ConcatenateMethod implements MergeMethod = type:ConcatenateType "(" argumentListing:ConcatenateArgumentListing ")";
    ConcatenateArgumentListing implements ArgumentListing = arguments:(ConcatenateArgumentAssignment || ",")*;
    ConcatenateArgumentAssignment implements ArgumentAssignment = lhs:ConcatenateArgument "=" rhs:ArgumentRhs;
    enum ConcatenateArgument = "placeholder";
    enum ConcatenateType = "concatenate";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
93

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    AddMethod implements MergeMethod = type:AddType "(" argumentListing:AddArgumentListing ")";
    AddArgumentListing implements ArgumentListing = arguments:(AddArgumentAssignment|| ",")*;
    AddArgumentAssignment implements ArgumentAssignment = lhs:AddArgument "=" rhs:ArgumentRhs;
    enum AddArgument = "placeholder";
    enum AddType = "add";

    SplitMethod implements GroupMethod = type:SplitType "(" argumentListing:SplitArgumentListing ")";
    SplitArgumentListing implements ArgumentListing = arguments:(SplitArgumentAssignment || ",")*;
    SplitArgumentAssignment implements ArgumentAssignment = lhs:SplitArgument "=" rhs:ArgumentRhs;
    enum SplitArgument = "placeholder";
    enum SplitType = "split";


    ConvolutionMethod implements LayerMethod = type:ConvolutionType "(" argumentListing:ConvolutionArgumentListing ")";
    ConvolutionArgumentListing implements ArgumentListing = arguments:(ConvolutionArgumentAssignment || ",")*;
109
    ConvolutionArgumentAssignment implements ArgumentAssignment = lhs:ConvolutionArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
110
    enum ConvolutionArgument = KERNEL:"kernel"               //required
111
                             | FILTERS:"filters"             //required
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
112 113
                             | STRIDE:"stride"
                             | NOBIAS:"no_bias";
114
    enum ConvolutionType = "convolution";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
115

116 117
    FullyConnectedMethod implements LayerMethod = type:FullyConnectedType "(" argumentListing:FullyConnectedArgumentListing ")";
    FullyConnectedArgumentListing implements ArgumentListing = arguments:(FullyConnectedArgumentAssignment || ",")*;
118
    FullyConnectedArgumentAssignment implements ArgumentAssignment = lhs:FullyConnectedArgument "=" rhs:ArgumentRhs;
119
    enum FullyConnectedArgument = UNITS:"units"     //required
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
120
                                | NOBIAS:"no_bias";
121 122
    enum FullyConnectedType = "fullyConnected";

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
123

124 125
    ActivationMethod implements LayerMethod = "activation."type:ActivationType "(" argumentListing:ActivationArgumentListing ")";
    ActivationArgumentListing implements ArgumentListing = arguments:(ActivationArgumentAssignment || ",")*;
126
    ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:ArgumentRhs;
127 128 129 130 131
    enum ActivationArgument = "placeholder";
    enum ActivationType = "relu"
                        | "sigmoid"
                        | "tanh"
                        | "softmax";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
132

133 134 135

    PoolingMethod implements LayerMethod = "pooling."type:PoolingType "(" argumentListing:PoolingArgumentListing ")";
    PoolingArgumentListing implements ArgumentListing = arguments:(PoolingArgumentAssignment || ",")*;
136
    PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
137 138
    enum PoolingArgument = KERNEL:"kernel"                   //required
                         | STRIDE:"stride"
139 140 141
                         | Global:"global";
    enum PoolingType = "max"
                     | "avg";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
142 143


144 145 146 147 148
    DropoutMethod implements LayerMethod = type:DropoutType "(" argumentListing:DropoutArgumentListing ")";
    DropoutArgumentListing implements ArgumentListing = arguments:(DropoutArgumentAssignment || ",")*;
    DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:ArgumentRhs;
    enum DropoutArgument = P:"p";
    enum DropoutType = "dropout";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
149 150


151 152 153 154 155
    BatchNormMethod implements LayerMethod = type:BatchNormType "(" argumentListing:BatchNormArgumentListing ")";
    BatchNormArgumentListing implements ArgumentListing = arguments:(BatchNormArgumentAssignment || ",")*;
    BatchNormArgumentAssignment implements ArgumentAssignment = lhs:BatchNormArgument "=" rhs:ArgumentRhs;
    enum BatchNormArgument = "placeholder";
    enum BatchNormType = "batchNorm";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
156

157 158 159 160 161 162 163 164
    LrnMethod implements LayerMethod = type:LrnType "(" argumentListing:LrnArgumentListing ")";
    LrnArgumentListing implements ArgumentListing = arguments:(LrnArgumentAssignment || ",")*;
    LrnArgumentAssignment implements ArgumentAssignment = lhs:LrnArgument "=" rhs:ArgumentRhs;
    enum LrnArgument = NSIZE:"nsize"              //required
                     | ALPHA:"alpha"
                     | BETA:"beta"
                     | KNORM:"knorm";
    enum LrnType = "lrn";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
165

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
166
}