-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] No nullptr program_impl (#13155)
The `kernel_impl` has been storing a `program_impl` pointer. But none of the users of the `kernel_impl` need that, they just need the `PIProgram` . Conversely, some of the callers constructing `kernel_impl` don't have a `program_impl` ptr and so we were using nullptr, which leads to crashes in some simple use cases. Replacing the `program_impl` ptr with a `PIProgram` member var instead and ensuring that all callers provide one, with the least amount of change to the `kernel_impl` interface. Simple test added as well - it crashes without this PR.
- Loading branch information
1 parent
838198d
commit 9f296d8
Showing
6 changed files
with
92 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// This test finds a known kernel and runs it. | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
using namespace sycl; | ||
|
||
// Kernel finder | ||
class KernelFinder { | ||
queue &Queue; | ||
std::vector<sycl::kernel_id> AllKernelIDs; | ||
|
||
public: | ||
KernelFinder(queue &Q) : Queue(Q) { | ||
// Obtain kernel bundle | ||
kernel_bundle Bundle = | ||
get_kernel_bundle<bundle_state::executable>(Queue.get_context()); | ||
std::cout << "Bundle obtained\n"; | ||
AllKernelIDs = sycl::get_kernel_ids(); | ||
std::cout << "Number of kernels = " << AllKernelIDs.size() << std::endl; | ||
for (auto K : AllKernelIDs) { | ||
std::cout << "Kernel obtained: " << K.get_name() << std::endl; | ||
} | ||
} | ||
|
||
kernel get_kernel(const char *name) { | ||
kernel_bundle Bundle = | ||
get_kernel_bundle<bundle_state::executable>(Queue.get_context()); | ||
for (auto K : AllKernelIDs) { | ||
auto Kname = K.get_name(); | ||
if (strcmp(name, Kname) == 0) { | ||
kernel Kernel = Bundle.get_kernel(K); | ||
std::cout << "Found kernel\n"; | ||
return Kernel; | ||
} | ||
} | ||
std::cout << "No kernel found\n"; | ||
exit(1); | ||
} | ||
}; | ||
|
||
void sycl_kernel(queue Queue) { | ||
range<1> R1{1}; | ||
Queue.submit([&](handler &CGH) { | ||
CGH.parallel_for<class KernelB>(R1, [=](id<1> WIid) {}); | ||
}); | ||
Queue.wait(); | ||
} | ||
|
||
int test_sycl_kernel(queue Queue) { | ||
KernelFinder KF(Queue); | ||
|
||
kernel Kernel = KF.get_kernel("_ZTSZZ11sycl_kernelN4sycl3_V15queueEENKUlRNS0_" | ||
"7handlerEE_clES3_E7KernelB"); | ||
|
||
range<1> R1{1}; | ||
Queue.submit([&](handler &Handler) { Handler.parallel_for(R1, Kernel); }); | ||
Queue.wait(); | ||
|
||
return 0; | ||
} | ||
|
||
int main() { | ||
queue Queue; | ||
|
||
sycl_kernel(Queue); | ||
std::cout << "sycl_kernel done\n"; | ||
test_sycl_kernel(Queue); | ||
std::cout << "test_sycl_kernel done\n"; | ||
|
||
return 0; | ||
} |