Skip to content

Commit

Permalink
Fix std::type_info comparison issue in Clang 17+ on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
GagaLP committed Sep 16, 2024
1 parent cee889b commit e77123a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/simsycl/sycl/kernel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,16 @@ struct std::hash<simsycl::sycl::device_image<State>>

namespace simsycl::detail {

// apple std library has a bug where type_info for the same type don't compare equal across shared libraries
const std::type_info &get_unnamed_kernel_name_type_info();

template<typename KernelName, typename KernelFunc>
inline const sycl::kernel_id kernel_id_registration_v = register_kernel(typeid(KernelName *), typeid(KernelFunc));

template<typename KernelFunc>
inline const sycl::kernel_id kernel_id_registration_v<unnamed_kernel, KernelFunc>
= register_kernel(get_unnamed_kernel_name_type_info(), typeid(KernelFunc));

template<typename KernelName, typename KernelFunc>
void register_kernel_on_static_construction() {
// ensure global const is instantiated and not optimized out
Expand Down
6 changes: 3 additions & 3 deletions src/simsycl/kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace simsycl::detail {

const std::type_info &unnamed_kernel_type = typeid(unnamed_kernel *);
const std::type_info &get_unnamed_kernel_name_type_info() { return typeid(unnamed_kernel *); }

std::string demangle_name_from_pointer_type(const std::type_info &pointer_type) {
const auto mangled = pointer_type.name();
Expand All @@ -26,7 +26,7 @@ std::string demangle_name_from_pointer_type(const std::type_info &pointer_type)
}

std::string get_kernel_name_string(const std::type_info &pointer_to_name_type) {
if(pointer_to_name_type == unnamed_kernel_type) {
if(pointer_to_name_type == get_unnamed_kernel_name_type_info()) {
return "(unnamed kernel)";
} else {
return demangle_name_from_pointer_type(pointer_to_name_type);
Expand Down Expand Up @@ -57,7 +57,7 @@ sycl::kernel_id register_kernel(const std::type_info &pointer_to_name_type, cons
#if SIMSYCL_CHECK_MODE != SIMSYCL_CHECK_NONE
for(const auto &existing_id : get_registered_kernels()) {
const auto &existing_name_type = existing_id.state().pointer_to_name_type;
if(existing_name_type != unnamed_kernel_type) {
if(existing_name_type != get_unnamed_kernel_name_type_info()) {
SIMSYCL_CHECK_MSG(
existing_name_type != pointer_to_name_type, "kernel name %s not unique", kernel_id.get_name());
}
Expand Down

0 comments on commit e77123a

Please sign in to comment.