Skip to content

Commit 396eb5a

Browse files
authored
Removed inheritance in fpga_mem (#11917)
Currently the SPIRV translator has a hard time translating annotations that are in nested types. This bug is actively being worked on. In the mean time, this change removes class inheritance from `fpga_mem`, allowing SPIRV translator to properly translate annotations in more cases.
1 parent e143dcc commit 396eb5a

File tree

1 file changed

+36
-68
lines changed
  • sycl/include/sycl/ext/intel/experimental/fpga_mem

1 file changed

+36
-68
lines changed

sycl/include/sycl/ext/intel/experimental/fpga_mem/fpga_mem.hpp

Lines changed: 36 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,30 @@
2020
namespace sycl {
2121
inline namespace _V1 {
2222
namespace ext::intel::experimental {
23-
namespace detail {
2423

25-
// Hide the base implementation in details so that manipulation
26-
// of properties parameter pack can be modularized away from main logic
27-
template <typename T, typename... Props> class fpga_mem_base {
24+
// Primary template should never be deduced. Needed to establish which
25+
// parameters fpga_mem can be templated on
26+
template <typename T, typename PropertyListT =
27+
ext::oneapi::experimental::empty_properties_t>
28+
class fpga_mem {
29+
30+
static_assert(
31+
ext::oneapi::experimental::is_property_list<PropertyListT>::value,
32+
"Property list is invalid.");
33+
};
34+
35+
// Template specialization that all calls should use. Separates Props from
36+
// properties_t which allows the class to apply Props as attributes.
37+
template <typename T, typename... Props>
38+
class
39+
#ifdef __SYCL_DEVICE_ONLY__
40+
[[__sycl_detail__::add_ir_attributes_global_variable(
41+
"sycl-resource",
42+
ext::oneapi::experimental::detail::PropertyMetaInfo<Props>::name...,
43+
"DEFAULT",
44+
ext::oneapi::experimental::detail::PropertyMetaInfo<Props>::value...)]]
45+
#endif
46+
fpga_mem<T, ext::oneapi::experimental::detail::properties_t<Props...>> {
2847

2948
protected:
3049
T val
@@ -47,14 +66,14 @@ template <typename T, typename... Props> class fpga_mem_base {
4766
// All the initialization
4867
// constexpr is used as a hint to the compiler to try and evaluate the
4968
// constructor at compile-time
50-
template <typename... S> constexpr fpga_mem_base(S... args) : val{args...} {}
69+
template <typename... S> constexpr fpga_mem(S... args) : val{args...} {}
5170

52-
fpga_mem_base() = default;
71+
fpga_mem() = default;
5372

54-
fpga_mem_base(const fpga_mem_base &) = default;
55-
fpga_mem_base(fpga_mem_base &&) = default;
56-
fpga_mem_base &operator=(const fpga_mem_base &) = default;
57-
fpga_mem_base &operator=(fpga_mem_base &&) = default;
73+
fpga_mem(const fpga_mem &) = default;
74+
fpga_mem(fpga_mem &&) = default;
75+
fpga_mem &operator=(const fpga_mem &) = default;
76+
fpga_mem &operator=(fpga_mem &&) = default;
5877

5978
T &get() noexcept { return val; }
6079

@@ -66,75 +85,24 @@ template <typename T, typename... Props> class fpga_mem_base {
6685
// Allows for implicit conversion from this to T
6786
constexpr operator const T &() const noexcept { return get(); }
6887

69-
fpga_mem_base &operator=(const T &newValue) noexcept {
88+
fpga_mem &operator=(const T &newValue) noexcept {
7089
val = newValue;
7190
return *this;
7291
}
7392

74-
// Note that there is no need for "fpga_mem_base" to define member functions
93+
// Note that there is no need for "fpga_mem" to define member functions
7594
// for operators like "++", "[]", "->", comparison, etc. Instead, the type
7695
// "T" need only define these operators as non-member functions. Because
77-
// there is an implicit conversion from "fpga_mem_base" to "T&".
78-
};
79-
} // namespace detail
80-
81-
// alias for proper namespace
82-
template <typename... Props>
83-
using properties_t = ext::oneapi::experimental::detail::properties_t<Props...>;
84-
85-
// Empty property list specialization
86-
template <typename T, typename PropertyListT =
87-
ext::oneapi::experimental::empty_properties_t>
88-
class
89-
#ifdef __SYCL_DEVICE_ONLY__
90-
[[__sycl_detail__::add_ir_attributes_global_variable("sycl-resource",
91-
"DEFAULT")]]
92-
#endif
93-
fpga_mem : public detail::fpga_mem_base<T> {
94-
95-
using property_list_t = ext::oneapi::experimental::empty_properties_t;
96-
97-
// Inherits the base class' constructors
98-
using detail::fpga_mem_base<T>::fpga_mem_base;
99-
100-
public:
101-
template <typename propertyT> static constexpr bool has_property() {
102-
return property_list_t::template has_property<propertyT>();
103-
}
104-
105-
template <typename propertyT> static constexpr auto get_property() {
106-
return property_list_t::template get_property<propertyT>();
107-
}
108-
};
109-
110-
template <typename T, typename... Props>
111-
class
112-
#ifdef __SYCL_DEVICE_ONLY__
113-
[[__sycl_detail__::add_ir_attributes_global_variable(
114-
"sycl-resource",
115-
ext::oneapi::experimental::detail::PropertyMetaInfo<Props>::name...,
116-
"DEFAULT",
117-
ext::oneapi::experimental::detail::PropertyMetaInfo<Props>::value...)]]
118-
#endif
119-
fpga_mem<T, properties_t<Props...>>
120-
: public detail::fpga_mem_base<T, Props...> {
121-
122-
using property_list_t = properties_t<Props...>;
123-
124-
// Inherits the base class' constructors
125-
using detail::fpga_mem_base<T, Props...>::fpga_mem_base;
126-
127-
public:
128-
static_assert(
129-
ext::oneapi::experimental::is_property_list<property_list_t>::value,
130-
"Property list is invalid.");
96+
// there is an implicit conversion from "fpga_mem" to "T&".
13197

13298
template <typename propertyT> static constexpr bool has_property() {
133-
return property_list_t::template has_property<propertyT>();
99+
return ext::oneapi::experimental::detail::properties_t<
100+
Props...>::template has_property<propertyT>();
134101
}
135102

136103
template <typename propertyT> static constexpr auto get_property() {
137-
return property_list_t::template get_property<propertyT>();
104+
return ext::oneapi::experimental::detail::properties_t<
105+
Props...>::template get_property<propertyT>();
138106
}
139107
};
140108

0 commit comments

Comments
 (0)