-
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
Changes from 1 commit
22bfac9
21369cc
e7cc530
80459c5
ddab30c
efff6c7
3fb8800
8949fcb
68cbaf7
af7cd9f
889aba9
95e330b
9bda9d6
ef99102
5941048
b400143
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,26 @@ def _get_ptx_file(): | |
return regular_result[1] | ||
|
||
|
||
default_heap_size = int(2e6) | ||
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. I feel like this needs a big comment on why this is the default. This number seems a bit high considering 10M rows of 100 bytes each would only be 1GB. I suppose it makes sense since it is the largest strings column in bytes possible. Would it be too strange to make this configurable through an environment variable perhaps? 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. I introduced an environment variable to control this. I'm still open to discussion here as to what to set the value as. Indeed I did base it on the size of a strings column. |
||
heap_size = 0 | ||
|
||
|
||
def set_malloc_heap_size(size=default_heap_size): | ||
""" | ||
Heap size control for strings_udf, size in bytes. | ||
""" | ||
global heap_size | ||
if size == heap_size: | ||
return | ||
else: | ||
brandon-b-miller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(ret,) = cudart.cudaDeviceSetLimit(cudart.cudaLimit(2), size) | ||
brandon-b-miller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ret.value != 0: | ||
breakpoint() | ||
brandon-b-miller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise RuntimeError("Unable to set cudaMalloc heap size") | ||
|
||
heap_size = size | ||
|
||
|
||
ptxpath = None | ||
versions = safe_get_versions() | ||
if versions != NO_DRIVER: | ||
|
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!