Skip to content

Commit

Permalink
Merge branch 'branch-24.08' into fix-cudf-polars-duration-binops
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-b-miller committed Jul 23, 2024
2 parents 5e0c747 + e6d412c commit 02cfa9c
Show file tree
Hide file tree
Showing 35 changed files with 689 additions and 269 deletions.
13 changes: 9 additions & 4 deletions cpp/include/cudf/dictionary/dictionary_factories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,17 @@ std::unique_ptr<column> make_dictionary_column(
* @param indices_column Indices to use for the new dictionary column.
* @param null_mask Null mask for the output column.
* @param null_count Number of nulls for the output column.
* @param stream CUDA stream used for device memory operations and kernel launches.
* @param mr Device memory resource used to allocate the returned column's device memory.
* @return New dictionary column.
*/
std::unique_ptr<column> make_dictionary_column(std::unique_ptr<column> keys_column,
std::unique_ptr<column> indices_column,
rmm::device_buffer&& null_mask,
size_type null_count);
std::unique_ptr<column> make_dictionary_column(
std::unique_ptr<column> keys_column,
std::unique_ptr<column> indices_column,
rmm::device_buffer&& null_mask,
size_type null_count,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/**
* @brief Construct a dictionary column by taking ownership of the provided keys
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cudf/io/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ class json_reader_options {
*
* @param offset Number of bytes of offset
*/
void set_byte_range_offset(size_type offset) { _byte_range_offset = offset; }
void set_byte_range_offset(size_t offset) { _byte_range_offset = offset; }

/**
* @brief Set number of bytes to read.
*
* @param size Number of bytes to read
*/
void set_byte_range_size(size_type size) { _byte_range_size = size; }
void set_byte_range_size(size_t size) { _byte_range_size = size; }

/**
* @brief Set delimiter separating records in JSON lines
Expand Down
8 changes: 8 additions & 0 deletions cpp/include/cudf/lists/explode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ namespace cudf {
*
* @param input_table Table to explode.
* @param explode_column_idx Column index to explode inside the table.
* @param stream CUDA stream used for device memory operations and kernel launches.
* @param mr Device memory resource used to allocate the returned column's device memory.
*
* @return A new table with explode_col exploded.
*/
std::unique_ptr<table> explode(
table_view const& input_table,
size_type explode_column_idx,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/**
Expand Down Expand Up @@ -109,6 +111,7 @@ std::unique_ptr<table> explode(
*
* @param input_table Table to explode.
* @param explode_column_idx Column index to explode inside the table.
* @param stream CUDA stream used for device memory operations and kernel launches.
* @param mr Device memory resource used to allocate the returned column's device memory.
*
* @return A new table with exploded value and position. The column order of return table is
Expand All @@ -117,6 +120,7 @@ std::unique_ptr<table> explode(
std::unique_ptr<table> explode_position(
table_view const& input_table,
size_type explode_column_idx,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/**
Expand Down Expand Up @@ -152,13 +156,15 @@ std::unique_ptr<table> explode_position(
*
* @param input_table Table to explode.
* @param explode_column_idx Column index to explode inside the table.
* @param stream CUDA stream used for device memory operations and kernel launches.
* @param mr Device memory resource used to allocate the returned column's device memory.
*
* @return A new table with explode_col exploded.
*/
std::unique_ptr<table> explode_outer(
table_view const& input_table,
size_type explode_column_idx,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/**
Expand Down Expand Up @@ -196,13 +202,15 @@ std::unique_ptr<table> explode_outer(
*
* @param input_table Table to explode.
* @param explode_column_idx Column index to explode inside the table.
* @param stream CUDA stream used for device memory operations and kernel launches.
* @param mr Device memory resource used to allocate the returned column's device memory.
*
* @return A new table with explode_col exploded.
*/
std::unique_ptr<table> explode_outer_position(
table_view const& input_table,
size_type explode_column_idx,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/** @} */ // end of group
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cudf/lists/set_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ namespace cudf::lists {
* @param nulls_equal Flag to specify whether null elements should be considered as equal, default
* to be `UNEQUAL` which means only non-null elements are checked for overlapping
* @param nans_equal Flag to specify whether floating-point NaNs should be considered as equal
* @param mr Device memory resource used to allocate the returned object
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate the returned object
* @return A column of type BOOL containing the check results
*/
std::unique_ptr<column> have_overlap(
Expand Down
33 changes: 15 additions & 18 deletions cpp/include/cudf_test/stream_checking_resource_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

#include <iostream>

namespace cudf::test {

/**
* @brief Resource that verifies that the default stream is not used in any allocation.
*
* @tparam Upstream Type of the upstream resource used for
* allocation/deallocation.
*/
template <typename Upstream>
class stream_checking_resource_adaptor final : public rmm::mr::device_memory_resource {
public:
/**
Expand All @@ -40,14 +38,13 @@ class stream_checking_resource_adaptor final : public rmm::mr::device_memory_res
*
* @param upstream The resource used for allocating/deallocating device memory
*/
stream_checking_resource_adaptor(Upstream* upstream,
stream_checking_resource_adaptor(rmm::device_async_resource_ref upstream,
bool error_on_invalid_stream,
bool check_default_stream)
: upstream_{upstream},
error_on_invalid_stream_{error_on_invalid_stream},
check_default_stream_{check_default_stream}
{
CUDF_EXPECTS(nullptr != upstream, "Unexpected null upstream resource pointer.");
}

stream_checking_resource_adaptor() = delete;
Expand Down Expand Up @@ -86,7 +83,7 @@ class stream_checking_resource_adaptor final : public rmm::mr::device_memory_res
void* do_allocate(std::size_t bytes, rmm::cuda_stream_view stream) override
{
verify_stream(stream);
return upstream_->allocate(bytes, stream);
return upstream_.allocate_async(bytes, rmm::CUDA_ALLOCATION_ALIGNMENT, stream);
}

/**
Expand All @@ -101,7 +98,7 @@ class stream_checking_resource_adaptor final : public rmm::mr::device_memory_res
void do_deallocate(void* ptr, std::size_t bytes, rmm::cuda_stream_view stream) override
{
verify_stream(stream);
upstream_->deallocate(ptr, bytes, stream);
upstream_.deallocate_async(ptr, bytes, rmm::CUDA_ALLOCATION_ALIGNMENT, stream);
}

/**
Expand All @@ -113,8 +110,8 @@ class stream_checking_resource_adaptor final : public rmm::mr::device_memory_res
[[nodiscard]] bool do_is_equal(device_memory_resource const& other) const noexcept override
{
if (this == &other) { return true; }
auto cast = dynamic_cast<stream_checking_resource_adaptor<Upstream> const*>(&other);
if (cast == nullptr) { return upstream_->is_equal(other); }
auto cast = dynamic_cast<stream_checking_resource_adaptor const*>(&other);
if (cast == nullptr) { return false; }
return get_upstream_resource() == cast->get_upstream_resource();
}

Expand Down Expand Up @@ -150,7 +147,8 @@ class stream_checking_resource_adaptor final : public rmm::mr::device_memory_res
}
}

Upstream* upstream_; // the upstream resource used for satisfying allocation requests
rmm::device_async_resource_ref
upstream_; // the upstream resource used for satisfying allocation requests
bool error_on_invalid_stream_; // If true, throw an exception when the wrong stream is detected.
// If false, simply print to stdout.
bool check_default_stream_; // If true, throw an exception when the default stream is observed.
Expand All @@ -162,13 +160,12 @@ class stream_checking_resource_adaptor final : public rmm::mr::device_memory_res
* @brief Convenience factory to return a `stream_checking_resource_adaptor` around the
* upstream resource `upstream`.
*
* @tparam Upstream Type of the upstream `device_memory_resource`.
* @param upstream Pointer to the upstream resource
* @param upstream Reference to the upstream resource
*/
template <typename Upstream>
stream_checking_resource_adaptor<Upstream> make_stream_checking_resource_adaptor(
Upstream* upstream, bool error_on_invalid_stream, bool check_default_stream)
inline stream_checking_resource_adaptor make_stream_checking_resource_adaptor(
rmm::device_async_resource_ref upstream, bool error_on_invalid_stream, bool check_default_stream)
{
return stream_checking_resource_adaptor<Upstream>{
upstream, error_on_invalid_stream, check_default_stream};
return stream_checking_resource_adaptor{upstream, error_on_invalid_stream, check_default_stream};
}

} // namespace cudf::test
10 changes: 4 additions & 6 deletions cpp/include/cudf_test/testing_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
#include <rmm/mr/device/per_device_resource.hpp>
#include <rmm/mr/device/pool_memory_resource.hpp>

namespace cudf {
namespace test {
namespace cudf::test {

/// MR factory functions
inline auto make_cuda() { return std::make_shared<rmm::mr::cuda_memory_resource>(); }
Expand Down Expand Up @@ -91,8 +90,7 @@ inline std::shared_ptr<rmm::mr::device_memory_resource> create_memory_resource(
CUDF_FAIL("Invalid RMM allocation mode: " + allocation_mode);
}

} // namespace test
} // namespace cudf
} // namespace cudf::test

/**
* @brief Parses the cuDF test command line options.
Expand Down Expand Up @@ -182,8 +180,8 @@ inline auto make_stream_mode_adaptor(cxxopts::ParseResult const& cmd_opts)
auto const stream_error_mode = cmd_opts["stream_error_mode"].as<std::string>();
auto const error_on_invalid_stream = (stream_error_mode == "error");
auto const check_default_stream = (stream_mode == "new_cudf_default");
auto adaptor =
make_stream_checking_resource_adaptor(resource, error_on_invalid_stream, check_default_stream);
auto adaptor = cudf::test::make_stream_checking_resource_adaptor(
resource, error_on_invalid_stream, check_default_stream);
if ((stream_mode == "new_cudf_default") || (stream_mode == "new_testing_default")) {
rmm::mr::set_current_device_resource(&adaptor);
}
Expand Down
13 changes: 9 additions & 4 deletions cpp/src/dictionary/dictionary_factories.cu
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ std::unique_ptr<column> make_dictionary_column(column_view const& keys_column,
std::unique_ptr<column> make_dictionary_column(std::unique_ptr<column> keys_column,
std::unique_ptr<column> indices_column,
rmm::device_buffer&& null_mask,
size_type null_count)
size_type null_count,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_EXPECTS(!keys_column->has_nulls(), "keys column must not have nulls");
CUDF_EXPECTS(!indices_column->has_nulls(), "indices column must not have nulls");
Expand All @@ -89,7 +91,7 @@ std::unique_ptr<column> make_dictionary_column(std::unique_ptr<column> keys_colu
children.emplace_back(std::move(keys_column));
return std::make_unique<column>(data_type{type_id::DICTIONARY32},
count,
rmm::device_buffer{},
rmm::device_buffer{0, stream, mr},
std::move(null_mask),
null_count,
std::move(children));
Expand Down Expand Up @@ -134,8 +136,11 @@ std::unique_ptr<column> make_dictionary_column(std::unique_ptr<column> keys,
auto indices_column = [&] {
// If the types match, then just commandeer the column's data buffer.
if (new_type.id() == indices_type) {
return std::make_unique<column>(
new_type, indices_size, std::move(*(contents.data.release())), rmm::device_buffer{}, 0);
return std::make_unique<column>(new_type,
indices_size,
std::move(*(contents.data.release())),
rmm::device_buffer{0, stream, mr},
0);
}
// If the new type does not match, then convert the data.
cudf::column_view cast_view{
Expand Down
Loading

0 comments on commit 02cfa9c

Please sign in to comment.