Skip to content

Commit b0ad586

Browse files
committed
dont throw exception
1 parent 1346c62 commit b0ad586

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

sycl/source/platform.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ platform::get_backend_info() const {
8787

8888
#undef __SYCL_PARAM_TRAITS_SPEC
8989

90-
context platform::khr_get_default_context() const {
91-
if (!detail::SYCLConfig<detail::SYCL_ENABLE_DEFAULT_CONTEXTS>::get())
92-
throw std::runtime_error("SYCL default contexts are not enabled");
93-
90+
namespace detail {
91+
context get_default_context() {
9492
// Keeping the default context for platforms in the global cache to avoid
9593
// shared_ptr based circular dependency between platform and context classes
9694
std::unordered_map<detail::PlatformImplPtr, detail::ContextImplPtr>
@@ -108,9 +106,17 @@ context platform::khr_get_default_context() const {
108106

109107
return detail::createSyclObjFromImpl<context>(It->second);
110108
}
109+
} // namespace detail
110+
111+
context platform::khr_get_default_context() const {
112+
return detail::get_default_context();
113+
}
111114

112115
context platform::ext_oneapi_get_default_context() const {
113-
return khr_get_default_context();
116+
if (!detail::SYCLConfig<detail::SYCL_ENABLE_DEFAULT_CONTEXTS>::get())
117+
throw std::runtime_error("SYCL default contexts are not enabled");
118+
119+
return detail::get_default_context();
114120
}
115121

116122
std::vector<device> platform::ext_oneapi_get_composite_devices() const {

sycl/unittests/Extensions/DefaultContext.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,6 @@ void test_default_context_disabled() {
5454

5555
ASSERT_TRUE(catchException)
5656
<< "ext_oneapi_get_default_context did not throw an exception";
57-
58-
catchException = false;
59-
try {
60-
(void)Plt.khr_get_default_context();
61-
} catch (const std::exception &) {
62-
catchException = true;
63-
}
64-
65-
ASSERT_TRUE(catchException)
66-
<< "khr_get_default_context did not throw an exception";
6757
}
6858

6959
TEST(DefaultContextTest, DefaultContextTest) {

0 commit comments

Comments
 (0)