Skip to content

Commit 29d27d7

Browse files
authored
Make sure ext_oneapi_get_default_context doesn't broke runtime on windows (#2742)
Part of #2478 (to reduce diff) These are quite stable changes, we can merge it without CI on Windows. @gshimansky if you don't mind. --------- Signed-off-by: Anatoly Myachev <[email protected]>
1 parent cc1d4c5 commit 29d27d7

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

third_party/intel/backend/driver.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ struct BuildFlags {
166166
}
167167
};
168168

169+
sycl::context get_default_context(const sycl::device &sycl_device) {
170+
const auto &platform = sycl_device.get_platform();
171+
#ifdef WIN32
172+
sycl::context ctx;
173+
try {
174+
ctx = platform.ext_oneapi_get_default_context();
175+
} catch (const std::runtime_error &ex) {
176+
// This exception is thrown on Windows because
177+
// ext_oneapi_get_default_context is not implemented. But it can be safely
178+
// ignored it seems.
179+
#if _DEBUG
180+
std::cout << "ERROR: " << ex.what() << std::endl;
181+
#endif
182+
}
183+
return ctx;
184+
#else
185+
return platform.ext_oneapi_get_default_context();
186+
#endif
187+
}
188+
169189
static PyObject *loadBinary(PyObject *self, PyObject *args) {
170190
const char *name, *build_flags_ptr;
171191
int shared;
@@ -194,8 +214,7 @@ static PyObject *loadBinary(PyObject *self, PyObject *args) {
194214
const size_t binary_size = PyBytes_Size(py_bytes);
195215

196216
uint8_t *binary_ptr = (uint8_t *)PyBytes_AsString(py_bytes);
197-
const auto ctx =
198-
sycl_device.get_platform().ext_oneapi_get_default_context();
217+
const auto &ctx = get_default_context(sycl_device);
199218
const auto l0_device =
200219
sycl::get_native<sycl::backend::ext_oneapi_level_zero>(sycl_device);
201220
const auto l0_context =

utils/SPIRVRunner/SPIRVRunner.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ static inline T checkSyclErrors(const std::tuple<T, ze_result_t> tuple) {
122122
return std::get<0>(tuple);
123123
}
124124

125+
sycl::context get_default_context(const sycl::device &sycl_device) {
126+
const auto &platform = sycl_device.get_platform();
127+
#ifdef WIN32
128+
sycl::context ctx;
129+
try {
130+
ctx = platform.ext_oneapi_get_default_context();
131+
} catch (const std::runtime_error &ex) {
132+
// This exception is thrown on Windows because
133+
// ext_oneapi_get_default_context is not implemented. But it can be safely
134+
// ignored it seems.
135+
#if _DEBUG
136+
std::cout << "ERROR: " << ex.what() << std::endl;
137+
#endif
138+
}
139+
return ctx;
140+
#else
141+
return platform.ext_oneapi_get_default_context();
142+
#endif
143+
}
144+
125145
/** SYCL Functions **/
126146
std::tuple<sycl::kernel_bundle<sycl::bundle_state::executable>, sycl::kernel,
127147
int32_t, int32_t>
@@ -138,7 +158,8 @@ loadBinary(const std::string &kernel_name, const std::string &build_flags,
138158
const auto &sycl_l0_device_pair = g_sycl_l0_device_list[deviceId];
139159
const sycl::device sycl_device = sycl_l0_device_pair.first;
140160

141-
const auto ctx = sycl_device.get_platform().ext_oneapi_get_default_context();
161+
const auto &ctx = get_default_context(sycl_device);
162+
142163
const auto l0_device =
143164
sycl::get_native<sycl::backend::ext_oneapi_level_zero>(sycl_device);
144165
const auto l0_context =

0 commit comments

Comments
 (0)