Skip to content

[SYCL] Add property validation to sycl object ctors #15253

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

Merged
merged 29 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
91f0ce6
Add def based check for queue
KseniyaTikhomirova Sep 2, 2024
ae0b1d4
add test for queue
KseniyaTikhomirova Aug 29, 2024
6e673ac
fix code-review comments
KseniyaTikhomirova Sep 2, 2024
34d65d9
fix format
KseniyaTikhomirova Sep 2, 2024
05b7398
add check to buffer & image
KseniyaTikhomirova Sep 2, 2024
10bd181
fix format
KseniyaTikhomirova Sep 2, 2024
87a1691
fix build & format
KseniyaTikhomirova Sep 3, 2024
f3b6e39
add check to context
KseniyaTikhomirova Sep 3, 2024
db53824
add test for context
KseniyaTikhomirova Aug 29, 2024
c5a4eff
fix build
KseniyaTikhomirova Sep 3, 2024
d88c3f2
add check to sampler
KseniyaTikhomirova Sep 3, 2024
d83f367
add test for sampler
KseniyaTikhomirova Aug 30, 2024
8edf0c1
add check to stream
KseniyaTikhomirova Sep 3, 2024
a9c8c39
add test for stream
KseniyaTikhomirova Aug 29, 2024
0587a71
update tests
KseniyaTikhomirova Sep 3, 2024
f02ca36
add check to reduction
KseniyaTikhomirova Sep 3, 2024
72fc90d
add test for reduction
KseniyaTikhomirova Aug 30, 2024
4e5f586
add check to usm_allocator
KseniyaTikhomirova Sep 3, 2024
2d99591
add test for usm_allocator
KseniyaTikhomirova Aug 30, 2024
0973de0
update linux symbols
KseniyaTikhomirova Sep 3, 2024
e76b4ae
fix stream test
KseniyaTikhomirova Sep 3, 2024
4f25430
fix format
KseniyaTikhomirova Sep 3, 2024
80acde2
add check to accessor
KseniyaTikhomirova Sep 4, 2024
05cf71d
add test for sampled/unsampled_image
KseniyaTikhomirova Sep 4, 2024
24120ff
Merge branch 'sycl' into defbased_property
KseniyaTikhomirova Sep 17, 2024
f16372f
fix tests
KseniyaTikhomirova Sep 17, 2024
6fa9b2b
add a few accessor tests
KseniyaTikhomirova Oct 7, 2024
95ea264
Merge branch 'sycl' into defbased_property
KseniyaTikhomirova Oct 7, 2024
e44a496
fix win build
KseniyaTikhomirova Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sycl/include/sycl/detail/property_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class PropertyWithDataBase {
PropertyWithDataBase(int ID) : MID(ID) {}
bool isSame(int ID) const { return ID == MID; }
virtual ~PropertyWithDataBase() = default;
int getKind() const { return MID; }

private:
int MID = -1;
Expand All @@ -101,7 +102,7 @@ class PropertyWithDataBase {
template <int ID> class PropertyWithData : public PropertyWithDataBase {
public:
PropertyWithData() : PropertyWithDataBase(ID) {}
static int getKind() { return ID; }
static constexpr int getKind() { return ID; }
};

} // namespace detail
Expand Down
19 changes: 19 additions & 0 deletions sycl/include/sycl/detail/property_list_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ class PropertyListBase {
}
}

void checkPropsAndThrow(std::function<bool(int)> FunctionForDataless,
std::function<bool(int)> FunctionForData) const {
static const auto ErrorCode = sycl::make_error_code(errc::invalid);
static const auto ErrorMessage = "The property list contains property "
"unsupported for the current object";

for (int PropertyKind = 0;
PropertyKind < static_cast<int>(MDataLessProps.size());
PropertyKind++) {
if (MDataLessProps[PropertyKind] && !FunctionForDataless(PropertyKind))
throw sycl::exception(ErrorCode, ErrorMessage);
}

for (const auto &PropertyItem : MPropsWithData) {
if (!FunctionForData(PropertyItem->getKind()))
throw sycl::exception(ErrorCode, ErrorMessage);
}
}

// Stores enabled/disabled for simple properties
std::bitset<DataLessPropKind::DataLessPropKindSize> MDataLessProps;
// Stores shared_ptrs to complex properties
Expand Down
22 changes: 10 additions & 12 deletions sycl/include/sycl/properties/accessor_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@

