Skip to content

Commit

Permalink
Replace usages of thrust::optional with cuda::std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Mar 18, 2024
1 parent 2a85404 commit d3bee47
Show file tree
Hide file tree
Showing 39 changed files with 169 additions and 166 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 <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
{
// 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
4 changes: 2 additions & 2 deletions cpp/include/cudf/ast/detail/operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,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 @@ -41,7 +41,7 @@ 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
14 changes: 7 additions & 7 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 @@ -1318,13 +1318,13 @@ struct optional_accessor {
* @return A `thrust::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
4 changes: 2 additions & 2 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 <cuda/std/optional>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/optional.h>

namespace cudf {
namespace detail {
Expand Down Expand Up @@ -68,7 +68,7 @@ __launch_bounds__(block_size) CUDF_KERNEL
size_type index = tid;
while (warp_cur <= warp_end) {
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
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
12 changes: 6 additions & 6 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 @@ -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
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 <cuda/std/optional>

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 @@ -24,8 +24,8 @@
#include <rmm/exec_policy.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 @@ -40,9 +40,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
4 changes: 2 additions & 2 deletions cpp/src/binaryop/binaryop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <rmm/cuda_stream_view.hpp>

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

#include <jit_preprocessed_files/binaryop/jit/kernel.cu.jit.hpp>

Expand Down Expand Up @@ -166,7 +166,7 @@ template <typename Lhs, typename Rhs>
void fixed_point_binary_operation_validation(binary_operator op,
Lhs lhs,
Rhs rhs,
thrust::optional<cudf::data_type> output_type = {})
cuda::std::optional<cudf::data_type> output_type = {})
{
CUDF_EXPECTS((is_fixed_point(lhs) or is_fixed_point(rhs)),
"One of the inputs must have fixed_point data_type.");
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/io/json/legacy/json_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
#include <rmm/device_uvector.hpp>
#include <rmm/exec_policy.hpp>

#include <cuda/std/optional>
#include <thrust/advance.h>
#include <thrust/detail/copy.h>
#include <thrust/execution_policy.h>
#include <thrust/find.h>
#include <thrust/generate.h>
#include <thrust/iterator/reverse_iterator.h>
#include <thrust/mismatch.h>
#include <thrust/optional.h>
#include <thrust/pair.h>

using cudf::device_span;
Expand Down Expand Up @@ -484,7 +484,7 @@ CUDF_KERNEL void collect_keys_info_kernel(parse_options_view const options,
device_span<char const> const data,
device_span<uint64_t const> const row_offsets,
unsigned long long int* keys_cnt,
thrust::optional<mutable_table_device_view> keys_info)
cuda::std::optional<mutable_table_device_view> keys_info)
{
auto const rec_id = grid_1d::global_thread_id();
if (rec_id >= row_offsets.size()) return;
Expand Down Expand Up @@ -595,7 +595,7 @@ void collect_keys_info(parse_options_view const& options,
device_span<char const> const data,
device_span<uint64_t const> const row_offsets,
unsigned long long int* keys_cnt,
thrust::optional<mutable_table_device_view> keys_info,
cuda::std::optional<mutable_table_device_view> keys_info,
rmm::cuda_stream_view stream)
{
int block_size;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/io/json/legacy/json_gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <rmm/cuda_stream_view.hpp>

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

using cudf::device_span;

Expand Down Expand Up @@ -93,7 +93,7 @@ void collect_keys_info(parse_options_view const& options,
device_span<char const> data,
device_span<uint64_t const> row_offsets,
unsigned long long int* keys_cnt,
thrust::optional<mutable_table_device_view> keys_info,
cuda::std::optional<mutable_table_device_view> keys_info,
rmm::cuda_stream_view stream);

} // namespace cudf::io::json::detail::legacy
2 changes: 1 addition & 1 deletion cpp/src/io/json/legacy/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
#include <rmm/device_uvector.hpp>
#include <rmm/exec_policy.hpp>

#include <cuda/std/optional>
#include <thrust/for_each.h>
#include <thrust/functional.h>
#include <thrust/host_vector.h>
#include <thrust/iterator/constant_iterator.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/optional.h>
#include <thrust/pair.h>
#include <thrust/sort.h>
#include <thrust/transform.h>
Expand Down
Loading

0 comments on commit d3bee47

Please sign in to comment.