Commit 5f8a701a authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Refactor temp buffer IV

parent f3b0a367
......@@ -76,7 +76,7 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads {
IR_IfCondition(IR_IV_IsValidForDomain(p.domain.index),
IR_LoopOverDimensions(numDimsGrid, idxRange,
IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(vel, IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx),
IR_ArrayAccess(vel, IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx),
velAsVec(dir)))))
}
......@@ -99,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(
IR_IV_TemporaryBuffer.accessArray(velocityBuf, IR_LoopOverFragments.defIt * numCellsPerFrag * numDimsGrid + numDimsGrid * linearizedIdx + d),
IR_ArrayAccess(velocityBuf, IR_LoopOverFragments.defIt * numCellsPerFrag * numDimsGrid + numDimsGrid * linearizedIdx + d),
velAsVec(d)) : IR_Statement
}).to[ListBuffer]
......
......@@ -91,7 +91,7 @@ trait IR_PrintVisualizationSWE extends IR_PrintVisualizationTriangles {
IR_LoopOverDimensions(numDimsGrid, indexRangeCells,
(0 until numAccessesPerCell).to[ListBuffer].map(idx => {
IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(tmpBuf, offset + idx),
IR_ArrayAccess(tmpBuf, offset + idx),
IR_FieldAccess(discFields(tmpBuf.name)(idx), IR_IV_ActiveSlot(someCellField), IR_LoopOverDimensions.defIt(numDimsGrid))) : IR_Statement
}))))
}
......
......@@ -117,7 +117,7 @@ case class IR_PrintXdmfSWE(
IR_LoopOverDimensions(numDimsGrid, indexRangeCells,
(0 until numAccessesPerCell).to[ListBuffer].map(idx => {
IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(tmpBuf, offset + idx),
IR_ArrayAccess(tmpBuf, offset + idx),
IR_FieldAccess(nodalFields(name), IR_IV_ActiveSlot(nodalFields(name)), IR_LoopOverDimensions.defIt(numDimsGrid) + nodeOffsets(idx))) : IR_Statement
})))))
}
......
......@@ -26,7 +26,7 @@ case class IR_AccessFieldFunction(var field : IR_Field, var slot : IR_Expression
}
case class IR_AccessTempBufferFunction(var tempBuffer : IR_IV_TemporaryBuffer) extends IR_AccessFunction {
override def get(idx : IR_Index) = IR_IV_TemporaryBuffer.accessArray(tempBuffer, idx)
override def get(idx : IR_Index) = IR_ArrayAccess(tempBuffer, tempBuffer.linearizedIndex(idx))
}
/// IR_AccessPattern
......
......@@ -8,6 +8,7 @@ import exastencils.baseExt.ir.IR_ExpressionIndexRange
import exastencils.baseExt.ir.IR_InternalVariable
import exastencils.baseExt.ir.IR_LoopOverFragments
import exastencils.grid.ir.IR_Localization
import exastencils.prettyprinting.PpStream
/// IR_IV_TemporaryBuffer
// represents a temporary buffer where data is stored (fragment-wise) before writing it to file
......@@ -16,17 +17,6 @@ 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) = {
// TODO: should be done automatically
var base : IR_Expression = tempBuf
if (!tempBuf.blockwise)
base = IR_ArrayAccess(tempBuf, IR_LoopOverFragments.defIt)
IR_ArrayAccess(base, tempBuf.linearizedIndex(idx))
}
}
case class IR_IV_TemporaryBuffer(
var baseDatatype : IR_Datatype,
var localization : IR_Localization,
......@@ -34,7 +24,9 @@ case class IR_IV_TemporaryBuffer(
var domainIdx : Int,
var blockwise : Boolean,
dimsPerFrag : ListBuffer[IR_Expression],
) extends IR_InternalVariable(!blockwise, true, false, false, false) with IR_Access {
) extends IR_InternalVariable(!blockwise, true, false, false, false) {
override def prettyprint(out : PpStream) : Unit = out << this.resolveAccess()
override def resolveName() : String = name + resolvePostfix("", domainIdx.prettyprint, "", "", "")
override def resolveDatatype() : IR_Datatype = IR_PointerDatatype(baseDatatype)
......
......@@ -193,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(
IR_IV_TemporaryBuffer.accessArray(connectivityBuf, IR_LoopOverFragments.defIt * sizeConnectionFrag + connectivityForCell().length * linearizedLoopIdx + d),
IR_ArrayAccess(connectivityBuf, IR_LoopOverFragments.defIt * sizeConnectionFrag + connectivityForCell().length * linearizedLoopIdx + d),
connectivityForCell(global)(d)) : IR_Statement
}).to[ListBuffer]
......@@ -220,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(
IR_IV_TemporaryBuffer.accessArray(cellCentersBuf(dim), IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
IR_ArrayAccess(cellCentersBuf(dim), IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
getPos(IR_AtCellCenter, level, dim))
// declare, allocate and init temp. buffer with cell centers
......@@ -264,7 +264,7 @@ trait IR_PrintVisualization {
IR_LoopOverDimensions(numDimsGrid,
indexRange,
IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(facePositionsBuf(faceDir)(dim), IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
IR_ArrayAccess(facePositionsBuf(faceDir)(dim), IR_LoopOverFragments.defIt * dims.reduce(_ * _) + linearizedLoopIdx),
getPos(IR_AtFaceCenter(faceDir), level, dim)))))))
}
......@@ -285,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(
IR_IV_TemporaryBuffer.accessArray(nodePositionsBuf(dim), IR_LoopOverFragments.defIt * numPointsPerFrag + numAccPerCell * linearizedLoopIdx + n),
IR_ArrayAccess(nodePositionsBuf(dim), IR_LoopOverFragments.defIt * numPointsPerFrag + numAccPerCell * linearizedLoopIdx + n),
getPos(IR_AtNode, level, dim, IR_LoopOverDimensions.defIt(numDimsGrid) + nodeOffsets(n))) : IR_Statement
}).to[ListBuffer]
......
......@@ -266,11 +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(
IR_IV_TemporaryBuffer.accessArray(tmp, offset + idx),
IR_ArrayAccess(tmp, offset + idx),
buf.getAccess(IR_LoopOverDimensions.defIt(numDimsGrid) + accesses(idx))) : IR_Statement
}))))
IR_AddressOf(IR_IV_TemporaryBuffer.accessArray(tmp, 0))
IR_AddressOf(IR_ArrayAccess(tmp, 0))
} else {
buf.getBaseAddress
}
......
......@@ -129,7 +129,7 @@ abstract class IR_PrintXdmfStructured(ioMethod : IR_Expression) extends IR_Print
IR_IfCondition(IR_IV_IsValidForDomain(dataBuffer.domainIdx),
IR_LoopOverDimensions(numDimsGrid, idxRange,
IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(tmpBufDest, fragOff + linearizedIdx),
IR_ArrayAccess(tmpBufDest, fragOff + 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