-
Notifications
You must be signed in to change notification settings - Fork 915
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
Allow setting malloc heap size in string udfs #12094
Merged
rapids-bot
merged 16 commits into
rapidsai:branch-22.12
from
brandon-b-miller:fea-stringudf-heap
Nov 17, 2022
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
22bfac9
add lazy mechanism for setting the heap size
brandon-b-miller 21369cc
Merge branch 'branch-22.12' into fea-stringudf-heap
brandon-b-miller e7cc530
introduce env var to control heap, cleanup
brandon-b-miller 80459c5
fix logic error
brandon-b-miller ddab30c
Merge branch 'branch-22.12' into fea-stringudf-heap
brandon-b-miller efff6c7
Apply suggestions from code review
brandon-b-miller 3fb8800
Merge branch 'fea-stringudf-heap' of github.com:brandon-b-miller/cudf…
brandon-b-miller 8949fcb
style fix
brandon-b-miller 68cbaf7
Merge branch 'branch-22.12' into fea-stringudf-heap
brandon-b-miller af7cd9f
adjust logic
brandon-b-miller 889aba9
Update python/strings_udf/strings_udf/__init__.py
brandon-b-miller 95e330b
define _STRINGS_UDF_DEFAULT_HEAP_SIZE at init
brandon-b-miller 9bda9d6
use an lru cache
brandon-b-miller ef99102
Merge branch 'branch-22.12' into fea-stringudf-heap
brandon-b-miller 5941048
Update python/strings_udf/strings_udf/__init__.py
brandon-b-miller b400143
cleanup
brandon-b-miller 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import os | ||
|
||
from cubinlinker.patch import _numba_version_ok, get_logger, new_patched_linker | ||
from cuda import cudart | ||
from numba import cuda | ||
from numba.cuda.cudadrv.driver import Linker | ||
from ptxcompiler.patch import NO_DRIVER, safe_get_versions | ||
|
@@ -87,6 +88,31 @@ def _get_ptx_file(): | |
return regular_result[1] | ||
|
||
|
||
# Maximum size of a string column is 2gb | ||
brandon-b-miller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_STRINGS_UDF_DEFAULT_HEAP_SIZE = 2**31 | ||
heap_size = 0 | ||
|
||
|
||
def set_malloc_heap_size(size=None): | ||
""" | ||
Heap size control for strings_udf, size in bytes. | ||
""" | ||
global heap_size | ||
if size == None: | ||
brandon-b-miller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size = os.environ.get( | ||
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. Generally environment variables take effect at load time. I don't think we should allow/encourage the user to modify the environment of the process while it is running in order to change this. I think you want to define it on import rather than in the body of this function: _STRINGS_UDF_DEFAULT_HEAP_SIZE = os.environ.get("STRINGS_UDF_HEAP_SIZE", 2**31) |
||
"STRINGS_UDF_HEAP_SIZE", _STRINGS_UDF_DEFAULT_HEAP_SIZE | ||
) | ||
|
||
if size != heap_size: | ||
(ret,) = cudart.cudaDeviceSetLimit( | ||
cudart.cudaLimit.cudaLimitMallocHeapSize, size | ||
) | ||
if ret.value != 0: | ||
raise RuntimeError("Unable to set cudaMalloc heap size") | ||
|
||
heap_size = size | ||
|
||
|
||
ptxpath = None | ||
versions = safe_get_versions() | ||
if versions != NO_DRIVER: | ||
|
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.
The structure of this code makes it look like idempotency is its main goal, not laziness.
strings_udf.set_malloc_heap_size()
should only ever be called once, I think?Maybe this function or module in cudf (and not strings_udf) should own the “is it allocated already?” logic via a cache or global of some kind, and then the strings_udf logic doesn’t need to read env vars for the allocation size, etc.
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.
This is not an allocation. There is currently a malloc-heap-size by default (set to about 8MB on the GPUs I've tested on). This updates the heap size to a new value so "already allocated" is not the goal.
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.
Is
set_malloc_heap_size
intended to be a public API that can be called by a user, or is it an internal function? It's not entirely clear what the public API is here because this file doesn't define an__all__
. If the function is just for internal use, why does it need to be called every time someone accesses a string column rather than just callingcudaDeviceSetLimit
once when the package is imported (or after we can guarantee that the CUDA context/etc is initialized if that is the requirement that we're currently addressing by doing this "lazily")?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.
I think what we want to happen is:
STRING_UDF_HEAP_SIZE
to something else during the session.Does this seems reasonable?
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.
Seems we have 2 comment chains asking about the same thing.
#12094 (comment)
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.
Yes.
The "set" function should not be called. Avoid designs that try to set but exit early.
No. The
STRING_UDF_HEAP_SIZE
should not be modifiable (I argued separately that that variable should not exist at all). If the user needs to be able to set a specific size, then the "set" function should be public and the user should be able to call it explicitly with immediate effect (not waiting until the next UDF execution, because memory demands can change in the meantime).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.
With the changes in af7cd9f I still have
heap_size
available as a module level attribute ofstrings_udf
, what do you think about checking ifheap_size == 0
within the getter to determine if the function need be called or not?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 could use a cached function for this instead of a
global
that tracks whether the function has already been run. Following ideas from https://mail.python.org/archives/list/[email protected]/thread/5OR3LJO7LOL6SC4OOGKFIVNNH4KADBPG/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.
thanks this worked perfectly!