Skip to content

Prevent taking the GIL in ForAll - #4581

Merged
seibert merged 1 commit into
numba:masterfrom
pentschev:forall-prevent-gil-taking
Sep 19, 2019
Merged

seibert merged 1 commit into
numba:masterfrom
pentschev:forall-prevent-gil-taking

Conversation

@pentschev

Copy link
Copy Markdown
Contributor

This is the result of a long-running bug and discussion, detailed in rapidsai/ucx-py#187.

To summarize, calling ForAll incurs in a cuOccupancyMaxPotentialBlockSize that takes two functions pointers, one being the CUDA kernel, and the other a function to calculate the require shared memory. The latter was a Python lambda before this PR, which caused the cuOccupancyMaxPotentialBlockSize to ultimately end up trying to take the GIL. To prevent that from happening, we can pass the pointer to a pure C function instead.

I have added no further tests since we could only reproduce this issue on very long and complex pipelines. Suggestions on how we could add tests for this are much appreciated.

Finally, I'm not sure if defining the C function via a @cfunc decorator is the preferred way, nor if this is the preferred place for the _b2d_func to live, please let me know if not.

cc @quasiben @kkraus14 @shwina @mt-jones @Akshay-Venkatesh @mrocklin

@kkraus14

Copy link
Copy Markdown

cc @seibert @sklam

@sklam

sklam commented Sep 18, 2019

Copy link
Copy Markdown
Member

The patch makes sense. Using @cfunc is certainly the quickest way to add a native function. I couldn't think of any reason to not use @cfunc. The alternative is to write it in C in one of the numba helper lib, which feels like way too much work.

We just need to run it through the our internal smoketest and we can accept it once it pass.

@kkraus14

Copy link
Copy Markdown

The patch makes sense. Using @cfunc is certainly the quickest way to add a native function. I couldn't think of any reason to not use @cfunc. The alternative is to write it in C in one of the numba helper lib, which feels like way too much work.

We just need to run it through the our internal smoketest and we can accept it once it pass.

@sklam great, let us know if we can help in any way. This is unfortunately a big blocker for us.

@seibert

seibert commented Sep 18, 2019

Copy link
Copy Markdown
Contributor

Assuming nothing blows up in CI, it will be merged to master by the end of the day

@pentschev

Copy link
Copy Markdown
Contributor Author

That's great to hear, thanks @sklam and @seibert !

@seibert

seibert commented Sep 18, 2019

Copy link
Copy Markdown
Contributor

Passed CI, so marking this for merge this evening.

@seibert seibert added 5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed and removed 3 - Ready for Review Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm labels Sep 18, 2019
@pentschev

Copy link
Copy Markdown
Contributor Author

Thanks @seibert !

@harrism

harrism commented Sep 18, 2019

Copy link
Copy Markdown

The CUDA Occupancy API provides multiple versions of cuOccupancyMaxPotentialBlockSize, only one of which takes a function to calculate smem size. In this case Numba is passing a function that always returns zero. If Numba always does that, I would suggest instead changing Numba to only ever call a version of cuOccupancyMaxPotentialBlockSize that takes an integer amount of dynamic shared memory rather than a function pointer.

@pentschev

pentschev commented Sep 18, 2019 •

Copy link
Copy Markdown
Contributor Author

@harrism I just saw that the CUDA Occupancy API uses the runtime API, whereas Numba only uses the driver API (feel free to correct me if I'm wrong here), and that's probably why it uses cuOccupancyMaxPotentialBlockSize.

@seibert

seibert commented Sep 19, 2019

Copy link
Copy Markdown
Contributor

In the interest of unblocking ucx-py, we'll merge this PR, but investigate @harrism's suggestion.

@harrism

harrism commented Sep 19, 2019

Copy link
Copy Markdown

@pentschev yep, I was referring to the driver API. The driver API has a version of cuOccupancyMaxPotentialBlockSize that takes an integer amount of dynamic shared memory rather than a function callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed CUDA CUDA related issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants