Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 14 additions & 51 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2937,61 +2937,24 @@ host_accessor(buffer<DataT, Dimensions, AllocatorT>, Type1, Type2, Type3, Type4,
} // namespace _V1
} // namespace sycl

namespace std {
template <typename DataT, int Dimensions, sycl::access::mode AccessMode,
sycl::access::target AccessTarget,
sycl::access::placeholder IsPlaceholder>
struct hash<sycl::accessor<DataT, Dimensions, AccessMode, AccessTarget,
IsPlaceholder>> {
using AccType = sycl::accessor<DataT, Dimensions, AccessMode, AccessTarget,
IsPlaceholder>;

size_t operator()(const AccType &A) const {
#ifdef __SYCL_DEVICE_ONLY__
// Hash is not supported on DEVICE. Just return 0 here.
(void)A;
return 0;
#else
// getSyclObjImpl() here returns a pointer to either AccessorImplHost
// or LocalAccessorImplHost depending on the AccessTarget.
auto AccImplPtr = sycl::detail::getSyclObjImpl(A);
return hash<decltype(AccImplPtr)>()(AccImplPtr);
#endif
}
};
struct std::hash<
sycl::accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder>>
: public sycl::detail::sycl_obj_hash<
sycl::accessor<DataT, Dimensions, AccessMode, AccessTarget,
IsPlaceholder>,
true /*UnsupportedOnDevice*/> {};

template <typename DataT, int Dimensions, sycl::access_mode AccessMode>
struct hash<sycl::host_accessor<DataT, Dimensions, AccessMode>> {
using AccType = sycl::host_accessor<DataT, Dimensions, AccessMode>;

size_t operator()(const AccType &A) const {
#ifdef __SYCL_DEVICE_ONLY__
// Hash is not supported on DEVICE. Just return 0 here.
(void)A;
return 0;
#else
// getSyclObjImpl() here returns a pointer to AccessorImplHost.
auto AccImplPtr = sycl::detail::getSyclObjImpl(A);
return hash<decltype(AccImplPtr)>()(AccImplPtr);
#endif
}
};
struct std::hash<sycl::host_accessor<DataT, Dimensions, AccessMode>>
: public sycl::detail::sycl_obj_hash<
sycl::host_accessor<DataT, Dimensions, AccessMode>,
true /*UnsupportedOnDevice*/> {};

template <typename DataT, int Dimensions>
struct hash<sycl::local_accessor<DataT, Dimensions>> {
using AccType = sycl::local_accessor<DataT, Dimensions>;

size_t operator()(const AccType &A) const {
#ifdef __SYCL_DEVICE_ONLY__
// Hash is not supported on DEVICE. Just return 0 here.
(void)A;
return 0;
#else
// getSyclObjImpl() here returns a pointer to LocalAccessorImplHost.
auto AccImplPtr = sycl::detail::getSyclObjImpl(A);
return hash<decltype(AccImplPtr)>()(AccImplPtr);
#endif
}
};

} // namespace std
struct std::hash<sycl::local_accessor<DataT, Dimensions>>
: public sycl::detail::sycl_obj_hash<
sycl::local_accessor<DataT, Dimensions>,
true /*UnsupportedOnDevice*/> {};
67 changes: 17 additions & 50 deletions sycl/include/sycl/accessor_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,62 +1357,29 @@ class __SYCL_EBO host_sampled_image_accessor
} // namespace _V1
} // namespace sycl

