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 { ...@@ -76,7 +76,7 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads {
IR_IfCondition(IR_IV_IsValidForDomain(p.domain.index), IR_IfCondition(IR_IV_IsValidForDomain(p.domain.index),
IR_LoopOverDimensions(numDimsGrid, idxRange, IR_LoopOverDimensions(numDimsGrid, idxRange,
IR_Assignment( IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(vel, IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx), IR_ArrayAccess(vel, IR_LoopOverFragments.defIt * numCellsPerFrag + linearizedIdx),
velAsVec(dir))))) velAsVec(dir)))))
} }
...@@ -99,7 +99,7 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads { ...@@ -99,7 +99,7 @@ trait IR_PrintVisualizationNS extends IR_PrintVisualizationQuads {
val initBuffer : ListBuffer[IR_Statement] = (0 until numDimsGrid).map(d => { val initBuffer : ListBuffer[IR_Statement] = (0 until numDimsGrid).map(d => {
val linearizedIdx = idxRange.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid)) val linearizedIdx = idxRange.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
IR_Assignment( 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 velAsVec(d)) : IR_Statement
}).to[ListBuffer] }).to[ListBuffer]
......
...@@ -91,7 +91,7 @@ trait IR_PrintVisualizationSWE extends IR_PrintVisualizationTriangles { ...@@ -91,7 +91,7 @@ trait IR_PrintVisualizationSWE extends IR_PrintVisualizationTriangles {
IR_LoopOverDimensions(numDimsGrid, indexRangeCells, IR_LoopOverDimensions(numDimsGrid, indexRangeCells,
(0 until numAccessesPerCell).to[ListBuffer].map(idx => { (0 until numAccessesPerCell).to[ListBuffer].map(idx => {
IR_Assignment( 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 IR_FieldAccess(discFields(tmpBuf.name)(idx), IR_IV_ActiveSlot(someCellField), IR_LoopOverDimensions.defIt(numDimsGrid))) : IR_Statement
})))) }))))
} }
......
...@@ -117,7 +117,7 @@ case class IR_PrintXdmfSWE( ...@@ -117,7 +117,7 @@ case class IR_PrintXdmfSWE(
IR_LoopOverDimensions(numDimsGrid, indexRangeCells, IR_LoopOverDimensions(numDimsGrid, indexRangeCells,
(0 until numAccessesPerCell).to[ListBuffer].map(idx => { (0 until numAccessesPerCell).to[ListBuffer].map(idx => {
IR_Assignment( 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 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 ...@@ -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 { 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 /// IR_AccessPattern
......
...@@ -8,6 +8,7 @@ import exastencils.baseExt.ir.IR_ExpressionIndexRange ...@@ -8,6 +8,7 @@ import exastencils.baseExt.ir.IR_ExpressionIndexRange
import exastencils.baseExt.ir.IR_InternalVariable import exastencils.baseExt.ir.IR_InternalVariable
import exastencils.baseExt.ir.IR_LoopOverFragments import exastencils.baseExt.ir.IR_LoopOverFragments
import exastencils.grid.ir.IR_Localization import exastencils.grid.ir.IR_Localization
import exastencils.prettyprinting.PpStream
/// IR_IV_TemporaryBuffer /// IR_IV_TemporaryBuffer
// represents a temporary buffer where data is stored (fragment-wise) before writing it to file // 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 ...@@ -16,17 +17,6 @@ import exastencils.grid.ir.IR_Localization
// - only contains data of interest // - only contains data of interest
// - does not have layers to be excluded (e.g. pad/ghost/...) // - 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( case class IR_IV_TemporaryBuffer(
var baseDatatype : IR_Datatype, var baseDatatype : IR_Datatype,
var localization : IR_Localization, var localization : IR_Localization,
...@@ -34,7 +24,9 @@ case class IR_IV_TemporaryBuffer( ...@@ -34,7 +24,9 @@ case class IR_IV_TemporaryBuffer(
var domainIdx : Int, var domainIdx : Int,
var blockwise : Boolean, var blockwise : Boolean,
dimsPerFrag : ListBuffer[IR_Expression], 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 resolveName() : String = name + resolvePostfix("", domainIdx.prettyprint, "", "", "")
override def resolveDatatype() : IR_Datatype = IR_PointerDatatype(baseDatatype) override def resolveDatatype() : IR_Datatype = IR_PointerDatatype(baseDatatype)
......
...@@ -193,7 +193,7 @@ trait IR_PrintVisualization { ...@@ -193,7 +193,7 @@ trait IR_PrintVisualization {
val initBuffer : ListBuffer[IR_Statement] = connectivityForCell().indices.map(d => { val initBuffer : ListBuffer[IR_Statement] = connectivityForCell().indices.map(d => {
val linearizedLoopIdx = loopOverCells().indices.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid)) val linearizedLoopIdx = loopOverCells().indices.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
IR_Assignment( 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 connectivityForCell(global)(d)) : IR_Statement
}).to[ListBuffer] }).to[ListBuffer]
...@@ -220,7 +220,7 @@ trait IR_PrintVisualization { ...@@ -220,7 +220,7 @@ trait IR_PrintVisualization {
val dims = (indexRange.end - indexRange.begin).indices.to[ListBuffer] val dims = (indexRange.end - indexRange.begin).indices.to[ListBuffer]
val linearizedLoopIdx = indexRange.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid)) val linearizedLoopIdx = indexRange.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
val init = IR_Assignment( 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)) getPos(IR_AtCellCenter, level, dim))
// declare, allocate and init temp. buffer with cell centers // declare, allocate and init temp. buffer with cell centers
...@@ -264,7 +264,7 @@ trait IR_PrintVisualization { ...@@ -264,7 +264,7 @@ trait IR_PrintVisualization {
IR_LoopOverDimensions(numDimsGrid, IR_LoopOverDimensions(numDimsGrid,
indexRange, indexRange,
IR_Assignment( 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))))))) getPos(IR_AtFaceCenter(faceDir), level, dim)))))))
} }
...@@ -285,7 +285,7 @@ trait IR_PrintVisualization { ...@@ -285,7 +285,7 @@ trait IR_PrintVisualization {
val initBuffer : ListBuffer[IR_Statement] = (0 until numAccPerCell).map(n => { val initBuffer : ListBuffer[IR_Statement] = (0 until numAccPerCell).map(n => {
val linearizedLoopIdx = loopOverDims(isNodalLoop).indices.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid)) val linearizedLoopIdx = loopOverDims(isNodalLoop).indices.linearizeIndex(IR_LoopOverDimensions.defIt(numDimsGrid))
IR_Assignment( 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 getPos(IR_AtNode, level, dim, IR_LoopOverDimensions.defIt(numDimsGrid) + nodeOffsets(n))) : IR_Statement
}).to[ListBuffer] }).to[ListBuffer]
......
...@@ -266,11 +266,11 @@ abstract class IR_PrintExodus() extends IR_Statement with IR_Expandable with IR_ ...@@ -266,11 +266,11 @@ abstract class IR_PrintExodus() extends IR_Statement with IR_Expandable with IR_
IR_LoopOverDimensions(numDimsGrid, indexRangeTransformed, IR_LoopOverDimensions(numDimsGrid, indexRangeTransformed,
(0 until numAccesses).to[ListBuffer].map(idx => { (0 until numAccesses).to[ListBuffer].map(idx => {
IR_Assignment( IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(tmp, offset + idx), IR_ArrayAccess(tmp, offset + idx),
buf.getAccess(IR_LoopOverDimensions.defIt(numDimsGrid) + accesses(idx))) : IR_Statement 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 { } else {
buf.getBaseAddress buf.getBaseAddress
} }
......
...@@ -129,7 +129,7 @@ abstract class IR_PrintXdmfStructured(ioMethod : IR_Expression) extends IR_Print ...@@ -129,7 +129,7 @@ abstract class IR_PrintXdmfStructured(ioMethod : IR_Expression) extends IR_Print
IR_IfCondition(IR_IV_IsValidForDomain(dataBuffer.domainIdx), IR_IfCondition(IR_IV_IsValidForDomain(dataBuffer.domainIdx),
IR_LoopOverDimensions(numDimsGrid, idxRange, IR_LoopOverDimensions(numDimsGrid, idxRange,
IR_Assignment( IR_Assignment(
IR_IV_TemporaryBuffer.accessArray(tmpBufDest, fragOff + linearizedIdx), IR_ArrayAccess(tmpBufDest, fragOff + linearizedIdx),
mean)))) mean))))
stmts 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