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

[JNI] Add setKernelPinnedCopyThreshold and setPinnedAllocationThreshold #16288

Merged
Merged
Show file tree
Hide file tree
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
36 changes: 36 additions & 0 deletions java/src/main/java/ai/rapids/cudf/Cudf.java
Original file line number Diff line number Diff line change
@@ -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);
}
25 changes: 25 additions & 0 deletions java/src/main/native/src/CudfJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf/copying.hpp>
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/pinned_memory.hpp>

#include <sstream>

Expand Down Expand Up @@ -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<std::size_t>(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<std::size_t>(jthreshold);
cudf::set_allocate_host_as_pinned_threshold(threshold);
}
CATCH_STD(env, )
}

} // extern "C"
Loading