namespace std {
template <typename DataT, int Dimensions, sycl::access_mode AccessMode,
sycl::image_target AccessTarget>
struct hash<sycl::unsampled_image_accessor<DataT, Dimensions, AccessMode,
AccessTarget>> {
using AccType = sycl::unsampled_image_accessor<DataT, Dimensions, AccessMode,
AccessTarget>;

size_t operator()(const AccType &A) const {
#ifdef __SYCL_DEVICE_ONLY__
// Hash is not supported on DEVICE. Just return 0 here.
(void)A;
return 0;
#else
auto AccImplPtr = sycl::detail::getSyclObjImpl(A);
return hash<decltype(AccImplPtr)>()(AccImplPtr);
#endif
}
};
struct std::hash<
sycl::unsampled_image_accessor<DataT, Dimensions, AccessMode, AccessTarget>>
: public sycl::detail::sycl_obj_hash<
sycl::unsampled_image_accessor<DataT, Dimensions, AccessMode,
AccessTarget>,
true /*UnsupportedOnDevice*/> {};

template <typename DataT, int Dimensions, sycl::access_mode AccessMode>
struct hash<
sycl::host_unsampled_image_accessor<DataT, Dimensions, AccessMode>> {
using AccType =
sycl::host_unsampled_image_accessor<DataT, Dimensions, AccessMode>;

size_t operator()(const AccType &A) const {
auto AccImplPtr = sycl::detail::getSyclObjImpl(A);
return hash<decltype(AccImplPtr)>()(AccImplPtr);
}
struct std::hash<
sycl::host_unsampled_image_accessor<DataT, Dimensions, AccessMode>>
: public sycl::detail::sycl_obj_hash<
sycl::host_unsampled_image_accessor<DataT, Dimensions, AccessMode>> {
};

template <typename DataT, int Dimensions, sycl::image_target AccessTarget>
struct hash<sycl::sampled_image_accessor<DataT, Dimensions, AccessTarget>> {
using AccType = sycl::sampled_image_accessor<DataT, Dimensions, AccessTarget>;

size_t operator()(const AccType &A) const {
#ifdef __SYCL_DEVICE_ONLY__
// Hash is not supported on DEVICE. Just return 0 here.
(void)A;
return 0;
#else
auto AccImplPtr = sycl::detail::getSyclObjImpl(A);
return hash<decltype(AccImplPtr)>()(AccImplPtr);
#endif
}
};
struct std::hash<sycl::sampled_image_accessor<DataT, Dimensions, AccessTarget>>
: public sycl::detail::sycl_obj_hash<
sycl::sampled_image_accessor<DataT, Dimensions, AccessTarget>,
true /*UnsupportedOnDevice*/> {};

template <typename DataT, int Dimensions>
struct hash<sycl::host_sampled_image_accessor<DataT, Dimensions>> {
using AccType = sycl::host_sampled_image_accessor<DataT, Dimensions>;

size_t operator()(const AccType &A) const {
auto AccImplPtr = sycl::detail::getSyclObjImpl(A);
return hash<decltype(AccImplPtr)>()(AccImplPtr);
}
};

} // namespace std
struct std::hash<sycl::host_sampled_image_accessor<DataT, Dimensions>>
: public sycl::detail::sycl_obj_hash<
sycl::host_sampled_image_accessor<DataT, Dimensions>> {};
11 changes: 3 additions & 8 deletions sycl/include/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,12 +863,7 @@ buffer(const T *, const range<dimensions> &,
} // namespace _V1
} // namespace sycl

namespace std {
template <typename T, int dimensions, typename AllocatorT>
struct hash<sycl::buffer<T, dimensions, AllocatorT>> {
size_t operator()(const sycl::buffer<T, dimensions, AllocatorT> &b) const {
return hash<std::shared_ptr<sycl::detail::buffer_impl>>()(
sycl::detail::getSyclObjImpl(b));
}
};
} // namespace std
struct std::hash<sycl::buffer<T, dimensions, AllocatorT>>
: public sycl::detail::sycl_obj_hash<
sycl::buffer<T, dimensions, AllocatorT>> {};
11 changes: 3 additions & 8 deletions sycl/include/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ inline exception::exception(context Ctx, int EV,
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::context> {
size_t operator()(const sycl::context &Context) const {
return hash<std::shared_ptr<sycl::detail::context_impl>>()(
sycl::detail::getSyclObjImpl(Context));
}
};
} // namespace std
template <>
struct std::hash<sycl::context>
: public sycl::detail::sycl_obj_hash<sycl::context> {};
18 changes: 18 additions & 0 deletions sycl/include/sycl/detail/impl_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <cassert> // for assert
#include <functional> // for hash
#include <type_traits> // for add_pointer_t
#include <utility> // for forward

