Skip to content

Commit 9dd1ea3

Browse files
[SYCL] Throw runtime error when requested kernel ID is missing (#4521)
As per the SYCL 2020 specification, a diagnostic must be issued when `get_kernel_id` is called with an unrecognized kernel name. This patch adds such a diagnostic. Signed-off-by: Steffen Larsen <steffen.larsen@intel.com>
1 parent aaab3aa commit 9dd1ea3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,10 @@ kernel_id ProgramManager::getSYCLKernelID(const std::string &KernelName) {
12621262
std::lock_guard<std::mutex> KernelIDsGuard(m_KernelIDsMutex);
12631263

12641264
auto KernelID = m_KernelIDs.find(KernelName);
1265-
assert(KernelID != m_KernelIDs.end() && "Kernel ID missing");
1265+
if (KernelID == m_KernelIDs.end())
1266+
throw runtime_error("No kernel found with the specified name",
1267+
PI_INVALID_KERNEL_NAME);
1268+
12661269
return KernelID->second;
12671270
}
12681271

sycl/unittests/SYCL2020/KernelID.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,30 @@ TEST(KernelID, KernelIDHasKernel) {
269269
EXPECT_TRUE(InputBundle7.has_kernel(TestKernel2ID));
270270
EXPECT_TRUE(InputBundle7.has_kernel(TestKernel3ID));
271271
}
272+
273+
TEST(KernelID, InvalidKernelName) {
274+
sycl::platform Plt{sycl::default_selector()};
275+
if (Plt.is_host()) {
276+
std::cout << "Test is not supported on host, skipping\n";
277+
return; // test is not supported on host.
278+
}
279+
280+
if (Plt.get_backend() == sycl::backend::cuda) {
281+
std::cout << "Test is not supported on CUDA platform, skipping\n";
282+
return;
283+
}
284+
285+
sycl::unittest::PiMock Mock{Plt};
286+
setupDefaultMockAPIs(Mock);
287+
288+
try {
289+
sycl::get_kernel_id<class NotAKernel>();
290+
throw std::logic_error("sycl::runtime_error didn't throw");
291+
} catch (sycl::runtime_error const &e) {
292+
EXPECT_EQ(std::string("No kernel found with the specified name -46 "
293+
"(CL_INVALID_KERNEL_NAME)"),
294+
e.what());
295+
} catch (...) {
296+
FAIL() << "Expected sycl::runtime_error";
297+
}
298+
}

0 commit comments

Comments
 (0)