cccl icon indicating copy to clipboard operation
cccl copied to clipboard

[FEA]: Introduce sentinel ranges into cuda.parallel

Open gevtushenko opened this issue 1 year ago • 0 comments

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:

  1. device sum of repeat(1) is equal to num_items
  2. device sum of repeat(UserDefinedPair(1, 2)) is equal to UserDefinedPair(num_items, 2 * num_items)
  3. device sum of count(1) is equal to num_items * (num_items + 1) / 2

Describe alternatives you've considered

No response

Additional context

No response

gevtushenko avatar Sep 29 '24 20:09 gevtushenko