]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Start work on assignment iteration.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Tue, 8 May 2012 08:56:09 +0000 (09:56 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Tue, 8 May 2012 08:56:09 +0000 (09:56 +0100)
13 files changed:
src/ofc/codegen/FortranGenerator.scala
src/ofc/codegen/IterationContext.scala [moved from src/ofc/codegen/IteratedStatement.scala with 95% similarity]
src/ofc/generators/onetep/Field.scala
src/ofc/generators/onetep/InnerProduct.scala
src/ofc/generators/onetep/Laplacian.scala
src/ofc/generators/onetep/OnetepTypes.scala
src/ofc/generators/onetep/OnetepVariables.scala [new file with mode: 0644]
src/ofc/generators/onetep/Operand.scala [new file with mode: 0644]
src/ofc/generators/onetep/PPDFunctionSet.scala
src/ofc/generators/onetep/SPAM3.scala
src/ofc/generators/onetep/Scalar.scala
src/ofc/generators/onetep/ScalarLiteral.scala
src/ofc/generators/onetep/ScaledField.scala

index efccf6d312eb3326e6006381745a00cb08da8e63..aa73dd16e95857ebb91b2c8752a388872a2d9a6c 100644 (file)
@@ -139,7 +139,7 @@ class FortranGenerator {
       case (x : NullStatement) => ()
       case (x : Comment) => addLine("!" + x.getValue)
       case (x : BlockStatement) => processScope(x)
-      case (x : IteratedStatement) => processStatement(x.toConcrete)
+      case (x : IterationContext) => processStatement(x.toConcrete)
       case (x : ForLoop) => processForLoop(x)
       case (a : AssignStatement) => processAssignment(a)
       case (i : IfStatement) => processIf(i)
similarity index 95%
rename from src/ofc/codegen/IteratedStatement.scala
rename to src/ofc/codegen/IterationContext.scala
index c50b3b1db685df4762f73e94c99bdaec3d46e81c..c6876aa0e87be8cb95aaaa3e02405413cb5ca350 100644 (file)
@@ -2,7 +2,7 @@ package ofc.codegen
 import ofc.LogicError
 import ofc.util.DirectedGraph
 
-object IteratedStatement {
+object IterationContext {
   object Context {
     private def priority(context: Context) : Int = {
       // This ensures that the nesting ordering is Predicate, DerivedExpression, VariableRange
@@ -80,8 +80,8 @@ object IteratedStatement {
   }
 }
 
-class IteratedStatement extends Statement {
-  import IteratedStatement._
+class IterationContext extends Statement {
+  import IterationContext._
 
   var statement = new Comment("Placeholder statement for consumer.")
   var ranges : Seq[VariableRange] = Nil
@@ -104,8 +104,8 @@ class IteratedStatement extends Statement {
     predicates +:= new Predicate(condition)
   }
 
-  def merge(statement: IteratedStatement) : IteratedStatement = {
-    val result = new IteratedStatement
+  def merge(statement: IterationContext) : IterationContext = {
+    val result = new IterationContext
     result.ranges = ranges ++ statement.ranges
     result.predicates = predicates ++ statement.predicates
     result.expressions = expressions ++ statement.expressions
index 1e8514cbb74d8773a1e5ee93825ede6e139f5fd7..86d16c7bde389c234b24d50e1a62a86abafb52c6 100644 (file)
@@ -1,6 +1,6 @@
 package ofc.generators.onetep
 import ofc.codegen._
 
-trait Field {
+trait Field extends Operand {
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) : FieldFragment
 }
index 67e41343f6f093a98e6541d22566830c19f196f2..b13220be13d9e3bc5eca1b20fe3224c38a02aea8 100644 (file)
@@ -56,4 +56,10 @@ class InnerProduct(left: Field, right: Field) extends Scalar {
 
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) : ScalarFragment = 
     new LocalFragment(left.getFragment(indices), right.getFragment(indices))
+
+  def getIterationInfo : IterationInfo = {
+    var leftInfo = left.getIterationInfo
+    var rightInfo = right.getIterationInfo
+    leftInfo merge rightInfo
+  }
 }
index 46a295e8a668d551ae39a24cddd3f51df3983c21..445337e4b54daadd63e30c35951052c7fb77f10e 100644 (file)
@@ -75,4 +75,7 @@ class Laplacian(op: Field)  extends Field {
 
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) = 
     new LocalFragment(this, indices)
+
+  def getIterationInfo : IterationInfo =
+    op.getIterationInfo
 }
index f2f1d7e2e27e17a4f05020a0a8e42d820ceff334..455db5cddcc62817d7b68c852646952c562c05a2 100644 (file)
@@ -64,4 +64,8 @@ object OnetepTypes {
     val totalPts = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("total_pt"+dim)}.toSeq
     def getFortranAttributes = Set("type(FFTBOX_INFO)")
   }
+
+  object SPAM3 extends StructType {
+    def getFortranAttributes = Set("type(SPAM3)")
+  }
 }
diff --git a/src/ofc/generators/onetep/OnetepVariables.scala b/src/ofc/generators/onetep/OnetepVariables.scala
new file mode 100644 (file)
index 0000000..f08d80c
--- /dev/null
@@ -0,0 +1,8 @@
+package ofc.generators.onetep
+import ofc.codegen._
+
+object OnetepVariables {
+  // parallel_strategy
+  val pub_first_atom_on_node = new NamedUnboundVarSymbol[ArrayType[IntType]]("pub_first_atom_on_node", new ArrayType[IntType](1))
+  val pub_num_atoms_on_node = new NamedUnboundVarSymbol[ArrayType[IntType]]("pub_num_atoms_on_node", new ArrayType[IntType](1))
+}
diff --git a/src/ofc/generators/onetep/Operand.scala b/src/ofc/generators/onetep/Operand.scala
new file mode 100644 (file)
index 0000000..4f0d428
--- /dev/null
@@ -0,0 +1,11 @@
+package ofc.generators.onetep
+import ofc.codegen._
+
+class IterationInfo(val context: IterationContext, val indexMappings: Map[NamedIndex, Expression[IntType]]) {
+  def merge(other: IterationInfo) : IterationInfo = 
+    new IterationInfo(context merge other.context, indexMappings ++ other.indexMappings)
+}
+
+trait Operand {
+  def getIterationInfo : IterationInfo
+}
index d62400372277dbfa2d06efad7381031a04c0238e..24b68f39238f6cedcfb93bac26b0e6282f2837c5 100644 (file)
@@ -174,4 +174,11 @@ class PPDFunctionSet(basisName: String, dataName: String, indices: Seq[NamedInde
 
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) : FieldFragment =
     new LocalFragment(this, indices)
+
+  def getIterationInfo : IterationInfo = {
+    val context = new IterationContext
+    val numSpheres = basis % OnetepTypes.FunctionBasis.num
+    val sphereIndexExpr = context.addIteration("sphere_index", 1, numSpheres)
+    new IterationInfo(context, Map(getSphereIndex -> sphereIndexExpr))
+  }
 }
index d2d97e1e26738707b2238f621e0ea9d538a52c4f..38be25385d70544d7ed3150faf772d246966e008 100644 (file)
@@ -2,6 +2,8 @@ package ofc.generators.onetep
 import ofc.codegen._
 
 class SPAM3(name : String, indices: Seq[NamedIndex]) extends Scalar {
+  val mat = new NamedUnboundVarSymbol[StructType](name, OnetepTypes.SPAM3)
+
   class LocalFragment extends ScalarFragment {
     def setup(context: GenerationContext) {
     }
@@ -14,4 +16,9 @@ class SPAM3(name : String, indices: Seq[NamedIndex]) extends Scalar {
 
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) : ScalarFragment =
     new LocalFragment
+
+  def getIterationInfo : IterationInfo = {
+    val context = new IterationContext
+    throw new ofc.UnimplementedException("not yet implemented.")
+  }
 }
index 89a0f5136932bace9ae258fe2c21619587bd684d..e151dadd93d10646b7077d9859b66a217c68020c 100644 (file)
@@ -1,6 +1,6 @@
 package ofc.generators.onetep
 import ofc.codegen._
 
-trait Scalar {
+trait Scalar extends Operand {
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) : ScalarFragment
 }
index e3ed04b079e59d0553e02f2830c44ec9ca511be5..8c0704c371e129042e06a0751dfa860a99ae5ccb 100644 (file)
@@ -15,4 +15,7 @@ class ScalarLiteral(s: Double) extends Scalar {
 
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) : ScalarFragment =
     new LocalFragment(s)
+
+  def getIterationInfo : IterationInfo =
+    new IterationInfo(new IterationContext, Map.empty)
 }
index d48832719a3ce1354f71867776625f0ce88b973d..1e44f05c4f9ce6567ed6375d1bf7c8a8419dbd86 100644 (file)
@@ -62,4 +62,6 @@ class ScaledField(op: Field, factor: Scalar) extends Field {
   def getFragment(indices: Map[NamedIndex, Expression[IntType]]) = 
     new LocalFragment(this, indices)
 
+  def getIterationInfo : IterationInfo = 
+    op.getIterationInfo merge factor.getIterationInfo
 }