Skip to content

[DevSan][Refactor] Make Options an unified class shared by all sanitizers #17157

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

Merged
Show file tree
Hide file tree
Changes from all commits
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

This file was deleted.

4 changes: 1 addition & 3 deletions sycl/test-e2e/AddressSanitizer/common/options-redzone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// clang-format off
// RUN: env UR_LOG_SANITIZER=level:debug UR_LAYER_ASAN_OPTIONS=redzone:8 %{run} %t2.out 2>&1 | FileCheck --check-prefixes CHECK-MIN %s
// RUN: env UR_LOG_SANITIZER=level:debug UR_LAYER_ASAN_OPTIONS=max_redzone:4096 %{run} %t2.out 2>&1 | FileCheck --check-prefixes CHECK-MAX %s
// clang-format on

#include <sycl/usm.hpp>
Expand All @@ -25,8 +24,7 @@ int main() {
// CHECK: ERROR: DeviceSanitizer: out-of-bounds-access on Device USM
// CHECK: {{READ of size 1 at kernel <.*Test> LID\(0, 0, 0\) GID\(0, 0, 0\)}}
// CHECK: {{ #0 .* .*options-redzone.cpp:}}[[@LINE-7]]
// CHECK-MIN: Trying to set redzone size to a value less than 16 is ignored
// CHECK-MAX: Trying to set max redzone size to a value greater than 2048 is ignored
// CHECK-MIN: The valid range of "redzone" is [16, 2048]. Setting to the minimum value 16.

sycl::free(array, q);
return 0;
Expand Down
6 changes: 2 additions & 4 deletions unified-runtime/source/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ if(UR_ENABLE_SANITIZER)
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_interceptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_interceptor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_libdevice.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_options.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_options.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_quarantine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_quarantine.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan/asan_report.cpp
Expand All @@ -161,8 +159,6 @@ if(UR_ENABLE_SANITIZER)
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_interceptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_interceptor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_libdevice.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_options.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_options.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_report.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_report.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/msan/msan_shadow.cpp
Expand All @@ -176,6 +172,8 @@ if(UR_ENABLE_SANITIZER)
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/sanitizer_common/sanitizer_stacktrace.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/sanitizer_common/sanitizer_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/sanitizer_common/sanitizer_utils.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/sanitizer_common/sanitizer_options.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/sanitizer_common/sanitizer_options.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanddi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "asan_ddi.hpp"
#include "asan_interceptor.hpp"
#include "asan_options.hpp"
#include "sanitizer_common/sanitizer_stacktrace.hpp"
#include "sanitizer_common/sanitizer_utils.hpp"
#include "ur_sanitizer_layer.hpp"
Expand Down Expand Up @@ -1559,7 +1558,7 @@ __urdlllocal ur_result_t UR_APICALL urKernelSetArgPointer(
pArgValue);

std::shared_ptr<KernelInfo> KI;
if (getAsanInterceptor()->getOptions().DetectKernelArguments) {
if (getContext()->Options.DetectKernelArguments) {
auto &KI = getAsanInterceptor()->getOrCreateKernelInfo(hKernel);
std::scoped_lock<ur_shared_mutex> Guard(KI.Mutex);
KI.PointerArgs[argIndex] = {pArgValue, GetCurrentBacktrace()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@

#include "asan_interceptor.hpp"
#include "asan_ddi.hpp"
#include "asan_options.hpp"
#include "asan_quarantine.hpp"
#include "asan_report.hpp"
#include "asan_shadow.hpp"
#include "asan_validator.hpp"
#include "sanitizer_common/sanitizer_options.hpp"
#include "sanitizer_common/sanitizer_stacktrace.hpp"
#include "sanitizer_common/sanitizer_utils.hpp"

namespace ur_sanitizer_layer {
namespace asan {

AsanInterceptor::AsanInterceptor() {
if (getOptions().MaxQuarantineSizeMB) {
if (getContext()->Options.MaxQuarantineSizeMB) {
m_Quarantine = std::make_unique<Quarantine>(
static_cast<uint64_t>(getOptions().MaxQuarantineSizeMB) * 1024 * 1024);
getContext()->Options.MaxQuarantineSizeMB * 1024 * 1024);
}
}

Expand Down Expand Up @@ -90,8 +90,7 @@ ur_result_t AsanInterceptor::allocateMemory(ur_context_handle_t Context,
Alignment = MinAlignment;
}

uptr RZLog =
ComputeRZLog(Size, getOptions().MinRZSize, getOptions().MaxRZSize);
uptr RZLog = ComputeRZLog(Size, getContext()->Options.MinRZSize);
uptr RZSize = RZLog2Size(RZLog);
uptr RoundedSize = RoundUpTo(Size, Alignment);
uptr NeededSize = RoundedSize + RZSize * 2;
Expand Down Expand Up @@ -175,7 +174,7 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
if (!AllocInfoItOp) {
// "Addr" might be a host pointer
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
if (getOptions().HaltOnError) {
if (getContext()->Options.HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
Expand All @@ -193,23 +192,23 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
// "Addr" might be a host pointer
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
}
if (getOptions().HaltOnError) {
if (getContext()->Options.HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
}

if (Addr != AllocInfo->UserBegin) {
ReportBadFree(Addr, GetCurrentBacktrace(), AllocInfo);
if (getOptions().HaltOnError) {
if (getContext()->Options.HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
}

if (AllocInfo->IsReleased) {
ReportDoubleFree(Addr, GetCurrentBacktrace(), AllocInfo);
if (getOptions().HaltOnError) {
if (getContext()->Options.HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -736,7 +735,7 @@ ur_result_t AsanInterceptor::prepareLaunch(
LocalMemoryUsage, PrivateMemoryUsage);

// Validate pointer arguments
if (getOptions().DetectKernelArguments) {
if (getContext()->Options.DetectKernelArguments) {
for (const auto &[ArgIndex, PtrPair] : KernelInfo.PointerArgs) {
auto Ptr = PtrPair.first;
if (Ptr == nullptr) {
Expand Down Expand Up @@ -813,10 +812,10 @@ ur_result_t AsanInterceptor::prepareLaunch(
LaunchInfo.Data.Host.GlobalShadowOffset = DeviceInfo->Shadow->ShadowBegin;
LaunchInfo.Data.Host.GlobalShadowOffsetEnd = DeviceInfo->Shadow->ShadowEnd;
LaunchInfo.Data.Host.DeviceTy = DeviceInfo->Type;
LaunchInfo.Data.Host.Debug = getOptions().Debug ? 1 : 0;
LaunchInfo.Data.Host.Debug = getContext()->Options.Debug ? 1 : 0;

// Write shadow memory offset for local memory
if (getOptions().DetectLocals) {
if (getContext()->Options.DetectLocals) {
if (DeviceInfo->Shadow->AllocLocalShadow(
Queue, NumWG, LaunchInfo.Data.Host.LocalShadowOffset,
LaunchInfo.Data.Host.LocalShadowOffsetEnd) != UR_RESULT_SUCCESS) {
Expand All @@ -836,7 +835,7 @@ ur_result_t AsanInterceptor::prepareLaunch(
}

// Write shadow memory offset for private memory
if (getOptions().DetectPrivates) {
if (getContext()->Options.DetectPrivates) {
if (DeviceInfo->Shadow->AllocPrivateShadow(
Queue, NumWG, LaunchInfo.Data.Host.PrivateShadowOffset,
LaunchInfo.Data.Host.PrivateShadowOffsetEnd) != UR_RESULT_SUCCESS) {
Expand Down Expand Up @@ -928,7 +927,7 @@ ContextInfo::~ContextInfo() {
assert(URes == UR_RESULT_SUCCESS);

// check memory leaks
if (getAsanInterceptor()->getOptions().DetectLeaks &&
if (getContext()->Options.DetectLeaks &&
getAsanInterceptor()->isNormalExit()) {
std::vector<AllocationIterator> AllocInfos =
getAsanInterceptor()->findAllocInfoByContext(Handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#include "asan_allocator.hpp"
#include "asan_buffer.hpp"
#include "asan_libdevice.hpp"
#include "asan_options.hpp"
#include "asan_shadow.hpp"
#include "asan_statistics.hpp"
#include "sanitizer_common/sanitizer_common.hpp"
#include "sanitizer_common/sanitizer_options.hpp"
#include "ur_sanitizer_layer.hpp"

#include <memory>
Expand Down Expand Up @@ -342,8 +342,6 @@ class AsanInterceptor {
KernelInfo &getOrCreateKernelInfo(ur_kernel_handle_t Kernel);
ur_result_t eraseKernelInfo(ur_kernel_handle_t Kernel);

const AsanOptions &getOptions() { return m_Options; }

void exitWithErrors() {
m_NormalExit = false;
exit(1);
Expand Down Expand Up @@ -375,8 +373,6 @@ class AsanInterceptor {
ur_result_t registerSpirKernels(ur_program_handle_t Program);

private:
// m_Options may be used in other places, place it at the top
AsanOptions m_Options;
std::unordered_map<ur_context_handle_t, std::shared_ptr<ContextInfo>>
m_ContextMap;
ur_shared_mutex m_ContextMapMutex;
Expand Down
148 changes: 0 additions & 148 deletions unified-runtime/source/loader/layers/sanitizer/asan/asan_options.cpp

This file was deleted.

Loading
Loading