31
31
#include " utils_math.h"
32
32
#include " utils_sanitizers.h"
33
33
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
+ #define POISON_MEMORY 0
38
+
34
39
typedef struct umf_disjoint_pool_shared_limits_t {
35
40
size_t MaxSize;
36
41
std::atomic<size_t > TotalSize;
@@ -400,7 +405,9 @@ static void *memoryProviderAlloc(umf_memory_provider_handle_t hProvider,
400
405
if (ret != UMF_RESULT_SUCCESS) {
401
406
throw MemoryProviderError{ret};
402
407
}
408
+ #if POISON_MEMORY
403
409
utils_annotate_memory_inaccessible (ptr, size);
410
+ #endif
404
411
return ptr;
405
412
}
406
413
@@ -822,7 +829,9 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, bool &FromPool) try {
822
829
FromPool = false ;
823
830
if (Size > getParams ().MaxPoolableSize ) {
824
831
Ptr = memoryProviderAlloc (getMemHandle (), Size);
832
+ #if POISON_MEMORY
825
833
utils_annotate_memory_undefined (Ptr, Size);
834
+ #endif
826
835
return Ptr;
827
836
}
828
837
@@ -839,7 +848,9 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, bool &FromPool) try {
839
848
}
840
849
841
850
VALGRIND_DO_MEMPOOL_ALLOC (this , Ptr, Size);
851
+ #if POISON_MEMORY
842
852
utils_annotate_memory_undefined (Ptr, Bucket.getSize ());
853
+ #endif
843
854
844
855
return Ptr;
845
856
} catch (MemoryProviderError &e) {
@@ -877,7 +888,9 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, size_t Alignment,
877
888
FromPool = false ;
878
889
if (AlignedSize > getParams ().MaxPoolableSize ) {
879
890
Ptr = memoryProviderAlloc (getMemHandle (), Size, Alignment);
891
+ #if POISON_MEMORY
880
892
utils_annotate_memory_undefined (Ptr, Size);
893
+ #endif
881
894
return Ptr;
882
895
}
883
896
@@ -894,8 +907,9 @@ void *DisjointPool::AllocImpl::allocate(size_t Size, size_t Alignment,
894
907
}
895
908
896
909
VALGRIND_DO_MEMPOOL_ALLOC (this , AlignPtrUp (Ptr, Alignment), Size);
910
+ #if POISON_MEMORY
897
911
utils_annotate_memory_undefined (AlignPtrUp (Ptr, Alignment), Size);
898
-
912
+ # endif
899
913
return AlignPtrUp (Ptr, Alignment);
900
914
} catch (MemoryProviderError &e) {
901
915
umf::getPoolLastStatusRef<DisjointPool>() = e.code ;
@@ -962,8 +976,9 @@ void DisjointPool::AllocImpl::deallocate(void *Ptr, bool &ToPool) {
962
976
}
963
977
964
978
VALGRIND_DO_MEMPOOL_FREE (this , Ptr);
979
+ #if POISON_MEMORY
965
980
utils_annotate_memory_inaccessible (Ptr, Bucket.getSize ());
966
-
981
+ # endif
967
982
if (Bucket.getSize () <= Bucket.ChunkCutOff ()) {
968
983
Bucket.freeChunk (Ptr, Slab, ToPool);
969
984
} else {
0 commit comments