Call setDevice on each thread at entry point. #3269
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves the af_init function so that it calls cudaSetDevice for
each new thread when creating any ArrayFire objects.
Description
CUDA requires that cudaSetDevice be called in each thread before
any other calls are made to the CUDA API. This is done by default
on the main thread but it is not done on new threads created. This
commit changes the behavior or the af_init function so that it call
the cudaSetDevice when creating a new object in ArrayFire.
This commit also refactors the af_init function so that it calls a lower
overhead init function which initializes the device manager.
Changes to Users
Users may not need to call af::setDevice in new threads before they
can use ArrayFire functions.
Checklist
[ ] Functions added to unified API[ ] Functions documented