Skip to content

Commit 557204a

Browse files
author
Brox Chen
authored
[SYCL] Property list check for FPGA mmhost interface (#10405)
For annotated_arg/ptr feature. error out when user are using bad FPGA properties. For FPGA properties, the interface configuration cannot be set alone. The interface configurations have to be set with buffer location altogether.
1 parent 6f32df0 commit 557204a

File tree

4 files changed

+58
-16
lines changed

4 files changed

+58
-16
lines changed

sycl/include/sycl/ext/oneapi/annotated_arg/annotated_arg.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ __SYCL_TYPE(annotated_arg) annotated_arg<T, detail::properties_t<Props...>> {
180180
"Property list is invalid.");
181181
static_assert(check_property_list<T, Props...>::value,
182182
"The property list contains invalid property.");
183+
// check the set if FPGA specificed properties are used
184+
static_assert(detail::checkValidFPGAPropertySet<Props...>::value,
185+
"FPGA Interface properties (i.e. awidth, dwidth, etc.)"
186+
"can only be set with BufferLocation together.");
183187

184188
annotated_arg() noexcept = default;
185189
annotated_arg(const annotated_arg &) = default;

sycl/include/sycl/ext/oneapi/annotated_arg/annotated_ptr.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
121121
public:
122122
static_assert(is_property_list<property_list_t>::value,
123123
"Property list is invalid.");
124+
static_assert(check_property_list<T *, Props...>::value,
125+
"The property list contains invalid property.");
126+
// check the set if FPGA specificed properties are used
127+
static_assert(detail::checkValidFPGAPropertySet<Props...>::value,
128+
"FPGA Interface properties (i.e. awidth, dwidth, etc.)"
129+
"can only be set with BufferLocation together.");
124130

125131
annotated_ptr() noexcept = default;
126132
annotated_ptr(const annotated_ptr &) = default;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ struct alignment_key {
348348

349349
template <int K> inline constexpr alignment_key::value_t<K> alignment;
350350

351+
template <typename T, int W>
352+
struct is_valid_property<T, alignment_key::value_t<W>>
353+
: std::bool_constant<std::is_pointer<T>::value> {};
354+
351355
template <> struct is_property_key<alignment_key> : std::true_type {};
352356

353357
template <typename T, typename PropertyListT>
@@ -385,6 +389,23 @@ template <typename... Args>
385389
struct DeducedProperties<detail::properties_t<Args...>> {
386390
using type = detail::properties_t<Args...>;
387391
};
392+
393+
template <typename... Args> struct checkValidFPGAPropertySet {
394+
using list = std::tuple<Args...>;
395+
static constexpr bool has_BufferLocation =
396+
ContainsProperty<buffer_location_key, list>::value;
397+
398+
static constexpr bool has_InterfaceConfig =
399+
ContainsProperty<awidth_key, list>::value &&
400+
ContainsProperty<dwidth_key, list>::value &&
401+
ContainsProperty<latency_key, list>::value &&
402+
ContainsProperty<read_write_mode_key, list>::value &&
403+
ContainsProperty<maxburst_key, list>::value &&
404+
ContainsProperty<wait_request_key, list>::value &&
405+
ContainsProperty<alignment_key, list>::value;
406+
407+
static constexpr bool value = !(!has_BufferLocation && has_InterfaceConfig);
408+
};
388409
} // namespace detail
389410

390411
} // namespace experimental

sycl/test/extensions/annotated_arg/annotated_ptr.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ using namespace sycl;
1212
using namespace ext::oneapi::experimental;
1313

1414
using annotated_ptr_t1 =
15-
annotated_ptr<int, decltype(properties(awidth<32>, dwidth<32>))>;
15+
annotated_ptr<int, decltype(properties(buffer_location<0>, awidth<32>,
16+
dwidth<32>))>;
1617

1718
using annotated_ptr_t2 =
18-
annotated_ptr<int,
19-
decltype(properties(conduit, register_map, alignment<8>))>;
19+
annotated_ptr<int, decltype(properties(buffer_location<0>, conduit,
20+
register_map, alignment<8>))>;
2021

21-
using annotated_ptr_t3 = annotated_ptr<int, decltype(properties(awidth<32>))>;
22+
using annotated_ptr_t3 =
23+
annotated_ptr<int, decltype(properties(buffer_location<0>, awidth<32>))>;
2224

2325
struct MyIP {
24-
annotated_ptr<int, decltype(properties(awidth<32>, dwidth<32>))> a;
26+
annotated_ptr<int, decltype(properties(buffer_location<0>, awidth<32>,
27+
dwidth<32>))>
28+
a;
2529

2630
int b;
2731

@@ -38,7 +42,7 @@ struct MyIP {
3842

3943
template <typename T> T foo() {
4044
auto raw = new int;
41-
return annotated_ptr(raw, awidth<32>);
45+
return annotated_ptr(raw, buffer_location<0>, awidth<32>);
4246
}
4347

4448
void TestVectorAddWithAnnotatedMMHosts() {
@@ -60,33 +64,40 @@ void TestVectorAddWithAnnotatedMMHosts() {
6064
// Construct from raw pointers
6165
auto tmp11 = annotated_ptr(raw); // empty property list
6266
// Construct from raw pointers and a property list
63-
auto tmp12 = annotated_ptr<int, decltype(properties{awidth<32>})>(
64-
raw, properties{awidth<32>});
65-
auto tmp14 = annotated_ptr(raw, properties{awidth<32>}); // deduction guide
67+
auto tmp12 =
68+
annotated_ptr<int, decltype(properties{buffer_location<0>, awidth<32>})>(
69+
raw, properties{buffer_location<0>, awidth<32>});
70+
auto tmp14 = annotated_ptr(
71+
raw, properties{buffer_location<0>, awidth<32>}); // deduction guide
6672
static_assert(std::is_same<decltype(tmp14), annotated_ptr_t3>::value,
6773
"deduction guide failed 1");
6874
// Construct from raw pointers and variadic properties
69-
auto tmp13 = annotated_ptr(raw, dwidth<32>, awidth<32>); // deduction guide
75+
auto tmp13 = annotated_ptr(raw, buffer_location<0>, dwidth<32>,
76+
awidth<32>); // deduction guide
7077
static_assert(std::is_same<decltype(tmp13), annotated_ptr_t1>::value,
7178
"deduction guide failed 2");
72-
auto tmp15 = annotated_ptr(raw, awidth<32>);
79+
auto tmp15 = annotated_ptr(raw, buffer_location<0>, awidth<32>);
7380
static_assert(std::is_same<decltype(tmp15), annotated_ptr_t3>::value,
7481
"deduction guide failed 1");
7582

7683
// Construct from another annotated_ptr
7784
// templated copy constructor
78-
annotated_ptr<int, decltype(properties{awidth<32>, dwidth<32>})> arg11(tmp11);
85+
annotated_ptr<int, decltype(properties{buffer_location<0>, awidth<32>,
86+
dwidth<32>})>
87+
arg11(tmp11);
7988
auto arg12 =
80-
annotated_ptr<int, decltype(properties{dwidth<32>, awidth<32>})>(tmp11);
89+
annotated_ptr<int, decltype(properties{buffer_location<0>, dwidth<32>,
90+
awidth<32>})>(tmp11);
8191

8292
// default copy constructor
8393
auto arg13 = annotated_ptr(tmp12);
8494
static_assert(std::is_same<decltype(arg13), annotated_ptr_t3>::value,
8595
"deduction guide failed 3");
8696

8797
// Construct from another annotated_ptr and a property list
88-
annotated_ptr<int, decltype(properties{awidth<32>, dwidth<32>})> arg22(
89-
tmp12, properties{dwidth<32>});
98+
annotated_ptr<int, decltype(properties{buffer_location<0>, awidth<32>,
99+
dwidth<32>})>
100+
arg22(tmp12, properties{dwidth<32>});
90101
auto arg23 = annotated_ptr(tmp12, properties{dwidth<32>}); // deduction guide
91102
static_assert(std::is_same<decltype(arg22), annotated_ptr_t1>::value,
92103
"deduction guide failed 4");
@@ -99,7 +110,7 @@ void TestVectorAddWithAnnotatedMMHosts() {
99110
// properties{dwidth<32>}); // ERR
100111

101112
// Property merge
102-
auto arg31 = annotated_ptr_t3(raw, awidth<32>); // OK
113+
auto arg31 = annotated_ptr_t3(raw, buffer_location<0>, awidth<32>); // OK
103114
auto arg32 = annotated_ptr(arg31, properties{dwidth<32>}); // OK
104115
auto arg33 = annotated_ptr(arg32, properties{dwidth<32>, awidth<32>}); // OK
105116
auto arg34 = annotated_ptr(arg32, properties{awidth<32>, latency<22>}); // OK

0 commit comments

Comments
 (0)