Skip to content

Commit

Permalink
Mark some constexpr functions as CUDF_HOST_DEVICE that are needed in …
Browse files Browse the repository at this point in the history
…device code.
  • Loading branch information
vyasr committed Dec 6, 2024
1 parent 1a62b46 commit bbe6532
Show file tree
Hide file tree
Showing 32 changed files with 308 additions and 209 deletions.
18 changes: 10 additions & 8 deletions cpp/include/cudf/column/column_device_view.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
#include <rmm/cuda_stream_view.hpp>

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

#include <algorithm>
#include <type_traits>

/**
* @file column_device_view.cuh
Expand All @@ -56,8 +58,8 @@ namespace CUDF_EXPORT cudf {
*
*/
struct nullate {
struct YES : std::bool_constant<true> {};
struct NO : std::bool_constant<false> {};
struct YES : cuda::std::bool_constant<true> {};
struct NO : cuda::std::bool_constant<false> {};
/**
* @brief `nullate::DYNAMIC` defers the determination of nullability to run time rather than
* compile time. The calling code is responsible for specifying whether or not nulls are
Expand All @@ -80,7 +82,7 @@ struct nullate {
* @return `true` if nulls are expected in the operation in which this object is applied,
* otherwise false
*/
constexpr operator bool() const noexcept { return value; }
CUDF_HOST_DEVICE constexpr operator bool() const noexcept { return value; }
bool value; ///< True if nulls are expected
};
};
Expand Down Expand Up @@ -319,14 +321,14 @@ class alignas(16) column_device_view_base {
}

template <typename C, typename T, typename = void>
struct has_element_accessor_impl : std::false_type {};
struct has_element_accessor_impl : cuda::std::false_type {};

template <typename C, typename T>
struct has_element_accessor_impl<
C,
T,
void_t<decltype(std::declval<C>().template element<T>(std::declval<size_type>()))>>
: std::true_type {};
void_t<decltype(cuda::std::declval<C>().template element<T>(cuda::std::declval<size_type>()))>>
: cuda::std::true_type {};
};
// @cond
// Forward declaration
Expand Down Expand Up @@ -534,7 +536,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
* @return `true` if `column_device_view::element<T>()` has a valid overload, `false` otherwise
*/
template <typename T>
static constexpr bool has_element_accessor()
CUDF_HOST_DEVICE static constexpr bool has_element_accessor()
{
return has_element_accessor_impl<column_device_view, T>::value;
}
Expand Down Expand Up @@ -1044,7 +1046,7 @@ class alignas(16) mutable_column_device_view : public detail::column_device_view
* @return `true` if `mutable_column_device_view::element<T>()` has a valid overload, `false`
*/
template <typename T>
static constexpr bool has_element_accessor()
CUDF_HOST_DEVICE static constexpr bool has_element_accessor()
{
return has_element_accessor_impl<mutable_column_device_view, T>::value;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cudf/detail/aggregation/aggregation.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
namespace cudf {
namespace detail {
template <typename T>
constexpr bool is_product_supported()
CUDF_HOST_DEVICE constexpr bool is_product_supported()
{
return is_numeric<T>();
}
Expand Down
11 changes: 6 additions & 5 deletions cpp/include/cudf/detail/utilities/cuda.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ class grid_1d {
* @param num_threads_per_block The number of threads per block
* @return thread_index_type The global thread index
*/
static constexpr thread_index_type global_thread_id(thread_index_type thread_id,
thread_index_type block_id,
thread_index_type num_threads_per_block)
CUDF_HOST_DEVICE static constexpr thread_index_type global_thread_id(
thread_index_type thread_id,
thread_index_type block_id,
thread_index_type num_threads_per_block)
{
return thread_id + block_id * num_threads_per_block;
}
Expand Down Expand Up @@ -114,8 +115,8 @@ class grid_1d {
* @param num_threads_per_block The number of threads per block
* @return thread_index_type The global thread index
*/
static constexpr thread_index_type grid_stride(thread_index_type num_threads_per_block,
thread_index_type num_blocks_per_grid)
CUDF_HOST_DEVICE static constexpr thread_index_type grid_stride(
thread_index_type num_threads_per_block, thread_index_type num_blocks_per_grid)
{
return num_threads_per_block * num_blocks_per_grid;
}
Expand Down
33 changes: 18 additions & 15 deletions cpp/include/cudf/detail/utilities/device_operators.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 @@ -29,6 +29,9 @@
#include <cudf/utilities/error.hpp>
#include <cudf/utilities/traits.hpp>

#include <cuda/std/__algorithm/max.h>
#include <cuda/std/__algorithm/min.h>

#include <type_traits>

namespace cudf {
Expand All @@ -42,7 +45,7 @@ template <typename LHS,
std::enable_if_t<cudf::is_relationally_comparable<LHS, RHS>()>* = nullptr>
CUDF_HOST_DEVICE inline auto min(LHS const& lhs, RHS const& rhs)
{
return std::min(lhs, rhs);
return cuda::std::min(lhs, rhs);
}

/**
Expand All @@ -53,7 +56,7 @@ template <typename LHS,
std::enable_if_t<cudf::is_relationally_comparable<LHS, RHS>()>* = nullptr>
CUDF_HOST_DEVICE inline auto max(LHS const& lhs, RHS const& rhs)
{
return std::max(lhs, rhs);
return cuda::std::max(lhs, rhs);
}
} // namespace detail

Expand All @@ -68,20 +71,20 @@ struct DeviceSum {
}

template <typename T, std::enable_if_t<cudf::is_timestamp<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
return T{typename T::duration{0}};
}

template <typename T,
std::enable_if_t<!cudf::is_timestamp<T>() && !cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
return T{0};
}

template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
CUDF_FAIL("fixed_point does not yet support device operator identity");
return T{};
Expand All @@ -105,7 +108,7 @@ struct DeviceCount {
}

template <typename T>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
return T{};
}
Expand All @@ -125,7 +128,7 @@ struct DeviceMin {
template <typename T,
std::enable_if_t<!std::is_same_v<T, cudf::string_view> && !cudf::is_dictionary<T>() &&
!cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
// chrono types do not have std::numeric_limits specializations and should use T::max()
// https://eel.is/c++draft/numeric.limits.general#6
Expand All @@ -139,7 +142,7 @@ struct DeviceMin {
}

template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
CUDF_FAIL("fixed_point does not yet support DeviceMin identity");
return cuda::std::numeric_limits<T>::max();
Expand All @@ -153,7 +156,7 @@ struct DeviceMin {
}

template <typename T, std::enable_if_t<cudf::is_dictionary<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
return static_cast<T>(T::max_value());
}
Expand All @@ -173,7 +176,7 @@ struct DeviceMax {
template <typename T,
std::enable_if_t<!std::is_same_v<T, cudf::string_view> && !cudf::is_dictionary<T>() &&
!cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
// chrono types do not have std::numeric_limits specializations and should use T::min()
// https://eel.is/c++draft/numeric.limits.general#6
Expand All @@ -187,7 +190,7 @@ struct DeviceMax {
}

template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
CUDF_FAIL("fixed_point does not yet support DeviceMax identity");
return cuda::std::numeric_limits<T>::lowest();
Expand All @@ -200,7 +203,7 @@ struct DeviceMax {
}

template <typename T, std::enable_if_t<cudf::is_dictionary<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
return static_cast<T>(T::lowest_value());
}
Expand All @@ -217,13 +220,13 @@ struct DeviceProduct {
}

template <typename T, std::enable_if_t<!cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
return T{1};
}

template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
static constexpr T identity()
CUDF_HOST_DEVICE static constexpr T identity()
{
CUDF_FAIL("fixed_point does not yet support DeviceProduct identity");
return T{1, numeric::scale_type{0}};
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cudf/detail/utilities/integer_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2019 BlazingDB, Inc.
* Copyright 2019 Eyal Rozenberg <[email protected]>
* 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 Down Expand Up @@ -86,7 +86,7 @@ constexpr S round_down_safe(S number_to_round, S modulus) noexcept
* `modulus` is positive and does not check for overflow.
*/
template <typename S>
constexpr S round_up_unsafe(S number_to_round, S modulus) noexcept
CUDF_HOST_DEVICE constexpr S round_up_unsafe(S number_to_round, S modulus) noexcept
{
auto remainder = number_to_round % modulus;
if (remainder == 0) { return number_to_round; }
Expand Down Expand Up @@ -183,7 +183,7 @@ constexpr bool is_a_power_of_two(I val) noexcept
* @return Absolute value if value type is signed.
*/
template <typename T>
constexpr auto absolute_value(T value) -> T
CUDF_HOST_DEVICE constexpr auto absolute_value(T value) -> T
{
if constexpr (cuda::std::is_signed<T>()) return numeric::detail::abs(value);
return value;
Expand Down
7 changes: 4 additions & 3 deletions cpp/include/cudf/fixed_point/detail/floating_conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cuda/std/cmath>
#include <cuda/std/limits>
#include <cuda/std/type_traits>
#include <cuda/std/utility>

#include <cstring>

Expand Down Expand Up @@ -183,7 +184,7 @@ struct floating_converter {
* @param integer_rep The bit-casted floating value to extract the exponent from
* @return The stored base-2 exponent and significand, shifted for denormals
*/
CUDF_HOST_DEVICE inline static std::pair<IntegralType, int> get_significand_and_pow2(
CUDF_HOST_DEVICE inline static cuda::std::pair<IntegralType, int> get_significand_and_pow2(
IntegralType integer_rep)
{
// Extract the significand
Expand Down Expand Up @@ -1008,7 +1009,7 @@ CUDF_HOST_DEVICE inline auto shift_to_binary_pospow(DecimalRep decimal_rep, int
}

// Our shifting_rep is now the integer mantissa, return it and the powers of 2
return std::pair{shifting_rep, pow2};
return cuda::std::pair{shifting_rep, pow2};
}

/**
Expand Down Expand Up @@ -1075,7 +1076,7 @@ CUDF_HOST_DEVICE inline auto shift_to_binary_negpow(DecimalRep decimal_rep, int
}

// Our shifting_rep is now the integer mantissa, return it and the powers of 2
return std::pair{shifting_rep, pow2};
return cuda::std::pair{shifting_rep, pow2};
}

/**
Expand Down
Loading

0 comments on commit bbe6532

Please sign in to comment.