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

Use experimental make_strings_children for strings convert #15629

Merged
merged 1 commit into from
May 3, 2024
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
17 changes: 7 additions & 10 deletions cpp/src/strings/convert/convert_booleans.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,19 @@

#include <cudf/column/column_device_view.cuh>
#include <cudf/column/column_factories.hpp>
#include <cudf/detail/iterator.cuh>
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/strings/convert/convert_booleans.hpp>
#include <cudf/strings/detail/converters.hpp>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/strings/detail/strings_children_ex.cuh>
#include <cudf/strings/string_view.cuh>
#include <cudf/strings/strings_column_view.hpp>
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/traits.hpp>
#include <cudf/utilities/type_dispatcher.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>
#include <rmm/resource_ref.hpp>

#include <thrust/for_each.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/transform.h>

Expand Down Expand Up @@ -99,21 +95,22 @@ struct from_booleans_fn {
column_device_view const d_column;
string_view d_true;
string_view d_false;
size_type* d_offsets{};
size_type* d_sizes{};
char* d_chars{};
cudf::detail::input_offsetalator d_offsets;

__device__ void operator()(size_type idx) const
{
if (d_column.is_null(idx)) {
if (d_chars == nullptr) { d_offsets[idx] = 0; }
if (d_chars == nullptr) { d_sizes[idx] = 0; }
return;
}

if (d_chars != nullptr) {
auto const result = d_column.element<bool>(idx) ? d_true : d_false;
memcpy(d_chars + d_offsets[idx], result.data(), result.size_bytes());
} else {
d_offsets[idx] = d_column.element<bool>(idx) ? d_true.size_bytes() : d_false.size_bytes();
d_sizes[idx] = d_column.element<bool>(idx) ? d_true.size_bytes() : d_false.size_bytes();
}
};
};
Expand Down Expand Up @@ -143,8 +140,8 @@ std::unique_ptr<column> from_booleans(column_view const& booleans,
// copy null mask
rmm::device_buffer null_mask = cudf::detail::copy_bitmask(booleans, stream, mr);

auto [offsets, chars] =
make_strings_children(from_booleans_fn{d_column, d_true, d_false}, strings_count, stream, mr);
auto [offsets, chars] = experimental::make_strings_children(
from_booleans_fn{d_column, d_true, d_false}, strings_count, stream, mr);

return make_strings_column(strings_count,
std::move(offsets),
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/strings/convert/convert_datetime.cu
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/strings/convert/convert_datetime.hpp>
#include <cudf/strings/detail/converters.hpp>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/strings/detail/strings_children_ex.cuh>
#include <cudf/strings/detail/utilities.cuh>
#include <cudf/strings/string_view.cuh>
#include <cudf/strings/strings_column_view.hpp>
Expand All @@ -37,7 +37,6 @@
#include <rmm/resource_ref.hpp>

#include <thrust/execution_policy.h>
#include <thrust/for_each.h>
#include <thrust/functional.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/logical.h>
Expand Down Expand Up @@ -756,8 +755,9 @@ struct datetime_formatter_fn {
column_device_view const d_timestamps;
column_device_view const d_format_names;
device_span<format_item const> const d_format_items;
size_type* d_offsets{};
size_type* d_sizes{};
char* d_chars{};
cudf::detail::input_offsetalator d_offsets;

/**
* @brief Specialized modulo expression that handles negative values.
Expand Down Expand Up @@ -1087,14 +1087,14 @@ struct datetime_formatter_fn {
__device__ void operator()(size_type idx) const
{
if (d_timestamps.is_null(idx)) {
if (!d_chars) { d_offsets[idx] = 0; }
if (!d_chars) { d_sizes[idx] = 0; }
return;
}
auto const tstamp = d_timestamps.element<T>(idx);
if (d_chars) {
timestamp_to_string(tstamp, d_chars + d_offsets[idx]);
} else {
d_offsets[idx] = compute_output_size(tstamp);
d_sizes[idx] = compute_output_size(tstamp);
}
}
};
Expand All @@ -1109,7 +1109,7 @@ struct dispatch_from_timestamps_fn {
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr) const
{
return make_strings_children(
return experimental::make_strings_children(
datetime_formatter_fn<T>{d_timestamps, d_format_names, d_format_items},
d_timestamps.size(),
stream,
Expand Down
21 changes: 10 additions & 11 deletions cpp/src/strings/convert/convert_durations.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/strings/detail/convert/int_to_string.cuh>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/strings/detail/strings_children_ex.cuh>
#include <cudf/types.hpp>
#include <cudf/utilities/default_stream.hpp>

Expand All @@ -26,10 +26,8 @@
#include <rmm/resource_ref.hpp>

#include <thrust/execution_policy.h>
#include <thrust/for_each.h>
#include <thrust/functional.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/transform.h>
#include <thrust/transform_reduce.h>

Expand Down Expand Up @@ -192,8 +190,9 @@ struct from_durations_fn {
column_device_view d_durations;
format_item const* d_format_items;
size_type items_count;
size_type* d_offsets{};
size_type* d_sizes{};
char* d_chars{};
cudf::detail::input_offsetalator d_offsets;

__device__ int8_t format_length(char format_char, duration_component const* const timeparts) const
{
Expand Down Expand Up @@ -378,14 +377,14 @@ struct from_durations_fn {
__device__ void operator()(size_type idx)
{
if (d_durations.is_null(idx)) {
if (d_chars == nullptr) { d_offsets[idx] = 0; }
if (d_chars == nullptr) { d_sizes[idx] = 0; }
return;
}

if (d_chars != nullptr) {
set_chars(idx);
} else {
d_offsets[idx] = string_size(d_durations.template element<T>(idx));
d_sizes[idx] = string_size(d_durations.template element<T>(idx));
}
}
};
Expand Down Expand Up @@ -415,11 +414,11 @@ struct dispatch_from_durations_fn {
// copy null mask
rmm::device_buffer null_mask = cudf::detail::copy_bitmask(durations, stream, mr);

auto [offsets, chars] =
make_strings_children(from_durations_fn<T>{d_column, d_format_items, compiler.items_count()},
strings_count,
stream,
mr);
auto [offsets, chars] = experimental::make_strings_children(
from_durations_fn<T>{d_column, d_format_items, compiler.items_count()},
strings_count,
stream,
mr);

return make_strings_column(strings_count,
std::move(offsets),
Expand Down
16 changes: 7 additions & 9 deletions cpp/src/strings/convert/convert_fixed_point.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <cudf/strings/detail/convert/fixed_point.cuh>
#include <cudf/strings/detail/convert/fixed_point_to_string.cuh>
#include <cudf/strings/detail/converters.hpp>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/strings/detail/strings_children_ex.cuh>
#include <cudf/strings/string_view.cuh>
#include <cudf/strings/strings_column_view.hpp>
#include <cudf/utilities/default_stream.hpp>
Expand All @@ -37,10 +37,7 @@
#include <cuda/std/limits>
#include <cuda/std/type_traits>
#include <thrust/execution_policy.h>
#include <thrust/for_each.h>
#include <thrust/generate.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/optional.h>
#include <thrust/transform.h>

namespace cudf {
Expand Down Expand Up @@ -198,8 +195,9 @@ namespace {
template <typename DecimalType>
struct from_fixed_point_fn {
column_device_view d_decimals;
size_type* d_offsets{};
size_type* d_sizes{};
char* d_chars{};
cudf::detail::input_offsetalator d_offsets;

/**
* @brief Converts a decimal element into a string.
Expand All @@ -219,13 +217,13 @@ struct from_fixed_point_fn {
__device__ void operator()(size_type idx)
{
if (d_decimals.is_null(idx)) {
if (d_chars == nullptr) { d_offsets[idx] = 0; }
if (d_chars == nullptr) { d_sizes[idx] = 0; }
return;
}
if (d_chars != nullptr) {
fixed_point_element_to_string(idx);
} else {
d_offsets[idx] =
d_sizes[idx] =
fixed_point_string_size(d_decimals.element<DecimalType>(idx), d_decimals.type().scale());
}
}
Expand All @@ -244,8 +242,8 @@ struct dispatch_from_fixed_point_fn {

auto const d_column = column_device_view::create(input, stream);

auto [offsets, chars] =
make_strings_children(from_fixed_point_fn<DecimalType>{*d_column}, input.size(), stream, mr);
auto [offsets, chars] = experimental::make_strings_children(
from_fixed_point_fn<DecimalType>{*d_column}, input.size(), stream, mr);

return make_strings_column(input.size(),
std::move(offsets),
Expand Down
15 changes: 7 additions & 8 deletions cpp/src/strings/convert/convert_floats.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <cudf/strings/convert/convert_floats.hpp>
#include <cudf/strings/detail/convert/string_to_float.cuh>
#include <cudf/strings/detail/converters.hpp>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/strings/detail/strings_children_ex.cuh>
#include <cudf/strings/string_view.cuh>
#include <cudf/strings/strings_column_view.hpp>
#include <cudf/utilities/default_stream.hpp>
Expand All @@ -32,9 +32,7 @@
#include <rmm/exec_policy.hpp>
#include <rmm/resource_ref.hpp>

#include <thrust/for_each.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/transform.h>

#include <cmath>
Expand Down Expand Up @@ -356,8 +354,9 @@ struct ftos_converter {
template <typename FloatType>
struct from_floats_fn {
column_device_view d_floats;
size_type* d_offsets;
size_type* d_sizes;
char* d_chars;
cudf::detail::input_offsetalator d_offsets;

__device__ size_type compute_output_size(FloatType value)
{
Expand All @@ -375,13 +374,13 @@ struct from_floats_fn {
__device__ void operator()(size_type idx)
{
if (d_floats.is_null(idx)) {
if (d_chars == nullptr) { d_offsets[idx] = 0; }
if (d_chars == nullptr) { d_sizes[idx] = 0; }
return;
}
if (d_chars != nullptr) {
float_to_string(idx);
} else {
d_offsets[idx] = compute_output_size(d_floats.element<FloatType>(idx));
d_sizes[idx] = compute_output_size(d_floats.element<FloatType>(idx));
}
}
};
Expand All @@ -404,8 +403,8 @@ struct dispatch_from_floats_fn {
// copy the null mask
rmm::device_buffer null_mask = cudf::detail::copy_bitmask(floats, stream, mr);

auto [offsets, chars] =
make_strings_children(from_floats_fn<FloatType>{d_column}, strings_count, stream, mr);
auto [offsets, chars] = experimental::make_strings_children(
from_floats_fn<FloatType>{d_column}, strings_count, stream, mr);

return make_strings_column(strings_count,
std::move(offsets),
Expand Down
11 changes: 6 additions & 5 deletions cpp/src/strings/convert/convert_hex.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/strings/convert/convert_integers.hpp>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/strings/detail/strings_children_ex.cuh>
#include <cudf/strings/detail/utilities.cuh>
#include <cudf/strings/string_view.cuh>
#include <cudf/strings/strings_column_view.hpp>
Expand Down Expand Up @@ -123,8 +123,9 @@ struct dispatch_hex_to_integers_fn {
template <typename IntegerType>
struct integer_to_hex_fn {
column_device_view const d_column;
size_type* d_offsets{};
size_type* d_sizes{};
char* d_chars{};
cudf::detail::input_offsetalator d_offsets;

__device__ void byte_to_hex(uint8_t byte, char* hex)
{
Expand All @@ -141,7 +142,7 @@ struct integer_to_hex_fn {
__device__ void operator()(size_type idx)
{
if (d_column.is_null(idx)) {
if (!d_chars) { d_offsets[idx] = 0; }
if (!d_chars) { d_sizes[idx] = 0; }
return;
}

Expand All @@ -167,7 +168,7 @@ struct integer_to_hex_fn {
--byte_index;
}
} else {
d_offsets[idx] = static_cast<size_type>(bytes) * 2; // 2 hex characters per byte
d_sizes[idx] = static_cast<size_type>(bytes) * 2; // 2 hex characters per byte
}
}
};
Expand All @@ -181,7 +182,7 @@ struct dispatch_integers_to_hex_fn {
{
auto const d_column = column_device_view::create(input, stream);

auto [offsets_column, chars] = cudf::strings::detail::make_strings_children(
auto [offsets_column, chars] = experimental::make_strings_children(
integer_to_hex_fn<IntegerType>{*d_column}, input.size(), stream, mr);

return make_strings_column(input.size(),
Expand Down
15 changes: 7 additions & 8 deletions cpp/src/strings/convert/convert_integers.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <cudf/strings/detail/convert/int_to_string.cuh>
#include <cudf/strings/detail/convert/string_to_int.cuh>
#include <cudf/strings/detail/converters.hpp>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/strings/detail/strings_children_ex.cuh>
#include <cudf/strings/string_view.cuh>
#include <cudf/strings/strings_column_view.hpp>
#include <cudf/utilities/default_stream.hpp>
Expand All @@ -34,9 +34,7 @@
#include <rmm/resource_ref.hpp>

#include <thrust/execution_policy.h>
#include <thrust/for_each.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/logical.h>
#include <thrust/pair.h>
#include <thrust/transform.h>
Expand Down Expand Up @@ -314,8 +312,9 @@ namespace {
template <typename IntegerType>
struct from_integers_fn {
column_device_view d_integers;
size_type* d_offsets;
size_type* d_sizes;
char* d_chars;
cudf::detail::input_offsetalator d_offsets;

/**
* @brief Converts an integer element into a string.
Expand All @@ -334,13 +333,13 @@ struct from_integers_fn {
__device__ void operator()(size_type idx)
{
if (d_integers.is_null(idx)) {
if (d_chars == nullptr) { d_offsets[idx] = 0; }
if (d_chars == nullptr) { d_sizes[idx] = 0; }
return;
}
if (d_chars != nullptr) {
integer_element_to_string(idx);
} else {
d_offsets[idx] = count_digits(d_integers.element<IntegerType>(idx));
d_sizes[idx] = count_digits(d_integers.element<IntegerType>(idx));
}
}
};
Expand All @@ -363,8 +362,8 @@ struct dispatch_from_integers_fn {
// copy the null mask
rmm::device_buffer null_mask = cudf::detail::copy_bitmask(integers, stream, mr);

auto [offsets, chars] =
make_strings_children(from_integers_fn<IntegerType>{d_column}, strings_count, stream, mr);
auto [offsets, chars] = experimental::make_strings_children(
from_integers_fn<IntegerType>{d_column}, strings_count, stream, mr);

return make_strings_column(strings_count,
std::move(offsets),
Expand Down
Loading
Loading