Skip to content

Commit 960e9b9

Browse files
[SYCL] Adds properties for device_global (#5692)
These changes add the properties associated with device_global extension, specifically `device_image_scope`, `host_access`, `init_mode`, and `implement_in_csr`. Signed-off-by: Steffen Larsen <[email protected]>
1 parent 9d7a651 commit 960e9b9

File tree

3 files changed

+174
-1
lines changed

3 files changed

+174
-1
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//==----- properties.hpp - SYCL properties associated with device_global ---==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <sycl/ext/oneapi/properties/property.hpp>
10+
11+
__SYCL_INLINE_NAMESPACE(cl) {
12+
namespace sycl {
13+
namespace ext {
14+
namespace oneapi {
15+
namespace experimental {
16+
17+
struct device_image_scope_key {
18+
using value_t = property_value<device_image_scope_key>;
19+
};
20+
21+
enum class host_access_enum : std::uint16_t { read, write, read_write, none };
22+
23+
struct host_access_key {
24+
template <host_access_enum Access>
25+
using value_t =
26+
property_value<host_access_key,
27+
std::integral_constant<host_access_enum, Access>>;
28+
};
29+
30+
enum class init_mode_enum : std::uint16_t { reprogram, reset };
31+
32+
struct init_mode_key {
33+
template <init_mode_enum Trigger>
34+
using value_t =
35+
property_value<init_mode_key,
36+
std::integral_constant<init_mode_enum, Trigger>>;
37+
};
38+
39+
struct implement_in_csr_key {
40+
template <bool Enable>
41+
using value_t =
42+
property_value<implement_in_csr_key, std::bool_constant<Enable>>;
43+
};
44+
45+
inline constexpr device_image_scope_key::value_t device_image_scope;
46+
47+
template <host_access_enum Access>
48+
inline constexpr host_access_key::value_t<Access> host_access;
49+
inline constexpr host_access_key::value_t<host_access_enum::read>
50+
host_access_read;
51+
inline constexpr host_access_key::value_t<host_access_enum::write>
52+
host_access_write;
53+
inline constexpr host_access_key::value_t<host_access_enum::read_write>
54+
host_access_read_write;
55+
inline constexpr host_access_key::value_t<host_access_enum::none>
56+
host_access_none;
57+
58+
template <init_mode_enum Trigger>
59+
inline constexpr init_mode_key::value_t<Trigger> init_mode;
60+
inline constexpr init_mode_key::value_t<init_mode_enum::reprogram>
61+
init_mode_reprogram;
62+
inline constexpr init_mode_key::value_t<init_mode_enum::reset> init_mode_reset;
63+
64+
template <bool Enable>
65+
inline constexpr implement_in_csr_key::value_t<Enable> implement_in_csr;
66+
inline constexpr implement_in_csr_key::value_t<true> implement_in_csr_on;
67+
inline constexpr implement_in_csr_key::value_t<false> implement_in_csr_off;
68+
69+
template <> struct is_property_key<device_image_scope_key> : std::true_type {};
70+
template <> struct is_property_key<host_access_key> : std::true_type {};
71+
template <> struct is_property_key<init_mode_key> : std::true_type {};
72+
template <> struct is_property_key<implement_in_csr_key> : std::true_type {};
73+
74+
namespace detail {
75+
template <> struct PropertyToKind<device_image_scope_key> {
76+
static constexpr PropKind Kind = PropKind::DeviceImageScope;
77+
};
78+
template <> struct PropertyToKind<host_access_key> {
79+
static constexpr PropKind Kind = PropKind::HostAccess;
80+
};
81+
template <> struct PropertyToKind<init_mode_key> {
82+
static constexpr PropKind Kind = PropKind::InitMode;
83+
};
84+
template <> struct PropertyToKind<implement_in_csr_key> {
85+
static constexpr PropKind Kind = PropKind::ImplementInCSR;
86+
};
87+
88+
template <>
89+
struct IsCompileTimeProperty<device_image_scope_key> : std::true_type {};
90+
template <> struct IsCompileTimeProperty<host_access_key> : std::true_type {};
91+
template <> struct IsCompileTimeProperty<init_mode_key> : std::true_type {};
92+
template <>
93+
struct IsCompileTimeProperty<implement_in_csr_key> : std::true_type {};
94+
95+
} // namespace detail
96+
} // namespace experimental
97+
} // namespace oneapi
98+
} // namespace ext
99+
} // namespace sycl
100+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/sycl/ext/oneapi/properties/property.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ namespace detail {
144144

145145
// List of all properties.
146146
enum PropKind : uint32_t {
147-
PropKindSize = 0,
147+
DeviceImageScope = 0,
148+
HostAccess = 1,
149+
InitMode = 2,
150+
ImplementInCSR = 3,
151+
PropKindSize = 4,
148152
};
149153

150154
// This trait must be specialized for all properties and must have a unique
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s
2+
// expected-no-diagnostics
3+
4+
#include <CL/sycl.hpp>
5+
6+
#include <sycl/ext/oneapi/device_global/properties.hpp>
7+
8+
using namespace sycl::ext::oneapi::experimental;
9+
10+
constexpr host_access_enum TestAccess = host_access_enum::read_write;
11+
constexpr init_mode_enum TestTrigger = init_mode_enum::reset;
12+
13+
int main() {
14+
// Check that is_property_key is correctly specialized.
15+
static_assert(is_property_key<device_image_scope_key>::value);
16+
static_assert(is_property_key<host_access_key>::value);
17+
static_assert(is_property_key<init_mode_key>::value);
18+
static_assert(is_property_key<implement_in_csr_key>::value);
19+
20+
// Check that is_property_value is correctly specialized.
21+
static_assert(is_property_value<decltype(device_image_scope)>::value);
22+
static_assert(is_property_value<decltype(host_access<TestAccess>)>::value);
23+
static_assert(is_property_value<decltype(host_access_read)>::value);
24+
static_assert(is_property_value<decltype(host_access_write)>::value);
25+
static_assert(is_property_value<decltype(host_access_read_write)>::value);
26+
static_assert(is_property_value<decltype(host_access_none)>::value);
27+
static_assert(is_property_value<decltype(init_mode<TestTrigger>)>::value);
28+
static_assert(is_property_value<decltype(init_mode_reprogram)>::value);
29+
static_assert(is_property_value<decltype(init_mode_reset)>::value);
30+
static_assert(is_property_value<decltype(implement_in_csr<true>)>::value);
31+
static_assert(is_property_value<decltype(implement_in_csr_on)>::value);
32+
static_assert(is_property_value<decltype(implement_in_csr_off)>::value);
33+
34+
// Checks that fully specialized properties are the same as the templated
35+
// variants.
36+
static_assert(std::is_same_v<decltype(host_access_read),
37+
decltype(host_access<host_access_enum::read>)>);
38+
static_assert(std::is_same_v<decltype(host_access_write),
39+
decltype(host_access<host_access_enum::write>)>);
40+
static_assert(
41+
std::is_same_v<decltype(host_access_read_write),
42+
decltype(host_access<host_access_enum::read_write>)>);
43+
static_assert(std::is_same_v<decltype(host_access_none),
44+
decltype(host_access<host_access_enum::none>)>);
45+
static_assert(std::is_same_v<decltype(init_mode_reprogram),
46+
decltype(init_mode<init_mode_enum::reprogram>)>);
47+
static_assert(std::is_same_v<decltype(init_mode_reset),
48+
decltype(init_mode<init_mode_enum::reset>)>);
49+
static_assert(std::is_same_v<decltype(implement_in_csr_on),
50+
decltype(implement_in_csr<true>)>);
51+
static_assert(std::is_same_v<decltype(implement_in_csr_off),
52+
decltype(implement_in_csr<false>)>);
53+
54+
// Check that property lists will accept the new properties.
55+
using P =
56+
decltype(properties(device_image_scope, host_access<TestAccess>,
57+
init_mode<TestTrigger>, implement_in_csr<true>));
58+
static_assert(is_property_list_v<P>);
59+
static_assert(P::has_property<device_image_scope_key>());
60+
static_assert(P::has_property<host_access_key>());
61+
static_assert(P::has_property<init_mode_key>());
62+
static_assert(P::has_property<implement_in_csr_key>());
63+
static_assert(P::get_property<device_image_scope_key>() ==
64+
device_image_scope);
65+
static_assert(P::get_property<host_access_key>() == host_access<TestAccess>);
66+
static_assert(P::get_property<init_mode_key>() == init_mode<TestTrigger>);
67+
static_assert(P::get_property<implement_in_csr_key>() ==
68+
implement_in_csr<true>);
69+
}

0 commit comments

Comments
 (0)