Skip to content
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

Make sure ext_oneapi_get_default_context doesn't broke runtime on windows #2742

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions third_party/intel/backend/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,18 @@ static PyObject *loadBinary(PyObject *self, PyObject *args) {
const size_t binary_size = PyBytes_Size(py_bytes);

uint8_t *binary_ptr = (uint8_t *)PyBytes_AsString(py_bytes);
const auto ctx =
sycl_device.get_platform().ext_oneapi_get_default_context();
auto platform = sycl_device.get_platform();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have exceptions in this code block - but I suppose I might feel better if this was in a free function that had compile time definitions for windows (where we need the exception handling) and linux (where we don't).

Also, how can the code properly run with no valid context? What if a valid context is thrown on linux?

(I realize I probably approved the Windows PR that has this change but missed the details over there - maybe we should split some other changes out of the Windows PR for a more thorough individual review).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Also, how can the code properly run with no valid context?

This is a explanation for Windows case: https://github.com/intel/intel-xpu-backend-for-triton/pull/2478/files#r1844125901

sycl::context ctx;
try {
ctx = platform.ext_oneapi_get_default_context();
} catch (const std::runtime_error &ex) {
// This exception is thrown on Windows because
// ext_oneapi_get_default_context is not implemented. But it can be safely
// ignored it seems.
#if _DEBUG
std::cout << "ERROR: " << ex.what() << std::endl;
#endif
}
const auto l0_device =
sycl::get_native<sycl::backend::ext_oneapi_level_zero>(sycl_device);
const auto l0_context =
Expand Down
13 changes: 12 additions & 1 deletion utils/SPIRVRunner/SPIRVRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ loadBinary(const std::string &kernel_name, const std::string &build_flags,
const auto &sycl_l0_device_pair = g_sycl_l0_device_list[deviceId];
const sycl::device sycl_device = sycl_l0_device_pair.first;

const auto ctx = sycl_device.get_platform().ext_oneapi_get_default_context();
auto platform = sycl_device.get_platform();
sycl::context ctx;
try {
ctx = platform.ext_oneapi_get_default_context();
} catch (const std::runtime_error &ex) {
// This exception is thrown on Windows because
// ext_oneapi_get_default_context is not implemented. But it can be safely
// ignored it seems.
#if _DEBUG
std::cout << "ERROR: " << ex.what() << std::endl;
#endif
}
const auto l0_device =
sycl::get_native<sycl::backend::ext_oneapi_level_zero>(sycl_device);
const auto l0_context =
Expand Down