Skip to content

[SYCL] Avoid referencing deprecated sycl::runtime_error in tests #14489

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 1 commit into from
Jul 9, 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
2 changes: 1 addition & 1 deletion sycl/test-e2e/Config/device_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main() {
RejectEverything Selector;
try {
sycl::device Device(Selector);
} catch (sycl::runtime_error &E) {
} catch (sycl::exception &) {
return 0;
}
std::cerr << "Error. A device is found." << std::endl;
Expand Down
9 changes: 6 additions & 3 deletions sycl/test-e2e/FilterSelector/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ int main() {
try {
// pick something crazy
device d9(filter_selector("gpu:999"));
} catch (const sycl::runtime_error &e) {
} catch (const sycl::exception &e) {
assert(e.code() == sycl::errc::runtime);
const char *ErrorMesg =
"Could not find a device that matches the specified filter(s)!";
assert(std::string{e.what()}.find(ErrorMesg) == 0 &&
Expand All @@ -114,7 +115,8 @@ int main() {
try {
// pick something crazy
device d10(filter_selector("bob:gpu"));
} catch (const sycl::runtime_error &e) {
} catch (const sycl::exception &e) {
assert(e.code() == sycl::errc::runtime);
const char *ErrorMesg = "Invalid filter string!";
assert(std::string{e.what()}.find(ErrorMesg) == 0 &&
"filter_selector(\"bob:gpu\") unexpectedly selected a device");
Expand All @@ -123,7 +125,8 @@ int main() {
try {
// pick something crazy
device d11(filter_selector("opencl:bob"));
} catch (const sycl::runtime_error &e) {
} catch (const sycl::exception &e) {
assert(e.code() == sycl::errc::runtime);
const char *ErrorMesg = "Invalid filter string!";
assert(std::string{e.what()}.find(ErrorMesg) == 0 &&
"filter_selector(\"opencl:bob\") unexpectedly selected a device");
Expand Down
16 changes: 5 additions & 11 deletions sycl/test-e2e/HostInteropTask/interop-task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
int RC = clEnqueueCopyBuffer(NativeQ, SrcMem[0], DstMem[0], 0, 0,
sizeof(DataT) * SrcA.get_count(), 0, nullptr,
&Event);
if (RC != CL_SUCCESS)
throw runtime_error("Can't enqueue buffer copy", RC);
assert(RC == CL_SUCCESS);

RC = clWaitForEvents(1, &Event);
assert(RC == CL_SUCCESS);

if (RC != CL_SUCCESS)
throw runtime_error("Can't wait for event on buffer copy", RC);

if (Q.get_backend() != IH.get_backend())
throw runtime_error(
"interop_handle::get_backend() returned a wrong value",
CL_INVALID_VALUE);
assert(Q.get_backend() == IH.get_backend() &&
"interop_handle::get_backend() returned a wrong value");
};
CGH.host_task(Func);
});
Expand Down Expand Up @@ -172,8 +167,7 @@ void test3(queue &Q) {
std::vector<cl_event> Ev = get_native<backend::opencl>(Event);

int RC = clWaitForEvents(1, Ev.data());
if (RC != CL_SUCCESS)
throw runtime_error("Can't wait for events", RC);
assert(RC == CL_SUCCESS);
};
CGH.host_task(Func);
});
Expand Down
6 changes: 2 additions & 4 deletions sycl/test-e2e/OnlineCompiler/online_compiler_L0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ sycl::kernel getSYCLKernelWithIL(sycl::queue &Queue,
ze_module_handle_t ZeModule;
ze_result_t ZeResult = zeModuleCreate(ZeContext, ZeDevice, &ZeModuleDesc,
&ZeModule, &ZeBuildLog);
if (ZeResult != ZE_RESULT_SUCCESS)
throw sycl::runtime_error();
assert(ZeResult == ZE_RESULT_SUCCESS);

ze_kernel_handle_t ZeKernel = nullptr;

ze_kernel_desc_t ZeKernelDesc{ZE_STRUCTURE_TYPE_KERNEL_DESC, nullptr, 0,
"my_kernel"};
ZeResult = zeKernelCreate(ZeModule, &ZeKernelDesc, &ZeKernel);
if (ZeResult != ZE_RESULT_SUCCESS)
throw sycl::runtime_error();
assert(ZeResult == ZE_RESULT_SUCCESS);
sycl::kernel_bundle<sycl::bundle_state::executable> SyclKB =
sycl::make_kernel_bundle<sycl::backend::ext_oneapi_level_zero,
sycl::bundle_state::executable>(
Expand Down
9 changes: 3 additions & 6 deletions sycl/test-e2e/OnlineCompiler/online_compiler_OpenCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ sycl::kernel getSYCLKernelWithIL(sycl::queue &Queue,
cl_program ClProgram =
clCreateProgramWithIL(sycl::get_native<sycl::backend::opencl>(Context),
IL.data(), IL.size(), &Err);
if (Err != CL_SUCCESS)
throw sycl::runtime_error("clCreateProgramWithIL() failed", Err);
assert(Err == CL_SUCCESS);

Err = clBuildProgram(ClProgram, 0, nullptr, nullptr, nullptr, nullptr);
if (Err != CL_SUCCESS)
throw sycl::runtime_error("clBuildProgram() failed", Err);
assert(Err == CL_SUCCESS);

cl_kernel ClKernel = clCreateKernel(ClProgram, "my_kernel", &Err);
if (Err != CL_SUCCESS)
throw sycl::runtime_error("clCreateKernel() failed", Err);
assert(Err == CL_SUCCESS);

return sycl::make_kernel<sycl::backend::opencl>(ClKernel, Context);
}
Expand Down
4 changes: 2 additions & 2 deletions sycl/unittests/Extensions/DefaultContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ void test_default_context_disabled() {
bool catchException = false;
try {
(void)Plt.ext_oneapi_get_default_context();
} catch (const std::runtime_error &) {
} catch (const std::exception &) {
catchException = true;
}

ASSERT_TRUE(catchException)
<< "ext_oneapi_get_default_context did not throw and exception";
<< "ext_oneapi_get_default_context did not throw an exception";
}

TEST(DefaultContextTest, DefaultContextTest) {
Expand Down
7 changes: 4 additions & 3 deletions sycl/unittests/SYCL2020/KernelID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ TEST(KernelID, GetKernelIDInvalidKernelName) {

try {
sycl::get_kernel_id<class NotAKernel>();
throw std::logic_error("sycl::runtime_error didn't throw");
} catch (sycl::runtime_error const &e) {
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_TRUE(e.code() == sycl::errc::runtime);
EXPECT_EQ(std::string("No kernel found with the specified name -46 "
"(PI_ERROR_INVALID_KERNEL_NAME)"),
e.what());
} catch (...) {
FAIL() << "Expected sycl::runtime_error";
FAIL() << "Expected sycl::exception";
}
}
20 changes: 10 additions & 10 deletions sycl/unittests/allowlist/ParseAllowList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TEST(ParseAllowListTests, CheckUnsupportedKeyNameIsHandledInSingleDeviceDesc) {
try {
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
"BackendName:level_zero,SomeUnsupportedKey:gpu");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
Expand All @@ -66,7 +66,7 @@ TEST(
try {
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
"DriverVersion:{{value}}|SomeUnsupportedKey:gpu");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
Expand All @@ -85,7 +85,7 @@ TEST(
try {
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
"BackendName:level_zero|SomeUnsupportedKey:gpu");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
Expand All @@ -103,7 +103,7 @@ TEST(ParseAllowListTests,
try {
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
"DriverVersion:{{value1}}|SomeUnsupportedKey:{{value2}}");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
Expand Down Expand Up @@ -131,7 +131,7 @@ TEST(ParseAllowListTests, CheckMissingOpenDoubleCurlyBracesAreHandled) {
try {
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
"DeviceName:regex1}},DriverVersion:{{regex1|regex2}}");
throw std::logic_error("sycl::exception didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(std::string("Key DeviceName of SYCL_DEVICE_ALLOWLIST "
"should have value which starts with {{ -30 "
Expand All @@ -146,7 +146,7 @@ TEST(ParseAllowListTests, CheckMissingClosedDoubleCurlyBracesAreHandled) {
try {
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
"DeviceName:{{regex1}},DriverVersion:{{regex1|regex2");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(std::string("Key DriverVersion of SYCL_DEVICE_ALLOWLIST "
"should have value which ends with }} -30 "
Expand Down Expand Up @@ -195,7 +195,7 @@ TEST(ParseAllowListTests, CheckIncorrectBackendNameValueIsHandled) {
try {
sycl::detail::AllowListParsedT ActualValue =
sycl::detail::parseAllowList("BackendName:blablabla");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("Value blablabla for key BackendName is not valid in "
Expand All @@ -212,7 +212,7 @@ TEST(ParseAllowListTests, CheckIncorrectDeviceTypeValueIsHandled) {
try {
sycl::detail::AllowListParsedT ActualValue =
sycl::detail::parseAllowList("DeviceType:blablabla");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("Value blablabla for key DeviceType is not valid in "
Expand All @@ -229,7 +229,7 @@ TEST(ParseAllowListTests, CheckIncorrectDeviceVendorIdValueIsHandled) {
try {
sycl::detail::AllowListParsedT ActualValue =
sycl::detail::parseAllowList("DeviceVendorId:blablabla");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("Value blablabla for key DeviceVendorId is not valid in "
Expand Down Expand Up @@ -261,7 +261,7 @@ TEST(ParseAllowListTests, CheckExceptionIsThrownForValueWOColonDelim) {
try {
sycl::detail::AllowListParsedT ActualValue =
sycl::detail::parseAllowList("SomeValueWOColonDelimiter");
throw std::logic_error("sycl::runtime_error didn't throw");
FAIL() << "Expected an exception";
} catch (sycl::exception const &e) {
EXPECT_EQ(
std::string("SYCL_DEVICE_ALLOWLIST has incorrect format. For "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class MockHandler : public sycl::handler {
break;
}
default:
throw sycl::runtime_error("Unhandled type of command group",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"Unhandled type of command group");
}

return CommandGroup;
Expand Down
8 changes: 4 additions & 4 deletions sycl/unittests/scheduler/SchedulerTestUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ class MockHandler : public sycl::handler {
}

std::unique_ptr<sycl::detail::CG> finalize() {
throw sycl::runtime_error("Unhandled type of command group",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"Unhandled type of command group");

return nullptr;
}
Expand Down Expand Up @@ -318,8 +318,8 @@ class MockHandlerCustomFinalize : public MockHandler {
break;
}
default:
throw sycl::runtime_error("Unhandled type of command group",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"Unhandled type of command group");
}

return CommandGroup;
Expand Down
4 changes: 2 additions & 2 deletions sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class MockHandlerStreamInit : public MockHandler {
break;
}
default:
throw sycl::runtime_error("Unhandled type of command group",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"Unhandled type of command group");
}

return CommandGroup;
Expand Down
Loading