namespace sycl {
inline namespace _V1 {
namespace property {

class no_init : public detail::DataLessProperty<detail::NoInit> {};

class __SYCL2020_DEPRECATED("spelling is now: no_init") noinit
: public detail::DataLessProperty<detail::NoInit> {};

} // namespace property

inline constexpr property::no_init no_init;

__SYCL2020_DEPRECATED("spelling is now: no_init")
inline constexpr property::noinit noinit;
#define __SYCL_DATA_LESS_PROP_DEPRECATED_ALIAS(NS_QUALIFIER, PROP_NAME, \
ENUM_VAL, WARNING) \
namespace NS_QUALIFIER { \
class WARNING PROP_NAME \
: public sycl::detail::DataLessProperty<sycl::detail::ENUM_VAL> {}; \
} \
WARNING inline constexpr NS_QUALIFIER::PROP_NAME PROP_NAME;
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
__SYCL_DATA_LESS_PROP_DEPRECATED_ALIAS(NS_QUALIFIER, PROP_NAME, ENUM_VAL, )
#include <sycl/properties/runtime_accessor_properties.def>

namespace ext::intel {
namespace property {
Expand Down
19 changes: 19 additions & 0 deletions sycl/include/sycl/properties/buffer_properties.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// --*- c++ -*---
#ifndef __SYCL_DATA_LESS_PROP
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL)
#endif
#ifndef __SYCL_MANUALLY_DEFINED_PROP
#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
#endif

__SYCL_DATA_LESS_PROP(property::buffer, use_host_ptr, BufferUseHostPtr)
__SYCL_DATA_LESS_PROP(ext::oneapi::property::buffer, use_pinned_host_memory, BufferUsePinnedHostMemory)

// Contains data field, defined explicitly.
__SYCL_MANUALLY_DEFINED_PROP(property::buffer, use_mutex)
__SYCL_MANUALLY_DEFINED_PROP(property::buffer, context_bound)
__SYCL_MANUALLY_DEFINED_PROP(property::buffer, mem_channel)
__SYCL_MANUALLY_DEFINED_PROP(property::buffer::detail, buffer_location)

#undef __SYCL_DATA_LESS_PROP
#undef __SYCL_MANUALLY_DEFINED_PROP
49 changes: 15 additions & 34 deletions sycl/include/sycl/properties/buffer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

namespace sycl {
inline namespace _V1 {
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
namespace NS_QUALIFIER { \
class PROP_NAME \
: public sycl::detail::DataLessProperty<sycl::detail::ENUM_VAL> {}; \
}
#include <sycl/properties/buffer_properties.def>

namespace property::buffer {
class use_host_ptr : public detail::DataLessProperty<detail::BufferUseHostPtr> {
};

class use_mutex : public detail::PropertyWithData<detail::BufferUseMutex> {
public:
use_mutex(std::mutex &MutexRef) : MMutex(MutexRef) {}
Expand Down Expand Up @@ -69,41 +72,19 @@ class buffer_location
} // namespace detail
} // namespace property::buffer

namespace ext::oneapi::property::buffer {

class use_pinned_host_memory : public sycl::detail::DataLessProperty<
sycl::detail::BufferUsePinnedHostMemory> {};
} // namespace ext::oneapi::property::buffer

// Forward declaration
template <typename T, int Dimensions, typename AllocatorT, typename Enable>
class buffer;

// Buffer property trait specializations
template <typename T, int Dimensions, typename AllocatorT>
struct is_property_of<property::buffer::use_host_ptr,
buffer<T, Dimensions, AllocatorT, void>>
: std::true_type {};
template <typename T, int Dimensions, typename AllocatorT>
struct is_property_of<property::buffer::use_mutex,
buffer<T, Dimensions, AllocatorT, void>>
: std::true_type {};
template <typename T, int Dimensions, typename AllocatorT>
struct is_property_of<property::buffer::detail::buffer_location,
buffer<T, Dimensions, AllocatorT, void>>
: std::true_type {};
template <typename T, int Dimensions, typename AllocatorT>
struct is_property_of<property::buffer::context_bound,
buffer<T, Dimensions, AllocatorT, void>>
: std::true_type {};
template <typename T, int Dimensions, typename AllocatorT>
struct is_property_of<property::buffer::mem_channel,
buffer<T, Dimensions, AllocatorT, void>>
: std::true_type {};
template <typename T, int Dimensions, typename AllocatorT>
struct is_property_of<ext::oneapi::property::buffer::use_pinned_host_memory,
buffer<T, Dimensions, AllocatorT, void>>
: std::true_type {};
#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME) \
template <typename T, int Dimensions, typename AllocatorT> \
struct is_property_of<NS_QUALIFIER::PROP_NAME, \
buffer<T, Dimensions, AllocatorT, void>> \
: std::true_type {};
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
__SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)

#include <sycl/properties/buffer_properties.def>

} // namespace _V1
} // namespace sycl
16 changes: 16 additions & 0 deletions sycl/include/sycl/properties/image_properties.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// --*- c++ -*---
#ifndef __SYCL_DATA_LESS_PROP
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL)
#endif
#ifndef __SYCL_MANUALLY_DEFINED_PROP
#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
#endif

