Skip to content

Commit d1bf12e

Browse files
committed
Merge branch-25.06 into branch-25.08
2 parents 59122eb + c1ca525 commit d1bf12e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1833
-376
lines changed

conda/environments/all_cuda-118_arch-aarch64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dependencies:
5454
- nbsphinx
5555
- ninja
5656
- notebook
57-
- numba-cuda>=0.9.0,!=0.10.0
57+
- numba-cuda>=0.10.1,<0.11.0a0
5858
- numba>=0.59.1,<0.62.0a0
5959
- numpy>=1.23,<3.0a0
6060
- numpydoc

conda/environments/all_cuda-118_arch-x86_64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies:
5656
- nbsphinx
5757
- ninja
5858
- notebook
59-
- numba-cuda>=0.9.0,!=0.10.0
59+
- numba-cuda>=0.10.1,<0.11.0a0
6060
- numba>=0.59.1,<0.62.0a0
6161
- numpy>=1.23,<3.0a0
6262
- numpydoc

conda/environments/all_cuda-128_arch-aarch64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dependencies:
5454
- nbsphinx
5555
- ninja
5656
- notebook
57-
- numba-cuda>=0.9.0,!=0.10.0
57+
- numba-cuda>=0.10.1,<0.11.0a0
5858
- numba>=0.59.1,<0.62.0a0
5959
- numpy>=1.23,<3.0a0
6060
- numpydoc

conda/environments/all_cuda-128_arch-x86_64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies:
5555
- nbsphinx
5656
- ninja
5757
- notebook
58-
- numba-cuda>=0.9.0,!=0.10.0
58+
- numba-cuda>=0.10.1,<0.11.0a0
5959
- numba>=0.59.1,<0.62.0a0
6060
- numpy>=1.23,<3.0a0
6161
- numpydoc

conda/recipes/cudf/recipe.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ requirements:
7373
- typing_extensions >=4.0.0
7474
- pandas >=2.0,<2.2.4dev0
7575
- cupy >=12.0.0
76-
- numba-cuda >=0.9.0,!=0.10.0
76+
- numba-cuda >=0.10.1,<0.11.0a0
7777
- numba >=0.59.1,<0.62.0a0
7878
- numpy >=1.23,<3.0a0
7979
- pyarrow>=14.0.0,<20.0.0a0

cpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ add_library(
452452
src/groupby/sort/aggregate.cpp
453453
src/groupby/sort/group_argmax.cu
454454
src/groupby/sort/group_argmin.cu
455+
src/groupby/sort/group_bitwise.cu
455456
src/groupby/sort/group_collect.cu
456457
src/groupby/sort/group_correlation.cu
457458
src/groupby/sort/group_count.cu
@@ -633,6 +634,7 @@ add_library(
633634
src/quantiles/quantiles.cu
634635
src/reductions/all.cu
635636
src/reductions/any.cu
637+
src/reductions/bitwise.cu
636638
src/reductions/collect_ops.cu
637639
src/reductions/histogram.cu
638640
src/reductions/max.cu

cpp/include/cudf/aggregation.hpp

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ enum class rank_percentage : int32_t {
7070
ONE_NORMALIZED ///< (rank - 1) / (count - 1)
7171
};
7272

73+
/**
74+
* @brief Bitwise operations to use for BITWISE_AGG aggregations on numeric columns.
75+
*/
76+
enum class bitwise_op : int32_t {
77+
AND, ///< bitwise AND operation
78+
OR, ///< bitwise OR operation
79+
XOR ///< bitwise XOR operation
80+
};
81+
7382
/**
7483
* @brief Abstract base class for specifying the desired aggregation in an
7584
* `aggregation_request`.
@@ -84,44 +93,45 @@ class aggregation {
8493
* @brief Possible aggregation operations
8594
*/
8695
enum Kind {
87-
SUM, ///< sum reduction
88-
PRODUCT, ///< product reduction
89-
MIN, ///< min reduction
90-
MAX, ///< max reduction
91-
COUNT_VALID, ///< count number of valid elements
92-
COUNT_ALL, ///< count number of elements
93-
ANY, ///< any reduction
94-
ALL, ///< all reduction
95-
SUM_OF_SQUARES, ///< sum of squares reduction
96-
MEAN, ///< arithmetic mean reduction
97-
M2, ///< sum of squares of differences from the mean
98-
VARIANCE, ///< variance
99-
STD, ///< standard deviation
100-
MEDIAN, ///< median reduction
101-
QUANTILE, ///< compute specified quantile(s)
102-
ARGMAX, ///< Index of max element
103-
ARGMIN, ///< Index of min element
104-
NUNIQUE, ///< count number of unique elements
105-
NTH_ELEMENT, ///< get the nth element
106-
ROW_NUMBER, ///< get row-number of current index (relative to rolling window)
107-
EWMA, ///< get exponential weighted moving average at current index
108-
RANK, ///< get rank of current index
109-
COLLECT_LIST, ///< collect values into a list
110-
COLLECT_SET, ///< collect values into a list without duplicate entries
111-
LEAD, ///< window function, accesses row at specified offset following current row
112-
LAG, ///< window function, accesses row at specified offset preceding current row
113-
PTX, ///< PTX based UDF aggregation
114-
CUDA, ///< CUDA based UDF aggregation
115-
HOST_UDF, ///< host based UDF aggregation
116-
MERGE_LISTS, ///< merge multiple lists values into one list
117-
MERGE_SETS, ///< merge multiple lists values into one list then drop duplicate entries
118-
MERGE_M2, ///< merge partial values of M2 aggregation,
119-
COVARIANCE, ///< covariance between two sets of elements
120-
CORRELATION, ///< correlation between two sets of elements
121-
TDIGEST, ///< create a tdigest from a set of input values
122-
MERGE_TDIGEST, ///< create a tdigest by merging multiple tdigests together
123-
HISTOGRAM, ///< compute frequency of each element
124-
MERGE_HISTOGRAM ///< merge partial values of HISTOGRAM aggregation
96+
SUM, ///< sum reduction
97+
PRODUCT, ///< product reduction
98+
MIN, ///< min reduction
99+
MAX, ///< max reduction
100+
COUNT_VALID, ///< count number of valid elements
101+
COUNT_ALL, ///< count number of elements
102+
ANY, ///< any reduction
103+
ALL, ///< all reduction
104+
SUM_OF_SQUARES, ///< sum of squares reduction
105+
MEAN, ///< arithmetic mean reduction
106+
M2, ///< sum of squares of differences from the mean
107+
VARIANCE, ///< variance
108+
STD, ///< standard deviation
109+
MEDIAN, ///< median reduction
110+
QUANTILE, ///< compute specified quantile(s)
111+
ARGMAX, ///< Index of max element
112+
ARGMIN, ///< Index of min element
113+
NUNIQUE, ///< count number of unique elements
114+
NTH_ELEMENT, ///< get the nth element
115+
ROW_NUMBER, ///< get row-number of current index (relative to rolling window)
116+
EWMA, ///< get exponential weighted moving average at current index
117+
RANK, ///< get rank of current index
118+
COLLECT_LIST, ///< collect values into a list
119+
COLLECT_SET, ///< collect values into a list without duplicate entries
120+
LEAD, ///< window function, accesses row at specified offset following current row
121+
LAG, ///< window function, accesses row at specified offset preceding current row
122+
PTX, ///< PTX based UDF aggregation
123+
CUDA, ///< CUDA based UDF aggregation
124+
HOST_UDF, ///< host based UDF aggregation
125+
MERGE_LISTS, ///< merge multiple lists values into one list
126+
MERGE_SETS, ///< merge multiple lists values into one list then drop duplicate entries
127+
MERGE_M2, ///< merge partial values of M2 aggregation,
128+
COVARIANCE, ///< covariance between two sets of elements
129+
CORRELATION, ///< correlation between two sets of elements
130+
TDIGEST, ///< create a tdigest from a set of input values
131+
MERGE_TDIGEST, ///< create a tdigest by merging multiple tdigests together
132+
HISTOGRAM, ///< compute frequency of each element
133+
MERGE_HISTOGRAM, ///< merge partial values of HISTOGRAM aggregation
134+
BITWISE_AGG ///< bitwise aggregation on numeric columns
125135
};
126136

127137
aggregation() = delete;
@@ -783,12 +793,21 @@ std::unique_ptr<Base> make_tdigest_aggregation(int max_centroids = 1000);
783793
template <typename Base>
784794
std::unique_ptr<Base> make_merge_tdigest_aggregation(int max_centroids = 1000);
785795

796+
/**
797+
* @brief Factory to create a BITWISE_AGG aggregation.
798+
*
799+
* @param op The bitwise operation to perform on the input column
800+
* @return A BITWISE_AGG aggregation object
801+
*/
802+
template <typename Base>
803+
std::unique_ptr<Base> make_bitwise_aggregation(bitwise_op op);
804+
786805
/**
787806
* @brief Indicate if an aggregation is supported for a source datatype.
788807
*
789-
* @param source Type of the column to perform the aggregation on.
790-
* @param kind The kind of the aggregation.
791-
* @returns true if the aggregation is supported.
808+
* @param source Type of the column to perform the aggregation on
809+
* @param kind The kind of the aggregation
810+
* @returns true if the aggregation is supported
792811
*/
793812
bool is_valid_aggregation(data_type source, aggregation::Kind kind);
794813

cpp/include/cudf/detail/aggregation/aggregation.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class simple_aggregations_collector { // Declares the interface for the simple
107107
class tdigest_aggregation const& agg);
108108
virtual std::vector<std::unique_ptr<aggregation>> visit(
109109
data_type col_type, class merge_tdigest_aggregation const& agg);
110+
virtual std::vector<std::unique_ptr<aggregation>> visit(data_type col_type,
111+
class bitwise_aggregation const& agg);
110112
};
111113

112114
class aggregation_finalizer { // Declares the interface for the finalizer
@@ -148,6 +150,7 @@ class aggregation_finalizer { // Declares the interface for the finalizer
148150
virtual void visit(class tdigest_aggregation const& agg);
149151
virtual void visit(class merge_tdigest_aggregation const& agg);
150152
virtual void visit(class ewma_aggregation const& agg);
153+
virtual void visit(class bitwise_aggregation const& agg);
151154
};
152155

153156
/**
@@ -1221,6 +1224,41 @@ class merge_tdigest_aggregation final : public groupby_aggregation, public reduc
12211224
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
12221225
};
12231226

1227+
/**
1228+
* @brief Derived aggregation class for specifying BITWISE_AGG aggregation.
1229+
*/
1230+
class bitwise_aggregation final : public groupby_aggregation, public reduce_aggregation {
1231+
public:
1232+
explicit bitwise_aggregation(bitwise_op bit_op_) : aggregation{BITWISE_AGG}, bit_op{bit_op_} {}
1233+
1234+
bitwise_op bit_op;
1235+
1236+
[[nodiscard]] bool is_equal(aggregation const& _other) const override
1237+
{
1238+
if (!this->aggregation::is_equal(_other)) { return false; }
1239+
auto const& other = dynamic_cast<bitwise_aggregation const&>(_other);
1240+
return bit_op == other.bit_op;
1241+
}
1242+
1243+
[[nodiscard]] size_t do_hash() const override
1244+
{
1245+
return this->aggregation::do_hash() ^ static_cast<size_t>(bit_op);
1246+
}
1247+
1248+
[[nodiscard]] std::unique_ptr<aggregation> clone() const override
1249+
{
1250+
return std::make_unique<bitwise_aggregation>(*this);
1251+
}
1252+
1253+
std::vector<std::unique_ptr<aggregation>> get_simple_aggregations(
1254+
data_type col_type, simple_aggregations_collector& collector) const override
1255+
{
1256+
return collector.visit(col_type, *this);
1257+
}
1258+
1259+
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
1260+
};
1261+
12241262
/**
12251263
* @brief Sentinel value used for `ARGMAX` aggregation.
12261264
*
@@ -1503,6 +1541,14 @@ struct target_type_impl<SourceType, aggregation::HOST_UDF> {
15031541
using type = struct_view;
15041542
};
15051543

1544+
// BITWISE_AGG returns the same type as input for integral types.
1545+
template <typename Source>
1546+
struct target_type_impl<Source,
1547+
aggregation::BITWISE_AGG,
1548+
std::enable_if_t<std::is_integral_v<Source>>> {
1549+
using type = Source;
1550+
};
1551+
15061552
/**
15071553
* @brief Helper alias to get the accumulator type for performing aggregation
15081554
* `k` on elements of type `Source`
@@ -1622,6 +1668,8 @@ CUDF_HOST_DEVICE inline decltype(auto) aggregation_dispatcher(aggregation::Kind
16221668
return f.template operator()<aggregation::EWMA>(std::forward<Ts>(args)...);
16231669
case aggregation::HOST_UDF:
16241670
return f.template operator()<aggregation::HOST_UDF>(std::forward<Ts>(args)...);
1671+
case aggregation::BITWISE_AGG:
1672+
return f.template operator()<aggregation::BITWISE_AGG>(std::forward<Ts>(args)...);
16251673
default: {
16261674
#ifndef __CUDA_ARCH__
16271675
CUDF_FAIL("Unsupported aggregation.");

cpp/include/cudf/detail/utilities/device_operators.cuh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,92 @@ struct DeviceLeadLag {
251251
explicit CUDF_HOST_DEVICE inline DeviceLeadLag(size_type offset_) : row_offset(offset_) {}
252252
};
253253

254+
/**
255+
* @brief Binary bitwise `AND` operator
256+
*/
257+
struct DeviceBitAnd {
258+
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
259+
CUDF_HOST_DEVICE inline T operator()(T const& lhs, T const& rhs) const
260+
{
261+
return lhs & rhs;
262+
}
263+
264+
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
265+
CUDF_HOST_DEVICE static constexpr T identity()
266+
{
267+
if constexpr (std::is_same_v<T, bool>) {
268+
return true;
269+
} else {
270+
return ~T{0};
271+
}
272+
}
273+
274+
template <typename T, std::enable_if_t<!std::is_integral_v<T>>* = nullptr>
275+
CUDF_HOST_DEVICE static constexpr T identity()
276+
{
277+
#ifndef __CUDA_ARCH__
278+
CUDF_FAIL("Bitwise AND is only supported for integral types.");
279+
#else
280+
CUDF_UNREACHABLE("Bitwise AND is only supported for integral types.");
281+
#endif
282+
return T{};
283+
}
284+
};
285+
286+
/**
287+
* @brief Binary bitwise `OR` operator
288+
*/
289+
struct DeviceBitOr {
290+
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
291+
CUDF_HOST_DEVICE inline T operator()(T const& lhs, T const& rhs) const
292+
{
293+
return lhs | rhs;
294+
}
295+
296+
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
297+
CUDF_HOST_DEVICE static constexpr T identity()
298+
{
299+
return T{0};
300+
}
301+
302+
template <typename T, std::enable_if_t<!std::is_integral_v<T>>* = nullptr>
303+
CUDF_HOST_DEVICE static constexpr T identity()
304+
{
305+
#ifndef __CUDA_ARCH__
306+
CUDF_FAIL("Bitwise OR is only supported for integral types.");
307+
#else
308+
CUDF_UNREACHABLE("Bitwise OR is only supported for integral types.");
309+
#endif
310+
return T{};
311+
}
312+
};
313+
314+
/**
315+
* @brief Binary bitwise `XOR` operator
316+
*/
317+
struct DeviceBitXor {
318+
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
319+
CUDF_HOST_DEVICE inline T operator()(T const& lhs, T const& rhs) const
320+
{
321+
return lhs ^ rhs;
322+
}
323+
324+
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
325+
CUDF_HOST_DEVICE static constexpr T identity()
326+
{
327+
return T{0};
328+
}
329+
330+
template <typename T, std::enable_if_t<!std::is_integral_v<T>>* = nullptr>
331+
CUDF_HOST_DEVICE static constexpr T identity()
332+
{
333+
#ifndef __CUDA_ARCH__
334+
CUDF_FAIL("Bitwise XOR is only supported for integral types.");
335+
#else
336+
CUDF_UNREACHABLE("Bitwise XOR is only supported for integral types.");
337+
#endif
338+
return T{};
339+
}
340+
};
341+
254342
} // namespace cudf

0 commit comments

Comments
 (0)