cccl
cccl copied to clipboard
[FEA]: Introduce sentinel ranges into cuda.parallel
Is this a duplicate?
- [x] I confirmed there appear to be no duplicate issues for this request and that I agree to the Code of Conduct
Area
General CCCL
Is your feature request related to a problem? Please describe.
We are lacking functionality of sentinel fancy iterators such as thrust::counting_iterator, and thrust::constant_iterator in cuda.parallel.
Describe the solution you'd like
We should introduce cuda.parallel.experimental.itertools module with repeat(value) for thrust::constant_iterator, and count(start) for thrust::counting_iterator.
Naive implementation might look like:
class CountingIterator(ctypes.Structure):
_fields_ = [("offset", ctypes.c_int64)]
def advance(self_ptr, offset):
self_ptr[0] = self_ptr[0] + offset
def dereference(self_ptr):
return self_ptr[0]
def count(start):
return CountingIterator(start)
This issue can be closed by three tests in python/cuda_parallel/tests/test_reduce.py:
- device sum of
repeat(1)is equal tonum_items - device sum of
repeat(UserDefinedPair(1, 2))is equal toUserDefinedPair(num_items, 2 * num_items) - device sum of
count(1)is equal tonum_items * (num_items + 1) / 2
Describe alternatives you've considered
No response
Additional context
No response