From f10473a9a268964e07153ca13423a291506e0579 Mon Sep 17 00:00:00 2001 From: "Wu, Yingcong" Date: Fri, 13 Dec 2024 08:14:05 +0100 Subject: [PATCH] register globals --- .../loader/layers/sanitizer/asan/asan_interceptor.cpp | 10 ++++++++++ .../loader/layers/sanitizer/asan/asan_interceptor.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/source/loader/layers/sanitizer/asan/asan_interceptor.cpp b/source/loader/layers/sanitizer/asan/asan_interceptor.cpp index 19af8546c2..02dcb3d0d3 100644 --- a/source/loader/layers/sanitizer/asan/asan_interceptor.cpp +++ b/source/loader/layers/sanitizer/asan/asan_interceptor.cpp @@ -431,6 +431,12 @@ ur_result_t AsanInterceptor::unregisterProgram(ur_program_handle_t Program) { auto ProgramInfo = getProgramInfo(Program); assert(ProgramInfo != nullptr && "unregistered program!"); + std::scoped_lock Guard(m_AllocationMapMutex); + for (auto AI : ProgramInfo->AllocInfoForGlobals) { + m_AllocationMap.erase(AI->AllocBegin); + } + ProgramInfo->AllocInfoForGlobals.clear(); + ProgramInfo->InstrumentedKernels.clear(); return UR_RESULT_SUCCESS; @@ -549,6 +555,10 @@ AsanInterceptor::registerDeviceGlobals(ur_program_handle_t Program) { {}}); ContextInfo->insertAllocInfo({Device}, AI); + ProgramInfo->AllocInfoForGlobals.emplace(AI); + + std::scoped_lock Guard(m_AllocationMapMutex); + m_AllocationMap.emplace(AI->AllocBegin, std::move(AI)); } } diff --git a/source/loader/layers/sanitizer/asan/asan_interceptor.hpp b/source/loader/layers/sanitizer/asan/asan_interceptor.hpp index f1e80dae56..2270795969 100644 --- a/source/loader/layers/sanitizer/asan/asan_interceptor.hpp +++ b/source/loader/layers/sanitizer/asan/asan_interceptor.hpp @@ -112,6 +112,7 @@ struct ProgramInfo { std::atomic RefCount = 1; // Program is built only once, so we don't need to lock it + std::unordered_set> AllocInfoForGlobals; std::unordered_set InstrumentedKernels; explicit ProgramInfo(ur_program_handle_t Program) : Handle(Program) {