-
Notifications
You must be signed in to change notification settings - Fork 288
Unshimmify Arm helper methods to expose as public API #13424
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
Draft
rishic3
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
rishic3:unshim-arm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
29c681b
unshim Arm helper methods
rishic3 5c90181
add doc
rishic3 8ad6516
signoff
rishic3 b55c32e
address comments
rishic3 9077c85
use same example for consistency
rishic3 1775cf3
clarify usage
rishic3 9082dc7
Merge branch 'branch-25.10' into unshim-arm
rishic3 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -93,6 +93,48 @@ closed by the RAPIDS Accelerator, so the UDF only needs to close any | |
| intermediate data generated while producing the final result that is | ||
| returned. | ||
|
|
||
| #### ARM Helper Methods | ||
|
|
||
| For Scala, helper methods implementing the automatic resource management | ||
| pattern are exposed via the public Spark RAPIDS API under the `Arm` object: | ||
|
|
||
| ```scala | ||
| import com.nvidia.spark.rapids.Arm.{withResource, closeOnExcept} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we show both we should explain the difference and when to use one over the other
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, done |
||
| ``` | ||
|
|
||
| These patterns serve different use cases: | ||
| - `withResource`: closes the resource after the code block completes regardless | ||
| of whether it succeeds or throws an exception. This should be used for intermediate | ||
| resources that are unused beyond the code block. | ||
| - `closeOnExcept`: only closes the resource if an exception occurs within the | ||
| code block; if the block succeeds, the resource remains open. This should be used | ||
| if you want to continue using the resource after the code block but need to clean | ||
| up if an error occurs. | ||
|
|
||
| Examples: | ||
|
|
||
| ```scala | ||
| override def evaluateColumnar(numRows: Int, args: ColumnVector*): ColumnVector = { | ||
| val nullMask = withResource(args.head.isNull()) { nulls => // nulls always closed after code block | ||
| nulls.not() | ||
| } | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| ```scala | ||
| override def evaluateColumnar(numRows: Int, args: ColumnVector*): ColumnVector = { | ||
| val nullsCol = closeOnExcept(args.head.isNull()) { nulls => // nulls only closed if exception occurs | ||
| validate(nulls) // do something that might throw an exception | ||
| nulls | ||
| } | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| Note that these methods originated as a solution for Scala 2.12. Scala 2.13 introduced | ||
| the [Using](https://www.scala-lang.org/api/2.13.6/scala/util/Using$.html) utility, which is an alternative to `withResource` for 2.13 builds of Apache Spark. | ||
|
|
||
| ### Generating Columnar Output | ||
|
|
||
| The `evaluateColumnar` method must return a `ColumnVector` of an appropriate | ||
|
|
||
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.
It is worth pointing out that this originated as a solution for Scala 2.12- before Using was introduced in Scala 2.13. Thus, with 2.13 builds of Apache Spark it is an alternative as well.
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.
Done