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

[FEA]: Research stateful operators for cuda.parallel #2538

Open
1 task done
gevtushenko opened this issue Oct 10, 2024 · 1 comment
Open
1 task done

[FEA]: Research stateful operators for cuda.parallel #2538

gevtushenko opened this issue Oct 10, 2024 · 1 comment
Assignees
Labels
2.8.0 target for 2.8.0 release feature request New feature or request.

Comments

@gevtushenko
Copy link
Collaborator

Is this a duplicate?

Area

Not sure

Is your feature request related to a problem? Please describe.

At the moment, stateful operators lead to a lot of boilerplate code:

class BlockPrefixCallbackOp:
def __init__(self, running_total):
self.running_total = running_total
def __call__(self_ptr, block_aggregate):
old_prefix = self_ptr[0].running_total
self_ptr[0] = BlockPrefixCallbackOp(old_prefix + block_aggregate)
return old_prefix
class BlockPrefixCallbackOpType(types.Type):
def __init__(self):
super().__init__(name='BlockPrefixCallbackOp')
block_prefix_callback_op_type = BlockPrefixCallbackOpType()
@typeof_impl.register(BlockPrefixCallbackOp)
def typeof_block_prefix_callback_op(val, c):
return block_prefix_callback_op_type
@type_callable(BlockPrefixCallbackOp)
def type__block_prefix_callback_op(context):
def typer(running_total):
if isinstance(running_total, types.Integer):
return block_prefix_callback_op_type
return typer
@register_model(BlockPrefixCallbackOpType)
class BlockPrefixCallbackOpModel(models.StructModel):
def __init__(self, dmm, fe_type):
members = [('running_total', types.int64)]
models.StructModel.__init__(self, dmm, fe_type, members)
make_attribute_wrapper(BlockPrefixCallbackOpType,
'running_total', 'running_total')
@lower_builtin(BlockPrefixCallbackOp, types.Integer)
def impl_block_prefix_callback_op(context, builder, sig, args):
typ = sig.return_type
[running_total] = args
state = cgutils.create_struct_proxy(typ)(context, builder)
state.running_total = running_total
return state._getvalue()

Describe the solution you'd like

Ideally, I want users to write something along the lines of:

d_input = cp.array([8, 6, 7, 5, 3, 0, 9], dtype=dtype)
cudax.bulk(3, lambda i,d_input=d_input: print(d_input[i]))

That'd involve packing as if capture list was passed to a Numba kernel. Numba is already doing that on kernel launches, we just need a state pointer to be passed to C++ foreign function call instead of cuLaunchKernel

Describe alternatives you've considered

No response

Additional context

No response

@gevtushenko gevtushenko added the feature request New feature or request. label Oct 10, 2024
@github-project-automation github-project-automation bot moved this to Todo in CCCL Oct 10, 2024
@gevtushenko
Copy link
Collaborator Author

@gmarkall for visibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.8.0 target for 2.8.0 release feature request New feature or request.
Projects
Status: Todo
Development

No branches or pull requests

2 participants