Skip to content

Commit

Permalink
Fix CUDF_HOST_DEVICE.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Jan 6, 2022
1 parent d5a9251 commit 8824c31
Show file tree
Hide file tree
Showing 26 changed files with 309 additions and 269 deletions.
39 changes: 21 additions & 18 deletions cpp/include/cudf/ast/detail/operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ constexpr bool is_valid_unary_op = cuda::std::is_invocable<Op, T>::value;
* @param args Forwarded arguments to `operator()` of `f`.
*/
template <typename F, typename... Ts>
CUDF_HDI constexpr void ast_operator_dispatcher(ast_operator op, F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline constexpr void ast_operator_dispatcher(ast_operator op, F&& f, Ts&&... args)
{
switch (op) {
case ast_operator::ADD:
Expand Down Expand Up @@ -920,7 +920,7 @@ struct single_dispatch_binary_operator_types {
typename F,
typename... Ts,
std::enable_if_t<is_valid_binary_op<OperatorFunctor, LHS, LHS>>* = nullptr>
CUDF_HDI void operator()(F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline void operator()(F&& f, Ts&&... args)
{
f.template operator()<OperatorFunctor, LHS, LHS>(std::forward<Ts>(args)...);
}
Expand All @@ -929,7 +929,7 @@ struct single_dispatch_binary_operator_types {
typename F,
typename... Ts,
std::enable_if_t<!is_valid_binary_op<OperatorFunctor, LHS, LHS>>* = nullptr>
CUDF_HDI void operator()(F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline void operator()(F&& f, Ts&&... args)
{
#ifndef __CUDA_ARCH__
CUDF_FAIL("Invalid binary operation.");
Expand Down Expand Up @@ -958,7 +958,10 @@ struct type_dispatch_binary_op {
* @param args Forwarded arguments to `operator()` of `f`.
*/
template <ast_operator op, typename F, typename... Ts>
CUDF_HDI void operator()(cudf::data_type lhs_type, cudf::data_type rhs_type, F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline void operator()(cudf::data_type lhs_type,
cudf::data_type rhs_type,
F&& f,
Ts&&... args)
{
// Single dispatch (assume lhs_type == rhs_type)
type_dispatcher(
Expand All @@ -981,7 +984,7 @@ struct type_dispatch_binary_op {
* @param args Forwarded arguments to `operator()` of `f`.
*/
template <typename F, typename... Ts>
CUDF_HDI constexpr void binary_operator_dispatcher(
CUDF_HOST_DEVICE inline constexpr void binary_operator_dispatcher(
ast_operator op, cudf::data_type lhs_type, cudf::data_type rhs_type, F&& f, Ts&&... args)
{
ast_operator_dispatcher(op,
Expand All @@ -1006,7 +1009,7 @@ struct dispatch_unary_operator_types {
typename F,
typename... Ts,
std::enable_if_t<is_valid_unary_op<OperatorFunctor, InputT>>* = nullptr>
CUDF_HDI void operator()(F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline void operator()(F&& f, Ts&&... args)
{
f.template operator()<OperatorFunctor, InputT>(std::forward<Ts>(args)...);
}
Expand All @@ -1015,7 +1018,7 @@ struct dispatch_unary_operator_types {
typename F,
typename... Ts,
std::enable_if_t<!is_valid_unary_op<OperatorFunctor, InputT>>* = nullptr>
CUDF_HDI void operator()(F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline void operator()(F&& f, Ts&&... args)
{
#ifndef __CUDA_ARCH__
CUDF_FAIL("Invalid unary operation.");
Expand All @@ -1030,7 +1033,7 @@ struct dispatch_unary_operator_types {
*/
struct type_dispatch_unary_op {
template <ast_operator op, typename F, typename... Ts>
CUDF_HDI void operator()(cudf::data_type input_type, F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline void operator()(cudf::data_type input_type, F&& f, Ts&&... args)
{
type_dispatcher(
input_type,
Expand All @@ -1051,10 +1054,10 @@ struct type_dispatch_unary_op {
* @param args Forwarded arguments to `operator()` of `f`.
*/
template <typename F, typename... Ts>
CUDF_HDI constexpr void unary_operator_dispatcher(ast_operator op,
cudf::data_type input_type,
F&& f,
Ts&&... args)
CUDF_HOST_DEVICE inline constexpr void unary_operator_dispatcher(ast_operator op,
cudf::data_type input_type,
F&& f,
Ts&&... args)
{
ast_operator_dispatcher(op,
detail::type_dispatch_unary_op{},
Expand All @@ -1079,7 +1082,7 @@ struct return_type_functor {
typename LHS,
typename RHS,
std::enable_if_t<is_valid_binary_op<OperatorFunctor, LHS, RHS>>* = nullptr>
CUDF_HDI void operator()(cudf::data_type& result)
CUDF_HOST_DEVICE inline void operator()(cudf::data_type& result)
{
using Out = cuda::std::invoke_result_t<OperatorFunctor, LHS, RHS>;
result = cudf::data_type(cudf::type_to_id<Out>());
Expand All @@ -1089,7 +1092,7 @@ struct return_type_functor {
typename LHS,
typename RHS,
std::enable_if_t<!is_valid_binary_op<OperatorFunctor, LHS, RHS>>* = nullptr>
CUDF_HDI void operator()(cudf::data_type& result)
CUDF_HOST_DEVICE inline void operator()(cudf::data_type& result)
{
#ifndef __CUDA_ARCH__
CUDF_FAIL("Invalid binary operation. Return type cannot be determined.");
Expand All @@ -1108,7 +1111,7 @@ struct return_type_functor {
template <typename OperatorFunctor,
typename T,
std::enable_if_t<is_valid_unary_op<OperatorFunctor, T>>* = nullptr>
CUDF_HDI void operator()(cudf::data_type& result)
CUDF_HOST_DEVICE inline void operator()(cudf::data_type& result)
{
using Out = cuda::std::invoke_result_t<OperatorFunctor, T>;
result = cudf::data_type(cudf::type_to_id<Out>());
Expand All @@ -1117,7 +1120,7 @@ struct return_type_functor {
template <typename OperatorFunctor,
typename T,
std::enable_if_t<!is_valid_unary_op<OperatorFunctor, T>>* = nullptr>
CUDF_HDI void operator()(cudf::data_type& result)
CUDF_HOST_DEVICE inline void operator()(cudf::data_type& result)
{
#ifndef __CUDA_ARCH__
CUDF_FAIL("Invalid unary operation. Return type cannot be determined.");
Expand Down Expand Up @@ -1156,7 +1159,7 @@ inline cudf::data_type ast_operator_return_type(ast_operator op,
*/
struct arity_functor {
template <ast_operator op>
CUDF_HDI void operator()(cudf::size_type& result)
CUDF_HOST_DEVICE inline void operator()(cudf::size_type& result)
{
// Arity is not dependent on null handling, so just use the false implementation here.
result = operator_functor<op, false>::arity;
Expand All @@ -1169,7 +1172,7 @@ struct arity_functor {
* @param op Operator used to determine arity.
* @return Arity of the operator.
*/
CUDF_HDI cudf::size_type ast_operator_arity(ast_operator op)
CUDF_HOST_DEVICE inline cudf::size_type ast_operator_arity(ast_operator op)
{
auto result = cudf::size_type(0);
ast_operator_dispatcher(op, detail::arity_functor{}, result);
Expand Down
16 changes: 9 additions & 7 deletions cpp/include/cudf/detail/aggregation/aggregation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,9 @@ AGG_KIND_MAPPING(aggregation::VARIANCE, var_aggregation);
*/
#pragma nv_exec_check_disable
template <typename F, typename... Ts>
CUDF_HDI decltype(auto) aggregation_dispatcher(aggregation::Kind k, F&& f, Ts&&... args)
CUDF_HOST_DEVICE inline decltype(auto) aggregation_dispatcher(aggregation::Kind k,
F&& f,
Ts&&... args)
{
switch (k) {
case aggregation::SUM:
Expand Down Expand Up @@ -1416,7 +1418,7 @@ template <typename Element>
struct dispatch_aggregation {
#pragma nv_exec_check_disable
template <aggregation::Kind k, typename F, typename... Ts>
CUDF_HDI decltype(auto) operator()(F&& f, Ts&&... args) const
CUDF_HOST_DEVICE inline decltype(auto) operator()(F&& f, Ts&&... args) const
{
return f.template operator()<Element, k>(std::forward<Ts>(args)...);
}
Expand All @@ -1425,7 +1427,7 @@ struct dispatch_aggregation {
struct dispatch_source {
#pragma nv_exec_check_disable
template <typename Element, typename F, typename... Ts>
CUDF_HDI decltype(auto) operator()(aggregation::Kind k, F&& f, Ts&&... args) const
CUDF_HOST_DEVICE inline decltype(auto) operator()(aggregation::Kind k, F&& f, Ts&&... args) const
{
return aggregation_dispatcher(
k, dispatch_aggregation<Element>{}, std::forward<F>(f), std::forward<Ts>(args)...);
Expand All @@ -1449,10 +1451,10 @@ struct dispatch_source {
*/
#pragma nv_exec_check_disable
template <typename F, typename... Ts>
CUDF_HDI constexpr decltype(auto) dispatch_type_and_aggregation(data_type type,
aggregation::Kind k,
F&& f,
Ts&&... args)
CUDF_HOST_DEVICE inline constexpr decltype(auto) dispatch_type_and_aggregation(data_type type,
aggregation::Kind k,
F&& f,
Ts&&... args)
{
return type_dispatcher(type, dispatch_source{}, k, std::forward<F>(f), std::forward<Ts>(args)...);
}
Expand Down
52 changes: 35 additions & 17 deletions cpp/include/cudf/detail/indexalator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct base_indexalator {
/**
* @brief Prefix increment operator.
*/
CUDF_HDI T& operator++()
CUDF_HOST_DEVICE inline T& operator++()
{
T& derived = static_cast<T&>(*this);
derived.p_ += width_;
Expand All @@ -65,7 +65,7 @@ struct base_indexalator {
/**
* @brief Postfix increment operator.
*/
CUDF_HDI T operator++(int)
CUDF_HOST_DEVICE inline T operator++(int)
{
T tmp{static_cast<T&>(*this)};
operator++();
Expand All @@ -75,7 +75,7 @@ struct base_indexalator {
/**
* @brief Prefix decrement operator.
*/
CUDF_HDI T& operator--()
CUDF_HOST_DEVICE inline T& operator--()
{
T& derived = static_cast<T&>(*this);
derived.p_ -= width_;
Expand All @@ -85,7 +85,7 @@ struct base_indexalator {
/**
* @brief Postfix decrement operator.
*/
CUDF_HDI T operator--(int)
CUDF_HOST_DEVICE inline T operator--(int)
{
T tmp{static_cast<T&>(*this)};
operator--();
Expand All @@ -95,7 +95,7 @@ struct base_indexalator {
/**
* @brief Compound assignment by sum operator.
*/
CUDF_HDI T& operator+=(difference_type offset)
CUDF_HOST_DEVICE inline T& operator+=(difference_type offset)
{
T& derived = static_cast<T&>(*this);
derived.p_ += offset * width_;
Expand All @@ -105,7 +105,7 @@ struct base_indexalator {
/**
* @brief Increment by offset operator.
*/
CUDF_HDI T operator+(difference_type offset) const
CUDF_HOST_DEVICE inline T operator+(difference_type offset) const
{
auto tmp = T{static_cast<T const&>(*this)};
tmp.p_ += (offset * width_);
Expand All @@ -115,7 +115,7 @@ struct base_indexalator {
/**
* @brief Addition assignment operator.
*/
CUDF_HDI friend T operator+(difference_type offset, T const& rhs)
CUDF_HOST_DEVICE inline friend T operator+(difference_type offset, T const& rhs)
{
T tmp{rhs};
tmp.p_ += (offset * rhs.width_);
Expand All @@ -125,7 +125,7 @@ struct base_indexalator {
/**
* @brief Compound assignment by difference operator.
*/
CUDF_HDI T& operator-=(difference_type offset)
CUDF_HOST_DEVICE inline T& operator-=(difference_type offset)
{
T& derived = static_cast<T&>(*this);
derived.p_ -= offset * width_;
Expand All @@ -135,7 +135,7 @@ struct base_indexalator {
/**
* @brief Decrement by offset operator.
*/
CUDF_HDI T operator-(difference_type offset) const
CUDF_HOST_DEVICE inline T operator-(difference_type offset) const
{
auto tmp = T{static_cast<T const&>(*this)};
tmp.p_ -= (offset * width_);
Expand All @@ -145,7 +145,7 @@ struct base_indexalator {
/**
* @brief Subtraction assignment operator.
*/
CUDF_HDI friend T operator-(difference_type offset, T const& rhs)
CUDF_HOST_DEVICE inline friend T operator-(difference_type offset, T const& rhs)
{
T tmp{rhs};
tmp.p_ -= (offset * rhs.width_);
Expand All @@ -155,35 +155,53 @@ struct base_indexalator {
/**
* @brief Compute offset from iterator difference operator.
*/
CUDF_HDI difference_type operator-(T const& rhs) const
CUDF_HOST_DEVICE inline difference_type operator-(T const& rhs) const
{
return (static_cast<T const&>(*this).p_ - rhs.p_) / width_;
}

/**
* @brief Equals to operator.
*/
CUDF_HDI bool operator==(T const& rhs) const { return rhs.p_ == static_cast<T const&>(*this).p_; }
CUDF_HOST_DEVICE inline bool operator==(T const& rhs) const
{
return rhs.p_ == static_cast<T const&>(*this).p_;
}
/**
* @brief Not equals to operator.
*/
CUDF_HDI bool operator!=(T const& rhs) const { return rhs.p_ != static_cast<T const&>(*this).p_; }
CUDF_HOST_DEVICE inline bool operator!=(T const& rhs) const
{
return rhs.p_ != static_cast<T const&>(*this).p_;
}
/**
* @brief Less than operator.
*/
CUDF_HDI bool operator<(T const& rhs) const { return static_cast<T const&>(*this).p_ < rhs.p_; }
CUDF_HOST_DEVICE inline bool operator<(T const& rhs) const
{
return static_cast<T const&>(*this).p_ < rhs.p_;
}
/**
* @brief Greater than operator.
*/
CUDF_HDI bool operator>(T const& rhs) const { return static_cast<T const&>(*this).p_ > rhs.p_; }
CUDF_HOST_DEVICE inline bool operator>(T const& rhs) const
{
return static_cast<T const&>(*this).p_ > rhs.p_;
}
/**
* @brief Less than or equals to operator.
*/
CUDF_HDI bool operator<=(T const& rhs) const { return static_cast<T const&>(*this).p_ <= rhs.p_; }
CUDF_HOST_DEVICE inline bool operator<=(T const& rhs) const
{
return static_cast<T const&>(*this).p_ <= rhs.p_;
}
/**
* @brief Greater than or equals to operator.
*/
CUDF_HDI bool operator>=(T const& rhs) const { return static_cast<T const&>(*this).p_ >= rhs.p_; }
CUDF_HOST_DEVICE inline bool operator>=(T const& rhs) const
{
return static_cast<T const&>(*this).p_ >= rhs.p_;
}

protected:
/**
Expand Down
6 changes: 2 additions & 4 deletions cpp/include/cudf/detail/iterator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ struct scalar_optional_accessor : public scalar_value_accessor<Element> {
*
* @return a thrust::optional<Element> for the scalar value.
*/
CUDF_HDI
const value_type operator()(size_type) const
CUDF_HOST_DEVICE inline const value_type operator()(size_type) const
{
if (has_nulls) {
return (super_t::dscalar.is_valid()) ? Element{super_t::dscalar.value()}
Expand Down Expand Up @@ -454,8 +453,7 @@ struct scalar_pair_accessor : public scalar_value_accessor<Element> {
*
* @return a pair with value and validity of the scalar.
*/
CUDF_HDI
const value_type operator()(size_type) const
CUDF_HOST_DEVICE inline const value_type operator()(size_type) const
{
#if defined(__CUDA_ARCH__)
return {Element(super_t::dscalar.value()), super_t::dscalar.is_valid()};
Expand Down
Loading

0 comments on commit 8824c31

Please sign in to comment.