From 319b0887471fd1d83472e687af20720444f2ace3 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Tue, 2 Dec 2025 10:42:51 -0800 Subject: [PATCH] [NFCI][SYCL] Consolidate `[get|create]SyclObj[From]Impl into `ImplUtils` This way much less `friend` declarations are needed. --- sycl/include/sycl/accessor.hpp | 61 ++------------- sycl/include/sycl/accessor_image.hpp | 78 ++----------------- sycl/include/sycl/buffer.hpp | 5 +- sycl/include/sycl/context.hpp | 13 +--- sycl/include/sycl/detail/impl_utils.hpp | 75 ++++++++---------- sycl/include/sycl/device.hpp | 13 +--- sycl/include/sycl/event.hpp | 13 +--- .../ext/oneapi/bindless_images_memory.hpp | 5 +- .../experimental/async_alloc/memory_pool.hpp | 13 +--- .../experimental/graph/command_graph.hpp | 9 +-- .../ext/oneapi/experimental/graph/dynamic.hpp | 12 +-- .../experimental/graph/executable_graph.hpp | 6 +- .../experimental/graph/modifiable_graph.hpp | 11 +-- .../ext/oneapi/experimental/graph/node.hpp | 12 +-- .../ext/oneapi/virtual_mem/physical_mem.hpp | 10 +-- sycl/include/sycl/handler.hpp | 6 +- sycl/include/sycl/image.hpp | 33 ++------ sycl/include/sycl/kernel.hpp | 11 +-- sycl/include/sycl/kernel_bundle.hpp | 57 +++----------- sycl/include/sycl/platform.hpp | 12 +-- sycl/include/sycl/queue.hpp | 12 +-- sycl/include/sycl/sampler.hpp | 5 +- sycl/include/sycl/stream.hpp | 5 +- 23 files changed, 100 insertions(+), 377 deletions(-) diff --git a/sycl/include/sycl/accessor.hpp b/sycl/include/sycl/accessor.hpp index 3f48859aefed3..ad938b2685e07 100644 --- a/sycl/include/sycl/accessor.hpp +++ b/sycl/include/sycl/accessor.hpp @@ -516,6 +516,7 @@ using AccessorImplPtr = std::shared_ptr; class __SYCL_EXPORT AccessorBaseHost { protected: AccessorBaseHost(const AccessorImplPtr &Impl) : impl{Impl} {} + friend sycl::detail::ImplUtils; public: AccessorBaseHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange, @@ -550,16 +551,6 @@ class __SYCL_EXPORT AccessorBaseHost { void *getMemoryObject() const; - template - friend const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend class accessor; @@ -574,6 +565,8 @@ class LocalAccessorImplHost; using LocalAccessorImplPtr = std::shared_ptr; class __SYCL_EXPORT LocalAccessorBaseHost { + friend sycl::detail::ImplUtils; + protected: LocalAccessorBaseHost(const LocalAccessorImplPtr &Impl) : impl{Impl} {} @@ -589,17 +582,6 @@ class __SYCL_EXPORT LocalAccessorBaseHost { const property_list &getPropList() const; protected: - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - LocalAccessorImplPtr impl; }; } // namespace detail @@ -623,6 +605,8 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor : public detail::OwnerLessBase< accessor> { + friend sycl::detail::ImplUtils; + protected: static_assert((AccessTarget == access::target::global_buffer || AccessTarget == access::target::constant_buffer || @@ -854,17 +838,6 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor : friend class sycl::stream; friend class sycl::ext::intel::esimd::detail::AccessorPrivateProxy; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - public: // 4.7.6.9.1. Interface for buffer command accessors // value_type is defined as const DataT for read_only accessors, DataT @@ -2249,17 +2222,6 @@ class __SYCL_SPECIAL_CLASS local_accessor_base : return Result; } - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend class local_accessor; public: @@ -2474,6 +2436,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor access::placeholder::false_t>, public detail::OwnerLessBase> { + friend sycl::detail::ImplUtils; using local_acc = local_accessor_base(), @@ -2647,6 +2610,8 @@ template { + friend sycl::detail::ImplUtils; + protected: using AccessorT = accessor; @@ -2671,16 +2636,6 @@ class __SYCL_EBO host_accessor host_accessor(const detail::AccessorImplPtr &Impl) : accessor{Impl} {} - - template - friend const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); #endif // __SYCL_DEVICE_ONLY__ public: diff --git a/sycl/include/sycl/accessor_image.hpp b/sycl/include/sycl/accessor_image.hpp index db57a0943266b..be5eb3a697ae4 100644 --- a/sycl/include/sycl/accessor_image.hpp +++ b/sycl/include/sycl/accessor_image.hpp @@ -77,6 +77,7 @@ class __SYCL_EXPORT UnsampledImageAccessorBaseHost { protected: UnsampledImageAccessorBaseHost(const UnsampledImageAccessorImplPtr &Impl) : impl{Impl} {} + friend sycl::detail::ImplUtils; public: UnsampledImageAccessorBaseHost(sycl::range<3> Size, access_mode AccessMode, @@ -97,18 +98,6 @@ class __SYCL_EXPORT UnsampledImageAccessorBaseHost { const property_list &getPropList() const; protected: - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - UnsampledImageAccessorImplPtr impl; // The function references helper methods required by GDB pretty-printers @@ -151,6 +140,7 @@ class __SYCL_EXPORT SampledImageAccessorBaseHost { protected: SampledImageAccessorBaseHost(const SampledImageAccessorImplPtr &Impl) : impl{Impl} {} + friend sycl::detail::ImplUtils; public: SampledImageAccessorBaseHost(sycl::range<3> Size, void *SYCLMemObject, @@ -173,18 +163,6 @@ class __SYCL_EXPORT SampledImageAccessorBaseHost { const property_list &getPropList() const; protected: - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - SampledImageAccessorImplPtr impl; // The function references helper methods required by GDB pretty-printers @@ -789,6 +767,7 @@ class __SYCL_EBO unsampled_image_accessor : #endif // __SYCL_DEVICE_ONLY__ public detail::OwnerLessBase< unsampled_image_accessor> { + friend sycl::detail::ImplUtils; static_assert(std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v, @@ -940,18 +919,6 @@ class __SYCL_EBO unsampled_image_accessor : { (void)Impl; } - - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); }; template > { + friend sycl::detail::ImplUtils; static_assert(std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v, @@ -1082,18 +1050,6 @@ class __SYCL_EBO host_unsampled_image_accessor host_unsampled_image_accessor( const detail::UnsampledImageAccessorImplPtr &Impl) : base_class{Impl} {} - - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); }; template > { + friend sycl::detail::ImplUtils; static_assert(std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v, @@ -1231,18 +1188,6 @@ class __SYCL_EBO sampled_image_accessor : { (void)Impl; } - - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); }; template @@ -1250,6 +1195,7 @@ class __SYCL_EBO host_sampled_image_accessor : private detail::SampledImageAccessorBaseHost, public detail::OwnerLessBase< host_sampled_image_accessor> { + friend sycl::detail::ImplUtils; static_assert(std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v, @@ -1340,18 +1286,6 @@ class __SYCL_EBO host_sampled_image_accessor private: host_sampled_image_accessor(const detail::SampledImageAccessorImplPtr &Impl) : base_class{Impl} {} - - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); }; } // namespace _V1 diff --git a/sycl/include/sycl/buffer.hpp b/sycl/include/sycl/buffer.hpp index 4c0d9575c7807..da1814996c807 100644 --- a/sycl/include/sycl/buffer.hpp +++ b/sycl/include/sycl/buffer.hpp @@ -93,6 +93,8 @@ struct BufferInterop; // The non-template base for the sycl::buffer class class __SYCL_EXPORT buffer_plain { + friend sycl::detail::ImplUtils; + protected: buffer_plain(size_t SizeInBytes, size_t, const property_list &Props, std::unique_ptr Allocator); @@ -730,9 +732,6 @@ class buffer : public detail::buffer_plain, } private: - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); template friend class buffer; template backend_return_t; /// /// \ingroup sycl_api class __SYCL_EXPORT context : public detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// Constructs a SYCL context instance using an instance of default_selector. /// @@ -255,17 +257,6 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase { template friend auto get_native(const SyclT &Obj) -> backend_return_t; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - const property_list &getPropList() const; }; diff --git a/sycl/include/sycl/detail/impl_utils.hpp b/sycl/include/sycl/detail/impl_utils.hpp index 00f61558a88d4..f5307b03d5d52 100644 --- a/sycl/include/sycl/detail/impl_utils.hpp +++ b/sycl/include/sycl/detail/impl_utils.hpp @@ -8,55 +8,48 @@ #pragma once -#include // for assert -#include // for hash -#include // for add_pointer_t -#include // for forward +#include +#include +#include +#include +#include namespace sycl { inline namespace _V1 { +class handler; namespace detail { +// Note! This class relies on the fact that all SYCL interface +// classes contain "impl" field that points to implementation object. "impl" +// field should be accessible from this class. +struct ImplUtils { + // Helper function for extracting implementation from SYCL's interface + // objects. + template + static const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObj) { + assert(SyclObj.impl && "every constructor should create an impl"); + return SyclObj.impl; + } -// Helper function for extracting implementation from SYCL's interface objects. -// Note! This function relies on the fact that all SYCL interface classes -// contain "impl" field that points to implementation object. "impl" field -// should be accessible from this function. -// -// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it -// may not recognize the usage of this function in friend member declarations -// if the template parameter name there is not equal to the name used here, -// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration -// would trigger that error in MSVC: -// template -// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject); -template -const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObject) { - assert(SyclObject.impl && "every constructor should create an impl"); - return SyclObject.impl; -} - -// Helper function for creation SYCL interface objects from implementations. -// Note! These functions rely on the fact that all SYCL interface classes -// contain "impl" field that points to implementation object. "impl" field -// should be accessible from these functions. -template -T createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj) { - return T(std::forward(ImplObj)); -} + // Helper function for creation SYCL interface objects from implementations. + template + static SyclObject createSyclObjFromImpl(From &&from) { + if constexpr (std::is_same_v>>) + return SyclObject{from.shared_from_this()}; + else + return SyclObject{std::forward(from)}; + } +}; -template -T createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj) { - return T(ImplObj); +template +auto getSyclObjImpl(const Obj &SyclObj) + -> decltype(ImplUtils::getSyclObjImpl(SyclObj)) { + return ImplUtils::getSyclObjImpl(SyclObj); } -template -T createSyclObjFromImpl( - std::add_lvalue_reference_t()))>::element_type> - ImplRef) { - return createSyclObjFromImpl(ImplRef.shared_from_this()); +template +SyclObject createSyclObjFromImpl(From &&from) { + return ImplUtils::createSyclObjFromImpl(std::forward(from)); } template struct sycl_obj_hash { diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 381f537df3c4d..a2836228704f5 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -66,6 +66,8 @@ enum class peer_access { /// \ingroup sycl_api class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device : public detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// Constructs a SYCL device instance using the default device. device(); @@ -370,17 +372,6 @@ class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device ur_native_handle_t getNative() const; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend auto get_native(const SyclObjectT &Obj) -> backend_return_t; diff --git a/sycl/include/sycl/event.hpp b/sycl/include/sycl/event.hpp index 98e722e185bcc..0791ee0ecc650 100644 --- a/sycl/include/sycl/event.hpp +++ b/sycl/include/sycl/event.hpp @@ -42,6 +42,8 @@ class event_impl; /// /// \ingroup sycl_api class __SYCL_EXPORT event : public detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// Constructs a ready SYCL event. /// @@ -144,17 +146,6 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase { std::shared_ptr impl; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend auto get_native(const SyclObjectT &Obj) -> backend_return_t; diff --git a/sycl/include/sycl/ext/oneapi/bindless_images_memory.hpp b/sycl/include/sycl/ext/oneapi/bindless_images_memory.hpp index 88c5bdbb59c74..88e480684e4c1 100644 --- a/sycl/include/sycl/ext/oneapi/bindless_images_memory.hpp +++ b/sycl/include/sycl/ext/oneapi/bindless_images_memory.hpp @@ -58,6 +58,7 @@ class image_mem_impl { /// A class that represents image memory class __SYCL_EXPORT image_mem { + friend sycl::detail::ImplUtils; using raw_handle_type = image_mem_handle; public: @@ -93,10 +94,6 @@ class __SYCL_EXPORT image_mem { protected: std::shared_ptr impl; - - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); }; /// Direction to copy data from bindless image handle diff --git a/sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool.hpp b/sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool.hpp index d21c32a6945b4..3fc86d245229f 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool.hpp @@ -24,6 +24,8 @@ class memory_pool_impl; /// Memory pool class __SYCL_EXPORT memory_pool { + friend sycl::detail::ImplUtils; + public: template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template pool_properties stripProps(Properties props) { pool_properties poolProps{}; if constexpr (decltype(props)::template has_property()) { diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph/command_graph.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph/command_graph.hpp index b21336d608a98..29eb3e4bc9b72 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph/command_graph.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph/command_graph.hpp @@ -85,6 +85,8 @@ UnsupportedFeatureToString(UnsupportedGraphFeatures Feature) { /// Graph in the modifiable state. template class command_graph : public detail::modifiable_command_graph { + friend sycl::detail::ImplUtils; + public: /// Constructor. /// @param SyclContext Context to use for graph. @@ -113,13 +115,6 @@ class command_graph : public detail::modifiable_command_graph { /// @param Impl Detail implementation class to construct object with. command_graph(const std::shared_ptr &Impl) : modifiable_command_graph(Impl) {} - - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); }; template <> diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph/dynamic.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph/dynamic.hpp index c02ca02b0d0d9..ff78cc0c5ac53 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph/dynamic.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph/dynamic.hpp @@ -45,6 +45,8 @@ class dynamic_command_group_impl; } // namespace detail class __SYCL_EXPORT dynamic_command_group { + friend sycl::detail::ImplUtils; + public: dynamic_command_group( const command_graph &Graph, @@ -64,15 +66,13 @@ class __SYCL_EXPORT dynamic_command_group { } private: - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); - std::shared_ptr impl; }; namespace detail { class __SYCL_EXPORT dynamic_parameter_base { + friend sycl::detail::ImplUtils; + public: #ifdef __INTEL_PREVIEW_BREAKING_CHANGES dynamic_parameter_base(size_t ParamSize, const void *Data); @@ -114,10 +114,6 @@ class __SYCL_EXPORT dynamic_parameter_base { void updateAccessor(const sycl::detail::AccessorBaseHost *Acc); std::shared_ptr impl; - - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); }; class __SYCL_EXPORT dynamic_work_group_memory_base diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph/executable_graph.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph/executable_graph.hpp index e5e90b4a90046..37d589b2be6cb 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph/executable_graph.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph/executable_graph.hpp @@ -33,6 +33,8 @@ class exec_graph_impl; // Templateless executable command-graph base class. class __SYCL_EXPORT executable_command_graph : public sycl::detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// An executable command-graph is not user constructable. executable_command_graph() = delete; @@ -74,10 +76,6 @@ class __SYCL_EXPORT executable_command_graph const sycl::context &Ctx, const property_list &PropList = {}); - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); - /// Creates a backend representation of the graph in \p impl member variable. void finalizeImpl(); diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph/modifiable_graph.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph/modifiable_graph.hpp index 99808f76575f9..8ddd5f200e88b 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph/modifiable_graph.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph/modifiable_graph.hpp @@ -41,6 +41,8 @@ class graph_impl; // Templateless modifiable command-graph base class. class __SYCL_EXPORT modifiable_command_graph : public sycl::detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// Constructor. /// @param SyclContext Context to use for graph. @@ -202,15 +204,6 @@ class __SYCL_EXPORT modifiable_command_graph void print_graph(sycl::detail::string_view path, bool verbose = false) const; - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); std::shared_ptr impl; static void checkNodePropertiesAndThrow(const property_list &Properties); diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph/node.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph/node.hpp index 91c756e32049f..0978fa4b8eb23 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph/node.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph/node.hpp @@ -47,6 +47,8 @@ enum class node_type { /// Class representing a node in the graph, returned by command_graph::add(). class __SYCL_EXPORT node { + friend sycl::detail::ImplUtils; + public: node() = delete; @@ -81,16 +83,6 @@ class __SYCL_EXPORT node { private: node(const std::shared_ptr &Impl) : impl(Impl) {} - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - std::shared_ptr impl; }; diff --git a/sycl/include/sycl/ext/oneapi/virtual_mem/physical_mem.hpp b/sycl/include/sycl/ext/oneapi/virtual_mem/physical_mem.hpp index c7338474e50ac..aecef93473911 100644 --- a/sycl/include/sycl/ext/oneapi/virtual_mem/physical_mem.hpp +++ b/sycl/include/sycl/ext/oneapi/virtual_mem/physical_mem.hpp @@ -28,6 +28,8 @@ enum class address_access_mode : char { none = 0, read = 1, read_write = 2 }; class __SYCL_EXPORT physical_mem : public sycl::detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: physical_mem(const device &SyclDevice, const context &SyclContext, size_t NumBytes); @@ -57,14 +59,6 @@ class __SYCL_EXPORT physical_mem private: std::shared_ptr impl; - - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T sycl::detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); }; } // namespace ext::oneapi::experimental diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index f73d362123272..2217e3cade53b 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -419,6 +419,8 @@ template bool range_size_fits_in_size_t(const range &r) { /// /// \ingroup sycl_api class __SYCL_EXPORT handler { + friend sycl::detail::ImplUtils; + private: /// Constructs SYCL handler from the pre-constructed stack-allocated /// `handler_impl` (not enforced, but meaningless to do a heap allocation @@ -2865,10 +2867,6 @@ class __SYCL_EXPORT handler { class _propertiesT, class> friend class ext::intel::experimental::pipe; - template - friend const decltype(Obj::impl) & - sycl::detail::getSyclObjImpl(const Obj &SyclObject); - /// Read from a host pipe given a host address and /// \param Name name of the host pipe to be passed into lower level runtime /// \param Ptr host pointer of host pipe as identified by address of its const diff --git a/sycl/include/sycl/image.hpp b/sycl/include/sycl/image.hpp index cff83ee1efd0b..a2dbff58c4af7 100644 --- a/sycl/include/sycl/image.hpp +++ b/sycl/include/sycl/image.hpp @@ -170,6 +170,7 @@ inline image_channel_order FormatChannelOrder(image_format Format) { class __SYCL_EXPORT image_plain { protected: image_plain(const std::shared_ptr &Impl) : impl{Impl} {} + friend sycl::detail::ImplUtils; image_plain(image_channel_order Order, image_channel_type Type, const range<3> &Range, @@ -347,6 +348,7 @@ class image_common : public image_plain { template class unsampled_image_common : public image_common { private: + friend sycl::detail::ImplUtils; using common_base = typename detail::image_common; protected: @@ -427,6 +429,7 @@ class unsampled_image_common : public image_common { template class image : public detail::unsampled_image_common { private: + friend sycl::detail::ImplUtils; using common_base = typename detail::unsampled_image_common; @@ -694,10 +697,6 @@ class image : public detail::unsampled_image_common { make_image(const backend_input_t> &BackendObject, const context &TargetContext, event AvailableEvent); - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - template @@ -713,6 +712,7 @@ class unsampled_image : public detail::unsampled_image_common, public detail::OwnerLessBase> { private: + friend sycl::detail::ImplUtils; using common_base = typename detail::unsampled_image_common; @@ -981,18 +981,6 @@ class unsampled_image } private: - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend class host_unsampled_image_accessor; @@ -1006,6 +994,7 @@ class sampled_image : public detail::image_common, public detail::OwnerLessBase> { private: + friend sycl::detail::ImplUtils; using common_base = typename detail::image_common; sampled_image(const std::shared_ptr &Impl) @@ -1122,18 +1111,6 @@ class sampled_image } private: - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend class host_sampled_image_accessor; template diff --git a/sycl/include/sycl/kernel.hpp b/sycl/include/sycl/kernel.hpp index bb44daf12b9c3..42e5c00dfec00 100644 --- a/sycl/include/sycl/kernel.hpp +++ b/sycl/include/sycl/kernel.hpp @@ -67,6 +67,8 @@ template struct get_kernel_name_t { /// /// \ingroup sycl_api class __SYCL_EXPORT kernel : public detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// Constructs a SYCL kernel instance from an OpenCL cl_kernel /// @@ -250,15 +252,6 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase { std::shared_ptr impl; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); template friend auto get_native(const SyclObjectT &Obj) -> backend_return_t; diff --git a/sycl/include/sycl/kernel_bundle.hpp b/sycl/include/sycl/kernel_bundle.hpp index 08d0428216300..b4af63c854b08 100644 --- a/sycl/include/sycl/kernel_bundle.hpp +++ b/sycl/include/sycl/kernel_bundle.hpp @@ -67,6 +67,8 @@ std::enable_if_t, kernel_id> get_kernel_id(); /// /// \ingroup sycl_api class __SYCL_EXPORT kernel_id : public detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: kernel_id() = delete; @@ -84,18 +86,6 @@ class __SYCL_EXPORT kernel_id : public detail::OwnerLessBase { : impl(std::move(Impl)) {} std::shared_ptr impl; - - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); }; namespace detail { @@ -104,6 +94,8 @@ class device_image_impl; // The class is used as a base for device_image for "untemplating" public // methods. class __SYCL_EXPORT device_image_plain { + friend sycl::detail::ImplUtils; + public: device_image_plain(const std::shared_ptr &Impl) : impl(Impl) {} @@ -133,18 +125,6 @@ class __SYCL_EXPORT device_image_plain { std::shared_ptr impl; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - backend ext_oneapi_get_backend_impl() const noexcept; #if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) @@ -158,6 +138,8 @@ class __SYCL_EXPORT device_image_plain { template class device_image : public detail::device_image_plain, public detail::OwnerLessBase> { + friend sycl::detail::ImplUtils; + public: device_image() = delete; @@ -201,18 +183,6 @@ class device_image : public detail::device_image_plain, device_image(std::shared_ptr Impl) : device_image_plain(std::move(Impl)) {} - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - // To allow calling device_image_plain::getNative() template friend class kernel_bundle; }; @@ -223,6 +193,8 @@ using KernelBundleImplPtr = std::shared_ptr; // The class is used as a base for kernel_bundle to "untemplate" it's methods class __SYCL_EXPORT kernel_bundle_plain { + friend sycl::detail::ImplUtils; + public: kernel_bundle_plain(const detail::KernelBundleImplPtr &Impl) : impl(std::move(Impl)) {} @@ -324,6 +296,8 @@ class __SYCL_EXPORT kernel_bundle_plain { template class kernel_bundle : public detail::kernel_bundle_plain, public detail::OwnerLessBase> { + friend sycl::detail::ImplUtils; + public: using device_image_iterator = const device_image *; @@ -583,17 +557,6 @@ class kernel_bundle : public detail::kernel_bundle_plain, kernel_bundle(detail::KernelBundleImplPtr Impl) : kernel_bundle_plain(std::move(Impl)) {} - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend auto get_native(const kernel_bundle &Obj) -> backend_return_t>; diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index ccb1e795610cf..6197daa74427a 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -63,6 +63,8 @@ class filter_selector; /// /// \ingroup sycl_api class __SYCL_EXPORT platform : public detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// Constructs a SYCL platform using the default device. platform(); @@ -210,16 +212,6 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase { platform(const device &Device); - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - template friend auto get_native(const SyclObjectT &Obj) -> backend_return_t; diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index 459bb522a8553..1e02a5fd930bc 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -295,6 +295,8 @@ event submit_with_event_impl(const queue &Q, PropertiesT Props, /// /// \ingroup sycl_api class __SYCL_EXPORT queue : public detail::OwnerLessBase { + friend sycl::detail::ImplUtils; + public: /// Constructs a SYCL queue instance using the device returned by an instance /// of default_selector. @@ -3751,16 +3753,6 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase { std::shared_ptr impl; queue(std::shared_ptr impl) : impl(impl) {} - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); - template - friend T detail::createSyclObjFromImpl( - std::add_rvalue_reference_t ImplObj); - template - friend T detail::createSyclObjFromImpl( - std::add_lvalue_reference_t ImplObj); - template friend auto get_native(const SyclObjectT &Obj) -> backend_return_t; diff --git a/sycl/include/sycl/sampler.hpp b/sycl/include/sycl/sampler.hpp index 6dd69ff4ac734..feb3699976439 100644 --- a/sycl/include/sycl/sampler.hpp +++ b/sycl/include/sycl/sampler.hpp @@ -63,6 +63,8 @@ class sampler_impl; /// /// \ingroup sycl_api class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(sampler) sampler { + friend sycl::detail::ImplUtils; + public: sampler(coordinate_normalization_mode normalizationMode, addressing_mode addressingMode, filtering_mode filteringMode, @@ -119,9 +121,6 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(sampler) sampler { private: #else std::shared_ptr impl; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); #endif template { + friend sycl::detail::ImplUtils; + private: #ifndef __SYCL_DEVICE_ONLY__ // Constructor for recreating a stream. @@ -909,9 +911,6 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(stream) stream char padding[sizeof(std::shared_ptr)]; #else std::shared_ptr impl; - template - friend const decltype(Obj::impl) & - detail::getSyclObjImpl(const Obj &SyclObject); #endif // NOTE: Some members are required for reconstructing the stream, but are not