Skip to content

Commit

Permalink
[ABI Break][SYCL] Remove has/get_property template specializations fr…
Browse files Browse the repository at this point in the history
…om ABI (#14494)

We already have ctors following SYCL 2020 requirement: "Each of the
following classes: accessor, buffer, host_accessor,
host_sampled_image_accessor, host_unsampled_image_accessor, context,
local_accessor, queue, sampled_image, sampled_image_accessor, stream,
unsampled_image, unsampled_image_accessor and usm_allocator provide an
optional parameter in each of their constructors to provide a
property_list which contains zero or more properties.".
 
However, it is only accessor that implemented has/get_property in an
inline header only function with the entire propList passing ABI
boundary. Other classes had a dedicated entry point for each property
that required error-prone explicit instantiation on the library side.
 
This PR aligns all those classes to follow accessor's implementation.

---------

Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
  • Loading branch information
KseniyaTikhomirova committed Jul 12, 2024
1 parent ece363d commit a9b2ead
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 523 deletions.
10 changes: 8 additions & 2 deletions sycl/include/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,13 @@ class __SYCL_EXPORT buffer_plain {
const void *Type, uint32_t Dim,
uint32_t ElemType, size_t Range[3]);

template <typename propertyT> bool has_property() const noexcept;
template <typename propertyT> bool has_property() const noexcept {
return getPropList().template has_property<propertyT>();
}

template <typename propertyT> propertyT get_property() const;
template <typename propertyT> propertyT get_property() const {
return getPropList().template get_property<propertyT>();
}

std::vector<pi_native_handle> getNativeVector(backend BackendName) const;

Expand All @@ -147,6 +151,8 @@ class __SYCL_EXPORT buffer_plain {
void handleRelease() const;

std::shared_ptr<detail::buffer_impl> impl;

const property_list &getPropList() const;
};

} // namespace detail
Expand Down
10 changes: 8 additions & 2 deletions sycl/include/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,19 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {
/// Checks if this context has a property of type propertyT.
///
/// \return true if this context has a property of type propertyT.
template <typename propertyT> bool has_property() const noexcept;
template <typename propertyT> bool has_property() const noexcept {
return getPropList().template has_property<propertyT>();
}

/// Gets the specified property of this context.
///
/// Throws an exception with errc::invalid error code if this context does not
/// have a property of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const;
template <typename propertyT> propertyT get_property() const {
return getPropList().template get_property<propertyT>();
}

/// Gets OpenCL interoperability context.
///
Expand Down Expand Up @@ -250,6 +254,8 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {

template <class T>
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);

const property_list &getPropList() const;
};

// context.hpp depends on exception.hpp but we can't define these ctors in
Expand Down
16 changes: 0 additions & 16 deletions sycl/include/sycl/detail/properties_traits.def

This file was deleted.

10 changes: 8 additions & 2 deletions sycl/include/sycl/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,13 @@ class __SYCL_EXPORT image_plain {
image_channel_type Type, bool OwnNativeHandle,
range<3> Range3WithOnes);

template <typename propertyT> bool has_property() const noexcept;
template <typename propertyT> bool has_property() const noexcept {
return getPropList().template has_property<propertyT>();
}

template <typename propertyT> propertyT get_property() const;
template <typename propertyT> propertyT get_property() const {
return getPropList().template get_property<propertyT>();
}

range<3> get_range() const;

Expand Down Expand Up @@ -301,6 +305,8 @@ class __SYCL_EXPORT image_plain {
void unsampledImageDestructorNotification(void *UserObj);

std::shared_ptr<detail::image_impl> impl;

const property_list &getPropList() const;
};

