Commit 0501ad6d authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Merge branch 'devel/adapt_alloc' into 'master'

Add option for more compact buffer allocation

See merge request exastencils/exastencils!90
parents d243c6d7 2501aaa9
......@@ -144,6 +144,9 @@ object IR_DefaultLayerHandler extends IR_LayerHandler {
else
IR_Expand.doUntilDone()
if (Knowledge.experimental_compactBufferAllocation)
IR_AdaptAllocateDataFunction.apply()
// HACK: create discr_h* again if there are no multigrid level and the field size was defined explicitly
// currently this works only if all fields are equally sized
if (Knowledge.domain_rect_generate && Knowledge.maxLevel <= 0) {
......
......@@ -672,6 +672,10 @@ object Knowledge {
/// experimental features
// compact buffer allocation
var experimental_compactBufferAllocation : Boolean = false
var experimental_compactBufferAllocationSize : Int = 0 // 0: automatic, else: user-defined
// generates call stacks for all employed timers
var experimental_disableIterationOffsets : Boolean = false
var experimental_bc_checkOnlyMainAxis : Boolean = true
......
......@@ -21,7 +21,11 @@ package exastencils.globals.ir
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.communication.NeighborInfo
import exastencils.config.Knowledge
import exastencils.datastructures.DefaultStrategy
import exastencils.datastructures.Transformation
import exastencils.field.ir._
/// IR_AllocateDataFunction
......@@ -30,6 +34,26 @@ object IR_AllocateDataFunction {
val fctName = "setupBuffers"
}
object IR_AdaptAllocateDataFunction extends DefaultStrategy("Enable closely spaced allocations") {
this += Transformation("Add workaround", {
case func : IR_Function if func.name == IR_AllocateDataFunction.fctName =>
if (!IR_GlobalCollection.get.externalDependencies.contains("malloc.h"))
IR_GlobalCollection.get.externalDependencies += "malloc.h"
val maxFieldSize = IR_FieldCollection.objects.map(field => (0 until field.layout.numDimsData).map(d =>
field.layout.defTotal(d)).product * field.resolveBaseDatatype.typicalByteSize).max
val allocSize = if (Knowledge.experimental_compactBufferAllocationSize > 0)
Knowledge.experimental_compactBufferAllocationSize
else
math.ceil(maxFieldSize / 1024.0).toInt * 1024
func.body.prepend(IR_FunctionCall(IR_ExternalFunctionReference("mallopt"), "M_MMAP_THRESHOLD", allocSize))
func
})
}
// TODO: split to separate functions for (host) fields, communication buffers and device data
case class IR_AllocateDataFunction(
var fields : ListBuffer[IR_Field],
......
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