-
Notifications
You must be signed in to change notification settings - Fork 68
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
Hyper log log plus plus(HLL++) #2522
base: branch-25.02
Are you sure you want to change the base?
Changes from 24 commits
03c0f5a
df8b223
2daca3f
3afdfde
956af39
8aaf0f6
5bfb544
f8c6a02
208d67e
e29d5a1
9f7ec44
3c70a30
3e22512
aa7ca68
f0970c0
2e74412
7fe4a39
b7058a7
78cc207
4d202f4
2281d69
d045020
a7cef89
278d8d9
86832ae
b331db9
7b929b4
6fcf7e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,76 @@ | ||||||
/* | ||||||
* Copyright (c) 2024-2025, NVIDIA CORPORATION. | ||||||
* | ||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
* you may not use this file except in compliance with the License. | ||||||
* You may obtain a copy of the License at | ||||||
* | ||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||
* | ||||||
* Unless required by applicable law or agreed to in writing, software | ||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
* See the License for the specific language governing permissions and | ||||||
* limitations under the License. | ||||||
*/ | ||||||
|
||||||
#include "cudf_jni_apis.hpp" | ||||||
#include "hyper_log_log_plus_plus.hpp" | ||||||
#include "hyper_log_log_plus_plus_host_udf.hpp" | ||||||
|
||||||
#include <cudf/aggregation/host_udf.hpp> | ||||||
|
||||||
extern "C" { | ||||||
|
||||||
JNIEXPORT jlong JNICALL | ||||||
Java_com_nvidia_spark_rapids_jni_HyperLogLogPlusPlusHostUDF_createHLLPPHostUDF(JNIEnv* env, | ||||||
jclass, | ||||||
jint agg_type, | ||||||
int precision) | ||||||
{ | ||||||
try { | ||||||
cudf::jni::auto_set_device(env); | ||||||
auto udf_ptr = [&] { | ||||||
// The value of agg_type must be sync with | ||||||
// `HyperLogLogPlusPlusHostUDF.java#AggregationType`. | ||||||
switch (agg_type) { | ||||||
case 0: return spark_rapids_jni::create_hllpp_reduction_host_udf(precision); | ||||||
case 1: return spark_rapids_jni::create_hllpp_reduction_merge_host_udf(precision); | ||||||
case 2: return spark_rapids_jni::create_hllpp_groupby_host_udf(precision); | ||||||
case 3: return spark_rapids_jni::create_hllpp_groupby_merge_host_udf(precision); | ||||||
default: CUDF_FAIL("Invalid aggregation type."); | ||||||
} | ||||||
}(); | ||||||
CUDF_EXPECTS(udf_ptr != nullptr, "Invalid HyperLogLogPlusPlus(HLLPP) UDF instance."); | ||||||
|
||||||
return reinterpret_cast<jlong>(udf_ptr.release()); | ||||||
ttnghia marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
} | ||||||
CATCH_STD(env, 0); | ||||||
} | ||||||
|
||||||
JNIEXPORT jlong JNICALL | ||||||
Java_com_nvidia_spark_rapids_jni_HyperLogLogPlusPlusHostUDF_estimateDistinctValueFromSketches( | ||||||
JNIEnv* env, jclass, jlong sketches, jint precision) | ||||||
{ | ||||||
JNI_NULL_CHECK(env, sketches, "Sketch column is null", 0); | ||||||
try { | ||||||
cudf::jni::auto_set_device(env); | ||||||
auto const sketch_view = reinterpret_cast<cudf::column_view const*>(sketches); | ||||||
return cudf::jni::ptr_as_jlong( | ||||||
spark_rapids_jni::estimate_from_hll_sketches(*sketch_view, precision).release()); | ||||||
} | ||||||
CATCH_STD(env, 0); | ||||||
} | ||||||
|
||||||
JNIEXPORT void JNICALL Java_com_nvidia_spark_rapids_jni_HyperLogLogPlusPlusHostUDF_close( | ||||||
JNIEnv* env, jclass class_object, jlong ptr) | ||||||
{ | ||||||
try { | ||||||
cudf::jni::auto_set_device(env); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
auto to_del = reinterpret_cast<cudf::host_udf_base*>(ptr); | ||||||
delete to_del; | ||||||
} | ||||||
CATCH_STD(env, ); | ||||||
} | ||||||
|
||||||
} // extern "C" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we will need to set device when creating the UDF instance, as we don't start the computation yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this.
If it's removed, then there is no set device any more in this file, in general, there should be at least one set device.