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

Avoid specializations of the same submitters with the some policy type but with different type qualifiers (l-value, r-value) #2093

Open
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

SergeyKopienko
Copy link
Contributor

@SergeyKopienko SergeyKopienko commented Mar 3, 2025

In this PR we fix the issue #2083 and #2041

The problem statement.

Usually, oneDPL submitters which do sycl::queue::submit() calls are implemented in three ways:

  • operator() implementation inside some class / struct;
  • submit() function implementation inside some class / struct;
  • some free function.

In all cases, these functions are template functions parametrized by _ExecutioPolicy type. Also they have _ExecutioPolicy&& __exec in the list of functions parameters.
This approach means that we may have two specializations of these functions:

  • one specialization for the case when __exec is r-value;
  • another specialization for other cases.

The problems of this approach which already implemented in oneDPL:

  • we should generate unique Kernel-names using not only _ExecutionPolicy type but also their qualifiers (l-value, r-value);
  • we increase the amount of sycl-kernel code and their compile-time;
  • we increase the amount of host code in compile-time.

The solution

As solution in this PR proposed the idea of @akukanov - to declare _ExecutionPolicy in submitters and on one upper level as const _ExecutionPolicy& (const reference).
This approach fixes all point of the problem described below.

Some key changes in the code

  • the usage of _ExecutionPolicy is not required inside __kernel_name_generator template parameters anymore:
    -- before:
    template <typename... _Name>
    using _SegScanPrefixPhase = __seg_scan_prefix_kernel<__is_inclusive, _Name...>;

    template <typename _BackendTag, typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3,
              typename _BinaryPredicate, typename _BinaryOperator, typename _T>
    void
    operator()(_BackendTag, _ExecutionPolicy&& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_values,
               _BinaryPredicate __binary_pred, _BinaryOperator __binary_op, _T __init, _T __identity)
    {
        using _CustomName = oneapi::dpl::__internal::__policy_kernel_name<_ExecutionPolicy>;

        using _SegScanWgKernel = oneapi::dpl::__par_backend_hetero::__internal::__kernel_name_generator<
            _SegScanWgPhase, _CustomName, _ExecutionPolicy, _Range1, _Range2, _Range3, _BinaryPredicate,
            _BinaryOperator>;

        // ...
    }

-- now:

    template <typename _BackendTag, typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3,
              typename _BinaryPredicate, typename _BinaryOperator, typename _T>
    void
    operator()(_BackendTag, const _ExecutionPolicy& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_values,
               _BinaryPredicate __binary_pred, _BinaryOperator __binary_op, _T __init, _T __identity)
    {
        using _CustomName = oneapi::dpl::__internal::__policy_kernel_name<_ExecutionPolicy>;

        // We should avoid using _ExecutionPolicy in __kernel_name_generator template params
        // because we always specialize this operator() calls only by _ExecutionPolicy as "const reference".
        // So, from this template param point of view, only one specialization is possible.
        using _SegScanWgKernel = oneapi::dpl::__par_backend_hetero::__internal::__kernel_name_generator<
            _SegScanWgPhase, _CustomName, _Range1, _Range2, _Range3, _BinaryPredicate, _BinaryOperator>;

        // ...
    }

Now we able to detect a lot of errors as described in #2041 - this test coverage implemented in the PR #2102

Another approach has been prepared in #2082

Please review this PR under switched off option "File changed - Gear button - Hide whitespace"

@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/fix_exec_policy_type_in_submitters_V1 branch 4 times, most recently from 0976051 to 0102ab8 Compare March 3, 2025 16:27
@SergeyKopienko SergeyKopienko changed the title Avoid specializations of the same submitters with the some policy type but with different qualifiers - V1 Avoid specializations of the same submitters with the some policy type but with different qualifiers Mar 3, 2025
@SergeyKopienko SergeyKopienko added this to the 2022.9.0 milestone Mar 3, 2025
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/fix_exec_policy_type_in_submitters_V1 branch 4 times, most recently from 629a956 to e005551 Compare March 4, 2025 09:51
@SergeyKopienko SergeyKopienko marked this pull request as ready for review March 4, 2025 10:46
@SergeyKopienko SergeyKopienko changed the title Avoid specializations of the same submitters with the some policy type but with different qualifiers Avoid specializations of the same submitters with the some policy type but with different type qualifiers (l-value, r-value and etc.) Mar 4, 2025
@SergeyKopienko SergeyKopienko changed the title Avoid specializations of the same submitters with the some policy type but with different type qualifiers (l-value, r-value and etc.) Avoid specializations of the same submitters with the some policy type but with different type qualifiers (l-value, r-value) Mar 4, 2025
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/fix_exec_policy_type_in_submitters_V1 branch 2 times, most recently from fe6cd52 to 1880b1e Compare March 4, 2025 12:32
SergeyKopienko and others added 29 commits March 6, 2025 18:57
…an_static_single_group_submitter::operator(), __parallel_transform_scan_dynamic_single_group_submitter::oeprator()
…tatic_single_group_submitter::operator(), __parallel_copy_if_static_single_group_submitter::operator()
…ral_registers_local_reduction_submitter::operator()
…_private_global_atomics_submitter::operator()
…rs_local_reduction, __histogram_general_local_atomics, __histogram_general_private_global_atomics
…impl, __parallel_transform_reduce_mid_impl, __parallel_transform_reduce_impl
….h - remove :: before std::decay_t in __kernel_name_generator
Co-authored-by: Dan Hoeflinger <109972525+danhoeflinger@users.noreply.github.com>
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/fix_exec_policy_type_in_submitters_V1 branch from 3d9988c to ca5f2da Compare March 6, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants