Skip to content

[SYCL] Adds compile-time properties #4976

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 24 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
68d59b0
[SYCL] Adds compile-time property list
steffenlarsen Nov 10, 2021
861af21
Fix formatting
steffenlarsen Nov 17, 2021
27a9e26
Fix formatting but clang-format does not agree
steffenlarsen Nov 17, 2021
c61d569
Mark test XFAIL on CUDA
steffenlarsen Nov 17, 2021
1f283f9
Attempt to fix MSVC overload issue
steffenlarsen Nov 17, 2021
f565f5c
Propagate is_device_copyable on property_list
steffenlarsen Nov 18, 2021
9601c4c
Propagate is_device_copyable onto const
steffenlarsen Nov 18, 2021
17fe53c
Disallow SYCL 2020 properties and add runtime properties
steffenlarsen Dec 2, 2021
31d391e
Fix formatting
steffenlarsen Dec 2, 2021
0f9bf8f
Move property_list to experimental
steffenlarsen Jan 14, 2022
43149a4
Adjust for renaming
steffenlarsen Jan 14, 2022
335be0c
XFAIL properties_device_copyable on HIP backend
steffenlarsen Jan 21, 2022
5e6cbac
Fix XFAIL
steffenlarsen Jan 21, 2022
83a9875
Fix XFAIL part 2
steffenlarsen Jan 21, 2022
8e3a42e
Testing and error reporting cleanup
steffenlarsen Jan 24, 2022
cd4b002
Renable device_copyable test for CUDA
steffenlarsen Jan 24, 2022
0b23c3e
Simplify negative tests
steffenlarsen Jan 24, 2022
294efcb
is_device_copyable specialization for const properties and associated…
steffenlarsen Feb 2, 2022
95682f1
Rename and clarify AllUnique type-trait
steffenlarsen Feb 2, 2022
0cae2e5
Fix formatting
steffenlarsen Feb 2, 2022
4f41fd4
Add missing end-of-file lines
steffenlarsen Feb 2, 2022
4608676
Fix reference to is_property in how-to
steffenlarsen Feb 24, 2022
de41a0f
Fix formatting
steffenlarsen Feb 24, 2022
d33bc77
Adhere to new formatting
steffenlarsen Feb 24, 2022
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
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#include <sycl/ext/oneapi/filter_selector.hpp>
#include <sycl/ext/oneapi/group_algorithm.hpp>
#include <sycl/ext/oneapi/matrix/matrix.hpp>
#include <sycl/ext/oneapi/properties/properties.hpp>
#include <sycl/ext/oneapi/properties/property_value.hpp>
#include <sycl/ext/oneapi/reduction.hpp>
#include <sycl/ext/oneapi/sub_group.hpp>
#include <sycl/ext/oneapi/sub_group_mask.hpp>
224 changes: 224 additions & 0 deletions sycl/include/sycl/ext/oneapi/properties/properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
//==---------- properties.hpp --- SYCL extended property list --------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/detail/property_helper.hpp>
#include <CL/sycl/types.hpp>
#include <sycl/ext/oneapi/properties/property.hpp>
#include <sycl/ext/oneapi/properties/property_utils.hpp>
#include <sycl/ext/oneapi/properties/property_value.hpp>

