}
class CodeGenerator {
+ val code = new StringBuilder()
val indexNames = new IndexNames()
+ var nextVarIndex = 0
+
+ def newLocalVar : String = {
+ val name = "var_" + nextVarIndex
+ nextVarIndex += 1
+ name
+ }
def apply(assignment: Assignment) {
generateCode(assignment)
// We search for all indices bound to the one being destroyed
// We generate a composite iteration over those loops
// If GeneralInnerProduct rebuilds derived indices, we need to be able to construct a valid size
+ val concreteIndexList = destroyedIndices.toList
+ val storageName = newLocalVar
+ code append "real(kind=DP), allocatable, dimension" + (":"*concreteIndexList.size).mkString("(",",",")") + " :: " +
+ storageName + "\n"
+ code append "allocate("+ storageName +
+ (concreteIndexList map ((x : Index) => x.getDenseWidth)).mkString("(",",",")") + ", stat=ierr)"
+
+ // We've declared temporary storage, now create the loops to populate it
+ //for (index <- concreteIndexList) code append index.generateIterationHeader(indexNames)
+
+ println(code.mkString)
System.exit(0)
}
trait Index {
def getName : String
def getDependencies : Set[Index]
+ def getDenseWidth : String
+ //def generateIterationHeader(names: IndexNames) : String
}
+
trait SpatialIndex extends Index
trait DiscreteIndex extends Index
class GeneralInnerProduct(operands: List[IterationSpace], removedIndices: Set[Index]) extends IterationSpace {
- class DenseSpatialIndex(parent: GeneralInnerProduct) extends SpatialIndex{
+ class DenseSpatialIndex(parent: GeneralInnerProduct, original: SpatialIndex) extends SpatialIndex{
def getDependencies = Set()
def getName = "dense_spatial_index"
+ def getDenseWidth = original.getDenseWidth
}
- class DenseDiscreteIndex(parent: GeneralInnerProduct) extends DiscreteIndex {
+ class DenseDiscreteIndex(parent: GeneralInnerProduct, original: DiscreteIndex) extends DiscreteIndex {
def getDependencies = Set()
def getName = "dense_discrete_index"
+ def getDenseWidth = original.getDenseWidth
}
val spatialIndices =
if (index.getDependencies.intersect(removedIndices).isEmpty)
index
else
- new DenseSpatialIndex(this)
+ new DenseSpatialIndex(this, index)
val discreteIndices =
for(op <- operands; index <- op.getDiscreteIndices; if (!removedIndices.contains(index))) yield
if (index.getDependencies.intersect(removedIndices).isEmpty)
index
else
- new DenseDiscreteIndex(this)
+ new DenseDiscreteIndex(this, index)
def getOperands = operands
def getSpatialIndices() = spatialIndices
}
class Reciprocal(op: IterationSpace) extends IterationSpace {
- class BlockIndex(parent: Reciprocal, dimension: Int) extends SpatialIndex {
+ class BlockIndex(parent: Reciprocal, dimension: Int, original: SpatialIndex) extends SpatialIndex {
def getName = "reciprocal_index_" + dimension
def getDependencies = Set()
+ def getDenseWidth = original.getDenseWidth
}
- val spatialIndices = for (dimension <- 0 to op.getSpatialIndices.size) yield new BlockIndex(this, dimension)
+
+ val spatialIndices = for (dimension <- 0 until op.getSpatialIndices.size) yield
+ new BlockIndex(this, dimension, op.getSpatialIndices()(dimension))
def getOperands = List(op)
def getSpatialIndices() = spatialIndices.toList
class RestrictedIndex(parent: SpatialRestriction, dimension: Int) extends SpatialIndex {
def getName = "restriction_index_" + dimension
def getDependencies = Set()
+ def getDenseWidth = throw new UnimplementedException("Restriction unimplemnted")
}
- val spatialIndices = for (dimension <- 0 to op.getSpatialIndices.size) yield new RestrictedIndex(this, dimension)
+ val spatialIndices = for (dimension <- 0 until op.getSpatialIndices.size) yield new RestrictedIndex(this, dimension)
def getOperands() = List(op)
def getSpatialIndices() = spatialIndices.toList
override def toString = parent + ".row"
def getName = "row_index"
def getDependencies = Set()
+ def getDenseWidth = throw new UnimplementedException("Matrix size unimplemented")
}
class ColIndex(parent: SPAM3) extends DiscreteIndex {
override def toString = parent + ".col"
def getName = "row_index"
def getDependencies = Set()
+ def getDenseWidth = throw new UnimplementedException("Matrix size unimplemented")
}
val rowIndex = new RowIndex(this)
def getAccessExpression(indexNames: IndexNames) = throw new UnimplementedException("Access failed")
}
-class PPDFunctionSet(basis : String, data : String) extends FunctionSet {
+class PPDFunctionSet(val basis : String, data : String) extends FunctionSet {
class SphereIndex(parent: PPDFunctionSet) extends DiscreteIndex {
def getName = "sphere_index"
def getDependencies = Set()
+ def getDenseWidth = throw new UnimplementedException("Sphere count unimplemented")
+ //TODO: def getSphere = parent.basis + "%spheres(????)"
}
class PPDIndex(parent: PPDFunctionSet) extends DiscreteIndex {
def getName = "ppd_index"
def getDependencies = Set[Index](parent.getSphereIndex())
+ //TODO: def getDenseWidth = parent.getSphereIndex.getSphere + "%n_ppds_sphere"
+ def getDenseWidth = parent.basis+"%max_n_ppds_sphere"
}
class IntraPPDIndex(parent: PPDFunctionSet, dimension: Int) extends SpatialIndex {
def getName = "intra_ppd_index_" + dimension
def getDependencies = Set[Index](parent.getPPDIndex)
+ def getDenseWidth = "pub_cell%total_pt"+(dimension+1)
}
val ppdIndex = new PPDIndex(this)