Commit 2cf95be6 authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Refactor IR_AccessPattern to hold an IR_AccessFunction instance instead of a...

Refactor IR_AccessPattern to hold an IR_AccessFunction instance instead of a lambda. Refactor IR_IV_TemporaryBuffer and add member to distinguish fragment/block-wise storage.
parent b08359e8
......@@ -49,11 +49,12 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads {
// for exodusII: velocity vector must be provided as separate components
def velocityComponentX = IR_IV_TemporaryBuffer(u.resolveBaseDatatype, IR_AtCellCenter, "velX", domainIndex,
ListBuffer(numCells_x, numCells_y, numCells_z))
blockwise = true, ListBuffer(numCells_x, numCells_y, numCells_z))
def velocityComponentY = IR_IV_TemporaryBuffer(v.resolveBaseDatatype, IR_AtCellCenter, "velY", domainIndex,
ListBuffer(numCells_x, numCells_y, numCells_z))
blockwise = true, ListBuffer(numCells_x, numCells_y, numCells_z))
def velocityComponentZ : Option[IR_IV_TemporaryBuffer] = if (numDimsGrid > 2)
Some(IR_IV_TemporaryBuffer(w.resolveBaseDatatype, IR_AtCellCenter, "velZ", domainIndex, ListBuffer(numCells_x, numCells_y, numCells_z)))
Some(IR_IV_TemporaryBuffer(w.resolveBaseDatatype, IR_AtCellCenter, "velZ", domainIndex,
blockwise = true, ListBuffer(numCells_x, numCells_y, numCells_z)))
else
None
......@@ -75,7 +76,7 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads {
IR_IfCondition(IR_IV_IsValidForDomain(p.domain.index),
IR_LoopOverDimensions(numDimsGrid, idxRange,
IR_Assignment(
vel.at(IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx),
IR_IV_TemporaryBuffer.accessArray(vel, IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx),
velAsVec(dir)))))
}
......@@ -83,7 +84,7 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads {
}
def velocityBuf = IR_IV_TemporaryBuffer(u.resolveBaseDatatype, IR_AtCellCenter, "vel", domainIndex,
ListBuffer(IR_IntegerConstant(numDimsGrid), numCells_x, numCells_y, numCells_z))
blockwise = true, ListBuffer(IR_IntegerConstant(numDimsGrid), numCells_x, numCells_y, numCells_z))
def setupVelocityBuf : ListBuffer[IR_Statement] = {
// init buffer with values of vector field
......@@ -98,7 +99,7 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads {
val initBuffer : ListBuffer[IR_Statement] = (0 until numDimsGrid).map(d => {
val linearizedIdx = idxRange.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
IR_Assignment(
velocityBuf.at(IR_LoopOverFragments.defIt * numCellsPerFrag * numDimsGrid + numDimsGrid * linearizedIdx + d),
IR_IV_TemporaryBuffer.accessArray(velocityBuf, IR_LoopOverFragments.defIt * numCellsPerFrag * numDimsGrid + numDimsGrid * linearizedIdx + d),
velAsVec(d)) : IR_Statement
}).to[ListBuffer]
......
......@@ -36,7 +36,7 @@ trait IR_PrintVisualizationSWE extends IR_PrintVisualizationTriangles {
def discFields : ListMap[String, ListBuffer[IR_Field]] = ListMap(
discFieldCollection.map(discField => getBasenameDiscField(discField) -> discField) : _*)
def discFieldsReduced : ListMap[String, IR_IV_TemporaryBuffer] = discFields.map { discField =>
discField._1 -> IR_IV_TemporaryBuffer(discField._2.head.resolveBaseDatatype, IR_AtNode, discField._1, domainIndex, dimsPositionsFrag)
discField._1 -> IR_IV_TemporaryBuffer(discField._2.head.resolveBaseDatatype, IR_AtNode, discField._1, domainIndex, blockwise = true, dimsPositionsFrag)
}
def etaDiscLower0 : IR_Field = IR_FieldCollection.getByIdentifier("etaDiscLower0", level).get
......@@ -70,7 +70,7 @@ trait IR_PrintVisualizationSWE extends IR_PrintVisualizationTriangles {
- can be enabled for comparison in Xdmf printers via "swe_interleaveDiscComponentsPrint" flag
*/
def discFieldBuffers : ListMap[String, IR_IV_TemporaryBuffer] = discFields.map { discField =>
discField._1 -> IR_IV_TemporaryBuffer(discField._2.head.resolveBaseDatatype, IR_AtNode, discField._1, domainIndex, dimsPositionsFrag)
discField._1 -> IR_IV_TemporaryBuffer(discField._2.head.resolveBaseDatatype, IR_AtNode, discField._1, domainIndex, blockwise = true, dimsPositionsFrag)
}
def setupNonReducedDiscData() : ListBuffer[IR_Statement] = {
......@@ -91,7 +91,7 @@ trait IR_PrintVisualizationSWE extends IR_PrintVisualizationTriangles {
IR_LoopOverDimensions(numDimsGrid, indexRangeCells,
(0 until numAccessesPerCell).to[ListBuffer].map(idx => {
IR_Assignment(
tmpBuf.at(offset + idx),
IR_IV_TemporaryBuffer.accessArray(tmpBuf, offset + idx),
IR_FieldAccess(discFields(tmpBuf.name)(idx), IR_IV_ActiveSlot(someCellField), IR_LoopOverDimensions.defIt(numDimsGrid))) : IR_Statement
}))))
}
......@@ -106,9 +106,9 @@ trait IR_PrintVisualizationSWE extends IR_PrintVisualizationTriangles {
Some(nodeOffsets.map(_.toExpressionIndex))
def nodalAccess(field : IR_Field) = if (Knowledge.swe_nodalReductionPrint)
IR_RegularAccessPattern((idx : IR_Index) => IR_FieldAccess(field, IR_IV_ActiveSlot(field), idx.toExpressionIndex))
IR_RegularAccessPattern(IR_AccessFieldFunction(field, IR_IV_ActiveSlot(field)))
else
IR_SWEAccessPattern((idx : IR_Index) => IR_FieldAccess(field, IR_IV_ActiveSlot(field), idx.toExpressionIndex), accessIndices)
IR_SWEAccessPattern(IR_AccessFieldFunction(field, IR_IV_ActiveSlot(field)), accessIndices)
// glue logic for disc fields to be mapped to data buffers
def discFieldsToDatabuffers(discField : ListBuffer[IR_Field]) : ListBuffer[IR_DataBuffer] = ???
......
......@@ -94,7 +94,7 @@ case class IR_PrintXdmfSWE(
*/
val enforceCopiesHdf5 : Boolean = ioInterface == "hdf5" && !Knowledge.swe_nodalReductionPrint
def nodalFieldBuffersHdf5 : ListMap[String, IR_IV_TemporaryBuffer] = ListMap(nodalFields.toSeq.map { nodeFieldMap =>
nodeFieldMap._1 -> IR_IV_TemporaryBuffer(nodeFieldMap._2.resolveBaseDatatype, IR_AtNode, nodeFieldMap._1, domainIndex, dimsPositionsFrag)
nodeFieldMap._1 -> IR_IV_TemporaryBuffer(nodeFieldMap._2.resolveBaseDatatype, IR_AtNode, nodeFieldMap._1, domainIndex, blockwise = true, dimsPositionsFrag)
} : _*)
def setupNodalFieldsHdf5 : ListBuffer[IR_Statement] = {
......@@ -117,7 +117,7 @@ case class IR_PrintXdmfSWE(
IR_LoopOverDimensions(numDimsGrid, indexRangeCells,
(0 until numAccessesPerCell).to[ListBuffer].map(idx => {
IR_Assignment(
tmpBuf.at(offset + idx),
IR_IV_TemporaryBuffer.accessArray(tmpBuf, offset + idx),
IR_FieldAccess(nodalFields(name), IR_IV_ActiveSlot(nodalFields(name)), IR_LoopOverDimensions.defIt(numDimsGrid) + nodeOffsets(idx))) : IR_Statement
})))))
}
......@@ -260,9 +260,9 @@ case class IR_PrintXdmfSWE(
numDimsGrid = field.layout.numDimsGrid,
numDimsData = field.layout.numDimsData,
domainIdx = field.domain.index,
accessPattern = IR_RegularAccessPattern((idx : IR_Index) => IR_FieldAccess(field, slot, idx.toExpressionIndex)),
accessPattern = IR_RegularAccessPattern(IR_AccessFieldFunction(field, slot)),
datasetName = datasetFields(getBasenameDiscField(discField))(fid),
name = field.name,
name = field.codeName,
fieldLayoutTransformed = IR_DataBuffer.inLayoutTransformationCollection(field),
canonicalStorageLayout = false,
accessBlockwise = false,
......
......@@ -6,9 +6,26 @@ import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.baseExt.ir._
import exastencils.config.Knowledge
import exastencils.field.ir.IR_Field
import exastencils.field.ir.IR_FieldAccess
import exastencils.grid.ir.IR_Localization
import exastencils.logger.Logger
abstract class IR_AccessFunction extends IR_Node {
def get(idx : IR_Index) : IR_Access
}
case class IR_AccessFieldFunction(var field : IR_Field, var slot : IR_Expression, var hodtComponentIndex : Option[IR_Index] = None) extends IR_AccessFunction {
override def get(idx : IR_Index) : IR_Access = {
val index = if (hodtComponentIndex.isDefined) idx + hodtComponentIndex.get else idx
IR_FieldAccess(field, slot, index.toExpressionIndex)
}
}
case class IR_AccessTempBufferFunction(var tempBuffer : IR_IV_TemporaryBuffer) extends IR_AccessFunction {
override def get(idx : IR_Index) = IR_IV_TemporaryBuffer.accessArray(tempBuffer, idx)
}
/// IR_AccessPattern
// consists of callback function and members to describe different access patterns
// callbacks are registered and called by IR_DataBuffer (e.g. IR_FieldAccess for underlying IR_Field)
......@@ -16,12 +33,12 @@ import exastencils.logger.Logger
abstract class IR_AccessPattern extends IR_Node {
def accessCallbackFuntion : IR_Index => IR_Access // callback function to be registered and used by IR_DataBuffer wrapper
def accessFunction : IR_AccessFunction // callback function to be registered and used by IR_DataBuffer wrapper
def accessIndices : Option[ListBuffer[IR_Index]] // contains N indices to be accessed for each grid element (e.g. nodes/cells/...)
def numAccesses : Int = if (accessIndices.isDefined) accessIndices.get.length else 1
def callAccessFunction(index : IR_Index) : IR_Access = accessCallbackFuntion(index)
def callAccessFunction(index : IR_Index) : IR_Access = accessFunction.get(index)
// get list of accesses for each index defined by the pattern
def accessesForPattern(indices : IR_Index*) : ListBuffer[ListBuffer[IR_Access]]
......@@ -34,8 +51,7 @@ abstract class IR_AccessPattern extends IR_Node {
}
// regular access pattern. no special treatment required
case class IR_RegularAccessPattern(
var accessCallbackFuntion : IR_Index => IR_Access) extends IR_AccessPattern {
case class IR_RegularAccessPattern(var accessFunction : IR_AccessFunction) extends IR_AccessPattern {
override def accessIndices : Option[ListBuffer[IR_Index]] = None
......@@ -52,7 +68,7 @@ case class IR_RegularAccessPattern(
// special access pattern for nodal fields in SWE (e.g. node positions and bath) applications
// 6 elements are accesses per grid cell
case class IR_SWEAccessPattern(
var accessCallbackFuntion : IR_Index => IR_Access,
var accessFunction : IR_AccessFunction,
var accessIndices : Option[ListBuffer[IR_Index]]) extends IR_AccessPattern {
if (accessIndices.isEmpty || (accessIndices.isDefined && accessIndices.get.size != 6))
......
......@@ -3,14 +3,13 @@ package exastencils.io.ir
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir._
import exastencils.baseExt.ir._
import exastencils.config.Knowledge
import exastencils.core.Duplicate
import exastencils.domain.ir.IR_IV_FragmentIndex
import exastencils.field.ir.IR_Field
import exastencils.field.ir.IR_FieldAccess
import exastencils.grid.ir.IR_Localization
import exastencils.layoutTransformation.ir.IR_GenericTransform
import exastencils.layoutTransformation.ir.IR_LayoutTransformationCollection
......@@ -35,7 +34,7 @@ object IR_DataBuffer {
}
// determines if field layout was transformed
def inLayoutTransformationCollection(field: IR_Field) = IR_LayoutTransformationCollection.getOpt.isDefined &&
def inLayoutTransformationCollection(field: IR_Field) : Boolean = IR_LayoutTransformationCollection.getOpt.isDefined &&
IR_LayoutTransformationCollection.getOpt.get.trafoStmts
.collect { case stmt : IR_GenericTransform => stmt } // only consider generic transformations
.exists(_.fields.exists { case (name, lvl) => name == field.name && lvl == field.level }) // check if any trafo contains field
......@@ -79,8 +78,8 @@ object IR_DataBuffer {
numDimsGrid = field.layout.numDimsGrid,
numDimsData = field.layout.numDimsData,
domainIdx = field.domain.index,
name = field.name,
accessPattern = pattern getOrElse IR_RegularAccessPattern((idx : IR_Index) => IR_FieldAccess(field, Duplicate(slot), idx.toExpressionIndex)),
name = field.codeName,
accessPattern = pattern getOrElse IR_RegularAccessPattern(IR_AccessFieldFunction(field, Duplicate(slot))),
datasetName = dataset getOrElse IR_NullExpression,
canonicalStorageLayout = canonicalOrder,
fieldLayoutTransformed = inLayoutTransformationCollection(field),
......@@ -102,13 +101,13 @@ object IR_DataBuffer {
canonicalOrder : Boolean) : IR_DataBuffer = {
// access component
def highDimIndex(idx : IR_Index) = IR_ExpressionIndex(idx.toExpressionIndex.indices :+ indexRow :+ indexCol)
val componentIndex = Some(IR_ExpressionIndex(indexRow, indexCol))
val slot = 0
val pattern = if (accessIndices.isDefined && accessIndices.get.size == 6)
IR_SWEAccessPattern((idx : IR_Index) => IR_FieldAccess(matField, slot, highDimIndex(idx)), accessIndices)
IR_SWEAccessPattern(IR_AccessFieldFunction(matField, slot, componentIndex), accessIndices)
else
IR_RegularAccessPattern((idx : IR_Index) => IR_FieldAccess(matField, slot, highDimIndex(idx)))
IR_RegularAccessPattern(IR_AccessFieldFunction(matField, slot, componentIndex))
new IR_DataBuffer(
slot = slot,
......@@ -121,7 +120,7 @@ object IR_DataBuffer {
numDimsGrid = matField.layout.numDimsGrid,
numDimsData = matField.layout.numDimsGrid,
domainIdx = matField.domain.index,
name = matField.name,
name = matField.codeName,
accessPattern = pattern,
datasetName = dataset getOrElse IR_NullExpression,
canonicalStorageLayout = canonicalOrder,
......@@ -150,7 +149,7 @@ object IR_DataBuffer {
numDimsData = tmpBuf.numDims,
domainIdx = tmpBuf.domainIdx,
name = tmpBuf.name,
accessPattern = pattern getOrElse IR_RegularAccessPattern((idx : IR_Index) => tmpBuf.at(idx)),
accessPattern = pattern getOrElse IR_RegularAccessPattern(IR_AccessTempBufferFunction(tmpBuf)),
datasetName = dataset getOrElse IR_NullExpression,
canonicalStorageLayout = false,
fieldLayoutTransformed = false,
......@@ -180,8 +179,8 @@ case class IR_DataBuffer(
var datasetName : IR_Expression, // dataset name to be used in netCDF/HDF5 files
var fieldLayoutTransformed : Boolean, // field layout transformed
var canonicalStorageLayout : Boolean, // describes the data layout in the file
var accessBlockwise : Boolean, // specifies if the data is stored per fragment (field) or block (temp. buffers)
var isTemporaryBuffer : Boolean // specified if underlying buffer is a temp. buffer (can be used to implement temp. buffers where data is stored per fragment in the future)
var accessBlockwise : Boolean, // specifies if the data is stored per fragment (field/temp. buffers) or block (temp. buffers)
var isTemporaryBuffer : Boolean // specified if underlying buffer is a temp. buffer
) {
/* In this implementation, two data layouts are supported:
......
......@@ -179,7 +179,7 @@ case class IR_FileAccess_HDF5(
statements ++= H5Pcreate(fcpl, IR_VariableAccess("H5P_FILE_CREATE", IR_UnknownDatatype))
if (Knowledge.hdf5_use_chunking) {
val ik = IR_SimplifyExpression.simplifyIntegralExpr(
dataBuffers.map(buf => if (buf.isTemporaryBuffer) IR_IntegerConstant(Knowledge.mpi_numThreads) else IR_IV_TotalNumFrags(domainIdx)).reduce(_ + _) / 2
dataBuffers.map(buf => if (buf.accessBlockwise) IR_IntegerConstant(Knowledge.mpi_numThreads) else IR_IV_TotalNumFrags(domainIdx)).reduce(_ + _) / 2
)
statements += IR_IfCondition(ik > 1 AndAnd ik < 65536, // cannot exceed limit: https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetIstoreK
H5Pset_istore_k(err, fcpl, ik))
......
......@@ -2,10 +2,11 @@ package exastencils.io.ir
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir._
import exastencils.baseExt.ir.IR_ExpressionIndexRange
import exastencils.baseExt.ir.IR_InternalVariable
import exastencils.baseExt.ir.IR_LoopOverFragments
import exastencils.grid.ir.IR_Localization
/// IR_IV_TemporaryBuffer
......@@ -15,58 +16,62 @@ import exastencils.grid.ir.IR_Localization
// - only contains data of interest
// - does not have layers to be excluded (e.g. pad/ghost/...)
object IR_IV_TemporaryBuffer {
def accessArray(tempBuf : IR_IV_TemporaryBuffer, idx : IR_Expression) = {
IR_ArrayAccess(tempBuf, tempBuf.linearizedIndex(idx))
}
}
case class IR_IV_TemporaryBuffer(
var baseDatatype : IR_Datatype,
var localization : IR_Localization,
var name : String,
var domainIdx : Int,
dimsPerFrag : ListBuffer[IR_Expression]
) extends IR_InternalVariable(false, true, false, false, false) {
var blockwise : Boolean,
dimsPerFrag : ListBuffer[IR_Expression],
) extends IR_InternalVariable(!blockwise, true, false, false, false) with IR_Access {
override def resolveName() : String = name + resolvePostfix("", domainIdx.prettyprint, "", "", "")
override def resolveDatatype() : IR_Datatype = IR_PointerDatatype(baseDatatype)
override def resolveDefValue() = Some(0)
def numDims : Int = dimsPerFrag.length + 1
def numDims : Int = dimsPerFrag.length + (if (blockwise) 1 else 0)
// NOTE: temp. buffers contain the data for a whole block -> Reduces the number of file accesses where each has a greater granularity compared to fragment-wise accesses
def dimsLocal : ListBuffer[IR_Expression] = dimsPerFrag :+ IR_IV_NumValidFrags(domainIdx)
def dimsGlobal : ListBuffer[IR_Expression] = dimsPerFrag :+ IR_IV_TotalNumFrags(domainIdx)
def dimsLocal : ListBuffer[IR_Expression] = dimsPerFrag ++ (if (blockwise) List(IR_IV_NumValidFrags(domainIdx)) else Nil)
def dimsGlobal : ListBuffer[IR_Expression] = dimsPerFrag ++ (if (blockwise) List(IR_IV_TotalNumFrags(domainIdx)) else Nil)
def referenceOffset = IR_ExpressionIndex(Array.fill(numDims)(0))
def beginIndices : ListBuffer[IR_Expression] = referenceOffset.indices.to[ListBuffer]
def endIndices : ListBuffer[IR_Expression] = dimsLocal
def totalDimsLocal : ListBuffer[IR_Expression] = dimsLocal
val access : IR_Expression = resolveAccess(IR_VariableAccess(resolveName(), resolveDatatype()), IR_NullExpression, domainIdx, IR_NullExpression, IR_NullExpression, IR_NullExpression)
def resolveAccess() : IR_Expression = resolveAccess(resolveName(),
if (!blockwise) IR_LoopOverFragments.defIt else IR_NullExpression, domainIdx, IR_NullExpression, IR_NullExpression, IR_NullExpression)
def at(index : IR_Expression) : IR_Access = index match {
def linearizedIndex(index : IR_Expression) = index match {
case idx : IR_Index =>
val linearizedIdx = IR_ExpressionIndexRange(
IR_ExpressionIndexRange(
IR_ExpressionIndex(Array.fill(numDims)(0)),
IR_ExpressionIndex(dimsLocal.toArray)
).linearizeIndex(idx)
IR_ArrayAccess(
access,
linearizedIdx)
case _ =>
IR_ArrayAccess(access, index)
index
}
def allocateMemory = IR_IfCondition(IR_Negation(access),
IR_ArrayAllocation(this, baseDatatype, dimsLocal.reduce(_ * _)))
def allocateMemory = wrapInLoops(IR_IfCondition(IR_Negation(resolveAccess()),
IR_ArrayAllocation(resolveAccess(), baseDatatype, dimsLocal.reduce(_ * _))))
override def getCtor() : Option[IR_Statement] = Some(
IR_Assignment(
IR_VariableAccess(resolveName(), resolveDatatype()),
resolveDefValue().get))
wrapInLoops(IR_Assignment(
resolveAccess(),
resolveDefValue().get)))
override def getDtor() : Option[IR_Statement] = {
Some(wrapInLoops(
IR_IfCondition(access,
IR_IfCondition(resolveAccess(),
ListBuffer[IR_Statement](
IR_ArrayFree(access),
IR_Assignment(access, 0)))))
IR_ArrayFree(resolveAccess()),
IR_Assignment(resolveAccess(), 0)))))
}
}
......@@ -180,7 +180,8 @@ trait IR_PrintVisualization {
initBuffer)
}
def connectivityBuf = IR_IV_TemporaryBuffer(IR_IntegerDatatype, IR_AtCellCenter, "connectivity", domainIndex, ListBuffer[IR_Expression]() ++ dimsConnectivityFrag)
def connectivityBuf = IR_IV_TemporaryBuffer(IR_IntegerDatatype, IR_AtCellCenter, "connectivity",
domainIndex, blockwise = true, ListBuffer[IR_Expression]() ++ dimsConnectivityFrag)
// allocates and initializes buffer with connectivity info. this buffer is then passed to the I/O library
def setupConnectivity(global : Boolean) : ListBuffer[IR_Statement] = {
......@@ -192,7 +193,7 @@ trait IR_PrintVisualization {
val initBuffer : ListBuffer[IR_Statement] = connectivityForCell().indices.map(d => {
val linearizedLoopIdx = loopOverCells().indices.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
IR_Assignment(
connectivityBuf.at(IR_LoopOverFragments.defIt * sizeConnectionFrag + connectivityForCell().length * linearizedLoopIdx + d),
IR_IV_TemporaryBuffer.accessArray(connectivityBuf, IR_LoopOverFragments.defIt * sizeConnectionFrag + connectivityForCell().length * linearizedLoopIdx + d),
connectivityForCell(global)(d)) : IR_Statement
}).to[ListBuffer]
......@@ -207,7 +208,8 @@ trait IR_PrintVisualization {
val gridPositionsCopied : Boolean = Knowledge.grid_isAxisAligned || Knowledge.grid_isUniform // otherwise we directly use a vf's associated field
def cellCentersBuf : ListBuffer[IR_IV_TemporaryBuffer] = (0 until numDimsGrid).to[ListBuffer].map { d =>
val dims = (loopOverCells().indices.end - loopOverCells().indices.begin).indices.to[ListBuffer]
IR_IV_TemporaryBuffer(IR_RealDatatype, IR_AtCellCenter, "cellCenter" + ('X' + d).toChar.toString, domainIndex, dims)
IR_IV_TemporaryBuffer(IR_RealDatatype, IR_AtCellCenter, "cellCenter" + ('X' + d).toChar.toString,
domainIndex, blockwise = true, dims)
}
// on some occasions, the virtual field can be directly passed to the library. this buffer is then passed to the I/O library
......@@ -218,7 +220,7 @@ trait IR_PrintVisualization {
val dims = (indexRange.end - indexRange.begin).indices.to[ListBuffer]
val linearizedLoopIdx = indexRange.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
val init = IR_Assignment(
cellCentersBuf(dim).at(IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
IR_IV_TemporaryBuffer.accessArray(cellCentersBuf(dim), IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
getPos(IR_AtCellCenter, level, dim))
// declare, allocate and init temp. buffer with cell centers
......@@ -243,7 +245,8 @@ trait IR_PrintVisualization {
indexRange.end(faceDir) += 1
val dims = (indexRange.end - indexRange.begin).indices.to[ListBuffer]
(0 until numDimsGrid).map(d => IR_IV_TemporaryBuffer(IR_RealDatatype, IR_AtFaceCenter(faceDir), "facePos" + ('X' + d).toChar.toString, domainIndex, dims)).to[ListBuffer]
(0 until numDimsGrid).map(d => IR_IV_TemporaryBuffer(IR_RealDatatype, IR_AtFaceCenter(faceDir), "facePos" + ('X' + d).toChar.toString,
domainIndex, blockwise = true, dims)).to[ListBuffer]
}
def initFacePosBuf(faceDir : Int)(dim : Int) : ListBuffer[IR_Statement] = {
......@@ -261,7 +264,7 @@ trait IR_PrintVisualization {
IR_LoopOverDimensions(numDimsGrid,
indexRange,
IR_Assignment(
facePositionsBuf(faceDir)(dim).at(IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
IR_IV_TemporaryBuffer.accessArray(facePositionsBuf(faceDir)(dim), IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
getPos(IR_AtFaceCenter(faceDir), level, dim)))))))
}
......@@ -269,7 +272,8 @@ trait IR_PrintVisualization {
def setupFacePositions(faceDir : Int) : ListBuffer[IR_Statement] = (0 until numDimsGrid).flatMap(initFacePosBuf(faceDir)).to[ListBuffer]
def nodePositionsBuf : ListBuffer[IR_IV_TemporaryBuffer] = (0 until numDimsGrid).to[ListBuffer].map { d =>
IR_IV_TemporaryBuffer(IR_RealDatatype, IR_AtNode, "nodePosition" + ('X' + d).toChar.toString, domainIndex, dimsPositionsFrag)
IR_IV_TemporaryBuffer(IR_RealDatatype, IR_AtNode, "nodePosition" + ('X' + d).toChar.toString,
domainIndex, blockwise = true, dimsPositionsFrag)
}
def initNodePosBuf(dim : Int, copyNodePositions : Boolean = gridPositionsCopied) : ListBuffer[IR_Statement] = if (!copyNodePositions) {
......@@ -281,7 +285,7 @@ trait IR_PrintVisualization {
val initBuffer : ListBuffer[IR_Statement] = (0 until numAccPerCell).map(n => {
val linearizedLoopIdx = loopOverDims(isNodalLoop).indices.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
IR_Assignment(
nodePositionsBuf(dim).at(IR_LoopOverFragments.defIt * numPointsPerFrag + numAccPerCell * linearizedLoopIdx + n),
IR_IV_TemporaryBuffer.accessArray(nodePositionsBuf(dim), IR_LoopOverFragments.defIt * numPointsPerFrag + numAccPerCell * linearizedLoopIdx + n),
getPos(IR_AtNode, level, dim, IR_LoopOverDimensions.defIt(numDimsGrid) + nodeOffsets(n))) : IR_Statement
}).to[ListBuffer]
......
......@@ -255,7 +255,7 @@ abstract class IR_PrintExodus() extends IR_Statement with IR_Expandable with IR_
val indexRangeTransformed = buf.accessPattern.transformExpressionIndexRange(indexRange.begin, indexRange.end)
val dims = buf.accessPattern.transformDataExtents((indexRange.end - indexRange.begin).indices.to[ListBuffer], buf.localization, orderKJI = false)
val tmp = IR_IV_TemporaryBuffer(buf.datatype.resolveBaseDatatype, buf.localization, "tmp" + buf.name, buf.domainIdx, dims)
val tmp = IR_IV_TemporaryBuffer(buf.datatype.resolveBaseDatatype, buf.localization, "tmp" + buf.name, buf.domainIdx, blockwise = true, dims)
val accesses = buf.accessPattern.accessIndices getOrElse ListBuffer(IR_ConstIndex(Array.fill(buf.numDimsData)(0)))
val numAccesses = buf.accessPattern.numAccesses
val offset = IR_LoopOverFragments.defIt * dims.reduce(_ * _) + numAccesses * indexRangeTransformed.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
......@@ -266,10 +266,11 @@ abstract class IR_PrintExodus() extends IR_Statement with IR_Expandable with IR_
IR_LoopOverDimensions(numDimsGrid, indexRangeTransformed,
(0 until numAccesses).to[ListBuffer].map(idx => {
IR_Assignment(
tmp.at(offset + idx), buf.getAccess(IR_LoopOverDimensions.defIt(numDimsGrid) + accesses(idx))) : IR_Statement
IR_IV_TemporaryBuffer.accessArray(tmp, offset + idx),
buf.getAccess(IR_LoopOverDimensions.defIt(numDimsGrid) + accesses(idx))) : IR_Statement
}))))
IR_AddressOf(tmp.at(0))
IR_AddressOf(IR_IV_TemporaryBuffer.accessArray(tmp, 0))
} else {
buf.getBaseAddress
}
......
......@@ -53,7 +53,7 @@ abstract class IR_PrintXdmfStructured(
}
val tmpBufStag : Option[IR_IV_TemporaryBuffer] = if (staggerDim >= 0) {
val dims = ListBuffer[IR_Expression](numCells_x, numCells_y, numCells_z).take(numDimsGrid)
Some(IR_IV_TemporaryBuffer(field.resolveBaseDatatype, IR_AtCellCenter, "tmp_" + field.name, domainIndex, dims))
Some(IR_IV_TemporaryBuffer(field.resolveBaseDatatype, IR_AtCellCenter, "tmp_" + field.name, domainIndex, blockwise = true, dims))
} else {
None
}
......@@ -133,7 +133,7 @@ abstract class IR_PrintXdmfStructured(
IR_IfCondition(IR_IV_IsValidForDomain(dataBuffer.domainIdx),
IR_LoopOverDimensions(numDimsGrid, idxRange,
IR_Assignment(
tmpBufDest.at(IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx),
IR_IV_TemporaryBuffer.accessArray(tmpBufDest, IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx),
mean))))
stmts
......
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