diff --git a/cpp/include/cudf/io/memory_resource.hpp b/cpp/include/cudf/io/memory_resource.hpp index e31ebce4b1f..a36e220ae7b 100644 --- a/cpp/include/cudf/io/memory_resource.hpp +++ b/cpp/include/cudf/io/memory_resource.hpp @@ -57,7 +57,9 @@ struct host_mr_options { * @throws cudf::logic_error if called after the default host memory resource has been created * * @param opts Options to configure the default host memory resource + * @return True if this call successfully configured the host memory resource, false if a + * a resource was already configured. */ -void config_default_host_memory_resource(host_mr_options const& opts); +bool config_default_host_memory_resource(host_mr_options const& opts); } // namespace cudf::io diff --git a/cpp/src/io/utilities/config_utils.cpp b/cpp/src/io/utilities/config_utils.cpp index 7720c073a97..dad1135e766 100644 --- a/cpp/src/io/utilities/config_utils.cpp +++ b/cpp/src/io/utilities/config_utils.cpp @@ -244,16 +244,20 @@ CUDF_EXPORT std::mutex& host_mr_mutex() } // Must be called with the host_mr_mutex mutex held -CUDF_EXPORT rmm::host_async_resource_ref& make_host_mr(std::optional const& opts) +CUDF_EXPORT rmm::host_async_resource_ref& make_host_mr(std::optional const& opts, + bool* did_configure = nullptr) { static rmm::host_async_resource_ref* mr_ref = nullptr; + bool configured = false; if (mr_ref == nullptr) { - mr_ref = &make_default_pinned_mr(opts ? opts->pool_size : std::nullopt); - } else { - // Throw an error if the user tries to reconfigure the default host resource - CUDF_EXPECTS(opts == std::nullopt, "The default host memory resource has already been created"); + configured = true; + mr_ref = &make_default_pinned_mr(opts ? opts->pool_size : std::nullopt); } + // If the user passed an out param to detect whether this call configured a resource + // set the result + if (did_configure != nullptr) { *did_configure = configured; } + return *mr_ref; } @@ -278,10 +282,12 @@ rmm::host_async_resource_ref get_host_memory_resource() return host_mr(); } -void config_default_host_memory_resource(host_mr_options const& opts) +bool config_default_host_memory_resource(host_mr_options const& opts) { std::scoped_lock lock{host_mr_mutex()}; - make_host_mr(opts); + auto did_configure = false; + make_host_mr(opts, &did_configure); + return did_configure; } } // namespace cudf::io diff --git a/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java b/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java index 9038700cb30..83b801db7fb 100644 --- a/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java +++ b/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java @@ -260,9 +260,12 @@ private synchronized void free(long address, long size) { * * @param size initial and maximum size for the cuDF default pinned pool. * Pass size=0 to disable the default pool. + * + * @return true if we were able to setup the default resource, false if there was + * a resource already set. */ - public static synchronized void configureDefaultCudfPinnedPoolSize(long size) { - Rmm.configureDefaultCudfPinnedPoolSize(size); + public static synchronized boolean configureDefaultCudfPinnedPoolSize(long size) { + return Rmm.configureDefaultCudfPinnedPoolSize(size); } } diff --git a/java/src/main/java/ai/rapids/cudf/Rmm.java b/java/src/main/java/ai/rapids/cudf/Rmm.java index fdbdfdfff6f..4dee1b7aa24 100755 --- a/java/src/main/java/ai/rapids/cudf/Rmm.java +++ b/java/src/main/java/ai/rapids/cudf/Rmm.java @@ -273,8 +273,11 @@ public static synchronized void initialize(int allocationMode, LogConf logConf, * * @param size initial and maximum size for the cuDF default pinned pool. * Pass size=0 to disable the default pool. + * + * @return true if we were able to setup the default resource, false if there was + * a resource already set. */ - public static synchronized native void configureDefaultCudfPinnedPoolSize(long size); + public static synchronized native boolean configureDefaultCudfPinnedPoolSize(long size); /** * Get the most recently set pool size or -1 if RMM has not been initialized or pooling is diff --git a/java/src/main/native/src/RmmJni.cpp b/java/src/main/native/src/RmmJni.cpp index 9c015fee409..fa78f6ca4e2 100644 --- a/java/src/main/native/src/RmmJni.cpp +++ b/java/src/main/native/src/RmmJni.cpp @@ -1035,7 +1035,6 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCuioPinnedPoolMemoryResource(J // create a pinned fallback pool that will allocate pinned memory // if the regular pinned pool is exhausted pinned_fallback_mr.reset(new pinned_fallback_host_memory_resource(pool)); - // set the cuio host mr and store the prior resource in our static variable prior_cuio_host_mr() = cudf::io::set_host_memory_resource(*pinned_fallback_mr); } CATCH_STD(env, ) @@ -1107,14 +1106,14 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeFromFallbackPinnedPool(JNIEnv CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_configureDefaultCudfPinnedPoolSize(JNIEnv* env, - jclass clazz, - jlong size) +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Rmm_configureDefaultCudfPinnedPoolSize(JNIEnv* env, + jclass clazz, + jlong size) { try { cudf::jni::auto_set_device(env); - cudf::io::config_default_host_memory_resource(cudf::io::host_mr_options{size}); + return cudf::io::config_default_host_memory_resource(cudf::io::host_mr_options{size}); } - CATCH_STD(env, ) + CATCH_STD(env, false) } }