-
Notifications
You must be signed in to change notification settings - Fork 125
[UR][layer] Add exception sanitizer layer #2216
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
Conversation
2e932e0
to
c1be939
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this was never tested :D So might be good to enable this in CI for CTS.
c1be939
to
1cf0578
Compare
f26923e
to
375ab46
Compare
Thanks have done so. I'm not sure what the failures are related to. |
375ab46
to
f5ac85b
Compare
ebc7760
to
942e682
Compare
Add basic exception sanitizer layer that will call std::abort if an exception is thrown.
And initialize UR_ENABLE_EXCEPTION_SANITIZER to OFF.
Add compile time macro and also fix typos in ur_lib.hpp.
Don't allow UR_CHECK_ERROR to be called outside of a try block.
942e682
to
dbe486a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for improving our code quality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the missing part here is actually enabling the layer in the CTS environment setup, something along the lines of this:
diff --git a/test/conformance/source/environment.cpp b/test/conformance/source/environment.cpp
index 006ea09b..737d26d2 100644
--- a/test/conformance/source/environment.cpp
+++ b/test/conformance/source/environment.cpp
@@ -90,6 +90,14 @@ uur::PlatformEnvironment::PlatformEnvironment(int argc, char **argv)
error = "Failed to enable validation layer";
return;
}
+#ifdef UR_ENABLE_EXCEPTION_SANITIZER
+ if (urLoaderConfigEnableLayer(config, "UR_LAYER_EXCEPTION_SANITIZER") !=
+ UR_RESULT_SUCCESS) {
+ urLoaderConfigRelease(config);
+ error = "Failed to enable exception sanitizer layer";
+ return;
+ }
+#endif
} else {
error = "Failed to create loader config handle";
return;
CMakeLists.txt
Outdated
@@ -43,6 +43,7 @@ option(UR_USE_TSAN "enable ThreadSanitizer" OFF) | |||
option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF) | |||
option(UR_ENABLE_SANITIZER "enable device sanitizer" ON) | |||
option(UR_ENABLE_SYMBOLIZER "enable symoblizer for sanitizer" OFF) | |||
option(UR_ENABLE_EXCEPTION_SANITIZER "enable exception sanitizer" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need a separate option, we could always enable this as part of UR_DEVELOPER_MODE
since that's enabled in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, have removed.
Co-authored-by: Kenneth Benzie (Benie) <[email protected]>
Co-authored-by: Kenneth Benzie (Benie) <[email protected]>
Interesting, how was the layer working here without this call? |
The init function of all layers gets called unconditionally, and the layer themselves need to check whether they are on the enabled list. |
Aha thanks @pbalcer that explains it |
Have updated. Should be good to go. |
bb96bde
to
56287f5
Compare
I think we should actually have a separate option to enable/disable this layer. Right now, as I understand, there is no way to disable this layer for L0 and L0 v2 adapter (other than disabling developer mode). In L0 and L0 v2, we use exceptions to propagate errors, expecting that the loader will translate them into error codes, like here: https://github.com/oneapi-src/unified-runtime/blob/main/source/adapters/level_zero/v2/kernel.cpp#L77 .There should be no abort for L0 |
My personal view of this is it's a bad idea and adapters should never allow exceptions to escape the UR entry points because it is a C API. The reason this layer was created is due to exceptions crossing that ABI boundry causing crashes. |
If so, I think we should then enforce each function in an adapter to be wrapped by try/catch (that is, move those auto-generated checks from loader: https://github.com/oneapi-src/unified-runtime/blob/main/source/loader/ur_libapi.cpp#L2422 to each adapter function). We could also consider making all functions (and ddi pointers) noexcept. This might allow compiler/coverity to complain if there is an uncaught exception. |
Since the adapters are not generated from the yaml source, that could get quite manual and annoying.
This is an interesting approach and should be much less of a burden to add to adapters. I doubt we could do that as part of the |
Well, we could also add this try/catch to urGet*ProcAddTable when creating a ddi tables in adapters (which are auto-generated). Something like this:
I belive the compiler will optimize it so there should be no additional overhead but we can verify that. |
For the static linking use case there won't be any DDI tables, this needs to happen in the adapters not in some wrapping layer. |
Okay, I see; then it's probably case by case. I will add the necessary try/catch blocks to the v2 adapter. |
Unified Runtime -> intel/llvm Repo Move NoticeInformationThe source code of Unified Runtime has been moved to intel/llvm under the unified-runtime top-level directory, The code will be mirrored to oneapi-src/unified-runtime and the specification will continue to be hosted at oneapi-src.github.io/unified-runtime. The contribution guide has been updated with new instructions for contributing to Unified Runtime. PR MigrationAll open PRs including this one will be labelled auto-close and shall be automatically closed after 30 days. Should you wish to continue with your PR you will need to migrate it to intel/llvm. This is an automated comment. |
Unified Runtime -> intel/llvm Repo Move NoticeFollowing on from the previous notice, we have now enabled workflows to automatically label and close PRs because the Unified Runtime source code has moved to intel/llvm. This PR has now been marked with the Please review the previous notice for more information, including assistance with migrating your PR to intel/llvm. Should there be a reason for this PR to remain open, manually remove the This is an automated comment. |
Automatic PR Closure NoticeInformationThis PR has been closed automatically. It was marked with the All Unified Runtime development should be done in intel/llvm, details can be found in the updated contribution guide. Next StepsShould you wish to re-open this PR it must be moved to intel/llvm. We have provided a script to help automate this process, otherwise no actions are required. This is an automated comment. |
Add basic exception sanitizer layer that will call std::abort if an exception is thrown. This layer can be used to make sure an adapter isn't throwing, which is prohibited for a C interface. The layer can be enabled by building with the option
-DUR_ENABLE_EXCEPTION_SANITIZER=ON