Skip to content

Commit

Permalink
JNI bit cast (#7493)
Browse files Browse the repository at this point in the history
In #7373 logical_cast is renamed to bit_cast. That breaks JNI, and this fixes it.

Authors:
  - Robert (Bobby) Evans (@revans2)
  - Nghia Truong (@ttnghia)

Approvers:
  - Raza Jafri (@razajafri)
  - Jason Lowe (@jlowe)
  - Alessandro Bellina (@abellina)

URL: #7493
  • Loading branch information
revans2 authored Mar 3, 2021
1 parent 5bd6f94 commit c69b6f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
19 changes: 17 additions & 2 deletions java/src/main/java/ai/rapids/cudf/ColumnView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1304,9 +1304,24 @@ public ColumnVector castTo(DType type) {
* types must match.
* @param type the type you want to go to.
* @return a ColumnView that cannot outlive the Column that owns the actual data it points to.
* @deprecated this has changed to bit_cast in C++ so use that name instead
*/
@Deprecated
public ColumnView logicalCastTo(DType type) {
return new ColumnView(logicalCastTo(getNativeView(),
return bitCastTo(type);
}

/**
* Zero-copy cast between types with the same underlying length.
*
* Similar to bit_cast in C++. This will take the underlying data and create new metadata
* so it is interpreted as a new type. Not all types are supported the width of the
* types must match.
* @param type the type you want to go to.
* @return a ColumnView that cannot outlive the Column that owns the actual data it points to.
*/
public ColumnView bitCastTo(DType type) {
return new ColumnView(bitCastTo(getNativeView(),
type.typeId.getNativeId(), type.getScale()));
}

Expand Down Expand Up @@ -2607,7 +2622,7 @@ private static native long stringReplaceWithBackrefs(long columnView, String pat

private static native long castTo(long nativeHandle, int type, int scale);

private static native long logicalCastTo(long nativeHandle, int type, int scale);
private static native long bitCastTo(long nativeHandle, int type, int scale);

private static native long byteListCast(long nativeHandle, boolean config);

Expand Down
8 changes: 4 additions & 4 deletions java/src/main/native/src/ColumnViewJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas
CATCH_STD(env, 0);
}

JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_logicalCastTo(JNIEnv *env, jclass,
jlong handle, jint type,
jint scale) {
JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitCastTo(JNIEnv *env, jclass,
jlong handle, jint type,
jint scale) {
JNI_NULL_CHECK(env, handle, "native handle is null", 0);
try {
cudf::jni::auto_set_device(env);
cudf::column_view *column = reinterpret_cast<cudf::column_view *>(handle);
cudf::data_type n_data_type = cudf::jni::make_data_type(type, scale);
std::unique_ptr<cudf::column_view> result = std::make_unique<cudf::column_view>();
*result = cudf::logical_cast(*column, n_data_type);
*result = cudf::bit_cast(*column, n_data_type);
return reinterpret_cast<jlong>(result.release());
}
CATCH_STD(env, 0);
Expand Down
4 changes: 2 additions & 2 deletions java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2061,10 +2061,10 @@ void emptyStringColumnFindReplaceAll() {
}

@Test
void testLogicalCast() {
void testBitCast() {
try (ColumnVector cv = ColumnVector.decimalFromLongs(-2, 1L, 2L, 100L, 552L);
ColumnVector expected = ColumnVector.fromLongs(1L, 2L, 100L, 552L);
ColumnView casted = cv.logicalCastTo(DType.INT64)) {
ColumnView casted = cv.bitCastTo(DType.INT64)) {
assertColumnsAreEqual(expected, casted);
}
}
Expand Down

0 comments on commit c69b6f8

Please sign in to comment.