-
Notifications
You must be signed in to change notification settings - Fork 242
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
Fix two potential OOM issues in GPU aggregate. #11908
Merged
winningsix
merged 5 commits into
NVIDIA:branch-25.02
from
firestarman:nested-lit-presplit
Jan 10, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
121 changes: 121 additions & 0 deletions
121
tests/src/test/scala/com/nvidia/spark/rapids/unit/LiteralSizeEstimationTest.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,121 @@ | ||
/* | ||
* Copyright (c) 2025, 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.unit | ||
|
||
import ai.rapids.cudf.ColumnVector | ||
import com.nvidia.spark.rapids.{GpuScalar, GpuUnitTests, PreProjectSplitIterator} | ||
import com.nvidia.spark.rapids.Arm.withResource | ||
|
||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, ArrayData} | ||
import org.apache.spark.sql.types._ | ||
import org.apache.spark.unsafe.types.UTF8String | ||
|
||
/** These tests only cover nested type literals for the PreProjectSplitIterator case */ | ||
class LiteralSizeEstimationTest extends GpuUnitTests { | ||
private val numRows = 1000 | ||
|
||
private def testLiteralSizeEstimate(lit: Any, litType: DataType): Unit = { | ||
val col = withResource(GpuScalar.from(lit, litType))(ColumnVector.fromScalar(_, numRows)) | ||
val actualSize = withResource(col)(_.getDeviceMemorySize) | ||
val estimatedSize = PreProjectSplitIterator.calcSizeForLiteral(lit, litType, numRows) | ||
assertResult(actualSize)(estimatedSize) | ||
} | ||
|
||
test("estimate the array(int) literal size") { | ||
val litType = ArrayType(IntegerType, true) | ||
val lit = ArrayData.toArrayData(Array(null, 1, 2, null)) | ||
testLiteralSizeEstimate(lit, litType) | ||
} | ||
|
||
test("estimate the array(string) literal size") { | ||
val litType = ArrayType(StringType, true) | ||
val lit = ArrayData.toArrayData( | ||
Array(null, UTF8String.fromString("s1"), UTF8String.fromString("s2"))) | ||
testLiteralSizeEstimate(lit, litType) | ||
} | ||
|
||
test("estimate the array(array(array(int))) literal size") { | ||
val litType = ArrayType(ArrayType(ArrayType(IntegerType, true), true), true) | ||
val nestedElem1 = ArrayData.toArrayData(Array(null, 1, 2, null)) | ||
val nestedElem2 = ArrayData.toArrayData(Array(null)) | ||
val nestedElem3 = ArrayData.toArrayData(Array()) | ||
val elem1 = ArrayData.toArrayData(Array(nestedElem1, null)) | ||
val elem2 = ArrayData.toArrayData(Array(nestedElem2, null, nestedElem3)) | ||
val lit = ArrayData.toArrayData(Array(null, elem1, null, elem2, null)) | ||
testLiteralSizeEstimate(lit, litType) | ||
} | ||
|
||
test("estimate the array(array(array(string))) literal size") { | ||
val litType = ArrayType(ArrayType(ArrayType(StringType, true), true), true) | ||
val nestedElem1 = ArrayData.toArrayData( | ||
Array(null, UTF8String.fromString("s1"), UTF8String.fromString("s2"))) | ||
val nestedElem2 = ArrayData.toArrayData(Array(null)) | ||
val nestedElem3 = ArrayData.toArrayData(Array()) | ||
val elem1 = ArrayData.toArrayData(Array(nestedElem1, null)) | ||
val elem2 = ArrayData.toArrayData(Array(nestedElem2, null, nestedElem3)) | ||
val lit = ArrayData.toArrayData(Array(null, elem1, null, elem2, null)) | ||
testLiteralSizeEstimate(lit, litType) | ||
} | ||
|
||
test("estimate the struct(int, string) literal size") { | ||
val litType = StructType(Seq( | ||
StructField("int1", IntegerType), | ||
StructField("string2", StringType) | ||
)) | ||
// null | ||
testLiteralSizeEstimate(InternalRow(null, null), litType) | ||
// normal case | ||
testLiteralSizeEstimate(InternalRow(1, UTF8String.fromString("s1")), litType) | ||
} | ||
|
||
test("estimate the struct(int, array(string)) literal size") { | ||
val litType = StructType(Seq( | ||
StructField("int1", IntegerType), | ||
StructField("string2", ArrayType(StringType, true)) | ||
)) | ||
testLiteralSizeEstimate(InternalRow(null, null), litType) | ||
val arrayLit = ArrayData.toArrayData( | ||
Array(null, UTF8String.fromString("s1"), UTF8String.fromString("s2"))) | ||
// normal case | ||
testLiteralSizeEstimate(InternalRow(1, arrayLit), litType) | ||
} | ||
|
||
test("estimate the list(struct(int, array(string))) literal size") { | ||
val litType = ArrayType( | ||
StructType(Seq( | ||
StructField("int1", IntegerType), | ||
StructField("string2", ArrayType(StringType, true)) | ||
)), true) | ||
val arrayLit = ArrayData.toArrayData( | ||
Array(null, UTF8String.fromString("a1"), UTF8String.fromString("a2"))) | ||
val elem1 = InternalRow(1, arrayLit) | ||
val elem2 = InternalRow(null, null) | ||
val lit = ArrayData.toArrayData(Array(null, elem1, elem2)) | ||
testLiteralSizeEstimate(lit, litType) | ||
} | ||
|
||
test("estimate the map(int, array(string)) literal size") { | ||
val litType = MapType(IntegerType, ArrayType(StringType, true), true) | ||
val arrayLit = ArrayData.toArrayData( | ||
Array(null, UTF8String.fromString("s1"), UTF8String.fromString("s2"))) | ||
val valueLit = ArrayData.toArrayData(Array(null, arrayLit)) | ||
val keyLit = ArrayData.toArrayData(Array(1, 2)) | ||
val lit = new ArrayBasedMapData(keyLit, valueLit) | ||
testLiteralSizeEstimate(lit, litType) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may need use a separate PR for this as it is irrelevant to the description in #11903
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for review. @binmahone Could you help file an issue for this? Then I will follow your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also consider modifying the description in 11903 :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated