-
Notifications
You must be signed in to change notification settings - Fork 10
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
Move env var checks into patch_needed() function #22
Move env var checks into patch_needed() function #22
Conversation
With this change, the `patch_needed()` function can also be used from other libraries without them needing to reimplement the logic and env vars to decide whether to check the driver and runtime versions.
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 the logic would be easier to read with my suggested changes (less double negation and tracking values over distance), but otherwise looks fine.
if apply is not None: | ||
logger.debug(f"PTXCOMPILER_APPLY_NUMBA_CODEGEN_PATCH={apply}") | ||
try: | ||
apply = int(apply) | ||
except ValueError: | ||
apply = False | ||
|
||
if apply: | ||
return True |
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.
Maybe:
if apply is not None: | |
logger.debug(f"PTXCOMPILER_APPLY_NUMBA_CODEGEN_PATCH={apply}") | |
try: | |
apply = int(apply) | |
except ValueError: | |
apply = False | |
if apply: | |
return True | |
if apply is not None: | |
logger.debug(f"PTXCOMPILER_APPLY_NUMBA_CODEGEN_PATCH={apply}") | |
try: | |
return int(apply) | |
except ValueError: | |
return False |
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 this changes the behaviour so that the check won't be performed if the user sets PTXCOMPILER_APPLY_NUMBA_CODEGEN_PATCH
to 0
. Do we want to change this?
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.
Ah yes, I see I changed the logic here too. I think we should leave as is. So APPLY=1
is a hard "definitely apply" and APPLY=0
is a soft "don't apply": first check if CHECK=1
if check is not None: | ||
logger.debug(f"PTXCOMPILER_CHECK_NUMBA_CODEGEN_PATCH_NEEDED={check}") | ||
try: | ||
check = int(check) | ||
except ValueError: | ||
check = False | ||
else: | ||
check = True | ||
|
||
if not check: | ||
return False |
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.
if check is not None: | |
logger.debug(f"PTXCOMPILER_CHECK_NUMBA_CODEGEN_PATCH_NEEDED={check}") | |
try: | |
check = int(check) | |
except ValueError: | |
check = False | |
else: | |
check = True | |
if not check: | |
return False | |
if check is not None: | |
logger.debug(f"PTXCOMPILER_CHECK_NUMBA_CODEGEN_PATCH_NEEDED={check}") | |
try: | |
return int(check) | |
except ValueError: | |
return False |
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.
If the user sets PTXCOMPILER_CHECK_NUMBA_CODEGEN_PATCH_NEEDED
to 1
, won't this end up always applying the patch instead of checking if the patch is needed?
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.
Ah sorry, yes.
@wence- Many thanks for the review - comments / suggestions replied to. |
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.
Logic seems fine to me.
Many thanks all! |
With this change, the
patch_needed()
function can also be used from other libraries without them needing to reimplement the logic and env vars to decide whether to check the driver and runtime versions.I also updated the message about not patching the Numba codegen - the reason for not patching the codegen is not always the driver version (sometimes it's the environment variable) and the reason should be apparent from previous log lines, so it now only states that the codegen is not being patched.
Some of my experiments/checks with this change (similar to those I did for #20):