Repository navigation
Refactor registry init. - #6948
Conversation
This moves the implementations of core supported features out of the base context and into explicit targets. This is to ensure that targets only carry implementations of things they actually support.
from numba import cuda
import numpy as np
@cuda.jit
def f(x):
s = slice(1, 10, 2)
x[0] = s.start
x[1] = s.stop
x[2] = s.step
x = np.zeros(3, dtype=np.int64)
f[1, 1](x)
print(x)prints with this PR even though the slicing registry is not installed on the CUDA target - how is it working now? (Not that it shouldn't be, of course!) |
|
RE slicing. Seems like a lot of registries are being populated as a side effect of import. In the case of |
| unexpected = set(banlist) & set(modlist) | ||
| self.assertFalse(unexpected, "some modules unexpectedly imported") | ||
|
|
||
| def test_no_impl_import(self): |
There was a problem hiding this comment.
@gmarkall thoughts on having a test like this for the CUDA target? Essentially something to make sure that from numba import cuda / from numba.cuda import jit doesn't trigger import of modules that are known to have registration side effects.
There was a problem hiding this comment.
Sounds good, I'll have an experiment with adding a test like this.
There was a problem hiding this comment.
Seems that from numba import cuda ends up importing numba.cpython.cmathimpl and numba.cpython.mathimpl.
There was a problem hiding this comment.
... though, this seems to be quite easily fixable.
There was a problem hiding this comment.
Test and fix added in 0611f05 - what do you think @stuartarchibald ?
There was a problem hiding this comment.
Thanks @gmarkall, the patch looks good. Are you happy for me to include it in this branch?
There was a problem hiding this comment.
Great, thanks for confirming :)
The rest of the patches on this PR are to deal with this! They make it so that modules that register lowering implementations are not imported at import time, or at decoration time, but only once compilation starts. The side effect of this is that nothing (not even the NRT) is |
|
@stuartarchibald, the only way I can think of to avoid the move for |
Thanks @sklam, I think this approach may well work, it's similar to previous shims. As discussed OOB, first Python 3.6 removal is required, will open a new PR for that. |
This also required a small fix to prevent the registration of mathimpl and cmathimpl when `cuda` was imported.
Conflicts: numba/cuda/target.py
| # Initialize typed containers | ||
| import numba.typed |
There was a problem hiding this comment.
@sklam Do you recall why this is here? Could it go into the CPU context?
There was a problem hiding this comment.
I think this is needed to register the typed containers for cases where they are used by implicitly; e.g. d = {}
sklam
left a comment
There was a problem hiding this comment.
The changes look good. It's good to see the reduction in import time and that the import side-effects are better controlled.
I profile the import time again from python -X importtime -c "import numba". Here is a descending list of cumulative import time:
self | cumulative | package
0.2% | 26.3% | numba.core.config
0.1% | 21.6% | llvmlite.binding
0.1% | 21.2% | numba.core.decorators
0.1% | 20.9% | numba.stencils.stencil
0.1% | 19.7% | numba.core.types
0.1% | 19.6% | llvmlite.binding.dylib
1.1% | 19.0% | llvmlite.binding.ffi
7.0% | 17.8% | pkg_resources
5.3% | 17.2% | numpy
0.1% | 14.7% | numba.core.registry
0.1% | 14.5% | numba.core.dispatcher
0.7% | 14.1% | numba.core.compiler
0.1% | 6.4% | numba.core.callconv
1.3% | 6.3% | numba.core.base
0.0% | 5.9% | numba.testing
0.2% | 5.6% | numba.core.ir_utils
If we are interested in further importtime reduction, we should try using PEP562 in numba/__init__.py to defer more of the import
|
Thanks for the review @sklam. |
This moves the implementations of core supported features out of
the base context and into explicit targets. This is to ensure that
targets only carry implementations of things they actually
support.