// Common base class for image implementations
Expand Down
11 changes: 8 additions & 3 deletions sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,16 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {

/// \return true if the queue was constructed with property specified by
/// PropertyT.
template <typename PropertyT> bool has_property() const noexcept;
template <typename PropertyT> bool has_property() const noexcept {
return getPropList().template has_property<PropertyT>();
}

/// \return a copy of the property of type PropertyT that the queue was
/// constructed with. If the queue was not constructed with the PropertyT
/// property, an SYCL exception with errc::invalid error code.
template <typename PropertyT> PropertyT get_property() const;
/// property, an SYCL exception with errc::invalid error code is thrown.
template <typename PropertyT> PropertyT get_property() const {
return getPropList().template get_property<PropertyT>();
}

/// Fills the specified memory with the specified pattern.
///
Expand Down Expand Up @@ -2884,6 +2888,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
bool IsDeviceImageScope, size_t NumBytes,
size_t Offset,
const std::vector<event> &DepEvents);
const property_list &getPropList() const;
};

} // namespace _V1
Expand Down
10 changes: 8 additions & 2 deletions sycl/include/sycl/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,19 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(sampler) sampler {
/// Checks if this sampler has a property of type propertyT.
///
/// \return true if this sampler has a property of type propertyT.
template <typename propertyT> bool has_property() const noexcept;
template <typename propertyT> bool has_property() const noexcept {
return getPropList().template has_property<propertyT>();
}

/// Gets the specified property of this sampler.
///
/// Throws an exception with errc::invalid if this sampler does not have a
/// property of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const;
template <typename propertyT> propertyT get_property() const {
return getPropList().template get_property<propertyT>();
}

addressing_mode get_addressing_mode() const;

Expand All @@ -127,6 +131,8 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(sampler) sampler {
sycl::access::target AccessTarget,
access::placeholder IsPlaceholder>
friend class detail::image_accessor;

const property_list &getPropList() const;
};

// SYCL 2020 image_sampler struct
Expand Down
10 changes: 8 additions & 2 deletions sycl/include/sycl/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,13 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(stream) stream

bool operator!=(const stream &LHS) const;

template <typename propertyT> bool has_property() const noexcept;
template <typename propertyT> bool has_property() const noexcept {
return getPropList().template has_property<propertyT>();
}

template <typename propertyT> propertyT get_property() const;
template <typename propertyT> propertyT get_property() const {
return getPropList().template get_property<propertyT>();
}

private:
#ifdef __SYCL_DEVICE_ONLY__
Expand Down Expand Up @@ -1108,6 +1112,8 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(stream) stream
template <int Dimensions>
friend const stream &operator<<(const stream &Out,
const h_item<Dimensions> &RHS);

const property_list &getPropList() const;
};

#if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
Expand Down
22 changes: 4 additions & 18 deletions sycl/source/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,6 @@ void buffer_plain::set_write_back(bool NeedWriteBack) {
impl->set_write_back(NeedWriteBack);
}

#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
template <> \
__SYCL_EXPORT bool buffer_plain::has_property<param_type>() const noexcept { \
return impl->has_property<param_type>(); \
}
#include <sycl/detail/properties_traits.def>

#undef __SYCL_PARAM_TRAITS_SPEC

#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
template <> \
__SYCL_EXPORT param_type buffer_plain::get_property<param_type>() const { \
return impl->get_property<param_type>(); \
}
#include <sycl/detail/properties_traits.def>

#undef __SYCL_PARAM_TRAITS_SPEC

std::vector<pi_native_handle>
buffer_plain::getNativeVector(backend BackendName) const {
return impl->getNativeVector(BackendName);
Expand Down Expand Up @@ -128,6 +110,10 @@ void buffer_plain::handleRelease() const {
impl->detachMemoryObject(impl);
}

const property_list &buffer_plain::getPropList() const {
return impl->getPropList();
}

} // namespace detail
} // namespace _V1
} // namespace sycl
22 changes: 4 additions & 18 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,6 @@ context::get_backend_info() const {

#undef __SYCL_PARAM_TRAITS_SPEC

#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
template <> \
__SYCL_EXPORT bool context::has_property<param_type>() const noexcept { \
return impl->has_property<param_type>(); \
}
#include <sycl/detail/properties_traits.def>

#undef __SYCL_PARAM_TRAITS_SPEC

#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
template <> \
__SYCL_EXPORT param_type context::get_property<param_type>() const { \
return impl->get_property<param_type>(); \
}
#include <sycl/detail/properties_traits.def>

#undef __SYCL_PARAM_TRAITS_SPEC

cl_context context::get() const { return impl->get(); }

backend context::get_backend() const noexcept { return impl->getBackend(); }
Expand All @@ -138,5 +120,9 @@ context::context(std::shared_ptr<detail::context_impl> Impl) : impl(Impl) {}

pi_native_handle context::getNative() const { return impl->getNative(); }

const property_list &context::getPropList() const {
return impl->getPropList();
}

} // namespace _V1
} // namespace sycl
19 changes: 2 additions & 17 deletions sycl/source/detail/context_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,6 @@ class context_impl {

~context_impl();

/// Checks if this context_impl has a property of type propertyT.
///
/// \return true if this context_impl has a property of type propertyT.
template <typename propertyT> bool has_property() const noexcept {
return MPropList.has_property<propertyT>();
}

/// Gets the specified property of this context_impl.
///
/// Throws an exception with errc::invalid error code if this context_impl
/// does not have a property of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const {
return MPropList.get_property<propertyT>();
}

