Skip to content

Conversation

danhoeflinger
Copy link
Contributor

This PR allows users to provide a resource_adapter alongside a resource where the resulting base_resource = resource_adapter(resource) defines the default backend implementation.

This enables a use case where a user may want a resource to contain more or even a different variant as compared to the core base resource which defines a backend implementation.

The motivating use case is using sycl::queue* as the resource type alongside an adapter which dereferences. This allows less overhead copying pointers rather than full queues. It also allows the pointer to be used as a unique identifier to do things like look up a memory space in a global map.

Alternatively, you could envision a resource being provided which is a std::pair<sycl::queue, usm_pointer>, and an adapter functor std::get<0> to solve a similar use case (without the potential benefit of reducing overhead).

@danhoeflinger danhoeflinger marked this pull request as draft August 1, 2025 16:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces support for resource adapters in the dynamic selection framework, allowing users to provide a resource_adapter alongside a resource where the resulting base_resource = resource_adapter(resource) defines the default backend implementation. This enables use cases like using sycl::queue* as the resource type with a dereference adapter to reduce copying overhead and enable pointer-based lookup patterns.

Key Changes

  • Adds ResourceAdapter template parameter to policy classes and backend implementations
  • Updates test utilities to support passing adapter arguments to policy constructors
  • Extends test coverage to include pointer-based resource scenarios with dereference adapters

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/support/test_dynamic_selection_utils.h Updated test utility functions to accept variadic arguments for adapter support
test/support/test_dynamic_load_utils.h Enhanced dynamic load test utilities with adapter support and templated initialization
test/parallel_api/dynamic_selection/sycl/test_round_robin_policy_sycl.pass.cpp Added tests for both direct sycl::queue and sycl::queue* with dereference adapter
test/parallel_api/dynamic_selection/sycl/test_fixed_resource_policy_sycl.pass.cpp Extended tests to cover pointer-based resources with adapters
test/parallel_api/dynamic_selection/sycl/test_dynamic_load_policy_sycl.pass.cpp Added comprehensive testing for dynamic load policy with adapter support
include/oneapi/dpl/internal/dynamic_selection_impl/sycl_backend.h Refactored to support ResourceAdapter template parameter and adapter-based resource handling
include/oneapi/dpl/internal/dynamic_selection_impl/round_robin_policy.h Added ResourceAdapter template parameter with default std::identity
include/oneapi/dpl/internal/dynamic_selection_impl/policy_base.h Updated initialization to support variadic arguments for adapter passing
include/oneapi/dpl/internal/dynamic_selection_impl/fixed_resource_policy.h Enhanced with ResourceAdapter support and updated constructor signatures
include/oneapi/dpl/internal/dynamic_selection_impl/dynamic_load_policy.h Added ResourceAdapter template parameter and updated policy instantiation
include/oneapi/dpl/internal/dynamic_selection_impl/default_backend.h Restructured with default_backend_impl base class and ResourceAdapter support
Comments suppressed due to low confidence (1)

Signed-off-by: Dan Hoeflinger <[email protected]>
ResourceAdapter __adapter;
};

template <typename ResourceType, typename ResourceAdapter = std::identity>
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like std::identity is c++20, are we able to implement its functionality for use with c++17?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we have an alternative in oneDPL we can use.

@danhoeflinger danhoeflinger marked this pull request as ready for review August 6, 2025 13:30
@danhoeflinger danhoeflinger changed the title [Draft] Dynamic Selection Adding ResourceAdapter to support queue* Dynamic Selection Adding ResourceAdapter to support queue* Aug 13, 2025
@danhoeflinger danhoeflinger merged commit 2a1f8c4 into dev/egfefey/custom_backend_tests Sep 10, 2025
@danhoeflinger danhoeflinger deleted the dev/dhoeflin/resource_adapter_function branch September 10, 2025 20:59
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.

2 participants