__SYCL_DATA_LESS_PROP(property::image, use_host_ptr, ImageUseHostPtr)

// Contains data field, defined explicitly.
__SYCL_MANUALLY_DEFINED_PROP(property::image, use_mutex)
__SYCL_MANUALLY_DEFINED_PROP(property::image, context_bound)

#undef __SYCL_DATA_LESS_PROP
#undef __SYCL_MANUALLY_DEFINED_PROP
67 changes: 31 additions & 36 deletions sycl/include/sycl/properties/image_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@

namespace sycl {
inline namespace _V1 {
namespace property::image {
class use_host_ptr : public detail::DataLessProperty<detail::ImageUseHostPtr> {
};
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
namespace NS_QUALIFIER { \
class PROP_NAME \
: public sycl::detail::DataLessProperty<sycl::detail::ENUM_VAL> {}; \
}
#include <sycl/properties/image_properties.def>

namespace property::image {
class use_mutex : public detail::PropertyWithData<detail::ImageUseMutex> {
public:
use_mutex(std::mutex &MutexRef) : MMutex(MutexRef) {}
Expand Down Expand Up @@ -50,41 +54,32 @@ template <int Dimensions, typename AllocatorT> class sampled_image;
template <int Dimensions, typename AllocatorT> class unsampled_image;

// SYCL 1.2.1 image property trait specializations
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::use_host_ptr,
image<Dimensions, AllocatorT>> : std::true_type {};
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::use_mutex, image<Dimensions, AllocatorT>>
: std::true_type {};
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::context_bound,
image<Dimensions, AllocatorT>> : std::true_type {};
#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME) \
template <int Dimensions, typename AllocatorT> \
struct is_property_of<NS_QUALIFIER::PROP_NAME, \
image<Dimensions, AllocatorT>> : std::true_type {};
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
__SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
#include <sycl/properties/image_properties.def>

// SYCL 2020 image property trait specializations
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::use_host_ptr,
sampled_image<Dimensions, AllocatorT>> : std::true_type {
};
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::use_mutex,
sampled_image<Dimensions, AllocatorT>> : std::true_type {
};
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::context_bound,
sampled_image<Dimensions, AllocatorT>> : std::true_type {
};
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::use_host_ptr,
unsampled_image<Dimensions, AllocatorT>>
: std::true_type {};
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::use_mutex,
unsampled_image<Dimensions, AllocatorT>>
: std::true_type {};
template <int Dimensions, typename AllocatorT>
struct is_property_of<property::image::context_bound,
unsampled_image<Dimensions, AllocatorT>>
: std::true_type {};
#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME) \
template <int Dimensions, typename AllocatorT> \
struct is_property_of<NS_QUALIFIER::PROP_NAME, \
sampled_image<Dimensions, AllocatorT>> \
: std::true_type {};
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
__SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
#include <sycl/properties/image_properties.def>

#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME) \
template <int Dimensions, typename AllocatorT> \
struct is_property_of<NS_QUALIFIER::PROP_NAME, \
unsampled_image<Dimensions, AllocatorT>> \
: std::true_type {};
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
__SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
#include <sycl/properties/image_properties.def>

} // namespace _V1
} // namespace sycl
12 changes: 12 additions & 0 deletions sycl/include/sycl/properties/reduction_properties.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// --*- c++ -*---
#ifndef __SYCL_DATA_LESS_PROP
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL)
#endif
#ifndef __SYCL_MANUALLY_DEFINED_PROP
#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
#endif

__SYCL_DATA_LESS_PROP(property::reduction, initialize_to_identity, InitializeToIdentity)

#undef __SYCL_DATA_LESS_PROP
#undef __SYCL_MANUALLY_DEFINED_PROP
10 changes: 6 additions & 4 deletions sycl/include/sycl/properties/reduction_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

namespace sycl {
inline namespace _V1 {
namespace property::reduction {
class initialize_to_identity
: public detail::DataLessProperty<detail::InitializeToIdentity> {};
} // namespace property::reduction
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
namespace NS_QUALIFIER { \
class PROP_NAME \
: public sycl::detail::DataLessProperty<sycl::detail::ENUM_VAL> {}; \
}
#include <sycl/properties/reduction_properties.def>

// Reduction property trait specializations
} // namespace _V1
Expand Down
17 changes: 17 additions & 0 deletions sycl/include/sycl/properties/runtime_accessor_properties.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// --*- c++ -*---
#ifndef __SYCL_DATA_LESS_PROP
#define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL)
#endif
#ifndef __SYCL_MANUALLY_DEFINED_PROP
#define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
#endif
#ifndef __SYCL_DATA_LESS_PROP_DEPRECATED_ALIAS
#define __SYCL_DATA_LESS_PROP_DEPRECATED_ALIAS(NS_QUALIFIER, PROP_NAME, ENUM_VAL, WARNING)
#endif

__SYCL_DATA_LESS_PROP(property, no_init, NoInit)
__SYCL_DATA_LESS_PROP_DEPRECATED_ALIAS(property, noinit, NoInit, __SYCL2020_DEPRECATED("spelling is now: no_init"))

#undef __SYCL_DATA_LESS_PROP
#undef __SYCL_MANUALLY_DEFINED_PROP
#undef __SYCL_DATA_LESS_PROP_DEPRECATED_ALIAS
15 changes: 15 additions & 0 deletions sycl/include/sycl/property_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ inline namespace _V1 {
namespace ext::oneapi {
template <typename... PropsT> class accessor_property_list;
} // namespace ext::oneapi
namespace detail {
class PropertyValidator;
} // namespace detail

/// Objects of the property_list class are containers for the SYCL properties
///
Expand Down Expand Up @@ -72,7 +75,19 @@ class property_list : protected detail::PropertyListBase {

template <typename... PropsT>
friend class ext::oneapi::accessor_property_list;
friend class detail::PropertyValidator;
};

namespace detail {
class PropertyValidator {
public:
static void checkPropsAndThrow(const property_list &PropList,
std::function<bool(int)> FunctionForDataless,
std::function<bool(int)> FunctionForData) {
PropList.checkPropsAndThrow(FunctionForDataless, FunctionForData);
}
};
} // namespace detail

} // namespace _V1
} // namespace sycl
8 changes: 8 additions & 0 deletions sycl/include/sycl/reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ class ReducerElement {
private:
value_type MValue;
};

__SYCL_EXPORT void verifyReductionProps(const property_list &Props);
} // namespace detail

// We explicitly claim std::optional as device-copyable in sycl/types.hpp.
Expand Down Expand Up @@ -2842,6 +2844,7 @@ template <typename T, typename AllocatorT, typename BinaryOperation>
auto reduction(buffer<T, 1, AllocatorT> Var, handler &CGH,
BinaryOperation Combiner, const property_list &PropList = {}) {
std::ignore = CGH;
detail::verifyReductionProps(PropList);
bool InitializeToIdentity =
PropList.has_property<property::reduction::initialize_to_identity>();
return detail::make_reduction<BinaryOperation, 0, 1, false>(
Expand All @@ -2856,6 +2859,7 @@ auto reduction(buffer<T, 1, AllocatorT> Var, handler &CGH,
template <typename T, typename BinaryOperation>
auto reduction(T *Var, BinaryOperation Combiner,
const property_list &PropList = {}) {
detail::verifyReductionProps(PropList);
bool InitializeToIdentity =
PropList.has_property<property::reduction::initialize_to_identity>();
return detail::make_reduction<BinaryOperation, 0, 1, false>(
Expand All @@ -2869,6 +2873,7 @@ template <typename T, typename AllocatorT, typename BinaryOperation>
auto reduction(buffer<T, 1, AllocatorT> Var, handler &CGH, const T &Identity,
BinaryOperation Combiner, const property_list &PropList = {}) {
std::ignore = CGH;
detail::verifyReductionProps(PropList);
bool InitializeToIdentity =
PropList.has_property<property::reduction::initialize_to_identity>();
return detail::make_reduction<BinaryOperation, 0, 1, true>(
Expand All @@ -2881,6 +2886,7 @@ auto reduction(buffer<T, 1, AllocatorT> Var, handler &CGH, const T &Identity,
template <typename T, typename BinaryOperation>
auto reduction(T *Var, const T &Identity, BinaryOperation Combiner,
const property_list &PropList = {}) {
detail::verifyReductionProps(PropList);
bool InitializeToIdentity =
PropList.has_property<property::reduction::initialize_to_identity>();
return detail::make_reduction<BinaryOperation, 0, 1, true>(
Expand All @@ -2896,6 +2902,7 @@ template <typename T, size_t Extent, typename BinaryOperation,
typename = std::enable_if_t<Extent != dynamic_extent>>
auto reduction(span<T, Extent> Span, BinaryOperation Combiner,
const property_list &PropList = {}) {
detail::verifyReductionProps(PropList);
bool InitializeToIdentity =
PropList.has_property<property::reduction::initialize_to_identity>();
return detail::make_reduction<BinaryOperation, 1, Extent, false>(
Expand All @@ -2909,6 +2916,7 @@ template <typename T, size_t Extent, typename BinaryOperation,
typename = std::enable_if_t<Extent != dynamic_extent>>
auto reduction(span<T, Extent> Span, const T &Identity,
BinaryOperation Combiner, const property_list &PropList = {}) {
detail::verifyReductionProps(PropList);
bool InitializeToIdentity =
PropList.has_property<property::reduction::initialize_to_identity>();
return detail::make_reduction<BinaryOperation, 1, Extent, true>(
Expand Down
Loading
Loading