Skip to content

Commit

Permalink
Replace usages of thrust::optional with std::optional
Browse files Browse the repository at this point in the history
We want to get rid of thrust types in API bundaries so replace them by the better suited std types
  • Loading branch information
miscco committed Feb 20, 2024
1 parent c9dd325 commit 6544074
Show file tree
Hide file tree
Showing 39 changed files with 179 additions and 181 deletions.
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 <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
std::optional<cudf::size_type> right_row_index = {}) const
{
// 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
std::optional<cudf::size_type> right_row_index = {}) const
{
CUDF_UNREACHABLE("Unsupported type in resolve_input.");
}
Expand Down
8 changes: 4 additions & 4 deletions cpp/include/cudf/ast/detail/operators.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
* Copyright (c) 2020-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 All @@ -20,7 +20,7 @@
#include <cudf/utilities/error.hpp>
#include <cudf/utilities/type_dispatcher.hpp>

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

#include <cuda/std/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 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 = 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 <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 `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 `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 `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 `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 `std::optional{column[i]}` if
* element `i` is not null and `std::optional{}` if element `i` is null.
* For `DYNAMIC{false}` the return value will always be `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 `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 `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 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)) ? std::optional<T>{col.element<T>(i)}
: std::optional<T>{std::nullopt};
}
return thrust::optional<T>{col.element<T>(i)};
return std::optional<T>{col.element<T>(i)};
}

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

#include <rmm/device_scalar.hpp>

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

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

// update validity
Expand Down Expand Up @@ -154,7 +153,7 @@ std::unique_ptr<column> copy_if_else(bool nullable,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
// This is the type of the thrust::optional element in the passed iterators
// This is the type of the 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
14 changes: 7 additions & 7 deletions cpp/include/cudf/detail/indexalator.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
* Copyright (c) 2020-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 All @@ -23,9 +23,9 @@
#include <cudf/scalar/scalar.hpp>
#include <cudf/utilities/traits.hpp>

#include <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 @@ -377,10 +377,10 @@ struct indexalator_factory {
iter = make_input_iterator(col);
}

__device__ thrust::optional<size_type> operator()(size_type i) const
__device__ 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) ? std::nullopt
: std::make_optional(iter[i]);
}
};

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

__device__ thrust::optional<size_type> operator()(size_type) const
__device__ std::optional<size_type> operator()(size_type) const
{
return is_null ? thrust::nullopt : thrust::make_optional(*iter);
return is_null ? std::nullopt : 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 <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 `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 `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 `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 `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 `std::optional{scalar}` when the
* scalar is valid and a `std::optional{}` when the scalar is invalid.
* For `DYNAMIC{false}` the return value will always be a `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 = 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{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 `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 std::optional
*/
template <typename Element, typename Nullate>
auto inline make_optional_iterator(scalar const& scalar_value, Nullate has_nulls)
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cudf/json/json.hpp
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 All @@ -20,7 +20,7 @@

#include <rmm/mr/device/per_device_resource.hpp>

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

namespace cudf {

Expand Down
10 changes: 5 additions & 5 deletions cpp/include/cudf/strings/detail/convert/fixed_point.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 All @@ -17,7 +17,7 @@

#include <cudf/fixed_point/temporary.hpp>

#include <thrust/optional.h>
#include <optional>
#include <thrust/pair.h>

#include <cuda/std/type_traits>
Expand Down Expand Up @@ -89,7 +89,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__ 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 @@ -106,12 +106,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 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 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 @@ -24,7 +24,7 @@
#include <rmm/exec_policy.hpp>

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

#include <cuda/functional>
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.
* `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.
* `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
Loading

0 comments on commit 6544074

Please sign in to comment.