From: Francis Russell Date: Tue, 3 Apr 2012 18:16:01 +0000 (+0100) Subject: More work on characterising producers. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=4c761ba2e48709d5fccc68b2b3c46aee9cc35422;p=francis%2Fofc.git More work on characterising producers. --- diff --git a/src/ofc/codegen/Expression.scala b/src/ofc/codegen/Expression.scala index 3036318..7f132bf 100644 --- a/src/ofc/codegen/Expression.scala +++ b/src/ofc/codegen/Expression.scala @@ -4,8 +4,6 @@ class Expression { def %(field: FieldSymbol) : Expression = new FieldAccess(this, field) def readAt(index: List[Expression]) : Expression = new ArrayRead(this, index) def apply(index: Expression*) : Expression = this.readAt(index.toList) - - implicit def fromInt(value: Int) : Expression = new IntegerLiteral(value) } // Variable references diff --git a/src/ofc/codegen/IterationTemplate.scala b/src/ofc/codegen/IterationTemplate.scala deleted file mode 100644 index c7ea71e..0000000 --- a/src/ofc/codegen/IterationTemplate.scala +++ /dev/null @@ -1,4 +0,0 @@ -package ofc.codegen - -class IterationTemplate(statement: Statement) { -} diff --git a/src/ofc/codegen/ProducerStatement.scala b/src/ofc/codegen/ProducerStatement.scala new file mode 100644 index 0000000..96c119a --- /dev/null +++ b/src/ofc/codegen/ProducerStatement.scala @@ -0,0 +1,23 @@ +package ofc.codegen + +class ProducerStatement extends Statement { + class VariableRange(symbol: Symbol, count: Expression) + class Predicate + + var statement = new NullStatement + var ranges : List[VariableRange] = List.empty + var predicates : List[Predicate] = List.empty + var expressions : Map[Symbol, Expression] = Map.empty + + def addExpression(name: String, expression: Expression) : VarSymbol = { + val symbol = new DeclaredVarSymbol(name) + expressions += symbol -> expression + symbol + } + + def addIteration(name: String, count: Expression) : VarSymbol = { + val symbol = new DeclaredVarSymbol(name) + ranges +:= new VariableRange(symbol, count) + symbol + } +} diff --git a/src/ofc/codegen/ScopeStatement.scala b/src/ofc/codegen/ScopeStatement.scala index 22cbf32..4606ead 100644 --- a/src/ofc/codegen/ScopeStatement.scala +++ b/src/ofc/codegen/ScopeStatement.scala @@ -1,6 +1,12 @@ package ofc.codegen +import scala.collection.mutable.ArrayBuffer + +class ScopeStatement(initialStatements: List[Statement]) extends Statement { + + val statements = initialStatements.toBuffer -class ScopeStatement(var statements: List[Statement]) extends Statement { def this() = this(List.empty) - def +=(stat: Statement) = statements += stat + def +=(stat: Statement) { + statements += stat + } } diff --git a/src/ofc/generators/onetep/IterationSpace.scala b/src/ofc/generators/onetep/IterationSpace.scala index 6b6ff2e..70f86a7 100644 --- a/src/ofc/generators/onetep/IterationSpace.scala +++ b/src/ofc/generators/onetep/IterationSpace.scala @@ -1,5 +1,5 @@ package ofc.generators.onetep -import ofc.codegen.IterationTemplate +import ofc.codegen.{Statement,NullStatement} /* object IterationSpace { @@ -28,11 +28,13 @@ trait IterationSpace { val operands = getOperands operands.toSet ++ operands.flatMap(_.getDependencies) } - def getReader : IterationTemplate + def getReaderFragment : Statement + def getSuffixFragment : Statement } trait DataSpace extends IterationSpace { def getOperands = Nil + def getReaderFragment = new NullStatement } trait Matrix extends DataSpace diff --git a/src/ofc/generators/onetep/PPDFunctionSet.scala b/src/ofc/generators/onetep/PPDFunctionSet.scala index 175bf85..346e239 100644 --- a/src/ofc/generators/onetep/PPDFunctionSet.scala +++ b/src/ofc/generators/onetep/PPDFunctionSet.scala @@ -7,14 +7,22 @@ class PPDFunctionSet(val basisName: String, dataName: String) extends FunctionSe val pubCell = NamedUnboundVarSymbol("pub_cell") val numSpheres = basis % FieldSymbol("num"); - val ppdWidths = for(dim <- 1 to 3) yield pubCell % FieldSymbol("n_ppds_a"+dim) + val ppdWidths = for(dim <- 1 to 3) yield pubCell % FieldSymbol("n_pt"+dim) + val cellWidthInPPDs = for(dim <- 1 to 3) yield pubCell % FieldSymbol("n_ppds_a"+dim) - def getReader = { - var sphereIndex = new IterationSymbol("sphere_index", numSpheres) + def getSuffixFragment = { + val producer = new ProducerStatement + val sphereIndex = producer.addIteration("sphere_index", numSpheres) val numPPDs = (basis % FieldSymbol("n_ppds_sphere"))(sphereIndex) - val ppdIndex = new IterationSymbol("ppd_index", numPPDs) - val ppdRanges = for(dim <- 1 to 3) yield new IterationSymbol("point"+dim, ppdWidths(dim)) - new IterationTemplate(sphereLoop) + val ppdIndex = producer.addIteration("ppd_index", numPPDs) + val ppdGlobalCount = (basis % FieldSymbol("ppd_list"))(ppdIndex, new IntegerLiteral(1)) + + // We need to calculate the integer co-ordinates of the PPD + + //val ppdRanges = for(dim <- 0 to 2) yield producer.addIteration("point"+(dim+1), ppdWidths(dim)) + val tightbox = basis % FieldSymbol("tight_boxes") + + producer } def getDiscreteIndices = List.empty