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]: Design operator specialization for cuda.parallel / C Parallel #3574

Open
1 task done
gevtushenko opened this issue Jan 28, 2025 · 1 comment
Open
1 task done
Assignees
Labels
feature request New feature or request.

Comments

@gevtushenko
Copy link
Collaborator

Is this a duplicate?

Area

cuda.parallel (Python)

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

Currently, cuda.parallel only provides generic version of parallel reduction:

def reduce_into(
d_in: DeviceArrayLike | IteratorBase,
d_out: DeviceArrayLike,
op: Callable,
h_init: np.ndarray,
):

On the C++ end, we have specialized code paths for some operators:

template <class U = T>
_CCCL_DEVICE _CCCL_FORCEINLINE
typename ::cuda::std::enable_if<(::cuda::std::is_same<int, U>::value || ::cuda::std::is_same<unsigned int, U>::value)
&& detail::reduce_add_exists<>::value,
T>::type
ReduceImpl(Int2Type<1> /* all_lanes_valid */, T input, int /* valid_items */, ::cuda::std::plus<> /* reduction_op */)
{
T output = input;
NV_IF_TARGET(
NV_PROVIDES_SM_80,
(output = __reduce_add_sync(member_mask, input);),
(output = ReduceImpl<::cuda::std::plus<>>(Int2Type<1>{}, input, LOGICAL_WARP_THREADS, ::cuda::std::plus<>{});));
return output;
}

cuda.parallel doesn't use these optimizations, because generic operators are not classified as, say, cuda::std::plus.

Describe the solution you'd like

cuda.parallel should have a way of recognizing standard operators and mapping them to underlying C++ concepts.

Describe alternatives you've considered

This problem can be split into the interface and implementation components.
On the interface end, one way to achieve that would be through different overloads #2542.
But we can also consider introspecting the operator, or recognizing built-in functions like sum on Python end.
Regardless, before addressing the interface question, we need a machinery to support it on the implementation end.
This issue can be closed by a prototype of an operator specialization machinery that'd allow cuda.parallel to request standard operators like cuda::std::plus, cuda::minimum, cuda::maximum, etc.

Additional context

No response

@shwina
Copy link
Contributor

shwina commented Jan 28, 2025

I know we want to punt on the interface question, but worth noting the operator module from the Python standard library: https://docs.python.org/3/library/operator.html

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

No branches or pull requests

3 participants