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

Hyper log log plus plus(HLL++) #2522

Open
wants to merge 32 commits into
base: branch-25.02
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
03c0f5a
Add HLL++ evaluation function
Oct 16, 2024
df8b223
Update function comments
Nov 4, 2024
2daca3f
Fix
Nov 19, 2024
3afdfde
Use exec_policy_nosync instead of exec_policy
Nov 26, 2024
956af39
Format code; Remove a useless file
Nov 26, 2024
8aaf0f6
Merge branch 'branch-25.02' into hll
Nov 27, 2024
5bfb544
Use UDF
Dec 15, 2024
f8c6a02
Use UDF
Dec 17, 2024
208d67e
Use UDF
Dec 17, 2024
e29d5a1
Address comments
Dec 18, 2024
9f7ec44
Merge branch 'branch-25.02' into hll
Dec 18, 2024
3c70a30
Merge branch 'branch-25.02' into hll
Dec 19, 2024
3e22512
Fix compile error
Dec 19, 2024
aa7ca68
Handle null inputs: must ignore the null input values
Dec 20, 2024
f0970c0
Rename refactor: Correct spelling errors
Dec 23, 2024
2e74412
Update copyright for new year 2025
Jan 13, 2025
7fe4a39
Use get_current_device_resource_ref
Jan 13, 2025
b7058a7
Fix comments
Jan 13, 2025
78cc207
Fix comments
Jan 13, 2025
4d202f4
Merge branch 'branch-25.02' into hll
Jan 13, 2025
2281d69
Merge branch 'branch-25.02' into hll
Jan 15, 2025
d045020
Close host UDF instance using JNI
Jan 15, 2025
a7cef89
Address comments
Jan 15, 2025
278d8d9
Fix compile error
Jan 15, 2025
86832ae
Address comments
Jan 16, 2025
b331db9
Address comments
Jan 16, 2025
7b929b4
Address comments
Jan 16, 2025
6fcf7e0
Address comments
Jan 16, 2025
024da64
Change make device uvector from async to sync
Jan 16, 2025
c9f4bfb
Add test case
Jan 18, 2025
b678c17
Format and Copyright
Jan 19, 2025
cbc3d12
Update according to cuDF UDF instance management change
Jan 22, 2025
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
7 changes: 5 additions & 2 deletions src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# =============================================================================
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
# Copyright (c) 2022-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
Expand Down Expand Up @@ -199,6 +199,7 @@ add_library(
src/HashJni.cpp
src/HistogramJni.cpp
src/HostTableJni.cpp
src/HyperLogLogPlusPlusHostUDFJni.cpp
src/JSONUtilsJni.cpp
src/NativeParquetJni.cpp
src/ParseURIJni.cpp
Expand All @@ -221,6 +222,9 @@ add_library(
src/from_json_to_structs.cu
src/get_json_object.cu
src/histogram.cu
src/hive_hash.cu
src/hyper_log_log_plus_plus.cu
src/hyper_log_log_plus_plus_host_udf.cu
src/json_utils.cu
src/murmur_hash.cu
src/parse_uri.cu
Expand All @@ -230,7 +234,6 @@ add_library(
src/timezones.cu
src/utilities.cu
src/xxhash64.cu
src/hive_hash.cu
src/zorder.cu
)

Expand Down
63 changes: 63 additions & 0 deletions src/main/cpp/src/HyperLogLogPlusPlusHostUDFJni.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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"

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);
Copy link
Collaborator

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.

Suggested change
cudf::jni::auto_set_device(env);

Copy link
Collaborator Author

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.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

udf_ptr is a raw pointer.

Suggested change
return reinterpret_cast<jlong>(udf_ptr.release());
return reinterpret_cast<jlong>(udf_ptr);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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);
}

} // extern "C"
Loading
Loading