Skip to content

[SYCL] Fix unintentional vtable ABI break in HostKernelBase #15310

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

Merged
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
16 changes: 8 additions & 8 deletions sycl/include/sycl/detail/cg_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ runKernelWithArg(KernelType KernelName, ArgType Arg) {
// The pure virtual class aimed to store lambda/functors of any type.
class HostKernelBase {
public:
// NOTE: InstatitateKernelOnHost() should not be called.
virtual void InstatitateKernelOnHost() = 0;
// Return pointer to the lambda object.
// Used to extract captured variables.
virtual char *getPtr() = 0;
virtual ~HostKernelBase() = default;
// NOTE: InstatiateKernelOnHost() should not be called.
virtual void InstantiateKernelOnHost() = 0;
};

// Class which stores specific lambda object.
Expand All @@ -174,11 +174,15 @@ class HostKernel : public HostKernelBase {
public:
HostKernel(KernelType Kernel) : MKernel(Kernel) {}

char *getPtr() override { return reinterpret_cast<char *>(&MKernel); }

~HostKernel() = default;

// This function is needed for host-side compilation to keep kernels
// instantitated. This is important for debuggers to be able to associate
// kernel code instructions with source code lines.
// NOTE: InstatitateKernelOnHost() should not be called.
void InstatitateKernelOnHost() override {
// NOTE: InstatiateKernelOnHost() should not be called.
void InstantiateKernelOnHost() override {
if constexpr (std::is_same_v<KernelArgType, void>) {
runKernelWithoutArg(MKernel);
} else if constexpr (std::is_same_v<KernelArgType, sycl::id<Dims>>) {
Expand Down Expand Up @@ -217,10 +221,6 @@ class HostKernel : public HostKernelBase {
runKernelWithArg<KernelArgType>(MKernel, KernelArgType{});
}
}

char *getPtr() override { return reinterpret_cast<char *>(&MKernel); }

~HostKernel() = default;
};

} // namespace detail
Expand Down
10 changes: 5 additions & 5 deletions sycl/test/abi/vtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
// Guide for further instructions.

void foo(sycl::detail::HostKernelBase &HKB) {
HKB.InstatitateKernelOnHost();
HKB.InstantiateKernelOnHost();
}
// CHECK: Vtable for 'sycl::detail::HostKernelBase' (6 entries).
// CHECK-NEXT: 0 | offset_to_top (0)
// CHECK-NEXT: 1 | sycl::detail::HostKernelBase RTTI
// CHECK-NEXT: -- (sycl::detail::HostKernelBase, 0) vtable address --
// CHECK-NEXT: 2 | void sycl::detail::HostKernelBase::InstatitateKernelOnHost() [pure]
// CHECK-NEXT: 3 | char *sycl::detail::HostKernelBase::getPtr() [pure]
// CHECK-NEXT: 4 | sycl::detail::HostKernelBase::~HostKernelBase() [complete]
// CHECK-NEXT: 5 | sycl::detail::HostKernelBase::~HostKernelBase() [deleting]
// CHECK-NEXT: 2 | char *sycl::detail::HostKernelBase::getPtr() [pure]
// CHECK-NEXT: 3 | sycl::detail::HostKernelBase::~HostKernelBase() [complete]
// CHECK-NEXT: 4 | sycl::detail::HostKernelBase::~HostKernelBase() [deleting]
// CHECK-NEXT: 5 | void sycl::detail::HostKernelBase::InstantiateKernelOnHost() [pure]

void foo(sycl::detail::PropertyWithDataBase *Prop) { delete Prop; }
// CHECK: Vtable for 'sycl::detail::PropertyWithDataBase' (4 entries).
Expand Down
Loading