Skip to content

Commit

Permalink
Explicitly set legacy or per-thread default stream in JNI (#6690)
Browse files Browse the repository at this point in the history
Fixes an issue where nvcomp could use the wrong stream when cudf is compiled with PTDS
  • Loading branch information
rongou authored Nov 7, 2020
1 parent bc43878 commit aac682b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- PR #6540 Add dictionary support to `cudf::unary_operation`
- PR #6537 Refactor ORC timezone
- PR #6527 Refactor DeviceColumnViewAccess to avoid JNI returning an array
- PR #6690 Explicitly set legacy or per-thread default stream in JNI
- PR #6545 Pin cmake policies to cmake 3.17 version
- PR #6556 Add dictionary support to `cudf::inner_join`, `cudf::left_join` and `cudf::full_join`
- PR #6557 Support nullable timestamp columns in time range window functions
Expand Down
21 changes: 14 additions & 7 deletions java/src/main/java/ai/rapids/cudf/Cuda.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
import org.slf4j.LoggerFactory;

public class Cuda {
// This needs to happen first before calling any native methods.
static {
NativeDepsLoader.loadNativeDeps();
}

// Defined in driver_types.h in cuda library.
static final int CPU_DEVICE_ID = -1;
static final long CUDA_STREAM_DEFAULT = 0;
static final long CUDA_STREAM_LEGACY = 1;
static final long CUDA_STREAM_PER_THREAD = 2;
private final static long DEFAULT_STREAM_ID = isPtdsEnabled() ? CUDA_STREAM_PER_THREAD : CUDA_STREAM_LEGACY;
private static final Logger log = LoggerFactory.getLogger(Cuda.class);
private static Boolean isCompat = null;

static {
NativeDepsLoader.loadNativeDeps();
}

private static class StreamCleaner extends MemoryCleaner.Cleaner {
private long stream;

Expand All @@ -39,7 +44,9 @@ private static class StreamCleaner extends MemoryCleaner.Cleaner {
protected boolean cleanImpl(boolean logErrorIfNotClean) {
boolean neededCleanup = false;
long origAddress = stream;
if (stream != 0) {
if (stream != CUDA_STREAM_DEFAULT &&
stream != CUDA_STREAM_LEGACY &&
stream != CUDA_STREAM_PER_THREAD) {
destroyStream(stream);
stream = 0;
neededCleanup = true;
Expand Down Expand Up @@ -89,7 +96,7 @@ public void waitOn(Event event) {
}

public long getStream() {
return cleaner == null ? 0 : cleaner.stream;
return cleaner == null ? DEFAULT_STREAM_ID : cleaner.stream;
}

/**
Expand Down Expand Up @@ -206,7 +213,7 @@ public void record(Stream stream) {
}

/**
* Captures the contents of stream 0 at the time of this call.
* Captures the contents of the default stream at the time of this call.
*/
public void record() {
record(DEFAULT_STREAM);
Expand Down

0 comments on commit aac682b

Please sign in to comment.