Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safely close multiple resources in RapidsBufferCatalog #11307

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,6 @@

package com.nvidia.spark.rapids

import scala.collection
import scala.collection.generic.CanBuildFrom
import scala.collection.mutable
import scala.reflect.ClassTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package com.nvidia.spark.rapids
import java.util.concurrent.ConcurrentHashMap
import java.util.function.BiFunction

import scala.collection.JavaConverters.collectionAsScalaIterableConverter

import ai.rapids.cudf.{ContiguousTable, Cuda, DeviceMemoryBuffer, HostMemoryBuffer, MemoryBuffer, Rmm, Table}
import com.nvidia.spark.rapids.Arm.{closeOnExcept, withResource}
import com.nvidia.spark.rapids.RapidsBufferCatalog.getExistingRapidsBufferAndAcquire
Expand Down Expand Up @@ -727,9 +729,8 @@ class RapidsBufferCatalog(
def numBuffers: Int = bufferMap.size()

override def close(): Unit = {
bufferIdToHandles.values.forEach { handles =>
handles.foreach(_.close())
}
bufferIdToHandles.values.asScala.toSeq.flatMap(_.seq).safeClose()
gerashegalov marked this conversation as resolved.
Show resolved Hide resolved

bufferIdToHandles.clear()
}
}
Expand Down Expand Up @@ -864,30 +865,15 @@ object RapidsBufferCatalog extends Logging {
}

private def closeImpl(): Unit = synchronized {
if (_singleton != null) {
_singleton.close()
_singleton = null
}

if (memoryEventHandler != null) {
// Workaround for shutdown ordering problems where device buffers allocated with this handler
// are being freed after the handler is destroyed
//Rmm.clearEventHandler()
memoryEventHandler = null
}
val memoryEventHandlerCloser: AutoCloseable = () =>
if (memoryEventHandler != null) {
// Workaround for shutdown ordering problems where device buffers allocated
// with this handler are being freed after the handler is destroyed
//Rmm.clearEventHandler()
memoryEventHandler = null
}
gerashegalov marked this conversation as resolved.
Show resolved Hide resolved

if (deviceStorage != null) {
deviceStorage.close()
deviceStorage = null
}
if (hostStorage != null) {
hostStorage.close()
hostStorage = null
}
if (diskStorage != null) {
diskStorage.close()
diskStorage = null
}
Seq(_singleton, memoryEventHandlerCloser, deviceStorage, hostStorage, diskStorage).safeClose()
}

def getDeviceStorage: RapidsDeviceMemoryStore = deviceStorage
Expand Down