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

Multiple backends prototype #1509

Closed
wants to merge 26 commits into from

Conversation

SergeyKopienko
Copy link
Contributor

@SergeyKopienko SergeyKopienko commented Apr 17, 2024

This PR is only prototype for descussions.

The goal of this PR

The goal of this PR - redesign our host backends (SERIAL, TBB, OMP) :

  • to use them depends on backend_tag;
  • to safe use them together (if required).

How we trying to achieve these goals (the main idea):

  • in the namespace oneapi::dpl::__backend we declare common backend template structure:
// Template for backend implementations
template <typename __backend_tag>
struct __backend_impl;
  • in the namespace oneapi::dpl::__backend for each of our host backends (SERIAL, TBB, OMP) we create it's specializations:
// parallel_backend_omp.h
template <>
struct __backend_impl<oneapi::dpl::__internal::__omp_backend_tag>
{
    // Declare here public API functions of OMP backend
};

// parallel_backend_serial.h
template <>
struct __backend_impl<oneapi::dpl::__internal::__serial_backend_tag>
{
    // Declare here public API functions of SERIAL backend
};

// parallel_backend_tbb.h
template <>
struct __backend_impl<oneapi::dpl::__internal::__tbb_backend_tag>
{
    // Declare here public API functions of TBB backend
};
  • move backend public API functions into these structures;
  • move private backend functions into some separate namespaces: oneapi::dpl::__backend::__tbb_backend_details, oneapi::dpl::__backend::__omp_backend_details. These separate namespaces give guaranties to us that each backend implementation used their own implementation details.
  • in the file include/oneapi/dpl/pstl/parallel_backend.h create/modify some useful template aliases:
namespace oneapi
{
namespace dpl
{

template <typename __backend_tag>
using __par_backend = oneapi::dpl::__backend::__backend_impl<__backend_tag>;

template <typename __backend_tag, typename _ExecutionPolicy, typename _Tp>
using __par_backend_buffer = typename __par_backend<__backend_tag>::template __buffer<_ExecutionPolicy, _Tp>;

} // namespace dpl
} // namespace oneapi

The usage of this approach in the code (examples):

// __backend_tag{} removed from arguments here
__par_backend<__backend_tag>::__parallel_for(...);
__par_backend_buffer<__backend_tag, _ExecutionPolicy, bool> __mask_buf(__exec, __n);

If this approach looking good we are able to repack device and fpga backend by the same way too, implementing them inside two additional hetero backend implementations:

template <>
struct __backend_impl<oneapi::dpl::__internal::__device_backend_tag>
{
    // Declare here public API functions of device hetero backend
};

template <>
struct __backend_impl<oneapi::dpl::__internal::__fpga_backend_tag> : __backend_impl<oneapi::dpl::__internal::__device_backend_tag>
{
    // Declare here public API additional functions of FPGA hetero backend
};

@SergeyKopienko
Copy link
Contributor Author

@akukanov If this approach looks ok we may try to extend it for hetero backends too,

@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/multiple_backends_prototype branch 3 times, most recently from 04a015a to dedd021 Compare April 18, 2024 16:27
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/multiple_backends_prototype branch 4 times, most recently from 4963507 to 96ffc59 Compare April 25, 2024 12:21
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/multiple_backends_prototype branch from 96ffc59 to 8869f85 Compare May 3, 2024 07:35
@MikeDvorskiy
Copy link
Contributor

  • move backend public API functions into these structures;

Unfortunately, it breaks one of tag dispatching advantage - to have possibility to overload (via C++ function overloading mechanism) backend pattern implementation by a user tag.

@SergeyKopienko
Copy link
Contributor Author

SergeyKopienko commented May 7, 2024 via email

@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/multiple_backends_prototype branch from 8869f85 to 6c6bca9 Compare May 7, 2024 14:11
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/multiple_backends_prototype branch 3 times, most recently from f911969 to 547aa3a Compare May 23, 2024 07:44
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/multiple_backends_prototype branch from 547aa3a to ef66673 Compare June 10, 2024 14:51
…qual_value_by_pred required full namespace name due implemented in another namespace
…api::dpl::__internal namespace

Signed-off-by: Sergey Kopienko <[email protected]>
…ar_backend_buffer template aliases into oneapi::dpl namespace

Signed-off-by: Sergey Kopienko <[email protected]>
…l_for_body into namespace __tbb_backend_details

Signed-off-by: Sergey Kopienko <[email protected]>
Signed-off-by: Sergey Kopienko <[email protected]>
Signed-off-by: Sergey Kopienko <[email protected]>
Signed-off-by: Sergey Kopienko <[email protected]>
… two __parallel_stable_sort overloads into one and two implementation overloads

Signed-off-by: Sergey Kopienko <[email protected]>
Signed-off-by: Sergey Kopienko <[email protected]>
Signed-off-by: Sergey Kopienko <[email protected]>
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/multiple_backends_prototype branch from ef66673 to 43f3d72 Compare June 19, 2024 13:22
@SergeyKopienko SergeyKopienko deleted the dev/skopienko/multiple_backends_prototype branch October 22, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants