-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retry to RoundRobin Partitioner and Range Partitioner (#9419)
* Add retry to RoundRobin Partitioner and Range Partitioner Signed-off-by: Ferdinand Xu <ferdinandx@nvidia.com> * Revert some unintented changes * Fix some unintented changes * Fix * Fix failed cases * Address comments * Address comments * Address comments * Fix * Address comments --------- Signed-off-by: Ferdinand Xu <ferdinandx@nvidia.com>
- Loading branch information
1 parent
8b04945
commit ed37af8
Showing
3 changed files
with
154 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
tests/src/test/scala/com/nvidia/spark/rapids/ShufflePartitionerRetrySuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.nvidia.spark.rapids | ||
|
||
import ai.rapids.cudf.Table | ||
import com.nvidia.spark.rapids.Arm.withResource | ||
import com.nvidia.spark.rapids.RapidsPluginImplicits._ | ||
import com.nvidia.spark.rapids.jni.RmmSpark | ||
|
||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.catalyst.expressions.{Ascending, AttributeReference, ExprId, SortOrder, SpecificInternalRow} | ||
import org.apache.spark.sql.types.{DataType, IntegerType, StringType} | ||
import org.apache.spark.sql.vectorized.ColumnarBatch | ||
|
||
class ShufflePartitionerRetrySuite extends RmmSparkRetrySuiteBase { | ||
private def buildBatch(): ColumnarBatch = { | ||
withResource(new Table.TestBuilder() | ||
.column(9, null.asInstanceOf[java.lang.Integer], 8, 7, 6, 5, 4, 3, 2, 1) | ||
.column("nine", "eight", null, null, "six", "five", "four", "three", "two", "one") | ||
.build()) { table => | ||
GpuColumnVector.from(table, Array(IntegerType, StringType)) | ||
} | ||
} | ||
|
||
private def testRoundRobinPartitioner(partNum: Int) = { | ||
TestUtils.withGpuSparkSession(new SparkConf()) { _ => | ||
val rrp = GpuRoundRobinPartitioning(partNum) | ||
// batch will be closed within columnarEvalAny | ||
val batch = buildBatch | ||
RmmSpark.forceRetryOOM(RmmSpark.getCurrentThreadId, 1) | ||
var ret: Array[(ColumnarBatch, Int)] = null | ||
try { | ||
ret = rrp.columnarEvalAny(batch).asInstanceOf[Array[(ColumnarBatch, Int)]] | ||
assert(partNum === ret.size) | ||
} finally { | ||
if (ret != null) { | ||
ret.map(_._1).safeClose() | ||
} | ||
} | ||
} | ||
} | ||
|
||
test("GPU range partition with retry") { | ||
TestUtils.withGpuSparkSession(new SparkConf()) { _ => | ||
// Initialize range bounds | ||
val fieldTypes: Array[DataType] = Array(IntegerType) | ||
val bounds = new SpecificInternalRow(fieldTypes) | ||
bounds.setInt(0, 3) | ||
// Initialize GPU sorter | ||
val ref = GpuBoundReference(0, IntegerType, nullable = true)(ExprId(0), "a") | ||
val sortOrder = SortOrder(ref, Ascending) | ||
val attrs = AttributeReference(ref.name, ref.dataType, ref.nullable)() | ||
val gpuSorter = new GpuSorter(Seq(sortOrder), Array(attrs)) | ||
|
||
val rp = GpuRangePartitioner(Array.apply(bounds), gpuSorter) | ||
// batch will be closed within columnarEvalAny | ||
val batch = buildBatch | ||
RmmSpark.forceRetryOOM(RmmSpark.getCurrentThreadId, 1) | ||
var ret: Array[(ColumnarBatch, Int)] = null | ||
try { | ||
ret = rp.columnarEvalAny(batch).asInstanceOf[Array[(ColumnarBatch, Int)]] | ||
assert(ret.length === 2) | ||
} finally { | ||
if (ret != null) { | ||
ret.map(_._1).safeClose() | ||
} | ||
} | ||
} | ||
} | ||
|
||
test("GPU round robin partition with retry using multiple partition") { | ||
testRoundRobinPartitioner(4) | ||
} | ||
|
||
test("GPU round robin partitioner with retry using 1 partition") { | ||
testRoundRobinPartitioner(1) | ||
} | ||
} |