Expand Down Expand Up @@ -58,6 +59,23 @@ T createSyclObjFromImpl(
return createSyclObjFromImpl<T>(ImplRef.shared_from_this());
}

template <typename T, bool UnsupportedOnDevice = false> struct sycl_obj_hash {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider bool SupportedOnDevice = true, instead of double negation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm optimizing for the readability on the invocation here. IMO,

template std::hash<type> : sycl_obj_has<type, true /* UnsupportedOnDevice */> {}

reads better. @intel/llvm-reviewers-runtime , is there anybody who prefers @slawekptak's version more?

size_t operator()(const T &Obj) const {
if constexpr (UnsupportedOnDevice) {
#ifdef __SYCL_DEVICE_ONLY__
(void)Obj;
return 0;
#else
auto &Impl = sycl::detail::getSyclObjImpl(Obj);
return std::hash<std::decay_t<decltype(Impl)>>{}(Impl);
#endif
} else {
auto &Impl = sycl::detail::getSyclObjImpl(Obj);
return std::hash<std::decay_t<decltype(Impl)>>{}(Impl);
}
}
};

} // namespace detail
} // namespace _V1
} // namespace sycl
11 changes: 3 additions & 8 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,6 @@ class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::device> {
size_t operator()(const sycl::device &Device) const {
return hash<std::shared_ptr<sycl::detail::device_impl>>()(
sycl::detail::getSyclObjImpl(Device));
}
};
} // namespace std
template <>
struct std::hash<sycl::device>
: public sycl::detail::sycl_obj_hash<sycl::device> {};
11 changes: 3 additions & 8 deletions sycl/include/sycl/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::event> {
size_t operator()(const sycl::event &e) const {
return hash<std::shared_ptr<sycl::detail::event_impl>>()(
sycl::detail::getSyclObjImpl(e));
}
};
} // namespace std
template <>
struct std::hash<sycl::event>
: public sycl::detail::sycl_obj_hash<sycl::event> {};
14 changes: 4 additions & 10 deletions sycl/include/sycl/ext/oneapi/bindless_images_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,7 @@ enum class image_memory_handle_type : unsigned int {
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::ext::oneapi::experimental::image_mem> {
size_t operator()(
const sycl::ext::oneapi::experimental::image_mem &image_mem) const {
return hash<std::shared_ptr<
sycl::ext::oneapi::experimental::detail::image_mem_impl>>()(
sycl::detail::getSyclObjImpl(image_mem));
}
};
} // namespace std
template <>
struct std::hash<sycl::ext::oneapi::experimental::image_mem>
: public sycl::detail::sycl_obj_hash<
sycl::ext::oneapi::experimental::image_mem> {};
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ class __SYCL_EXPORT memory_pool {
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::ext::oneapi::experimental::memory_pool> {
size_t operator()(
const sycl::ext::oneapi::experimental::memory_pool &mem_pool) const {
return hash<std::shared_ptr<
sycl::ext::oneapi::experimental::detail::memory_pool_impl>>()(
sycl::detail::getSyclObjImpl(mem_pool));
}
};
} // namespace std
template <>
struct std::hash<sycl::ext::oneapi::experimental::memory_pool>
: public sycl::detail::sycl_obj_hash<
sycl::ext::oneapi::experimental::memory_pool> {};
13 changes: 4 additions & 9 deletions sycl/include/sycl/ext/oneapi/virtual_mem/physical_mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ class __SYCL_EXPORT physical_mem
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::ext::oneapi::experimental::physical_mem> {
size_t operator()(
const sycl::ext::oneapi::experimental::physical_mem &PhysicalMem) const {
return hash<std::shared_ptr<sycl::detail::physical_mem_impl>>()(
sycl::detail::getSyclObjImpl(PhysicalMem));
}
};
} // namespace std
template <>
struct std::hash<sycl::ext::oneapi::experimental::physical_mem>
: public sycl::detail::sycl_obj_hash<
sycl::ext::oneapi::experimental::physical_mem> {};
29 changes: 8 additions & 21 deletions sycl/include/sycl/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,30 +1160,17 @@ class sampled_image
} // namespace _V1
} // namespace sycl

