Skip to content

Commit 3fe23a3

Browse files
committed
Disable memory poisoning in DisjointPool
ASan throws an error whenever the memory poison is called for the memory allocated on GPU: "AddressSanitizer: CHECK failed: asan_mapping.h:359 "((AddrIsInMem(p))) != (0)" (0x0, 0x0)". This commit disables poisoning.
1 parent 5af717e commit 3fe23a3

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/pool/pool_disjoint.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@
3131
#include "utils_math.h"
3232
#include "utils_sanitizers.h"
3333

34+
// Temporary solution for disabling memory poisoning. This is needed because
35+
// AddressSanitizer does not support memory poisoning for GPU allocations.
36+
// More info: https://github.com/oneapi-src/unified-memory-framework/issues/634
37+
#ifndef POISON_MEMORY
38+
#define POISON_MEMORY 0
39+
#endif
40+
41+
static inline void annotate_memory_inaccessible([[maybe_unused]] void *ptr,
42+
[[maybe_unused]] size_t size) {
43+
#ifdef POISON_MEMORY
44+
utils_annotate_memory_inaccessible(ptr, size);
45+
#endif
46+
}
47+
48+
static inline void annotate_memory_undefined([[maybe_unused]] void *ptr,
49+
[[maybe_unused]] size_t size) {
50+
#ifdef POISON_MEMORY
51+
utils_annotate_memory_undefined(ptr, size);
52+
#endif
53+
}
54+
3455
typedef struct umf_disjoint_pool_shared_limits_t {
3556
size_t MaxSize;
3657
std::atomic<size_t> TotalSize;
@@ -400,7 +421,7 @@ static void *memoryProviderAlloc(umf_memory_provider_handle_t hProvider,
400421
if (ret != UMF_RESULT_SUCCESS) {
401422
throw MemoryProviderError{ret};
402423
}
403-
utils_annotate_memory_inaccessible(ptr, size);
424+
annotate_memory_inaccessible(ptr, size);
404425
return ptr;
405426
}
406427

@@ -822,7 +843,7 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, bool &FromPool) try {
822843
FromPool = false;
823844
if (Size > getParams().MaxPoolableSize) {
824845
Ptr = memoryProviderAlloc(getMemHandle(), Size);
825-
utils_annotate_memory_undefined(Ptr, Size);
846+
annotate_memory_undefined(Ptr, Size);
826847
return Ptr;
827848
}
828849

@@ -839,7 +860,7 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, bool &FromPool) try {
839860
}
840861

841862
VALGRIND_DO_MEMPOOL_ALLOC(this, Ptr, Size);
842-
utils_annotate_memory_undefined(Ptr, Bucket.getSize());
863+
annotate_memory_undefined(Ptr, Bucket.getSize());
843864

844865
return Ptr;
845866
} catch (MemoryProviderError &e) {
@@ -877,7 +898,7 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, size_t Alignment,
877898
FromPool = false;
878899
if (AlignedSize > getParams().MaxPoolableSize) {
879900
Ptr = memoryProviderAlloc(getMemHandle(), Size, Alignment);
880-
utils_annotate_memory_undefined(Ptr, Size);
901+
annotate_memory_undefined(Ptr, Size);
881902
return Ptr;
882903
}
883904

@@ -894,8 +915,7 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, size_t Alignment,
894915
}
895916

896917
VALGRIND_DO_MEMPOOL_ALLOC(this, AlignPtrUp(Ptr, Alignment), Size);
897-
utils_annotate_memory_undefined(AlignPtrUp(Ptr, Alignment), Size);
898-
918+
annotate_memory_undefined(AlignPtrUp(Ptr, Alignment), Size);
899919
return AlignPtrUp(Ptr, Alignment);
900920
} catch (MemoryProviderError &e) {
901921
umf::getPoolLastStatusRef<DisjointPool>() = e.code;
@@ -962,8 +982,7 @@ void DisjointPool::AllocImpl::deallocate(void *Ptr, bool &ToPool) {
962982
}
963983

964984
VALGRIND_DO_MEMPOOL_FREE(this, Ptr);
965-
utils_annotate_memory_inaccessible(Ptr, Bucket.getSize());
966-
985+
annotate_memory_inaccessible(Ptr, Bucket.getSize());
967986
if (Bucket.getSize() <= Bucket.ChunkCutOff()) {
968987
Bucket.freeChunk(Ptr, Slab, ToPool);
969988
} else {

0 commit comments

Comments
 (0)