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

Lazy sycl::queue creation in oneDPL hetero policies #1422

Closed

Conversation

SergeyKopienko
Copy link
Contributor

@SergeyKopienko SergeyKopienko commented Feb 27, 2024

Attention: ABI breaking change.

Yet another approach to lazy sycl::queue creation in oneDPL hetero policies:

The main implementation detail is std::once_flag and ::std::call_once usage packed into separate container

template <class TSYCLQueueFactory>
class sycl_queue_container
{
  public:
    template <typename... Args>
    sycl::queue
    get_queue(Args&&... args)
    {
        ::std::call_once(__is_created, [&]() {
            TSYCLQueueFactory factory;
            __queue.emplace(factory(::std::forward<Args>(args)...));
        });

        assert(__queue.has_value());
        return __queue.value();
    }

  private:
    ::std::once_flag __is_created;
    ::std::optional<sycl::queue> __queue;
};

This container shares between hetero policies instances:

template <typename TFactory>
using sycl_queue_container_ptr = ::std::shared_ptr<sycl_queue_container<TFactory>>;


// ...


template <typename KernelName = DefaultKernelName, class TSyclQueueFactory = TDefaultSYCLQueueFactory>
class device_policy
{
  public:
    // ...

  private:
    mutable sycl_queue_container_ptr<TSyclQueueFactory> q_container;       // <<<<<<-- shared sycl::queue container
};

From my point of view this approach is correct because it's simple repeat something like sycl::queue implementation (pimpl-implementation) and we don't introduce any new synchronization errors here.

@SergeyKopienko SergeyKopienko changed the title Lazy sycl::queue creation in oneDPL hetero policies Lazy sycl::queue creation in oneDPL hetero policies Feb 27, 2024
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from 8613cc4 to 2ebd0ab Compare February 27, 2024 11:04
@SergeyKopienko SergeyKopienko marked this pull request as ready for review February 27, 2024 11:48
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch 5 times, most recently from dfb26ce to b46bc59 Compare March 5, 2024 13:32
}

auto
get_sycl_queue_container() const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this function as part of public API?

@@ -78,32 +126,50 @@ class device_policy
}

private:
sycl::queue q;
mutable sycl_queue_container_ptr<TSyclQueueFactory> q_container;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea:
Consider changing sycl_queue_container_ptr::get_queue() to be const and sycl_queue_container_ptr::__queue to be mutable.
For me, it can be unclear why q_container is mutable from the device_policy implementation perspective.

//We can create device_policy object:
// 1. from sycl::queue
// 2. from sycl::device_selector (implicitly through sycl::queue)
// 3. from sycl::device
// 4. from other device_policy encapsulating the same queue type
template <typename KernelName = DefaultKernelName>
template <typename KernelName = DefaultKernelName, class TSyclQueueFactory = sycl_queue_factory_device>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see in oneDPL specification - device_policy class is a public API and hence its template parameters are also documented. So do we think that it is necessary to have TSyclQueueFactory template parameter as part of public API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this valiant - probably yes.

@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from b46bc59 to 3f19cba Compare March 7, 2024 11:33
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch 2 times, most recently from 48831a0 to f8a863c Compare March 21, 2024 14:51
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from f8a863c to 8726406 Compare April 5, 2024 15:20
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch 3 times, most recently from a69806f to 733892d Compare April 12, 2024 15:40
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch 3 times, most recently from e6b5b9d to c724558 Compare April 23, 2024 12:17
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from c724558 to 2cdad2e Compare April 25, 2024 08:42
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch 3 times, most recently from d102f95 to 03b8f22 Compare May 7, 2024 14:11
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from 03b8f22 to 5ed3583 Compare May 16, 2024 10:08
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch 3 times, most recently from 8ad5361 to dc5bcf7 Compare May 23, 2024 07:36
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from dc5bcf7 to 9de5fc0 Compare June 10, 2024 14:43
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from 9de5fc0 to 68a90c1 Compare June 19, 2024 13:21
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from 68a90c1 to ce03c8d Compare June 28, 2024 14:17
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch from ce03c8d to 12d1a93 Compare July 5, 2024 10:54
@akukanov
Copy link
Contributor

After merging #1652, this patch is outdated.

@SergeyKopienko SergeyKopienko deleted the dev/skopienko/hetero_policy_lazy_sycl_queue_creation branch July 10, 2024 13:06
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