Skip to content

Commit

Permalink
Add support for using the arena allocator (NVIDIA#871)
Browse files Browse the repository at this point in the history
Signed-off-by: Rong Ou <rong.ou@gmail.com>
  • Loading branch information
rongou authored Sep 30, 2020
1 parent 6b6a039 commit 0e76f2b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Name | Description | Default Value
<a name="memory.gpu.allocFraction"></a>spark.rapids.memory.gpu.allocFraction|The fraction of total GPU memory that should be initially allocated for pooled memory. Extra memory will be allocated as needed, but it may result in more fragmentation. This must be less than or equal to the maximum limit configured via spark.rapids.memory.gpu.maxAllocFraction.|0.9
<a name="memory.gpu.debug"></a>spark.rapids.memory.gpu.debug|Provides a log of GPU memory allocations and frees. If set to STDOUT or STDERR the logging will go there. Setting it to NONE disables logging. All other values are reserved for possible future expansion and in the mean time will disable logging.|NONE
<a name="memory.gpu.maxAllocFraction"></a>spark.rapids.memory.gpu.maxAllocFraction|The fraction of total GPU memory that limits the maximum size of the RMM pool. The value must be greater than or equal to the setting for spark.rapids.memory.gpu.allocFraction. Note that this limit will be reduced by the reserve memory configured in spark.rapids.memory.gpu.reserve.|1.0
<a name="memory.gpu.pooling.enabled"></a>spark.rapids.memory.gpu.pooling.enabled|Should RMM act as a pooling allocator for GPU memory, or should it just pass through to CUDA memory allocation directly.|true
<a name="memory.gpu.pool"></a>spark.rapids.memory.gpu.pool|Select the RMM pooling allocator to use. Valid values are "DEFAULT", "ARENA", and "NONE". With "DEFAULT", `rmm::mr::pool_memory_resource` is used; with "ARENA", `rmm::mr::arena_memory_resource` is used. If set to "NONE", pooling is disabled and RMM just passes through to CUDA memory allocation directly.|ARENA
<a name="memory.gpu.pooling.enabled"></a>spark.rapids.memory.gpu.pooling.enabled|Should RMM act as a pooling allocator for GPU memory, or should it just pass through to CUDA memory allocation directly. DEPRECATED: please use spark.rapids.memory.gpu.pool instead.|true
<a name="memory.gpu.reserve"></a>spark.rapids.memory.gpu.reserve|The amount of GPU memory that should remain unallocated by RMM and left for system use such as memory needed for kernels, kernel launches or JIT compilation.|1073741824
<a name="memory.host.spillStorageSize"></a>spark.rapids.memory.host.spillStorageSize|Amount of off-heap host memory to use for buffering spilled GPU data before spilling to local disk|1073741824
<a name="memory.pinnedPool.size"></a>spark.rapids.memory.pinnedPool.size|The size of the pinned memory pool in bytes unless otherwise specified. Use 0 to disable the pool.|0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,25 @@ object GpuDeviceManager extends Logging {
var init = RmmAllocationMode.CUDA_DEFAULT
val features = ArrayBuffer[String]()
if (conf.isPooledMemEnabled) {
init = init | RmmAllocationMode.POOL
features += "POOLED"
init = conf.rmmPool match {
case c if "default".equalsIgnoreCase(c) =>
features += "POOLED"
init | RmmAllocationMode.POOL
case c if "arena".equalsIgnoreCase(c) =>
features += "ARENA"
init | RmmAllocationMode.ARENA
case c if "none".equalsIgnoreCase(c) =>
// Pooling is disabled.
init
case c =>
throw new IllegalArgumentException(s"RMM pool set to '$c' is not supported.")
}
} else if (!"none".equalsIgnoreCase(conf.rmmPool)) {
logWarning("RMM pool is disabled since spark.rapids.memory.gpu.pooling.enabled is set " +
"to false; however, this configuration is deprecated and the behavior may change in a " +
"future release.")
}

if (conf.isUvmEnabled) {
init = init | RmmAllocationMode.CUDA_MANAGED_MEMORY
features += "UVM"
Expand Down Expand Up @@ -276,7 +292,7 @@ object GpuDeviceManager extends Logging {
private[this] val devId = getDeviceId.getOrElse {
throw new IllegalStateException("Device ID is not set")
}

override def newThread(runnable: Runnable): Thread = {
factory.newThread(() => {
Cuda.setDevice(devId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,19 @@ object RapidsConf {

val POOLED_MEM = conf("spark.rapids.memory.gpu.pooling.enabled")
.doc("Should RMM act as a pooling allocator for GPU memory, or should it just pass " +
"through to CUDA memory allocation directly.")
"through to CUDA memory allocation directly. DEPRECATED: please use " +
"spark.rapids.memory.gpu.pool instead.")
.booleanConf
.createWithDefault(true)

val RMM_POOL = conf("spark.rapids.memory.gpu.pool")
.doc("Select the RMM pooling allocator to use. Valid values are \"DEFAULT\", \"ARENA\", and " +
"\"NONE\". With \"DEFAULT\", `rmm::mr::pool_memory_resource` is used; with \"ARENA\", " +
"`rmm::mr::arena_memory_resource` is used. If set to \"NONE\", pooling is disabled and RMM " +
"just passes through to CUDA memory allocation directly.")
.stringConf
.createWithDefault("ARENA")

val CONCURRENT_GPU_TASKS = conf("spark.rapids.sql.concurrentGpuTasks")
.doc("Set the number of tasks that can execute concurrently per GPU. " +
"Tasks may temporarily block when the number of concurrent tasks in the executor " +
Expand Down Expand Up @@ -867,6 +876,8 @@ class RapidsConf(conf: Map[String, String]) extends Logging {

lazy val isPooledMemEnabled: Boolean = get(POOLED_MEM)

lazy val rmmPool: String = get(RMM_POOL)

lazy val rmmAllocFraction: Double = get(RMM_ALLOC_FRACTION)

lazy val rmmAllocMaxFraction: Double = get(RMM_ALLOC_MAX_FRACTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GpuDeviceManagerSuite extends FunSuite with Arm {
val maxPoolFraction = 0.2
val conf = new SparkConf()
.set(RapidsConf.POOLED_MEM.key, "true")
.set(RapidsConf.RMM_POOL.key, "ARENA")
.set(RapidsConf.RMM_ALLOC_FRACTION.key, initPoolFraction.toString)
.set(RapidsConf.RMM_ALLOC_MAX_FRACTION.key, maxPoolFraction.toString)
.set(RapidsConf.RMM_ALLOC_RESERVE.key, "0")
Expand Down

0 comments on commit 0e76f2b

Please sign in to comment.