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

Refactor host device macros #9797

Merged
merged 12 commits into from
Jan 10, 2022
144 changes: 66 additions & 78 deletions cpp/include/cudf/ast/detail/expression_evaluator.cuh

Large diffs are not rendered by default.

149 changes: 72 additions & 77 deletions cpp/include/cudf/ast/detail/operators.hpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions cpp/include/cudf/column/column_device_view.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ struct optional_accessor {
if (with_nulls) { CUDF_EXPECTS(_col.nullable(), "Unexpected non-nullable column."); }
}

CUDA_DEVICE_CALLABLE
CUDF_DI
vyasr marked this conversation as resolved.
Show resolved Hide resolved
thrust::optional<T> operator()(cudf::size_type i) const
{
if (has_nulls) {
Expand Down Expand Up @@ -1196,7 +1196,7 @@ struct pair_accessor {
if (has_nulls) { CUDF_EXPECTS(_col.nullable(), "Unexpected non-nullable column."); }
}

CUDA_DEVICE_CALLABLE
CUDF_DI
thrust::pair<T, bool> operator()(cudf::size_type i) const
{
return {col.element<T>(i), (has_nulls ? col.is_valid_nocheck(i) : true)};
Expand Down Expand Up @@ -1237,21 +1237,21 @@ struct pair_rep_accessor {
if (has_nulls) { CUDF_EXPECTS(_col.nullable(), "Unexpected non-nullable column."); }
}

CUDA_DEVICE_CALLABLE
CUDF_DI
thrust::pair<rep_type, bool> operator()(cudf::size_type i) const
{
return {get_rep<T>(i), (has_nulls ? col.is_valid_nocheck(i) : true)};
}

private:
template <typename R, std::enable_if_t<std::is_same_v<R, rep_type>, void>* = nullptr>
CUDA_DEVICE_CALLABLE auto get_rep(cudf::size_type i) const
CUDF_DI auto get_rep(cudf::size_type i) const
{
return col.element<R>(i);
}

template <typename R, std::enable_if_t<not std::is_same_v<R, rep_type>, void>* = nullptr>
CUDA_DEVICE_CALLABLE auto get_rep(cudf::size_type i) const
CUDF_DI auto get_rep(cudf::size_type i) const
{
return col.element<R>(i).value();
}
Expand Down
16 changes: 7 additions & 9 deletions cpp/include/cudf/detail/aggregation/aggregation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,9 +1324,7 @@ AGG_KIND_MAPPING(aggregation::VARIANCE, var_aggregation);
*/
#pragma nv_exec_check_disable
template <typename F, typename... Ts>
CUDA_HOST_DEVICE_CALLABLE decltype(auto) aggregation_dispatcher(aggregation::Kind k,
F&& f,
Ts&&... args)
CUDF_HDI decltype(auto) aggregation_dispatcher(aggregation::Kind k, F&& f, Ts&&... args)
{
switch (k) {
case aggregation::SUM:
Expand Down Expand Up @@ -1418,7 +1416,7 @@ template <typename Element>
struct dispatch_aggregation {
#pragma nv_exec_check_disable
template <aggregation::Kind k, typename F, typename... Ts>
CUDA_HOST_DEVICE_CALLABLE decltype(auto) operator()(F&& f, Ts&&... args) const
CUDF_HDI decltype(auto) operator()(F&& f, Ts&&... args) const
{
return f.template operator()<Element, k>(std::forward<Ts>(args)...);
}
Expand All @@ -1427,9 +1425,7 @@ struct dispatch_aggregation {
struct dispatch_source {
#pragma nv_exec_check_disable
template <typename Element, typename F, typename... Ts>
CUDA_HOST_DEVICE_CALLABLE decltype(auto) operator()(aggregation::Kind k,
F&& f,
Ts&&... args) const
CUDF_HDI 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 @@ -1453,8 +1449,10 @@ struct dispatch_source {
*/
#pragma nv_exec_check_disable
template <typename F, typename... Ts>
CUDA_HOST_DEVICE_CALLABLE constexpr decltype(auto) dispatch_type_and_aggregation(
data_type type, aggregation::Kind k, F&& f, Ts&&... args)
CUDF_HDI 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
62 changes: 22 additions & 40 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.
*/
CUDA_HOST_DEVICE_CALLABLE T& operator++()
CUDF_HDI T& operator++()
{
T& derived = static_cast<T&>(*this);
derived.p_ += width_;
Expand All @@ -65,7 +65,7 @@ struct base_indexalator {
/**
* @brief Postfix increment operator.
*/
CUDA_HOST_DEVICE_CALLABLE T operator++(int)
CUDF_HDI T operator++(int)
{
T tmp{static_cast<T&>(*this)};
operator++();
Expand All @@ -75,7 +75,7 @@ struct base_indexalator {
/**
* @brief Prefix decrement operator.
*/
CUDA_HOST_DEVICE_CALLABLE T& operator--()
CUDF_HDI T& operator--()
{
T& derived = static_cast<T&>(*this);
derived.p_ -= width_;
Expand All @@ -85,7 +85,7 @@ struct base_indexalator {
/**
* @brief Postfix decrement operator.
*/
CUDA_HOST_DEVICE_CALLABLE T operator--(int)
CUDF_HDI 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.
*/
CUDA_HOST_DEVICE_CALLABLE T& operator+=(difference_type offset)
CUDF_HDI 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.
*/
CUDA_HOST_DEVICE_CALLABLE T operator+(difference_type offset) const
CUDF_HDI 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.
*/
CUDA_HOST_DEVICE_CALLABLE friend T operator+(difference_type offset, T const& rhs)
CUDF_HDI 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.
*/
CUDA_HOST_DEVICE_CALLABLE T& operator-=(difference_type offset)
CUDF_HDI 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.
*/
CUDA_HOST_DEVICE_CALLABLE T operator-(difference_type offset) const
CUDF_HDI 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.
*/
CUDA_HOST_DEVICE_CALLABLE friend T operator-(difference_type offset, T const& rhs)
CUDF_HDI friend T operator-(difference_type offset, T const& rhs)
{
T tmp{rhs};
tmp.p_ -= (offset * rhs.width_);
Expand All @@ -155,53 +155,35 @@ struct base_indexalator {
/**
* @brief Compute offset from iterator difference operator.
*/
CUDA_HOST_DEVICE_CALLABLE difference_type operator-(T const& rhs) const
CUDF_HDI difference_type operator-(T const& rhs) const
{
return (static_cast<T const&>(*this).p_ - rhs.p_) / width_;
}

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

protected:
/**
Expand Down Expand Up @@ -253,7 +235,7 @@ struct input_indexalator : base_indexalator<input_indexalator> {
/**
* @brief Indirection operator returns the value at the current iterator position.
*/
CUDA_DEVICE_CALLABLE size_type operator*() const { return operator[](0); }
CUDF_DI size_type operator*() const { return operator[](0); }

/**
* @brief Dispatch functor for resolving a size_type value from any index type.
Expand All @@ -275,7 +257,7 @@ struct input_indexalator : base_indexalator<input_indexalator> {
* @brief Array subscript operator returns a value at the input
* `idx` position as a `size_type` value.
*/
CUDA_DEVICE_CALLABLE size_type operator[](size_type idx) const
CUDF_DI size_type operator[](size_type idx) const
{
void const* tp = p_ + (idx * width_);
return type_dispatcher(dtype_, index_as_size_type{}, tp);
Expand Down Expand Up @@ -339,14 +321,14 @@ struct output_indexalator : base_indexalator<output_indexalator> {
* @brief Indirection operator returns this iterator instance in order
* to capture the `operator=(size_type)` calls.
*/
CUDA_DEVICE_CALLABLE output_indexalator const& operator*() const { return *this; }
CUDF_DI output_indexalator const& operator*() const { return *this; }

/**
* @brief Array subscript operator returns an iterator instance at the specified `idx` position.
*
* This allows capturing the subsequent `operator=(size_type)` call in this class.
*/
CUDA_DEVICE_CALLABLE output_indexalator const operator[](size_type idx) const
CUDF_DI output_indexalator const operator[](size_type idx) const
{
output_indexalator tmp{*this};
tmp.p_ += (idx * width_);
Expand All @@ -372,7 +354,7 @@ struct output_indexalator : base_indexalator<output_indexalator> {
/**
* @brief Assign a size_type value to the current iterator position.
*/
CUDA_DEVICE_CALLABLE output_indexalator const& operator=(size_type const value) const
CUDF_DI output_indexalator const& operator=(size_type const value) const
{
void* tp = p_;
type_dispatcher(dtype_, size_type_to_index{}, tp, value);
Expand Down
16 changes: 8 additions & 8 deletions cpp/include/cudf/detail/iterator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct null_replaced_value_accessor {
if (has_nulls) CUDF_EXPECTS(col.nullable(), "column with nulls must have a validity bitmask");
}

CUDA_DEVICE_CALLABLE
CUDF_DI
Element operator()(cudf::size_type i) const
{
return has_nulls && col.is_null_nocheck(i) ? null_replacement : col.element<Element>(i);
Expand Down Expand Up @@ -135,7 +135,7 @@ struct validity_accessor {
CUDF_EXPECTS(_col.nullable(), "Unexpected non-nullable column.");
}

CUDA_DEVICE_CALLABLE
CUDF_DI
bool operator()(cudf::size_type i) const { return col.is_valid_nocheck(i); }
};

Expand Down Expand Up @@ -344,7 +344,7 @@ struct scalar_value_accessor {
*
* @return value of the scalar.
*/
CUDA_DEVICE_CALLABLE
CUDF_DI
const Element operator()(size_type) const
{
#if defined(__CUDA_ARCH__)
Expand Down Expand Up @@ -423,7 +423,7 @@ struct scalar_optional_accessor : public scalar_value_accessor<Element> {
*
* @return a thrust::optional<Element> for the scalar value.
*/
CUDA_HOST_DEVICE_CALLABLE
CUDF_HDI
const value_type operator()(size_type) const
{
if (has_nulls) {
Expand Down Expand Up @@ -457,7 +457,7 @@ struct scalar_pair_accessor : public scalar_value_accessor<Element> {
*
* @return a pair with value and validity of the scalar.
*/
CUDA_HOST_DEVICE_CALLABLE
CUDF_HDI
const value_type operator()(size_type) const
{
#if defined(__CUDA_ARCH__)
Expand Down Expand Up @@ -509,7 +509,7 @@ struct scalar_representation_pair_accessor : public scalar_value_accessor<Elemen
*
* @return a pair with representative value and validity of the scalar.
*/
CUDA_DEVICE_CALLABLE
CUDF_DI
const value_type operator()(size_type) const
{
return {get_rep(base::dscalar), base::dscalar.is_valid()};
Expand All @@ -518,14 +518,14 @@ struct scalar_representation_pair_accessor : public scalar_value_accessor<Elemen
private:
template <typename DeviceScalar,
std::enable_if_t<!has_rep_member<DeviceScalar>::value, void>* = nullptr>
CUDA_DEVICE_CALLABLE rep_type get_rep(DeviceScalar const& dscalar) const
CUDF_DI rep_type get_rep(DeviceScalar const& dscalar) const
{
return dscalar.value();
}

template <typename DeviceScalar,
std::enable_if_t<has_rep_member<DeviceScalar>::value, void>* = nullptr>
CUDA_DEVICE_CALLABLE rep_type get_rep(DeviceScalar const& dscalar) const
CUDF_DI rep_type get_rep(DeviceScalar const& dscalar) const
{
return dscalar.rep();
}
Expand Down
Loading