namespace std {
template <int Dimensions, typename AllocatorT>
struct hash<sycl::image<Dimensions, AllocatorT>> {
size_t operator()(const sycl::image<Dimensions, AllocatorT> &I) const {
return hash<std::shared_ptr<sycl::detail::image_impl>>()(
sycl::detail::getSyclObjImpl(I));
}
struct std::hash<sycl::image<Dimensions, AllocatorT>>
: public sycl::detail::sycl_obj_hash<sycl::image<Dimensions, AllocatorT>> {
};

template <int Dimensions, typename AllocatorT>
struct hash<sycl::unsampled_image<Dimensions, AllocatorT>> {
size_t
operator()(const sycl::unsampled_image<Dimensions, AllocatorT> &I) const {
return hash<std::shared_ptr<sycl::detail::image_impl>>()(
sycl::detail::getSyclObjImpl(I));
}
};
struct std::hash<sycl::unsampled_image<Dimensions, AllocatorT>>
: public sycl::detail::sycl_obj_hash<
sycl::unsampled_image<Dimensions, AllocatorT>> {};

template <int Dimensions, typename AllocatorT>
struct hash<sycl::sampled_image<Dimensions, AllocatorT>> {
size_t
operator()(const sycl::sampled_image<Dimensions, AllocatorT> &I) const {
return hash<std::shared_ptr<sycl::detail::image_impl>>()(
sycl::detail::getSyclObjImpl(I));
}
};
} // namespace std
struct std::hash<sycl::sampled_image<Dimensions, AllocatorT>>
: public sycl::detail::sycl_obj_hash<
sycl::sampled_image<Dimensions, AllocatorT>> {};
11 changes: 3 additions & 8 deletions sycl/include/sycl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,6 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase<kernel> {
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::kernel> {
size_t operator()(const sycl::kernel &Kernel) const {
return hash<std::shared_ptr<sycl::detail::kernel_impl>>()(
sycl::detail::getSyclObjImpl(Kernel));
}
};
} // namespace std
template <>
struct std::hash<sycl::kernel>
: public sycl::detail::sycl_obj_hash<sycl::kernel> {};
29 changes: 9 additions & 20 deletions sycl/include/sycl/kernel_bundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,25 +1362,14 @@ handler::get_specialization_constant() const {
} // namespace _V1
} // namespace sycl

namespace std {
template <> struct hash<sycl::kernel_id> {
size_t operator()(const sycl::kernel_id &KernelID) const {
return hash<std::shared_ptr<sycl::detail::kernel_id_impl>>()(
sycl::detail::getSyclObjImpl(KernelID));
}
};
template <>
struct std::hash<sycl::kernel_id>
: public sycl::detail::sycl_obj_hash<sycl::kernel_id> {};

template <sycl::bundle_state State> struct hash<sycl::device_image<State>> {
size_t operator()(const sycl::device_image<State> &DeviceImage) const {
return hash<std::shared_ptr<sycl::detail::device_image_impl>>()(
sycl::detail::getSyclObjImpl(DeviceImage));
}
};
template <sycl::bundle_state State>
struct std::hash<sycl::device_image<State>>
: public sycl::detail::sycl_obj_hash<sycl::device_image<State>> {};

template <sycl::bundle_state State> struct hash<sycl::kernel_bundle<State>> {
size_t operator()(const sycl::kernel_bundle<State> &KernelBundle) const {
return hash<std::shared_ptr<sycl::detail::kernel_bundle_impl>>()(
sycl::detail::getSyclObjImpl(KernelBundle));
}
};
} // namespace std
template <sycl::bundle_state State>
struct std::hash<sycl::kernel_bundle<State>>
: public sycl::detail::sycl_obj_hash<sycl::kernel_bundle<State>> {};
Loading
Loading