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

Fix JNI leak on copy to device #10229

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions java/src/main/java/ai/rapids/cudf/ColumnView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4012,20 +4012,29 @@ static ColumnVector createColumnVector(DType type, int rows, HostMemoryBuffer da
}
if (mainColOffsets != null) {
// The offset buffer has (no. of rows + 1) entries, where each entry is INT32.sizeInBytes
long offsetsLen = OFFSET_SIZE * (mainColRows + 1);
long offsetsLen = OFFSET_SIZE * (((long)mainColRows) + 1);
mainOffsetsDevBuff = DeviceMemoryBuffer.allocate(offsetsLen);
mainOffsetsDevBuff.copyFromHostBuffer(mainColOffsets, 0, offsetsLen);
}
List<DeviceMemoryBuffer> toClose = new ArrayList<>();
long[] childHandles = new long[devChildren.size()];
for (ColumnView.NestedColumnVector ncv : devChildren) {
toClose.addAll(ncv.getBuffersToClose());
}
for (int i = 0; i < devChildren.size(); i++) {
childHandles[i] = devChildren.get(i).getViewHandle();
try {
for (ColumnView.NestedColumnVector ncv : devChildren) {
toClose.addAll(ncv.getBuffersToClose());
}
for (int i = 0; i < devChildren.size(); i++) {
childHandles[i] = devChildren.get(i).createViewHandle();
}
return new ColumnVector(mainColType, mainColRows, nullCount, mainDataDevBuff,
mainValidDevBuff, mainOffsetsDevBuff, toClose, childHandles);
} finally {
for (int i = 0; i < childHandles.length; i++) {
if (childHandles[i] != 0) {
ColumnView.deleteColumnView(childHandles[i]);
childHandles[i] = 0;
}
}
}
return new ColumnVector(mainColType, mainColRows, nullCount, mainDataDevBuff,
mainValidDevBuff, mainOffsetsDevBuff, toClose, childHandles);
}

private static NestedColumnVector createNewNestedColumnVector(
Expand All @@ -4048,21 +4057,32 @@ private static NestedColumnVector createNewNestedColumnVector(
children);
}

long getViewHandle() {
private long createViewHandle() {
long[] childrenColViews = null;
if (children != null) {
childrenColViews = new long[children.size()];
for (int i = 0; i < children.size(); i++) {
childrenColViews[i] = children.get(i).getViewHandle();
try {
if (children != null) {
childrenColViews = new long[children.size()];
for (int i = 0; i < children.size(); i++) {
childrenColViews[i] = children.get(i).createViewHandle();
}
}
long dataAddr = data == null ? 0 : data.address;
long dataLen = data == null ? 0 : data.length;
long offsetAddr = offsets == null ? 0 : offsets.address;
long validAddr = valid == null ? 0 : valid.address;
int nc = nullCount.orElse(ColumnVector.OffHeapState.UNKNOWN_NULL_COUNT).intValue();
return makeCudfColumnView(dataType.typeId.getNativeId(), dataType.getScale(), dataAddr, dataLen,
offsetAddr, validAddr, nc, (int) rows, childrenColViews);
} finally {
if (childrenColViews != null) {
for (int i = 0; i < childrenColViews.length; i++) {
if (childrenColViews[i] != 0) {
deleteColumnView(childrenColViews[i]);
childrenColViews[i] = 0;
}
}
}
}
long dataAddr = data == null ? 0 : data.address;
long dataLen = data == null ? 0 : data.length;
long offsetAddr = offsets == null ? 0 : offsets.address;
long validAddr = valid == null ? 0 : valid.address;
int nc = nullCount.orElse(ColumnVector.OffHeapState.UNKNOWN_NULL_COUNT).intValue();
return makeCudfColumnView(dataType.typeId.getNativeId(), dataType.getScale() , dataAddr, dataLen,
offsetAddr, validAddr, nc, (int)rows, childrenColViews);
}

List<DeviceMemoryBuffer> getBuffersToClose() {
Expand Down