Commit fa320623 authored by Sebastian Nickels's avatar Sebastian Nickels

Removed unroll related stuff for merge

parent cd421d5f
Pipeline #157639 passed with stages
in 16 minutes and 50 seconds
......@@ -25,10 +25,6 @@ grammar CNNArch extends de.monticore.CommonExpressions, de.monticore.lang.Math,
parameters:(LayerParameter || ",")* ")" "{"
body:Stream "}";
UnrollDeclaration = "unroll" "<" timeParameter:LayerParameter ">"
Name "(" parameters:(LayerParameter || ",")* ")"
"{" body:Stream "}";
IODeclaration = "def"
(in:"input" | out:"output")
type:ArchType
......@@ -57,8 +53,7 @@ grammar CNNArch extends de.monticore.CommonExpressions, de.monticore.lang.Math,
@attribute body
The architecture of the neural network.
*/
Architecture = unrollDeclarations:UnrollDeclaration*
methodDeclaration:LayerDeclaration*
Architecture = methodDeclaration:LayerDeclaration*
instructions:(Instruction || ";")+ ";";
interface Instruction;
......@@ -73,10 +68,6 @@ grammar CNNArch extends de.monticore.CommonExpressions, de.monticore.lang.Math,
Layer implements ArchitectureElement = Name "(" arguments:(ArchArgument || ",")* ")";
Unroll implements ArchitectureElement = "unroll" "<" timeParameter:LayerParameter ">"
Name "(" arguments:(ArchArgument || ",")* ")"
"{" body:Stream "}";
ParallelBlock implements ArchitectureElement = "("
groups:Stream "|"
groups:(Stream || "|")+ ")";
......
......@@ -33,9 +33,6 @@ public class CNNArchSymbolCoCo {
else if (sym instanceof LayerDeclarationSymbol){
check((LayerDeclarationSymbol) sym);
}
else if (sym instanceof UnrollDeclarationSymbol){
check((UnrollDeclarationSymbol) sym);
}
else if (sym instanceof ArchitectureElementSymbol){
check((ArchitectureElementSymbol) sym);
}
......@@ -75,10 +72,6 @@ public class CNNArchSymbolCoCo {
//Override if needed
}
public void check(UnrollDeclarationSymbol sym){
//Override if needed
}
public void check(ArchitectureElementSymbol sym){
//Override if needed
}
......
......@@ -24,8 +24,6 @@ import de.monticore.lang.monticar.cnnarch._ast.ASTArchArgument;
import de.monticore.lang.monticar.cnnarch._symboltable.ArgumentSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.LayerDeclarationSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.LayerSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.UnrollDeclarationSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.UnrollSymbol;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.logging.Log;
......@@ -45,14 +43,6 @@ public class CheckArgument implements CNNArchASTArchArgumentCoCo {
, node.get_SourcePositionStart());
}
}else if(argument.getEnclosingScope().getSpanningSymbol().get() instanceof UnrollSymbol){
UnrollDeclarationSymbol layerDeclaration = argument.getUnroll().getDeclaration();
if (layerDeclaration != null && argument.getParameter() == null){
Log.error("0"+ ErrorCodes.UNKNOWN_ARGUMENT + " Unknown Argument. " +
"Parameter with name '" + node.getName() + "' does not exist. " +
"Possible arguments are: " + Joiners.COMMA.join(layerDeclaration.getParameters())
, node.get_SourcePositionStart());
}
}
}
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch._cocos;
import de.monticore.commonexpressions._ast.ASTArguments;
import de.monticore.lang.monticar.cnnarch._ast.ASTArchArgument;
import de.monticore.lang.monticar.cnnarch._ast.ASTLayer;
import de.monticore.lang.monticar.cnnarch._ast.ASTLayerParameter;
import de.monticore.lang.monticar.cnnarch._ast.ASTUnroll;
import de.monticore.lang.monticar.cnnarch._symboltable.*;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.logging.Log;
import java.util.HashSet;
import java.util.Set;
public class CheckUnroll implements CNNArchASTUnrollCoCo{
@Override
public void check(ASTUnroll node) {
Set<String> nameSet = new HashSet<>();
for (ASTArchArgument argument : node.getArgumentsList()){
String name = argument.getName();
if (nameSet.contains(name)){
Log.error("0" + ErrorCodes.DUPLICATED_ARG + " Duplicated name: " + name +
". Multiple values assigned to the same argument."
, argument.get_SourcePositionStart());
}
else {
nameSet.add(name);
}
}
LayerDeclarationSymbol layerDeclaration = ((LayerSymbol) node.getSymbolOpt().get()).getDeclaration();
if (layerDeclaration == null){
ArchitectureSymbol architecture = node.getSymbolOpt().get().getEnclosingScope().<ArchitectureSymbol>resolve("", ArchitectureSymbol.KIND).get();
Log.error("0" + ErrorCodes.UNKNOWN_LAYER + " Unknown layer. " +
"Layer with name '" + node.getName() + "' does not exist. " +
"Existing layers: " + Joiners.COMMA.join(architecture.getLayerDeclarations()) + "."
, node.get_SourcePositionStart());
}
else {
Set<String> requiredArguments = new HashSet<>();
for (VariableSymbol param : layerDeclaration.getParameters()){
if (!param.getDefaultExpression().isPresent()){
requiredArguments.add(param.getName());
}
}
for (ASTArchArgument argument : node.getArgumentsList()){
requiredArguments.remove(argument.getName());
}
for (String missingArgumentName : requiredArguments){
Log.error("0"+ErrorCodes.MISSING_ARGUMENT + " Missing argument. " +
"The argument '" + missingArgumentName + "' is required."
, node.get_SourcePositionStart());
}
}
}
}
......@@ -59,10 +59,6 @@ public class ArgumentSymbol extends CommonSymbol {
return (LayerSymbol) getEnclosingScope().getSpanningSymbol().get();
}
public UnrollSymbol getUnroll() {
return (UnrollSymbol) getEnclosingScope().getSpanningSymbol().get();
}
public ArchExpressionSymbol getRhs() {
return rhs;
}
......
......@@ -241,28 +241,6 @@ public class CNNArchSymbolTableCreator extends de.monticore.symboltable.CommonSy
removeCurrentScope();
}
@Override
public void visit(ASTUnrollDeclaration ast) {
UnrollDeclarationSymbol unrollDeclaration = new UnrollDeclarationSymbol(ast.getName());
addToScopeAndLinkWithNode(unrollDeclaration, ast);
}
@Override
public void endVisit(ASTUnrollDeclaration ast) {
UnrollDeclarationSymbol unrollDeclaration = (UnrollDeclarationSymbol) ast.getSymbolOpt().get();
unrollDeclaration.setBody((SerialCompositeElementSymbol) ast.getBody().getSymbolOpt().get());
List<VariableSymbol> parameters = new ArrayList<>(4);
for (ASTLayerParameter astParam : ast.getParametersList()){
VariableSymbol parameter = (VariableSymbol) astParam.getSymbolOpt().get();
parameters.add(parameter);
}
unrollDeclaration.setParameters(parameters);
removeCurrentScope();
}
@Override
public void visit(ASTLayerParameter ast) {
VariableSymbol variable = new VariableSymbol(ast.getName());
......@@ -339,26 +317,6 @@ public class CNNArchSymbolTableCreator extends de.monticore.symboltable.CommonSy
sym.setElements(elements);
}
@Override
public void visit(ASTUnroll ast) {
UnrollSymbol layer = new UnrollSymbol("BeamSearchStart");
addToScopeAndLinkWithNode(layer, ast);
}
@Override
public void endVisit(ASTUnroll ast) {
UnrollSymbol layer = (UnrollSymbol) ast.getSymbolOpt().get();
List<ArgumentSymbol> arguments = new ArrayList<>(6);
for (ASTArchArgument astArgument : ast.getArgumentsList()){
Optional<ArgumentSymbol> optArgument = astArgument.getSymbolOpt().map(e -> (ArgumentSymbol)e);
optArgument.ifPresent(arguments::add);
}
layer.setArguments(arguments);
removeCurrentScope();
}
@Override
public void visit(ASTParallelBlock node) {
ParallelCompositeElementSymbol compositeElement = new ParallelCompositeElementSymbol();
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.symboltable.SymbolKind;
public class UnrollDeclarationKind implements SymbolKind {
private static final String NAME = "de.monticore.lang.monticar.cnnarch._symboltable.UnrollDeclarationKind";
@Override
public String getName() {
return NAME;
}
@Override
public boolean isKindOf(SymbolKind kind) {
return NAME.equals(kind.getName()) || SymbolKind.super.isKindOf(kind);
}
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.Symbol;
import java.util.Optional;
public class UnrollDeclarationScope extends de.monticore.symboltable.CommonScope {
public UnrollDeclarationScope() {
super(true);
}
public UnrollDeclarationScope(Optional<MutableScope> enclosingScope) {
super(enclosingScope, true);
}
@Override
public void add(Symbol symbol) {
super.add(symbol);
if (symbol instanceof ArchitectureElementSymbol){
ArchitectureElementScope subScope = ((ArchitectureElementSymbol) symbol).getSpannedScope();
addSubScope(subScope);
subScope.setResolvingFilters(getResolvingFilters());
}
}
}
\ No newline at end of file
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
/* generated by template symboltable.ScopeSpanningSymbol*/
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedVariables;
import de.monticore.symboltable.CommonScopeSpanningSymbol;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class UnrollDeclarationSymbol extends CommonScopeSpanningSymbol {
public static final UnrollDeclarationKind KIND = new UnrollDeclarationKind();
private List<VariableSymbol> parameters;
private SerialCompositeElementSymbol body;
protected UnrollDeclarationSymbol(String name) {
super(name, KIND);
}
@Override
protected UnrollDeclarationScope createSpannedScope() {
return new UnrollDeclarationScope();
}
@Override
public UnrollDeclarationScope getSpannedScope() {
return (UnrollDeclarationScope) super.getSpannedScope();
}
public List<VariableSymbol> getParameters() {
return parameters;
}
protected void setParameters(List<VariableSymbol> parameters) {
this.parameters = parameters;
if (!getParameter(AllPredefinedVariables.CONDITIONAL_ARG_NAME).isPresent()){
VariableSymbol ifParam = AllPredefinedVariables.createConditionalParameter();
this.parameters.add(ifParam);
ifParam.putInScope(getSpannedScope());
}
if (!getParameter(AllPredefinedVariables.SERIAL_ARG_NAME).isPresent()){
VariableSymbol forParam = AllPredefinedVariables.createSerialParameter();
this.parameters.add(forParam);
forParam.putInScope(getSpannedScope());
}
if (!getParameter(AllPredefinedVariables.PARALLEL_ARG_NAME).isPresent()){
VariableSymbol forParam = AllPredefinedVariables.createParallelParameter();
this.parameters.add(forParam);
forParam.putInScope(getSpannedScope());
}
}
public SerialCompositeElementSymbol getBody() {
return body;
}
protected void setBody(SerialCompositeElementSymbol body) {
this.body = body;
}
public boolean isPredefined() {
//Override by PredefinedUnrollDeclaration
return false;
}
public Optional<VariableSymbol> getParameter(String name) {
Optional<VariableSymbol> res = Optional.empty();
for (VariableSymbol parameter : getParameters()){
if (parameter.getName().equals(name)){
res = Optional.of(parameter);
}
}
return res;
}
public ArchitectureElementSymbol call(UnrollSymbol layer) throws ArchResolveException{
checkForSequence(layer.getArguments());
if (isPredefined()){
return layer;
}
else {
reset();
set(layer.getArguments());
SerialCompositeElementSymbol copy = getBody().preResolveDeepCopy();
copy.putInScope(getSpannedScope());
copy.resolveOrError();
getSpannedScope().remove(copy);
getSpannedScope().removeSubScope(copy.getSpannedScope());
reset();
return copy;
}
}
private void reset(){
for (VariableSymbol param : getParameters()){
param.reset();
}
}
private void set(List<ArgumentSymbol> arguments){
for (ArgumentSymbol arg : arguments){
arg.set();
}
}
private void checkForSequence(List<ArgumentSymbol> arguments){
boolean valid = true;
for (ArgumentSymbol arg : arguments){
if (arg.getRhs() instanceof ArchAbstractSequenceExpression){
valid = false;
}
}
if (!valid){
throw new IllegalArgumentException("Arguments with sequence expressions have to be resolved first before calling the layer method.");
}
}
public UnrollDeclarationSymbol deepCopy() {
UnrollDeclarationSymbol copy = new UnrollDeclarationSymbol(getName());
if (getAstNode().isPresent()){
copy.setAstNode(getAstNode().get());
}
List<VariableSymbol> parameterCopies = new ArrayList<>(getParameters().size());
for (VariableSymbol parameter : getParameters()){
VariableSymbol parameterCopy = parameter.deepCopy();
parameterCopies.add(parameterCopy);
parameterCopy.putInScope(copy.getSpannedScope());
}
copy.setParameters(parameterCopies);
copy.setBody(getBody().preResolveDeepCopy());
copy.getBody().putInScope(copy.getSpannedScope());
return copy;
}
/*public static class Builder{
private List<VariableSymbol> parameters = new ArrayList<>();
private CompositeElementSymbol body;
private String name = "";
public Builder parameters(List<VariableSymbol> parameters) {
this.parameters = parameters;
return this;
}
public Builder parameters(VariableSymbol... parameters) {
this.parameters = new ArrayList<>(Arrays.asList(parameters));
return this;
}
public Builder body(CompositeElementSymbol body) {
this.body = body;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public UnrollDeclarationSymbol build(){
if (name == null || name.equals("")){
throw new IllegalStateException("Missing or empty name for UnrollDeclarationSymbol");
}
UnrollDeclarationSymbol sym = new UnrollDeclarationSymbol(name);
sym.setBody(body);
if (body != null){
body.putInScope(sym.getSpannedScope());
}
for (VariableSymbol param : parameters){
param.putInScope(sym.getSpannedScope());
}
sym.setParameters(parameters);
return sym;
}
}*/
}
......@@ -2,15 +2,6 @@ architecture Alexnet(img_height=224, img_width=224, img_channels=3, classes=10){
def input Z(0:255)^{img_channels, img_height, img_width} data
def output Q(0:1)^{classes} predictions
unroll<t=5> beamSearchStart (width=5, max_length=50){
FullyConnected(units=4096) ->
Relu() ->
Dropout()
}
def split1(i){
[i] ->
Convolution(kernel=(5,5), channels=128) ->
......@@ -32,18 +23,10 @@ architecture Alexnet(img_height=224, img_width=224, img_channels=3, classes=10){
Dropout()
}
data ->
Convolution(kernel=(11,11), channels=96, stride=(4,4), padding="no_loss") ->
Lrn(nsize=5, alpha=0.0001, beta=0.75) ->
Pooling(pool_type="max", kernel=(3,3), stride=(2,2), padding="no_loss") ->
unroll<t> BeamSearchStart (width=5, max_length=50){
FullyConnected(units=4096) ->
Relu() ->
Dropout()
} ->
Relu() ->
Split(n=2) ->
split1(i=[0|1]) ->
......@@ -53,7 +36,8 @@ architecture Alexnet(img_height=224, img_width=224, img_channels=3, classes=10){
Split(n=2) ->
split2(i=[0|1]) ->
Concatenate() ->
fc(->=2) ->
FullyConnected(units=10) ->
Softmax() ->
predictions;
}
\ 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