-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[WIP] better control of compilation of jitclass members #9565
base: main
Are you sure you want to change the base?
[WIP] better control of compilation of jitclass members #9565
Conversation
Ah, cool! Perhaps can you also consider how to do the similar thing for structref? It also has at least one location using Here: numba/numba/experimental/structref.py Lines 371 to 375 in e15cd68
|
It looks like it would be simple enough to roll a modification to |
Hi @andy-bell101, thanks for your contribution. What about, rather than using @jitclass(parallel=True)
class MyClass:
def my_method_1(self, a):
# this method is compiled with parallel=True
...
@update_jit_args(cache=True) # or @patch_jit_option(cache=True)
def my_method_2(self, b):
# this method is compiled with *only* the arguments given in
# the njit decorator here
# so just `cache=True` in this case
... |
If I understand your suggestion correctly I think it's the same behaviour as option 2 above, unless I missed something Edit: actually no, I misunderstood. I'm not sure what advantage using @update_jit_args is vs. calling njit directly |
I have been working on this in the background for a while. The current problem I'm stuck against is that the methods defined on the class are not the final methods on the object. There's an additional wrapper compiled around them (so you never hit the cache for the underlying method) and that wrapper itself is dynamically created via |
I'm attempting allowing users to control how the methods on their jitclasses are compiled. Currently everything is passed through
njit
and there's an opportunity to do something different.Proposed behaviours
There are two ideas for the behaviour that I had that I've listed below. At this stage I prefer option 1 because it's less complex and introduces fewer changes to the public API. But I can't deny that the second option would be more convenient for the use-case that prompted me to open the PR, since I'd just like to pass
cache=True
to all my member functions.Currently the code in the PR implements option 1.
Option 1: Options from jitclass or jitted method (but not both)
The first option is that you can "pre-jit" your method using
njit
and anynjit
options you give tojitclass
are irrelevant for that method.Option 2: Options from jitclass and jitted method are combined
The second option is that you can take the union of the two sets of arguments (with the method's keyword arguments taking priority) and compile the members that way. The easiest way I can think of to do this is to introduce a new
jitmethod
decorator that takes the same keyword arguments asnjit
.Notes
WIP
cache=True
parallel=True
nogil=True
StructRefProxy.__new__
to accept kwargs to control thenjit
of the constructor, and search for othernjit
uses inStructRef
andStructRefProxy
.