Added 2 new cocos for memory layers

parent 9dd5761f
......@@ -60,6 +60,7 @@ public class CNNArchCocos {
.addCoCo(new CheckLayerVariableDeclarationLayerType())
.addCoCo(new CheckLayerVariableDeclarationIsUsed())
.addCoCo(new CheckConstants())
.addCoCo(new CheckMemoryLayer())
.addCoCo(new CheckUnrollInputsOutputsTooMany());
}
......@@ -69,6 +70,7 @@ public class CNNArchCocos {
.addCoCo(new CheckVariableDeclarationName())
.addCoCo(new CheckVariableName())
.addCoCo(new CheckArgmaxLayer())
.addCoCo(new CheckReplayMemoryLayer())
.addCoCo(new CheckExpressions());
}
......
/**
*
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.monticore.lang.monticar.cnnarch._cocos;
import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureElementSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.LayerSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.ArgumentSymbol;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.se_rwth.commons.logging.Log;
import java.util.Optional;
import java.util.List;
public class CheckMemoryLayer extends CNNArchSymbolCoCo {
@Override
public void check(ArchitectureElementSymbol sym) {
if (sym instanceof LayerSymbol && sym.getName().equals("Memory")) {
checkMemoryLayer((LayerSymbol) sym);
}
}
public void checkMemoryLayer(LayerSymbol layer) {
List<ArgumentSymbol> arguments = layer.getArguments();
Integer subKeySize = new Integer(0);
Integer k = new Integer(0);
for (ArgumentSymbol arg : arguments) {
if (arg.getName().equals("subKeySize")) {
subKeySize = arg.getRhs().getIntValue().get();
} else if (arg.getName().equals("k")) {
k = arg.getRhs().getIntValue().get();
}
}
if (subKeySize < k) {
Log.error("0" + ErrorCodes.INVALID_MEMORY_LAYER_PARAMETERS +
" Invalid Memory layer Parameter values, subKeySize has to be greater or equal to k. ",
layer.getSourcePosition());
}
}
}
/**
*
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.cnnarch._cocos;
import de.monticore.lang.monticar.cnnarch._symboltable.StreamInstructionSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureElementSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.ParallelCompositeElementSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.SerialCompositeElementSymbol;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.se_rwth.commons.logging.Log;
import java.util.Optional;
import java.util.List;
public class CheckReplayMemoryLayer extends CNNArchSymbolCoCo {
@Override
public void check(StreamInstructionSymbol stream) {
List<ArchitectureElementSymbol> elements = stream.getBody().getElements();
for (ArchitectureElementSymbol element : elements){
if (element instanceof ParallelCompositeElementSymbol){
checkForReplayMemory((ParallelCompositeElementSymbol) element);
}
}
}
public void checkForReplayMemory(ParallelCompositeElementSymbol parallelElement) {
for (ArchitectureElementSymbol subStream: parallelElement.getElements()){
if (subStream instanceof SerialCompositeElementSymbol){ //should always be the case
for (ArchitectureElementSymbol element : ((SerialCompositeElementSymbol) subStream).getElements()){
if (element instanceof ParallelCompositeElementSymbol){
checkForReplayMemory((ParallelCompositeElementSymbol) element);
}
else if (element.getName().equals("ReplayMemory")) {
Log.error("0" + ErrorCodes.INVALID_REPLAY_MEMORY_LAYER_PLACEMENT +
" Invalid placement of ReplayMemory layer. It can't be placed inside a Prallalel execution block.",
element.getSourcePosition());
}
}
}
}
}
}
......@@ -37,6 +37,8 @@ public class ErrorCodes {
public static final String ILLEGAL_LAYER_USE = "x04845";
public static final String UNUSED_LAYER = "x04847";
public static final String INVALID_CONSTANT = "x04856";
public static final String INVALID_MEMORY_LAYER_PARAMETERS = "x04866";
public static final String INVALID_REPLAY_MEMORY_LAYER_PLACEMENT = "x04876";
public static final String OUTPUT_WRITTEN_TO_MULTIPLE_TIMES = "x04836";
public static final String UNROLL_INPUTS_TOO_MANY = "x02384";
public static final String UNROLL_OUTPUTS_TOO_MANY = "x02385";
......
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