Skip to content

Commit d35e68e

Browse files
committed
Fix extraction of values from device_global with different template args
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent fdaf3f6 commit d35e68e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

sycl/include/sycl/ext/oneapi/device_global/device_global.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ class device_global_base {
6868
pointer_t get_ptr() noexcept { return usmptr; }
6969
pointer_t get_ptr() const noexcept { return usmptr; }
7070

71+
template <typename, typename, typename> friend class device_global_base;
72+
73+
#ifndef __SYCL_DEVICE_ONLY__
74+
template <typename OtherT, typename OtherProps>
75+
static constexpr const T &
76+
ExtractInitialVal(const device_global_base<OtherT, OtherProps> &Other) {
77+
if constexpr (OtherProps::template has_property<device_image_scope_key>())
78+
return Other.val;
79+
else
80+
return Other.init_val;
81+
}
82+
#endif // __SYCL_DEVICE_ONLY__
83+
7184
public:
7285
#if __cpp_consteval
7386
// The SFINAE is to allow the copy constructors to take priority.
@@ -87,7 +100,7 @@ class device_global_base {
87100
typename = std::enable_if_t<std::is_convertible_v<OtherT, T>>>
88101
constexpr device_global_base(
89102
const device_global_base<OtherT, OtherProps> &DGB)
90-
: init_val{DGB.init_val} {}
103+
: init_val{ExtractInitialVal(DGB)} {}
91104
constexpr device_global_base(const device_global_base &DGB)
92105
: init_val{DGB.init_val} {}
93106
#else
@@ -127,6 +140,8 @@ class device_global_base<
127140
T *get_ptr() noexcept { return &val; }
128141
const T *get_ptr() const noexcept { return &val; }
129142

143+
template <typename, typename, typename> friend class device_global_base;
144+
130145
public:
131146
#if __cpp_consteval
132147
// The SFINAE is to allow the copy constructors to take priority.

0 commit comments

Comments
 (0)