#include <tuple>
#include <type_traits>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace ext {
namespace oneapi {
namespace experimental {

namespace detail {

// Checks if a tuple of properties contains a property.
template <typename PropT, typename PropertiesT>
struct ContainsProperty : std::false_type {};
template <typename PropT, typename T, typename... Ts>
struct ContainsProperty<PropT, std::tuple<T, Ts...>>
: ContainsProperty<PropT, std::tuple<Ts...>> {};
template <typename PropT, typename... Rest>
struct ContainsProperty<PropT, std::tuple<PropT, Rest...>> : std::true_type {};
template <typename PropT, typename... PropValuesTs, typename... Rest>
struct ContainsProperty<
PropT, std::tuple<property_value<PropT, PropValuesTs...>, Rest...>>
: std::true_type {};

// Finds the full property_value type of a property in a tuple of properties.
// type is void if the type was not found in the tuple of properties.
template <typename CTPropertyT, typename PropertiesT = void>
struct FindCompileTimePropertyValueType {
using type = void;
};
template <typename CTPropertyT, typename OtherProperty, typename... Rest>
struct FindCompileTimePropertyValueType<CTPropertyT,
std::tuple<OtherProperty, Rest...>> {
using type =
typename FindCompileTimePropertyValueType<CTPropertyT,
std::tuple<Rest...>>::type;
};
template <typename CTPropertyT, typename... CTPropertyValueTs, typename... Rest>
struct FindCompileTimePropertyValueType<
CTPropertyT,
std::tuple<property_value<CTPropertyT, CTPropertyValueTs...>, Rest...>> {
using type = property_value<CTPropertyT, CTPropertyValueTs...>;
};

template <typename CTPropertyT, bool HasProperty, typename PropertiesT = void>
static constexpr std::enable_if_t<
HasProperty,
typename FindCompileTimePropertyValueType<CTPropertyT, PropertiesT>::type>
get_property() {
return {};
}

template <typename CTPropertyT, bool HasProperty, typename PropertiesT = void>
static constexpr std::enable_if_t<!HasProperty, void> get_property() {
return;
}

// Filters for all runtime properties with data in a tuple of properties.
// NOTE: We only need storage for runtime properties with data.
template <typename T> struct RuntimePropertyStorage {};
template <typename... Ts> struct RuntimePropertyStorage<std::tuple<Ts...>> {
using type = std::tuple<>;
};
template <typename T, typename... Ts>
struct RuntimePropertyStorage<std::tuple<T, Ts...>>
: sycl::detail::conditional_t<
IsRuntimeProperty<T>::value,
PrependTuple<
T, typename RuntimePropertyStorage<std::tuple<Ts...>>::type>,
RuntimePropertyStorage<std::tuple<Ts...>>> {};

// Helper class to extract a subset of elements from a tuple.
// NOTES: This assumes no duplicate properties and that all properties in the
// struct template argument appear in the tuple passed to Extract.
template <typename PropertiesT> struct ExtractProperties {};
template <typename... PropertiesTs>
struct ExtractProperties<std::tuple<PropertiesTs...>> {
template <typename... PropertyValueTs>
using ExtractedPropertiesT = std::tuple<>;

template <typename... PropertyValueTs>
static ExtractedPropertiesT<PropertyValueTs...>
Extract(std::tuple<PropertyValueTs...> PropertyValues) {
return {};
}
};
template <typename PropertyT, typename... PropertiesTs>
struct ExtractProperties<std::tuple<PropertyT, PropertiesTs...>> {
template <typename... PropertyValueTs>
using NextExtractedPropertiesT =
typename ExtractProperties<std::tuple<PropertiesTs...>>::
template ExtractedPropertiesT<PropertyValueTs...>;
template <typename... PropertyValueTs>
using ExtractedPropertiesT =
typename PrependTuple<PropertyT,
NextExtractedPropertiesT<PropertyValueTs...>>::type;

template <typename... PropertyValueTs>
static ExtractedPropertiesT<PropertyValueTs...>
Extract(std::tuple<PropertyValueTs...> PropertyValues) {
PropertyT ThisExtractedProperty = std::get<PropertyT>(PropertyValues);
NextExtractedPropertiesT<PropertyValueTs...> NextExtractedProperties =
ExtractProperties<std::tuple<PropertiesTs...>>::template Extract<
PropertyValueTs...>(PropertyValues);
return std::tuple_cat(std::tuple<PropertyT>{ThisExtractedProperty},
NextExtractedProperties);
}
};

} // namespace detail

template <typename PropertiesT> class properties {
static_assert(detail::IsTuple<PropertiesT>::value,
"Properties must be in a tuple.");
static_assert(detail::AllPropertyValues<PropertiesT>::value,
"Unrecognized property in property list.");
static_assert(detail::IsSorted<PropertiesT>::value,
"Properties in property list are not sorted.");
static_assert(detail::SortedAllUnique<PropertiesT>::value,
"Duplicate properties in property list.");

public:
template <typename... PropertyValueTs>
properties(PropertyValueTs... props)
: Storage(detail::ExtractProperties<StorageT>::Extract(
std::tuple<PropertyValueTs...>{props...})) {}

template <typename PropertyT>
static constexpr std::enable_if_t<detail::IsProperty<PropertyT>::value, bool>
has_property() {
return detail::ContainsProperty<PropertyT, PropertiesT>::value;
}

template <typename PropertyT>
typename std::enable_if_t<detail::IsRuntimeProperty<PropertyT>::value &&
has_property<PropertyT>(),
PropertyT>
get_property() const {
return std::get<PropertyT>(Storage);
}

template <typename PropertyT>
typename std::enable_if_t<detail::IsRuntimeProperty<PropertyT>::value &&
!has_property<PropertyT>(),
void>
get_property() const {
static_assert(has_property<PropertyT>(),
"Property list does not contain the requested property.");
return;
}

template <typename PropertyT>
static constexpr auto get_property(
typename std::enable_if_t<detail::IsCompileTimeProperty<PropertyT>::value>
* = 0) {
static_assert(has_property<PropertyT>(),
"Property list does not contain the requested property.");
return detail::get_property<PropertyT, has_property<PropertyT>(),
PropertiesT>();
}

private:
using StorageT = typename detail::RuntimePropertyStorage<PropertiesT>::type;

StorageT Storage;
};

#ifdef __cpp_deduction_guides
// Deduction guides
template <typename... PropertyValueTs>
properties(PropertyValueTs... props)
-> properties<typename detail::Sorted<PropertyValueTs...>::type>;
#endif

// Property list traits
template <typename propertiesT> struct is_property_list : std::false_type {};
template <typename... PropertyValueTs>
struct is_property_list<properties<std::tuple<PropertyValueTs...>>>
: std::is_same<
properties<std::tuple<PropertyValueTs...>>,
properties<typename detail::Sorted<PropertyValueTs...>::type>> {};

#if __cplusplus > 201402L
template <typename propertiesT>
inline constexpr bool is_property_list_v = is_property_list<propertiesT>::value;
#endif

} // namespace experimental
} // namespace oneapi
} // namespace ext

// If property_list is not trivially copyable, allow properties to propagate
// is_device_copyable
template <typename PropertiesT>
struct is_device_copyable<
ext::oneapi::experimental::properties<PropertiesT>,
std::enable_if_t<!std::is_trivially_copyable<
ext::oneapi::experimental::properties<PropertiesT>>::value>>
: is_device_copyable<PropertiesT> {};
template <typename PropertiesT>
struct is_device_copyable<
const ext::oneapi::experimental::properties<PropertiesT>,
std::enable_if_t<!std::is_trivially_copyable<
const ext::oneapi::experimental::properties<PropertiesT>>::value>>
: is_device_copyable<PropertiesT> {};

} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
Loading