Skip to content
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

Support nogil=True for ufuncs and gufuncs #1317

Open
shoyer opened this issue Jul 11, 2015 · 10 comments
Open

Support nogil=True for ufuncs and gufuncs #1317

shoyer opened this issue Jul 11, 2015 · 10 comments
Labels
enhancement good first issue A good issue for a first time contributor Task
Milestone

Comments

@shoyer
Copy link

shoyer commented Jul 11, 2015

In [3]: @numba.vectorize(nogil=True)
   ...: def f(a, b):
   ...:     return a + b
   ...:

In [4]: f(1, 2)
KeyError: "Does not support option: 'nogil'"

This would be extremely useful for integrating numba ufuncs with dask.array.

@sklam
Copy link
Member

sklam commented Jul 11, 2015

I'm able to use all 4 cores with the following example. Numba is using numpy ufunc machinery, which is releasing the GIL. Note that it may need to warm up because the function is compiled on the first call.

from numba import vectorize
import numpy as np

@vectorize
def f(a, b):
    return np.sqrt(a) + np.cos(b) * np.sin(b) - a


nelem = 10**8
a = np.arange(nelem)
z = f(a, a)
print(z)


from concurrent.futures import ThreadPoolExecutor, as_completed

numthreads = 4
pool= ThreadPoolExecutor(numthreads)

futures = [pool.submit(f, a, a) for i in range(numthreads)]
for z in as_completed(futures):
    print(z)

@seibert
Copy link
Contributor

seibert commented Jul 11, 2015

In this case, should we make nogil=True on @vectorize simply print a warning that ufuncs always release the GIL?

@shoyer
Copy link
Author

shoyer commented Jul 14, 2015

I'm pleased to see this already exists!

I agree, a warning if nogil=True is passed seems appropriate.

@seibert seibert added this to the Numba 1.0 milestone Nov 3, 2017
@stuartarchibald stuartarchibald added the good first issue A good issue for a first time contributor label May 29, 2020
@stuartarchibald
Copy link
Contributor

Adding a warning for nogil=True being passed is the good first issue.

@sklam
Copy link
Member

sklam commented Sep 10, 2020

The enhancement task is: #1317 (comment)

@pradkrish
Copy link

is this task still available? I am a newcomer here and I would love to get my feet wet(with some guidance). Thanks.

@pradkrish
Copy link

In numba/np/ufunc/ufuncbuilder.py:85, before calling the method parse_as_flags(..), is that a good place to add a warning if nogil=True is present as one of the keys in topt?

@stuartarchibald
Copy link
Contributor

is this task still available? I am a newcomer here and I would love to get my feet wet(with some guidance). Thanks.

Yes! Thanks for taking it on.

@stuartarchibald
Copy link
Contributor

In numba/np/ufunc/ufuncbuilder.py:85, before calling the method parse_as_flags(..), is that a good place to add a warning if nogil=True is present as one of the keys in topt?

That looks like a good place as it'll also catch the use in guvectorize.

@pradkrish
Copy link

Lovely. Another question: After printing the warning, do you think nogil=True key-value pair should be deleted from topt before passing it on so that there won't be any KeyError down the chain?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue A good issue for a first time contributor Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants