Skip to content

Commit bcb2711

Browse files
add partial spec and base for std::hash support
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
1 parent b22192a commit bcb2711

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

libsycl/include/sycl/__impl/detail/obj_base.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
#include <sycl/__impl/detail/config.hpp>
1919

2020
#include <cassert>
21+
#include <optional>
2122
#include <type_traits>
2223
#include <utility>
2324

2425
_LIBSYCL_BEGIN_NAMESPACE_SYCL
2526

2627
namespace detail {
2728

28-
template <class Impl, class SyclObject> class ObjBase {
29+
template <typename Impl, typename SyclObject> class ObjBase;
30+
template <typename Impl, typename SyclObject>
31+
class ObjBase<Impl &, SyclObject> {
2932
public:
3033
using ImplType = Impl;
31-
using Base = ObjBase<Impl, SyclObject>;
34+
using Base = ObjBase<Impl &, SyclObject>;
3235

3336
protected:
3437
ImplType &impl;
@@ -57,6 +60,19 @@ Obj createSyclObjFromImpl(
5760
return Obj::Base::createSyclProxy(ImplObj);
5861
}
5962

63+
// std::hash support (4.5.2. Common reference semantics)
64+
template <typename T> struct HashBase {
65+
size_t operator()(const T &Obj) const {
66+
#ifdef __SYCL_DEVICE_ONLY__
67+
(void)Obj;
68+
return 0;
69+
#else
70+
auto &Impl = sycl::detail::getSyclObjImpl(Obj);
71+
return std::hash<std::decay_t<decltype(Impl)>>{}(Impl);
72+
#endif
73+
}
74+
};
75+
6076
} // namespace detail
6177

6278
_LIBSYCL_END_NAMESPACE_SYCL

libsycl/include/sycl/__impl/platform.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class platform_impl;
3131

3232
// 4.6.2. Platform class
3333
class _LIBSYCL_EXPORT platform
34-
: public detail::ObjBase<detail::platform_impl, platform> {
34+
: public detail::ObjBase<detail::platform_impl &, platform> {
3535
public:
3636
/// Constructs a platform object that is a copy of the platform which contains
3737
/// the device returned by default_selector_v.
@@ -104,9 +104,13 @@ class _LIBSYCL_EXPORT platform
104104
typename detail::is_platform_info_desc<Param>::return_type
105105
get_info_impl() const;
106106

107-
friend detail::ObjBase<detail::platform_impl, platform>;
107+
friend detail::ObjBase<detail::platform_impl &, platform>;
108108
}; // class platform
109109

110110
_LIBSYCL_END_NAMESPACE_SYCL
111111

112+
template <>
113+
struct std::hash<sycl::platform>
114+
: public sycl::detail::HashBase<sycl::platform> {};
115+
112116
#endif // _LIBSYCL___IMPL_PLATFORM_HPP

0 commit comments

Comments
 (0)