/// Gets OpenCL interoperability context handle.
///
/// \return an instance of OpenCL cl_context.
Expand Down Expand Up @@ -260,6 +243,8 @@ class context_impl {

enum PropertySupport { NotSupported = 0, Supported = 1, NotChecked = 2 };

const property_list &getPropList() const { return MPropList; }

private:
bool MOwnedByRuntime;
async_handler MAsyncHandler;
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ class queue_impl {
const std::shared_ptr<ext::oneapi::experimental::detail::graph_impl>
&Graph);

const property_list &getPropList() const { return MPropList; }

protected:
event discard_or_return(const event &Event);
// Hook to the scheduler to clean up any fusion command held on destruction.
Expand Down
19 changes: 2 additions & 17 deletions sycl/source/detail/sampler_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,10 @@ class sampler_impl {

sycl::detail::pi::PiSampler getOrCreateSampler(const context &Context);

/// Checks if this sampler_impl has a property of type propertyT.
///
/// \return true if this sampler_impl has a property of type propertyT.
template <typename propertyT> bool has_property() const noexcept {
return MPropList.has_property<propertyT>();
}

/// Gets the specified property of this sampler_impl.
///
/// Throws an exception with errc::invalid error code if this sampler_impl
/// does not have a property of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const {
return MPropList.get_property<propertyT>();
}

~sampler_impl();

const property_list &getPropList() const { return MPropList; }

private:
/// Protects all the fields that can be changed by class' methods.
std::mutex MMutex;
Expand Down
10 changes: 2 additions & 8 deletions sycl/source/detail/stream_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ class stream_impl {

size_t get_work_item_buffer_size() const;

template <typename propertyT> bool has_property() const noexcept {
return PropList_.has_property<propertyT>();
}

template <typename propertyT> propertyT get_property() const {
return PropList_.get_property<propertyT>();
}

void generateFlushCommand(handler &cgh);

const property_list &getPropList() const { return PropList_; }

private:
// Size of the stream buffer
size_t BufferSize_;
Expand Down
4 changes: 3 additions & 1 deletion sycl/source/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ class SYCLMemObjT : public SYCLMemObjI {

/// Returns true if any graphs are currently using this memory object.
bool isUsedInGraph() const { return MGraphUseCount > 0; }


const property_list &getPropList() const { return MProps; }

protected:
// An allocateMem helper that determines which host ptr to use
void determineHostPtr(bool InitFromUserData, void *&HostPtr,
Expand Down
22 changes: 4 additions & 18 deletions sycl/source/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,6 @@ image_plain::image_plain(pi_native_handle MemObject, const context &SyclContext,
Order, Type, OwnNativeHandle, Range3WithOnes);
}

#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
template <> \
__SYCL_EXPORT bool image_plain::has_property<param_type>() const noexcept { \
return impl->has_property<param_type>(); \
}
#include <sycl/detail/properties_traits.def>

#undef __SYCL_PARAM_TRAITS_SPEC

#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
template <> \
__SYCL_EXPORT param_type image_plain::get_property<param_type>() const { \
return impl->get_property<param_type>(); \
}
#include <sycl/detail/properties_traits.def>

#undef __SYCL_PARAM_TRAITS_SPEC

range<3> image_plain::get_range() const { return impl->get_range(); }

range<2> image_plain::get_pitch() const { return impl->get_pitch(); }
Expand Down Expand Up @@ -225,6 +207,10 @@ void image_plain::unsampledImageDestructorNotification(void *UserObj) {
impl->unsampledImageDestructorNotification(UserObj);
}

const property_list &image_plain::getPropList() const {
return impl->getPropList();
}

} // namespace detail
} // namespace _V1
} // namespace sycl
Loading

0 comments on commit a9b2ead

Please sign in to comment.