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

Move Stack classes to wrapper classes to fix non-deterministic build issue #9576

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -18,4 +18,36 @@ package com.nvidia.spark.rapids

import scala.collection.mutable.ArrayStack

class ScalaStack[T] extends ArrayStack[T]
class RapidsStack[T] extends Proxy {
private val stack = new ArrayStack[T]()

override def self = stack

def push(elem1: T): Unit = {
self.push(elem1)
}

def pop(): T = {
self.pop()
}

def isEmpty: Boolean = {
self.isEmpty
}

def nonEmpty: Boolean = {
self.nonEmpty
}

def size: Int = {
self.size
}

def toSeq: Seq[T] = {
self.toSeq
}

def clear(): Unit = {
self.clear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,36 @@ package com.nvidia.spark.rapids

import scala.collection.mutable.Stack

class ScalaStack[T] extends Stack[T]
class RapidsStack[T] extends Proxy {
private val stack = new Stack[T]()
override def self = stack

def push(elem1: T): RapidsStack[T] = {
self.push(elem1)
this
}

def pop(): T = {
self.pop()
}

def isEmpty: Boolean = {
self.isEmpty
}

def nonEmpty: Boolean = {
self.nonEmpty
}

def size(): Int = {
self.size
}

def toSeq(): Seq[T] = {
self.toSeq
}

def clear(): Unit = {
self.clear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ case class GpuOutOfCoreSortIterator(
while (!pending.isEmpty && sortedSize < targetSize) {
// Keep going until we have enough data to return
var bytesLeftToFetch = targetSize
val pendingSort = new ScalaStack[SpillableColumnarBatch]()
closeOnExcept(pendingSort) { _ =>
val pendingSort = new RapidsStack[SpillableColumnarBatch]()
closeOnExcept(pendingSort.toSeq) { _ =>
while (!pending.isEmpty &&
(bytesLeftToFetch - pending.peek().buffer.sizeInBytes >= 0 || pendingSort.isEmpty)) {
val buffer = pending.poll().buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ class GpuSorter(
* @return the sorted data.
*/
final def mergeSortAndCloseWithRetry(
spillableBatches: ScalaStack[SpillableColumnarBatch],
spillableBatches: RapidsStack[SpillableColumnarBatch],
sortTime: GpuMetric): SpillableColumnarBatch = {
closeOnExcept(spillableBatches) { _ =>
closeOnExcept(spillableBatches.toSeq) { _ =>
assert(spillableBatches.nonEmpty)
}
withResource(new NvtxWithMetrics("merge sort", NvtxColor.DARK_GREEN, sortTime)) { _ =>
Expand Down Expand Up @@ -277,9 +277,9 @@ class GpuSorter(
}
}
} else {
closeOnExcept(spillableBatches) { _ =>
val batchesToMerge = new ScalaStack[SpillableColumnarBatch]()
closeOnExcept(batchesToMerge) { _ =>
closeOnExcept(spillableBatches.toSeq) { _ =>
val batchesToMerge = new RapidsStack[SpillableColumnarBatch]()
closeOnExcept(batchesToMerge.toSeq) { _ =>
while (spillableBatches.nonEmpty || batchesToMerge.size > 1) {
// pop a spillable batch if there is one, and add it to `batchesToMerge`.
if (spillableBatches.nonEmpty) {
Expand All @@ -299,7 +299,7 @@ class GpuSorter(

// we no longer care about the old batches, we closed them
closeOnExcept(merged) { _ =>
batchesToMerge.safeClose()
batchesToMerge.toSeq.safeClose()
batchesToMerge.clear()
}

Expand Down