Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug with (real) Clang on MacOS #12

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading