-
Notifications
You must be signed in to change notification settings - Fork 240
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
Refactor the window code so it is not mostly kept in a few very large files [databricks] #10146
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a0b9d72
Move window ops to window package
revans2 4aa18db
Split large files up into smaller ones by functionality
revans2 2b95b68
Fixes for databricks
revans2 1f3b7bb
Addressed review comments
revans2 876aeeb
Rename object to make its usage clearer
revans2 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
2,230 changes: 0 additions & 2,230 deletions
2,230
sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuWindowExec.scala
This file was deleted.
Oops, something went wrong.
793 changes: 793 additions & 0 deletions
793
sql-plugin/src/main/scala/com/nvidia/spark/rapids/window/BasicWindowCalc.scala
Large diffs are not rendered by default.
Oops, something went wrong.
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
117 changes: 117 additions & 0 deletions
117
sql-plugin/src/main/scala/com/nvidia/spark/rapids/window/GpuBatchedWindowIterator.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,117 @@ | ||
/* | ||
* Copyright (c) 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. | ||
* 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.window | ||
|
||
import ai.rapids.cudf | ||
import ai.rapids.cudf.{DType, Scalar} | ||
import com.nvidia.spark.rapids.Arm.{withResource, withResourceIfAllowed} | ||
|
||
object GpuBatchedWindowIterator { | ||
def cudfAnd(lhs: cudf.ColumnVector, | ||
rhs: cudf.ColumnVector): cudf.ColumnVector = { | ||
withResource(lhs) { lhs => | ||
withResource(rhs) { rhs => | ||
lhs.and(rhs) | ||
} | ||
} | ||
} | ||
|
||
def areRowPartsEqual( | ||
scalars: Seq[Scalar], | ||
columns: Seq[cudf.ColumnVector], | ||
indexes: Seq[Int]): Array[Boolean] = { | ||
withResourceIfAllowed(arePartsEqual(scalars, columns)) { | ||
case scala.util.Right(ret) => Seq.fill(indexes.length)(ret).toArray | ||
case scala.util.Left(column) => | ||
indexes.map { index => | ||
withResource(column.getScalarElement(index)) { scalar => | ||
scalar.isValid && scalar.getBoolean | ||
} | ||
}.toArray | ||
} | ||
} | ||
|
||
def arePartsEqual( | ||
scalars: Seq[Scalar], | ||
columns: Seq[cudf.ColumnVector]): Either[cudf.ColumnVector, Boolean] = { | ||
if (scalars.length != columns.length) { | ||
scala.util.Right(false) | ||
} else if (scalars.isEmpty && columns.isEmpty) { | ||
scala.util.Right(true) | ||
} else { | ||
scala.util.Left(computeMask(scalars, columns)) | ||
} | ||
} | ||
|
||
private def computeMask( | ||
scalars: Seq[Scalar], | ||
columns: Seq[cudf.ColumnVector]): cudf.ColumnVector = { | ||
val dType = scalars.head.getType | ||
if (dType == DType.FLOAT32 || dType == DType.FLOAT64) { | ||
// We need to handle nans and nulls | ||
scalars.zip(columns).map { | ||
case (scalar, column) => | ||
withResource(scalar.equalToNullAware(column)) { eq => | ||
dType match { | ||
case DType.FLOAT32 if scalar.getFloat.isNaN => | ||
withResource(column.isNan) { isNan => | ||
isNan.or(eq) | ||
} | ||
case DType.FLOAT64 if scalar.getDouble.isNaN => | ||
withResource(column.isNan) { isNan => | ||
isNan.or(eq) | ||
} | ||
case _ => eq.incRefCount() | ||
} | ||
} | ||
}.reduce(cudfAnd) | ||
} else { | ||
scalars.zip(columns).map { | ||
case (scalar, column) => scalar.equalToNullAware(column) | ||
}.reduce(cudfAnd) | ||
} | ||
} | ||
|
||
def areOrdersEqual( | ||
scalars: Seq[Scalar], | ||
columns: Seq[cudf.ColumnVector], | ||
partsEqual: Either[cudf.ColumnVector, Boolean]): Either[cudf.ColumnVector, Boolean] = { | ||
if (scalars.length != columns.length) { | ||
scala.util.Right(false) | ||
} else if (scalars.isEmpty && columns.isEmpty) { | ||
// they are equal but only so far as the parts are also equal | ||
partsEqual match { | ||
case [email protected](_) => r | ||
case scala.util.Left(mask) => scala.util.Left(mask.incRefCount()) | ||
} | ||
} else { | ||
// Part mask and order by equality mask | ||
partsEqual match { | ||
case [email protected](false) => r | ||
case scala.util.Right(true) => | ||
scala.util.Left(computeMask(scalars, columns)) | ||
case scala.util.Left(partMask) => | ||
withResource(computeMask(scalars, columns)) { orderMask => | ||
scala.util.Left(orderMask.and(partMask)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
def getScalarRow(index: Int, columns: Seq[cudf.ColumnVector]): Array[Scalar] = | ||
columns.map(_.getScalarElement(index)).toArray | ||
} |
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.
Nit: Not new with this refactor, but doesn't this need to be a safeMap to better handle exceptions midway through the map?