-
Notifications
You must be signed in to change notification settings - Fork 124
[DeviceSanitizer] Fix interceptor destruction order #1879
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
Changes from all commits
df5fd8b
6449148
ae7dea6
9e6923f
56ed0b8
5859e3c
982667e
d67cfec
fbecf2a
250f759
864da64
3e3bd51
e264cc1
74d30dc
fe18b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,38 @@ ur_result_t setupContext(ur_context_handle_t Context, uint32_t numDevices, | |
|
|
||
| } // namespace | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| /// @brief Intercept function for urAdapterGet | ||
| __urdlllocal ur_result_t UR_APICALL urAdapterGet( | ||
| uint32_t | ||
| NumEntries, ///< [in] the number of adapters to be added to phAdapters. | ||
| ///< If phAdapters is not NULL, then NumEntries should be greater than | ||
| ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, | ||
| ///< will be returned. | ||
| ur_adapter_handle_t * | ||
| phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. | ||
| ///< If NumEntries is less than the number of adapters available, then | ||
| ///< ::urAdapterGet shall only retrieve that number of platforms. | ||
| uint32_t * | ||
| pNumAdapters ///< [out][optional] returns the total number of adapters available. | ||
| ) { | ||
| auto pfnAdapterGet = getContext()->urDdiTable.Global.pfnAdapterGet; | ||
|
|
||
| if (nullptr == pfnAdapterGet) { | ||
| return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; | ||
| } | ||
|
|
||
| ur_result_t result = pfnAdapterGet(NumEntries, phAdapters, pNumAdapters); | ||
| if (result == UR_RESULT_SUCCESS && phAdapters) { | ||
| const uint32_t NumAdapters = pNumAdapters ? *pNumAdapters : NumEntries; | ||
| for (uint32_t i = 0; i < NumAdapters; ++i) { | ||
| UR_CALL(getContext()->interceptor->holdAdapter(phAdapters[i])); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we needn't hold the handle of adapter, it seems ur loader has already hold this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. every time you call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| /// @brief Intercept function for urUSMHostAlloc | ||
| __urdlllocal ur_result_t UR_APICALL urUSMHostAlloc( | ||
|
|
@@ -1324,6 +1356,36 @@ __urdlllocal ur_result_t UR_APICALL urKernelSetArgPointer( | |
| return result; | ||
| } | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| /// @brief Exported function for filling application's Global table | ||
| /// with current process' addresses | ||
| /// | ||
| /// @returns | ||
| /// - ::UR_RESULT_SUCCESS | ||
| /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER | ||
| /// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION | ||
| __urdlllocal ur_result_t UR_APICALL urGetGlobalProcAddrTable( | ||
| ur_api_version_t version, ///< [in] API version requested | ||
| ur_global_dditable_t | ||
| *pDdiTable ///< [in,out] pointer to table of DDI function pointers | ||
| ) { | ||
| if (nullptr == pDdiTable) { | ||
| return UR_RESULT_ERROR_INVALID_NULL_POINTER; | ||
| } | ||
|
|
||
| if (UR_MAJOR_VERSION(ur_sanitizer_layer::getContext()->version) != | ||
| UR_MAJOR_VERSION(version) || | ||
| UR_MINOR_VERSION(ur_sanitizer_layer::getContext()->version) > | ||
| UR_MINOR_VERSION(version)) { | ||
| return UR_RESULT_ERROR_UNSUPPORTED_VERSION; | ||
| } | ||
|
|
||
| ur_result_t result = UR_RESULT_SUCCESS; | ||
|
|
||
| pDdiTable->pfnAdapterGet = ur_sanitizer_layer::urAdapterGet; | ||
|
|
||
| return result; | ||
| } | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| /// @brief Exported function for filling application's Context table | ||
| /// with current process' addresses | ||
|
|
@@ -1597,6 +1659,11 @@ ur_result_t context_t::init(ur_dditable_t *dditable, | |
|
|
||
| urDdiTable = *dditable; | ||
|
|
||
| if (UR_RESULT_SUCCESS == result) { | ||
| result = ur_sanitizer_layer::urGetGlobalProcAddrTable( | ||
| UR_API_VERSION_CURRENT, &dditable->Global); | ||
| } | ||
|
|
||
| if (UR_RESULT_SUCCESS == result) { | ||
| result = ur_sanitizer_layer::urGetContextProcAddrTable( | ||
| UR_API_VERSION_CURRENT, &dditable->Context); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright (C) 2023-2024 Intel Corporation | ||
| # Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| # See LICENSE.TXT | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| set(UR_SANITIZER_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| set(SAN_TEST_PREFIX sanitizer_test) | ||
|
|
||
| function(add_sanitizer_test_executable name) | ||
| add_ur_executable(${SAN_TEST_PREFIX}-${name} | ||
| ${ARGN}) | ||
| target_link_libraries(${SAN_TEST_PREFIX}-${name} | ||
| PRIVATE | ||
| ${PROJECT_NAME}::loader | ||
| ${PROJECT_NAME}::headers | ||
| ${PROJECT_NAME}::testing | ||
| ${PROJECT_NAME}::mock | ||
| GTest::gtest_main) | ||
| endfunction() | ||
|
|
||
| function(set_sanitizer_test_properties name) | ||
| set_tests_properties(${name} PROPERTIES LABELS "sanitizer") | ||
| set_property(TEST ${name} PROPERTY ENVIRONMENT | ||
| "UR_LOG_SANITIZER=level:debug\;flush:debug\;output:stdout") | ||
| endfunction() | ||
|
|
||
| function(add_sanitizer_test name) | ||
| add_sanitizer_test_executable(${name} ${ARGN}) | ||
|
|
||
| add_test(NAME ${name} | ||
| COMMAND ${SAN_TEST_PREFIX}-${name} | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
|
||
| set_sanitizer_test_properties(${name}) | ||
| endfunction() | ||
|
|
||
| add_sanitizer_test(asan asan.cpp) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * | ||
| * Copyright (C) 2024 Intel Corporation | ||
| * | ||
| * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| * See LICENSE.TXT | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| * | ||
| * @file asan.cpp | ||
| * | ||
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <ur_api.h> | ||
|
|
||
| TEST(DeviceAsan, Initialization) { | ||
| ur_result_t status; | ||
|
|
||
| ur_loader_config_handle_t loaderConfig; | ||
| status = urLoaderConfigCreate(&loaderConfig); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
| status = urLoaderConfigEnableLayer(loaderConfig, "UR_LAYER_ASAN"); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| status = urLoaderInit(0, loaderConfig); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| ur_adapter_handle_t adapter; | ||
| status = urAdapterGet(1, &adapter, nullptr); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| ur_platform_handle_t platform; | ||
| status = urPlatformGet(&adapter, 1, 1, &platform, nullptr); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| ur_device_handle_t device; | ||
| status = urDeviceGet(platform, UR_DEVICE_TYPE_DEFAULT, 1, &device, nullptr); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| ur_context_handle_t context; | ||
| status = urContextCreate(1, &device, nullptr, &context); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| status = urContextRelease(context); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| status = urDeviceRelease(device); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| status = urAdapterRelease(adapter); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| status = urLoaderTearDown(); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
|
|
||
| status = urLoaderConfigRelease(loaderConfig); | ||
| ASSERT_EQ(status, UR_RESULT_SUCCESS); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.