From 8fcf72a787acb0168c97d11b8ab9130146e9b37e Mon Sep 17 00:00:00 2001 From: Alessandro Bellina Date: Wed, 24 Jul 2024 12:06:29 -0500 Subject: [PATCH] [JNI] Add setKernelPinnedCopyThreshold and setPinnedAllocationThreshold (#16288) In 24.08 two new cuDF methods are being added, and the second method is still in flight (see: https://github.com/rapidsai/cudf/pull/16206): ``` cudf::set_kernel_pinned_copy_threshold cudf::set_allocate_host_as_pinned_threshold ``` We'd like to expose these methods in our JNI layer. I created a Cudf.java with the two static methods, and put the definitions in CudfJni.cpp. Marked as draft since I need https://github.com/rapidsai/cudf/pull/16206 to merge, and we are still testing it. Authors: - Alessandro Bellina (https://github.com/abellina) - Nghia Truong (https://github.com/ttnghia) Approvers: - Robert (Bobby) Evans (https://github.com/revans2) - Jason Lowe (https://github.com/jlowe) URL: https://github.com/rapidsai/cudf/pull/16288 --- java/src/main/java/ai/rapids/cudf/Cudf.java | 36 +++++++++++++++++++++ java/src/main/native/src/CudfJni.cpp | 25 ++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 java/src/main/java/ai/rapids/cudf/Cudf.java diff --git a/java/src/main/java/ai/rapids/cudf/Cudf.java b/java/src/main/java/ai/rapids/cudf/Cudf.java new file mode 100644 index 00000000000..d09e2f87ed4 --- /dev/null +++ b/java/src/main/java/ai/rapids/cudf/Cudf.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, 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. + */ + +package ai.rapids.cudf; + +public class Cudf { + + static { + NativeDepsLoader.loadNativeDeps(); + } + + /** + * cuDF copies that are smaller than the threshold will use a kernel to copy, instead + * of cudaMemcpyAsync. + */ + public static native void setKernelPinnedCopyThreshold(long kernelPinnedCopyThreshold); + + /** + * cudf allocations that are smaller than the threshold will use the pinned host + * memory resource. + */ + public static native void setPinnedAllocationThreshold(long pinnedAllocationThreshold); +} diff --git a/java/src/main/native/src/CudfJni.cpp b/java/src/main/native/src/CudfJni.cpp index 698a8f6ff02..2860dc2e4b2 100644 --- a/java/src/main/native/src/CudfJni.cpp +++ b/java/src/main/native/src/CudfJni.cpp @@ -18,6 +18,7 @@ #include #include +#include #include @@ -201,4 +202,28 @@ JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Cuda_isPtdsEnabled(JNIEnv* env, j return cudf::jni::is_ptds_enabled; } +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cudf_setKernelPinnedCopyThreshold(JNIEnv* env, + jclass clazz, + jlong jthreshold) +{ + try { + cudf::jni::auto_set_device(env); + auto threshold = static_cast(jthreshold); + cudf::set_kernel_pinned_copy_threshold(threshold); + } + CATCH_STD(env, ) +} + +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cudf_setPinnedAllocationThreshold(JNIEnv* env, + jclass clazz, + jlong jthreshold) +{ + try { + cudf::jni::auto_set_device(env); + auto threshold = static_cast(jthreshold); + cudf::set_allocate_host_as_pinned_threshold(threshold); + } + CATCH_STD(env, ) +} + } // extern "C"