From 795ca3c918c9a0cb4f45537318eb3b0be8d1fcd7 Mon Sep 17 00:00:00 2001 From: Suraj Aralihalli Date: Thu, 7 Sep 2023 15:42:24 -0700 Subject: [PATCH 1/2] overload make_device_uvector_async for bool type Signed-off-by: Suraj Aralihalli --- .../detail/utilities/vector_factories.hpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cpp/include/cudf/detail/utilities/vector_factories.hpp b/cpp/include/cudf/detail/utilities/vector_factories.hpp index 90ad98741ad..e2f02e746af 100644 --- a/cpp/include/cudf/detail/utilities/vector_factories.hpp +++ b/cpp/include/cudf/detail/utilities/vector_factories.hpp @@ -105,6 +105,31 @@ rmm::device_uvector make_device_uvector_async(host_span source_data, return ret; } +/** + * @brief Asynchronously construct a `device_uvector` containing a deep copy of data from a + * `host_span` containing only bool type + * + * @note This function does not synchronize `stream`. + * + * @param source_data The host_span of data to deep copy + * @param stream The stream on which to allocate memory and perform the copy + * @param mr The memory resource to use for allocating the returned device_uvector + * @return A device_uvector containing the copied data + */ +template ::value>> +rmm::device_uvector make_device_uvector_async(host_span source_data, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + rmm::device_uvector ret(source_data.size(), stream, mr); + for (std::size_t index = 0; index < source_data.size(); ++index) { + ret.set_element_async(index, + source_data[index], + stream); + } + return ret; +} + /** * @brief Asynchronously construct a `device_uvector` containing a deep copy of data from a host * container From 06dec6f48e4508bc48e0d35507521eb321adcf4d Mon Sep 17 00:00:00 2001 From: Suraj Aralihalli Date: Sun, 10 Sep 2023 23:46:09 -0700 Subject: [PATCH 2/2] extend make_device_uvector_async to all containers that cannot be converted to host_span implicitly Signed-off-by: Suraj Aralihalli --- .../detail/utilities/vector_factories.hpp | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cpp/include/cudf/detail/utilities/vector_factories.hpp b/cpp/include/cudf/detail/utilities/vector_factories.hpp index e2f02e746af..b84ef9defa6 100644 --- a/cpp/include/cudf/detail/utilities/vector_factories.hpp +++ b/cpp/include/cudf/detail/utilities/vector_factories.hpp @@ -106,26 +106,29 @@ rmm::device_uvector make_device_uvector_async(host_span source_data, } /** - * @brief Asynchronously construct a `device_uvector` containing a deep copy of data from a - * `host_span` containing only bool type + * @brief Asynchronously construct a `device_uvector` containing a deep copy of data from a host + * container that cannot be implicitly converted to a `host_span`. * * @note This function does not synchronize `stream`. * - * @param source_data The host_span of data to deep copy + * @tparam Container The type of the container to copy from + * @tparam T The type of the data to copy + * @param c The input host container from which to copy * @param stream The stream on which to allocate memory and perform the copy * @param mr The memory resource to use for allocating the returned device_uvector * @return A device_uvector containing the copied data */ -template ::value>> -rmm::device_uvector make_device_uvector_async(host_span source_data, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr) +template < + typename Container, + std::enable_if_t< + !std::is_convertible_v>>* = nullptr> +rmm::device_uvector make_device_uvector_async( + Container const& c, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - rmm::device_uvector ret(source_data.size(), stream, mr); - for (std::size_t index = 0; index < source_data.size(); ++index) { - ret.set_element_async(index, - source_data[index], - stream); + rmm::device_uvector ret(c.size(), stream, mr); + for (std::size_t index = 0; index < c.size(); ++index) { + typename Container::value_type element{c[index]}; + ret.set_element_async(index, element, stream); } return ret; }