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

Replace usages of thrust::optional with std::optional #15091

Merged
merged 10 commits into from
Aug 20, 2024
8 changes: 4 additions & 4 deletions cpp/include/cudf/ast/detail/expression_evaluator.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION.
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@

#include <rmm/cuda_stream_view.hpp>

#include <thrust/optional.h>
#include <cuda/std/optional>

namespace cudf {

Expand Down Expand Up @@ -278,7 +278,7 @@ struct expression_evaluator {
detail::device_data_reference const& input_reference,
IntermediateDataType<has_nulls>* thread_intermediate_storage,
cudf::size_type left_row_index,
thrust::optional<cudf::size_type> right_row_index = {}) const
cuda::std::optional<cudf::size_type> right_row_index = {}) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdice Do you think we could remove the optional here? There is a comment below that says in some cases right_row_index is ignored. I think just making this default to {} is enough to make this parameter optional without making it a formal cuda::std::optional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exploring this in #16604.

{
// TODO: Everywhere in the code assumes that the table reference is either
// left or right. Should we error-check somewhere to prevent
Expand Down Expand Up @@ -329,7 +329,7 @@ struct expression_evaluator {
detail::device_data_reference const& device_data_reference,
IntermediateDataType<has_nulls>* thread_intermediate_storage,
cudf::size_type left_row_index,
thrust::optional<cudf::size_type> right_row_index = {}) const
cuda::std::optional<cudf::size_type> right_row_index = {}) const
{
CUDF_UNREACHABLE("Unsupported type in resolve_input.");
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cudf/ast/detail/operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <cudf/utilities/error.hpp>
#include <cudf/utilities/type_dispatcher.hpp>

#include <cuda/std/optional>
#include <cuda/std/type_traits>
#include <thrust/optional.h>

#include <cmath>
#include <type_traits>
Expand All @@ -35,14 +35,14 @@ namespace ast {

namespace detail {

// Type trait for wrapping nullable types in a thrust::optional. Non-nullable
// Type trait for wrapping nullable types in a cuda::std::optional. Non-nullable
// types are returned as is.
template <typename T, bool has_nulls>
struct possibly_null_value;

template <typename T>
struct possibly_null_value<T, true> {
using type = thrust::optional<T>;
using type = cuda::std::optional<T>;
};

template <typename T>
Expand Down
28 changes: 14 additions & 14 deletions cpp/include/cudf/column/column_device_view.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

#include <rmm/cuda_stream_view.hpp>

#include <cuda/std/optional>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/optional.h>
#include <thrust/pair.h>

#include <algorithm>
Expand Down Expand Up @@ -614,7 +614,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
/**
* @brief Return an optional iterator to the first element of the column.
*
* Dereferencing the returned iterator returns a `thrust::optional<T>`.
* Dereferencing the returned iterator returns a `cuda::std::optional<T>`.
*
* The element of this iterator contextually converts to bool. The conversion returns true
* if the object contains a value and false if it does not contain a value.
Expand Down Expand Up @@ -739,7 +739,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
/**
* @brief Return an optional iterator to the element following the last element of the column.
*
* The returned iterator represents a `thrust::optional<T>` element.
* The returned iterator represents a `cuda::std::optional<T>` element.
*
* This function does not participate in overload resolution if
* `column_device_view::has_element_accessor<T>()` is false.
Expand Down Expand Up @@ -1272,21 +1272,21 @@ struct value_accessor {
* @brief optional accessor of a column
*
*
* The optional_accessor always returns a `thrust::optional` of `column[i]`. The validity
* The optional_accessor always returns a `cuda::std::optional` of `column[i]`. The validity
* of the optional is determined by the `Nullate` parameter which may be one of the following:
*
* - `nullate::YES` means that the column supports nulls and the optional returned
* might be valid or invalid.
*
* - `nullate::NO` means the caller attests that the column has no null values,
* no checks will occur and `thrust::optional{column[i]}` will be
* no checks will occur and `cuda::std::optional{column[i]}` will be
* return for each `i`.
*
* - `nullate::DYNAMIC` defers the assumption of nullability to runtime and the caller
* specifies if the column has nulls at runtime.
* For `DYNAMIC{true}` the return value will be `thrust::optional{column[i]}` if
* element `i` is not null and `thrust::optional{}` if element `i` is null.
* For `DYNAMIC{false}` the return value will always be `thrust::optional{column[i]}`.
* For `DYNAMIC{true}` the return value will be `cuda::std::optional{column[i]}` if
* element `i` is not null and `cuda::std::optional{}` if element `i` is null.
* For `DYNAMIC{false}` the return value will always be `cuda::std::optional{column[i]}`.
*
* @throws cudf::logic_error if column datatype and template T type mismatch.
* @throws cudf::logic_error if the column is not nullable and `with_nulls` evaluates to true
Expand All @@ -1312,19 +1312,19 @@ struct optional_accessor {
}

/**
* @brief Returns a `thrust::optional` of `column[i]`.
* @brief Returns a `cuda::std::optional` of `column[i]`.
*
* @param i The index of the element to return
* @return A `thrust::optional` that contains the value of `column[i]` is not null. If that
* @return A `cuda::std::optional` that contains the value of `column[i]` is not null. If that
* element is null, the resulting optional will not contain a value.
*/
__device__ inline thrust::optional<T> operator()(cudf::size_type i) const
__device__ inline cuda::std::optional<T> operator()(cudf::size_type i) const
{
if (has_nulls) {
return (col.is_valid_nocheck(i)) ? thrust::optional<T>{col.element<T>(i)}
: thrust::optional<T>{thrust::nullopt};
return (col.is_valid_nocheck(i)) ? cuda::std::optional<T>{col.element<T>(i)}
: cuda::std::optional<T>{cuda::std::nullopt};
}
return thrust::optional<T>{col.element<T>(i)};
return cuda::std::optional<T>{col.element<T>(i)};
}

Nullate has_nulls{}; ///< Indicates if the `col` should be checked for nulls.
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cudf/detail/copy_if_else.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <rmm/device_scalar.hpp>
#include <rmm/resource_ref.hpp>

#include <cuda/std/optional>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/optional.h>

namespace cudf {
namespace detail {
Expand Down Expand Up @@ -70,7 +70,7 @@ __launch_bounds__(block_size) CUDF_KERNEL
while (warp_cur <= warp_end) {
auto const index = static_cast<size_type>(tidx);
auto const opt_value =
(index < end) ? (filter(index) ? lhs[index] : rhs[index]) : thrust::nullopt;
(index < end) ? (filter(index) ? lhs[index] : rhs[index]) : cuda::std::nullopt;
if (opt_value) { out.element<T>(index) = static_cast<T>(*opt_value); }

// update validity
Expand Down Expand Up @@ -156,7 +156,7 @@ std::unique_ptr<column> copy_if_else(bool nullable,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
// This is the type of the thrust::optional element in the passed iterators
// This is the type of the cuda::std::optional element in the passed iterators
using Element = typename thrust::iterator_traits<LeftIter>::value_type::value_type;

size_type size = std::distance(lhs_begin, lhs_end);
Expand Down
12 changes: 6 additions & 6 deletions cpp/include/cudf/detail/indexalator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <cudf/scalar/scalar.hpp>
#include <cudf/utilities/traits.hpp>

#include <cuda/std/optional>
#include <thrust/iterator/constant_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/optional.h>
#include <thrust/pair.h>

namespace cudf {
Expand Down Expand Up @@ -376,10 +376,10 @@ struct indexalator_factory {
iter = make_input_iterator(col);
}

__device__ thrust::optional<size_type> operator()(size_type i) const
__device__ cuda::std::optional<size_type> operator()(size_type i) const
{
return has_nulls && !bit_is_set(null_mask, i + offset) ? thrust::nullopt
: thrust::make_optional(iter[i]);
return has_nulls && !bit_is_set(null_mask, i + offset) ? cuda::std::nullopt
: cuda::std::make_optional(iter[i]);
}
};

Expand All @@ -400,9 +400,9 @@ struct indexalator_factory {
iter = indexalator_factory::make_input_iterator(input);
}

__device__ thrust::optional<size_type> operator()(size_type) const
__device__ cuda::std::optional<size_type> operator()(size_type) const
{
return is_null ? thrust::nullopt : thrust::make_optional(*iter);
return is_null ? cuda::std::nullopt : cuda::std::make_optional(*iter);
}
};

Expand Down
26 changes: 13 additions & 13 deletions cpp/include/cudf/detail/iterator.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,10 +37,10 @@
#include <cudf/scalar/scalar.hpp>
#include <cudf/scalar/scalar_device_view.cuh>

#include <cuda/std/optional>
#include <thrust/iterator/constant_iterator.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/optional.h>
#include <thrust/pair.h>

#include <utility>
Expand Down Expand Up @@ -186,7 +186,7 @@ auto make_null_replacement_iterator(column_device_view const& column,
/**
* @brief Constructs an optional iterator over a column's values and its validity.
*
* Dereferencing the returned iterator returns a `thrust::optional<Element>`.
* Dereferencing the returned iterator returns a `cuda::std::optional<Element>`.
*
* The element of this iterator contextually converts to bool. The conversion returns true
* if the object contains a value and false if it does not contain a value.
Expand Down Expand Up @@ -237,7 +237,7 @@ auto make_null_replacement_iterator(column_device_view const& column,
* @param column The column to iterate
* @param has_nulls Indicates whether `column` is checked for nulls.
* @return Iterator that returns valid column elements and the validity of the
* element in a `thrust::optional`
* element in a `cuda::std::optional`
*/
template <typename Element, typename Nullate>
auto make_optional_iterator(column_device_view const& column, Nullate has_nulls)
Expand Down Expand Up @@ -393,22 +393,22 @@ auto inline make_scalar_iterator(scalar const& scalar_value)
/**
* @brief Optional accessor for a scalar
*
* The `scalar_optional_accessor` always returns a `thrust::optional` of the scalar.
* The `scalar_optional_accessor` always returns a `cuda::std::optional` of the scalar.
* The validity of the optional is determined by the `Nullate` parameter which may
* be one of the following:
*
* - `nullate::YES` means that the scalar may be valid or invalid and the optional returned
* will contain a value only if the scalar is valid.
*
* - `nullate::NO` means the caller attests that the scalar will always be valid,
* no checks will occur and `thrust::optional{column[i]}` will return a value
* no checks will occur and `cuda::std::optional{column[i]}` will return a value
* for each `i`.
*
* - `nullate::DYNAMIC` defers the assumption of nullability to runtime and the caller
* specifies if the scalar may be valid or invalid.
* For `DYNAMIC{true}` the return value will be a `thrust::optional{scalar}` when the
* scalar is valid and a `thrust::optional{}` when the scalar is invalid.
* For `DYNAMIC{false}` the return value will always be a `thrust::optional{scalar}`.
* For `DYNAMIC{true}` the return value will be a `cuda::std::optional{scalar}` when the
* scalar is valid and a `cuda::std::optional{}` when the scalar is invalid.
* For `DYNAMIC{false}` the return value will always be a `cuda::std::optional{scalar}`.
*
* @throws `cudf::logic_error` if scalar datatype and Element type mismatch.
*
Expand All @@ -418,7 +418,7 @@ auto inline make_scalar_iterator(scalar const& scalar_value)
template <typename Element, typename Nullate>
struct scalar_optional_accessor : public scalar_value_accessor<Element> {
using super_t = scalar_value_accessor<Element>;
using value_type = thrust::optional<Element>;
using value_type = cuda::std::optional<Element>;

scalar_optional_accessor(scalar const& scalar_value, Nullate with_nulls)
: scalar_value_accessor<Element>(scalar_value), has_nulls{with_nulls}
Expand All @@ -427,7 +427,7 @@ struct scalar_optional_accessor : public scalar_value_accessor<Element> {

__device__ inline value_type const operator()(size_type) const
{
if (has_nulls && !super_t::dscalar.is_valid()) { return value_type{thrust::nullopt}; }
if (has_nulls && !super_t::dscalar.is_valid()) { return value_type{cuda::std::nullopt}; }

if constexpr (cudf::is_fixed_point<Element>()) {
using namespace numeric;
Expand Down Expand Up @@ -519,7 +519,7 @@ struct scalar_representation_pair_accessor : public scalar_value_accessor<Elemen
/**
* @brief Constructs an optional iterator over a scalar's values and its validity.
*
* Dereferencing the returned iterator returns a `thrust::optional<Element>`.
* Dereferencing the returned iterator returns a `cuda::std::optional<Element>`.
*
* The element of this iterator contextually converts to bool. The conversion returns true
* if the object contains a value and false if it does not contain a value.
Expand Down Expand Up @@ -575,7 +575,7 @@ struct scalar_representation_pair_accessor : public scalar_value_accessor<Elemen
*
* @param scalar_value The scalar to be returned by the iterator.
* @param has_nulls Indicates if the scalar value may be invalid.
* @return Iterator that returns scalar and the validity of the scalar in a thrust::optional
* @return Iterator that returns scalar and the validity of the scalar in a cuda::std::optional
*/
template <typename Element, typename Nullate>
auto inline make_optional_iterator(scalar const& scalar_value, Nullate has_nulls)
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cudf/json/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <rmm/mr/device/per_device_resource.hpp>
#include <rmm/resource_ref.hpp>

#include <thrust/optional.h>
#include <cuda/std/optional>
miscco marked this conversation as resolved.
Show resolved Hide resolved

namespace cudf {

Expand Down
8 changes: 4 additions & 4 deletions cpp/include/cudf/strings/detail/convert/fixed_point.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <cudf/fixed_point/temporary.hpp>

#include <cuda/std/optional>
#include <cuda/std/type_traits>
#include <thrust/optional.h>
#include <thrust/pair.h>

namespace cudf {
Expand Down Expand Up @@ -88,7 +88,7 @@ __device__ inline thrust::pair<UnsignedDecimalType, int32_t> parse_integer(
* @return Integer value of the exponent
*/
template <bool check_only = false>
__device__ thrust::optional<int32_t> parse_exponent(char const* iter, char const* iter_end)
__device__ cuda::std::optional<int32_t> parse_exponent(char const* iter, char const* iter_end)
{
constexpr uint32_t exponent_max = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());

Expand All @@ -105,12 +105,12 @@ __device__ thrust::optional<int32_t> parse_exponent(char const* iter, char const
while (iter < iter_end) {
auto const ch = *iter++;
if (ch < '0' || ch > '9') {
if (check_only) { return thrust::nullopt; }
if (check_only) { return cuda::std::nullopt; }
break;
}

uint32_t exp_check = static_cast<uint32_t>(exp_ten * 10) + static_cast<uint32_t>(ch - '0');
if (check_only && (exp_check > exponent_max)) { return thrust::nullopt; } // check overflow
if (check_only && (exp_check > exponent_max)) { return cuda::std::nullopt; } // check overflow
exp_ten = static_cast<int32_t>(exp_check);
}

Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cudf/strings/detail/copy_if_else.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <rmm/resource_ref.hpp>

#include <cuda/functional>
#include <cuda/std/optional>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/optional.h>
#include <thrust/transform.h>

namespace cudf {
Expand All @@ -41,9 +41,9 @@ namespace detail {
* ```
*
* @tparam StringIterLeft A random access iterator whose value_type is
* `thrust::optional<string_view>` where the `optional` has a value iff the element is valid.
* `cuda::std::optional<string_view>` where the `optional` has a value iff the element is valid.
* @tparam StringIterRight A random access iterator whose value_type is
* `thrust::optional<string_view>` where the `optional` has a value iff the element is valid.
* `cuda::std::optional<string_view>` where the `optional` has a value iff the element is valid.
* @tparam Filter Functor that takes an index and returns a boolean.
*
* @param lhs_begin Start of first set of data. Used when `filter_fn` returns true.
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cudf/table/experimental/row_operators.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct sorting_physical_element_comparator {
}
};

using optional_dremel_view = thrust::optional<detail::dremel_device_view const>;
using optional_dremel_view = cuda::std::optional<detail::dremel_device_view const>;

// The has_nested_columns template parameter of the device_row_comparator is
// necessary to help the compiler optimize our code. Without it, the list and
Expand All @@ -223,12 +223,12 @@ using optional_dremel_view = thrust::optional<detail::dremel_device_view const>;
// std::optional<device_span<dremel_device_view>> in the
// preprocessed_table/device_row_comparator (which is always valid when
// has_nested_columns and is otherwise invalid) that is then unpacked to a
// thrust::optional<dremel_device_view> at the element_comparator level (which
// cuda::std::optional<dremel_device_view> at the element_comparator level (which
// is always valid for a list column and otherwise invalid). We cannot use an
// additional template parameter for the element_comparator on a per-column
// basis because we cannot conditionally define dremel_device_view member
// variables without jumping through extra hoops with inheritance, so the
// thrust::optional<dremel_device_view> member must be an optional rather than
// cuda::std::optional<dremel_device_view> member must be an optional rather than
// a raw dremel_device_view.
/**
* @brief Computes the lexicographic comparison between 2 rows.
Expand Down
Loading
Loading