Skip to content

Commit

Permalink
Use thread-local to track CUDA device in JNI (#6597)
Browse files Browse the repository at this point in the history
* Use thread-local to track CUDA device in JNI

* changelog
  • Loading branch information
jlowe authored Oct 26, 2020
1 parent 4205104 commit cbd2726
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
- PR #6581 Add JNI API to check if PTDS is enabled

## Improvements
- PR #6430 Add struct type support to `to_arrow` and `from_arrow`

- PR #6430 Add struct type support to `to_arrow` and `from_arrow`
- PR #6384 Add CSV fuzz tests with varying function parameters
- PR #6385 Add JSON fuzz tests with varying function parameters
- PR #6398 Remove function constructor macros in parquet reader
Expand All @@ -29,6 +29,7 @@
- PR #6555 Adapt JNI build to libcudf composition of multiple libraries
- PR #6564 Load JNI library dependencies with a thread pool
- PR #6573 Create `cudf::detail::byte_cast` for `cudf::byte_cast`
- PR #6597 Use thread-local to track CUDA device in JNI

## Bug Fixes

Expand Down
10 changes: 5 additions & 5 deletions java/src/main/native/src/CudaJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace {
/** The CUDA device that should be used by all threads using cudf */
int Cudf_device{cudaInvalidDeviceId};

thread_local int Thread_device = cudaInvalidDeviceId;

} // anonymous namespace

namespace cudf {
Expand All @@ -37,12 +39,10 @@ void set_cudf_device(int device) {
*/
void auto_set_device(JNIEnv *env) {
if (Cudf_device != cudaInvalidDeviceId) {
int device;
cudaError_t cuda_status = cudaGetDevice(&device);
jni_cuda_check(env, cuda_status);
if (device != Cudf_device) {
cuda_status = cudaSetDevice(Cudf_device);
if (Thread_device != Cudf_device) {
cudaError_t cuda_status = cudaSetDevice(Cudf_device);
jni_cuda_check(env, cuda_status);
Thread_device = Cudf_device;
}
}
}
Expand Down

0 comments on commit cbd2726

Please sign in to comment.