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

Add column constructor from device_uvector&& #11356

25 changes: 25 additions & 0 deletions cpp/include/cudf/column/column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <rmm/cuda_stream_view.hpp>
#include <rmm/device_buffer.hpp>
#include <rmm/device_uvector.hpp>
#include <rmm/mr/device/per_device_resource.hpp>

#include <memory>
Expand Down Expand Up @@ -75,6 +76,30 @@ class column {
*/
column(column&& other) noexcept;

/**
* @brief Construct a new column by taking ownership of the contents of a device_uvector.
*
* @param other The device_uvector whose contents will be moved into the new column.
* @param[in] null_mask Optional, column's null value indicator bitmask. May
SrikarVanavasam marked this conversation as resolved.
Show resolved Hide resolved
* be empty if `null_count` is 0 or `UNKNOWN_NULL_COUNT`.
* @param null_count Optional, the count of null elements. If unknown, specify
* `UNKNOWN_NULL_COUNT` to indicate that the null count should be computed on
* the first invocation of `null_count()`.
*/
template <typename T, CUDF_ENABLE_IF(cudf::is_numeric<T>() or cudf::is_chrono<T>())>
column(rmm::device_uvector<T>&& other,
rmm::device_buffer&& null_mask = {},
size_type null_count = cudf::UNKNOWN_NULL_COUNT)
: _type{cudf::type_to_id<T>()},
_size{static_cast<size_type>(other.size())},
_data{other.release()},
SrikarVanavasam marked this conversation as resolved.
Show resolved Hide resolved
_null_mask{std::forward<rmm::device_buffer>(null_mask)},
_null_count{null_count}
{
CUDF_EXPECTS(_size < std::numeric_limits<size_type>::max(),
"Input vector exceeds maximum column capacity");
SrikarVanavasam marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @brief Construct a new column from existing device memory.
*
Expand Down
36 changes: 36 additions & 0 deletions cpp/tests/column/column_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,42 @@ TYPED_TEST(TypedColumnTest, MoveConstructorWithMask)
EXPECT_EQ(original_mask, moved_to_view.null_mask());
}

TYPED_TEST(TypedColumnTest, DeviceUvectorConstructorNoMask)
{
rmm::device_uvector<TypeParam> original{static_cast<std::size_t>(this->num_elements()),
cudf::default_stream_value};
thrust::copy(thrust::device,
static_cast<TypeParam*>(this->data.data()),
static_cast<TypeParam*>(this->data.data()) + this->num_elements(),
original.begin());
auto original_data = original.data();
cudf::column moved_to{std::move(original)};
verify_column_views(moved_to);

// Verify move
cudf::column_view moved_to_view = moved_to;
EXPECT_EQ(original_data, moved_to_view.head());
}

TYPED_TEST(TypedColumnTest, DeviceUvectorConstructorWithMask)
{
rmm::device_uvector<TypeParam> original{static_cast<std::size_t>(this->num_elements()),
cudf::default_stream_value};
thrust::copy(thrust::device,
static_cast<TypeParam*>(this->data.data()),
static_cast<TypeParam*>(this->data.data()) + this->num_elements(),
original.begin());
auto original_data = original.data();
auto original_mask = this->all_valid_mask.data();
cudf::column moved_to{std::move(original), std::move(this->all_valid_mask)};
verify_column_views(moved_to);

// Verify move
cudf::column_view moved_to_view = moved_to;
EXPECT_EQ(original_data, moved_to_view.head());
EXPECT_EQ(original_mask, moved_to_view.null_mask());
}

TYPED_TEST(TypedColumnTest, ConstructWithChildren)
{
std::vector<std::unique_ptr<cudf::column>> children;
Expand Down