From: Francis Russell Date: Tue, 17 Apr 2012 17:53:57 +0000 (+0100) Subject: Start work on different composition strategy. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=bcbc04c2001d64b375bfb76d0edb80a30e0266ea;p=francis%2Fofc.git Start work on different composition strategy. --- diff --git a/src/ofc/codegen/ProducerStatement.scala b/src/ofc/codegen/ProducerStatement.scala index 9bd9bb4..485781f 100644 --- a/src/ofc/codegen/ProducerStatement.scala +++ b/src/ofc/codegen/ProducerStatement.scala @@ -104,10 +104,12 @@ class ProducerStatement extends Statement { predicates +:= new Predicate(condition) } - def merge(statement: ProducerStatement) { - ranges ++= statement.ranges - predicates ++= statement.predicates - expressions ++= statement.expressions + def merge(statement: ProducerStatement) : ProducerStatement = { + val result = new ProducerStatement + result.ranges = ranges ++ statement.ranges + result.predicates = predicates ++ statement.predicates + result.expressions = expressions ++ statement.expressions + result } def toConcrete : Statement = { diff --git a/src/ofc/generators/onetep/Assignment.scala b/src/ofc/generators/onetep/Assignment.scala index 90d432b..36414b8 100644 --- a/src/ofc/generators/onetep/Assignment.scala +++ b/src/ofc/generators/onetep/Assignment.scala @@ -6,8 +6,6 @@ class Assignment(indexBindings: IndexBindings, lhs: DataSpace, rhs: IterationSpa def getOperands = List(rhs) def getSpatialIndices = Nil def getDiscreteIndices = Nil - def getPrefixFragment = new ProducerStatement - def getSuffixFragment = new ProducerStatement - def getBodyFragment = new ProducerStatement + def getProducer(ancestors: Map[IterationSpace, ProducerStatement]) = ancestors.get(rhs).get def getDataValue = new FloatLiteral(0.0) } diff --git a/src/ofc/generators/onetep/CodeGenerator.scala b/src/ofc/generators/onetep/CodeGenerator.scala index bd88eae..4d6737e 100644 --- a/src/ofc/generators/onetep/CodeGenerator.scala +++ b/src/ofc/generators/onetep/CodeGenerator.scala @@ -59,18 +59,14 @@ class CodeGenerator(indexBindings: IndexBindings) { // TODO: Until we can handle multi-operand nodes assert(space.getOperands.size < 2) - val result = new ProducerStatement - result.merge(space.getBodyFragment) - result.merge(space.getPrefixFragment) - result.merge(space.getSuffixFragment) - + var operandProducers : Map[IterationSpace, ProducerStatement] = Map.empty for(operand <- space.getOperands) { - val opStatement = buildStatement(operand) + val opProducer = buildStatement(operand) for(discreteIndex <- operand.getDiscreteIndices) indexBindings.getBindingIndex(discreteIndex) match { case Some(bindingIndex) => { val symbol = indexSymbols.get(bindingIndex).get - val newData = opStatement.addPredicate(symbol |==| discreteIndex.getValue) + val newData = opProducer.addPredicate(symbol |==| discreteIndex.getValue) } case _ => () } @@ -78,14 +74,15 @@ class CodeGenerator(indexBindings: IndexBindings) { for(spatialIndex <- operand.getSpatialIndices) indexBindings.getBindingIndex(spatialIndex) match { case Some(bindingIndex) => { val symbol = indexSymbols.get(bindingIndex).get - val newData = opStatement.addPredicate(symbol |==| spatialIndex.getValue) + val newData = opProducer.addPredicate(symbol |==| spatialIndex.getValue) } case _ => () } - result.merge(opStatement) + operandProducers += operand -> opProducer } - result + + space.getProducer(operandProducers) } def generateCode(space: IterationSpace) { diff --git a/src/ofc/generators/onetep/DataSpaceIndexBinding.scala b/src/ofc/generators/onetep/DataSpaceIndexBinding.scala deleted file mode 100644 index ce74c84..0000000 --- a/src/ofc/generators/onetep/DataSpaceIndexBinding.scala +++ /dev/null @@ -1,9 +0,0 @@ -package ofc.generators.onetep -import ofc.codegen.NullStatement - -class DataSpaceIndexBinding(operand: DataSpace) extends DataSpace { - def getSpatialIndices = operand.getSpatialIndices - def getDiscreteIndices = Nil - def getDataValue = operand.getDataValue - def getSuffixFragment = operand.getSuffixFragment -} diff --git a/src/ofc/generators/onetep/IterationSpace.scala b/src/ofc/generators/onetep/IterationSpace.scala index 1770e75..d159245 100644 --- a/src/ofc/generators/onetep/IterationSpace.scala +++ b/src/ofc/generators/onetep/IterationSpace.scala @@ -27,16 +27,13 @@ trait IterationSpace { val operands = getOperands operands.toSet ++ operands.flatMap(_.getDependencies) } - - def getBodyFragment : ProducerStatement - def getPrefixFragment : ProducerStatement - def getSuffixFragment : ProducerStatement + def getProducer(ancestors: Map[IterationSpace, ProducerStatement]) : ProducerStatement } trait DataSpace extends IterationSpace { def getOperands = Nil - def getPrefixFragment = new ProducerStatement - def getBodyFragment = new ProducerStatement + def getProducer(ancestors: Map[IterationSpace, ProducerStatement]) = this.getProducer + def getProducer : ProducerStatement } trait Matrix extends DataSpace diff --git a/src/ofc/generators/onetep/IterationSpaceIndexBinding.scala b/src/ofc/generators/onetep/IterationSpaceIndexBinding.scala deleted file mode 100644 index 94e11a1..0000000 --- a/src/ofc/generators/onetep/IterationSpaceIndexBinding.scala +++ /dev/null @@ -1,12 +0,0 @@ -package ofc.generators.onetep -import ofc.codegen.NullStatement - -class IterationSpaceIndexBinding(operand: IterationSpace) extends IterationSpace { - def getOperands = operand.getOperands - def getSpatialIndices = operand.getSpatialIndices - def getDiscreteIndices = Nil - def getDataValue = operand.getDataValue - def getBodyFragment = operand.getBodyFragment - def getSuffixFragment = operand.getSuffixFragment - def getPrefixFragment = operand.getPrefixFragment -} diff --git a/src/ofc/generators/onetep/PPDFunctionSet.scala b/src/ofc/generators/onetep/PPDFunctionSet.scala index 1ecd583..60d3918 100644 --- a/src/ofc/generators/onetep/PPDFunctionSet.scala +++ b/src/ofc/generators/onetep/PPDFunctionSet.scala @@ -100,7 +100,7 @@ class PPDFunctionSet private(discreteIndices: Seq[DiscreteIndex], spatialIndices: Seq[SpatialIndex], data: Expression[FloatType], producer: ProducerStatement) extends FunctionSet { - def getSuffixFragment = producer + def getProducer = producer def getDiscreteIndices = discreteIndices def getSpatialIndices = spatialIndices def getDataValue = data diff --git a/src/ofc/generators/onetep/SPAM3.scala b/src/ofc/generators/onetep/SPAM3.scala index c22b353..6c50428 100644 --- a/src/ofc/generators/onetep/SPAM3.scala +++ b/src/ofc/generators/onetep/SPAM3.scala @@ -8,5 +8,5 @@ class SPAM3(name : String) extends Matrix { def getSpatialIndices = Nil def getDiscreteIndices = Nil def getDataValue = new FloatLiteral(0.0) - def getSuffixFragment = new ProducerStatement + def getProducer = new ProducerStatement } diff --git a/src/ofc/generators/onetep/SpatialRestriction.scala b/src/ofc/generators/onetep/SpatialRestriction.scala index 65e74f4..4809345 100644 --- a/src/ofc/generators/onetep/SpatialRestriction.scala +++ b/src/ofc/generators/onetep/SpatialRestriction.scala @@ -47,10 +47,8 @@ class SpatialRestriction private(op: IterationSpace, spatialIndices: Seq[SpatialIndex], producer: ProducerStatement) extends IterationSpace { def getOperands = List(op) def getDiscreteIndices = Nil - def getPrefixFragment = new ProducerStatement - def getSuffixFragment = new ProducerStatement def getDataValue = op.getDataValue - def getBodyFragment = producer + def getProducer(ancestors: Map[IterationSpace, ProducerStatement]) = producer merge ancestors.get(op).get def getSpatialIndices = spatialIndices }