diff --git a/include/nccl_ofi_freelist.h b/include/nccl_ofi_freelist.h index b8ee9d63f..7085bc43d 100644 --- a/include/nccl_ofi_freelist.h +++ b/include/nccl_ofi_freelist.h @@ -196,7 +196,7 @@ int nccl_ofi_freelist_add(nccl_ofi_freelist_t *freelist, /* * Set memcheck guards of freelist entry's user data to accessible but undefined */ -static inline void nccl_ofi_freelist_entry_set_undefined(nccl_ofi_freelist_t *freelist, void *entry_p) +static inline void nccl_ofi_freelist_entry_set_undefined(nccl_ofi_freelist_t *freelist, uintptr_t entry_p) { size_t user_entry_size = freelist->entry_size - MEMCHECK_REDZONE_SIZE; @@ -269,11 +269,11 @@ static inline void *nccl_ofi_freelist_entry_alloc(nccl_ofi_freelist_t *freelist) } entry = freelist->entries; - nccl_net_ofi_mem_defined_unaligned(entry, sizeof(*entry)); + nccl_net_ofi_mem_defined_unaligned((uintptr_t)entry, sizeof(*entry)); freelist->entries = entry->next; buf = entry->ptr; - nccl_ofi_freelist_entry_set_undefined(freelist, buf); + nccl_ofi_freelist_entry_set_undefined(freelist, (uintptr_t)buf); cleanup: nccl_net_ofi_mutex_unlock(&freelist->lock); @@ -300,7 +300,7 @@ static inline void nccl_ofi_freelist_entry_free(nccl_ofi_freelist_t *freelist, v if (freelist->have_reginfo) { entry = (struct nccl_ofi_freelist_elem_t *)((char*)entry_p + freelist->reginfo_offset); - nccl_net_ofi_mem_defined_unaligned(entry, sizeof(*entry)); + nccl_net_ofi_mem_defined_unaligned((uintptr_t)entry, sizeof(*entry)); } else { entry = (struct nccl_ofi_freelist_elem_t *)entry_p; entry->ptr = (void *)entry; @@ -309,7 +309,7 @@ static inline void nccl_ofi_freelist_entry_free(nccl_ofi_freelist_t *freelist, v entry->next = freelist->entries; freelist->entries = entry; - nccl_net_ofi_mem_noaccess(entry_p, user_entry_size); + nccl_net_ofi_mem_noaccess((uintptr_t)entry_p, user_entry_size); nccl_net_ofi_mutex_unlock(&freelist->lock); } diff --git a/include/nccl_ofi_memcheck.h b/include/nccl_ofi_memcheck.h index 52247eb25..2846ff986 100644 --- a/include/nccl_ofi_memcheck.h +++ b/include/nccl_ofi_memcheck.h @@ -52,7 +52,7 @@ static_assert(MEMCHECK_REDZONE_SIZE % MEMCHECK_GRANULARITY == 0, * @param size * The size of the memory area. */ -static inline void nccl_net_ofi_mem_defined(void *data, size_t size); +static inline void nccl_net_ofi_mem_defined(uintptr_t data, size_t size); /** * Mark a memory area as having an undefined content. This can result @@ -65,7 +65,7 @@ static inline void nccl_net_ofi_mem_defined(void *data, size_t size); * @param size * The size of the memory area. */ -static inline void nccl_net_ofi_mem_undefined(void *data, size_t size); +static inline void nccl_net_ofi_mem_undefined(uintptr_t data, size_t size); /** * Mark a memory area as being invalid for read or write accesss. Any @@ -77,16 +77,16 @@ static inline void nccl_net_ofi_mem_undefined(void *data, size_t size); * @param size * The size of the memory area. */ -static inline void nccl_net_ofi_mem_noaccess(void *data, size_t size); +static inline void nccl_net_ofi_mem_noaccess(uintptr_t data, size_t size); /** * Same as nccl_net_ofi_mem_defined() except that guard is applied to * memory region [NCCL_OFI_ROUND_DOWN(data, MEMCHECK_GRANULARITY), data + size). */ -static inline void nccl_net_ofi_mem_defined_unaligned(void *data, size_t size) +static inline void nccl_net_ofi_mem_defined_unaligned(uintptr_t data, size_t size) { - void *aligned = (void *)NCCL_OFI_ROUND_DOWN((uintptr_t)data, MEMCHECK_GRANULARITY); - size_t offset = data - aligned; + uintptr_t aligned = NCCL_OFI_ROUND_DOWN(data, MEMCHECK_GRANULARITY); + ptrdiff_t offset = data - aligned; nccl_net_ofi_mem_defined(data - offset, size + offset); } @@ -94,10 +94,10 @@ static inline void nccl_net_ofi_mem_defined_unaligned(void *data, size_t size) * Same as nccl_net_ofi_mem_undefined() except that guard is applied to * memory region [NCCL_OFI_ROUND_DOWN(data, MEMCHECK_GRANULARITY), data + size). */ -static inline void nccl_net_ofi_mem_undefined_unaligned(void *data, size_t size) +static inline void nccl_net_ofi_mem_undefined_unaligned(uintptr_t data, size_t size) { - void *aligned = (void *)NCCL_OFI_ROUND_DOWN((uintptr_t)data, MEMCHECK_GRANULARITY); - size_t offset = data - aligned; + uintptr_t aligned = NCCL_OFI_ROUND_DOWN(data, MEMCHECK_GRANULARITY); + ptrdiff_t offset = data - aligned; nccl_net_ofi_mem_undefined(data - offset, size + offset); } @@ -105,10 +105,10 @@ static inline void nccl_net_ofi_mem_undefined_unaligned(void *data, size_t size) * Same as nccl_net_ofi_mem_noaccess() except that guard is applied to * memory region [NCCL_OFI_ROUND_DOWN(data, MEMCHECK_GRANULARITY), data + size). */ -static inline void nccl_net_ofi_mem_noaccess_unaligned(void *data, size_t size) +static inline void nccl_net_ofi_mem_noaccess_unaligned(uintptr_t data, size_t size) { - void *aligned = (void *)NCCL_OFI_ROUND_DOWN((uintptr_t)data, MEMCHECK_GRANULARITY); - size_t offset = data - aligned; + uintptr_t aligned = NCCL_OFI_ROUND_DOWN(data, MEMCHECK_GRANULARITY); + ptrdiff_t offset = data - aligned; nccl_net_ofi_mem_noaccess(data - offset, size + offset); } @@ -127,7 +127,7 @@ static inline void nccl_net_ofi_mem_noaccess_unaligned(void *data, size_t size) * @param size * The size of the memory area. */ -static inline void nccl_net_ofi_mem_create_mempool(void *handle, void *data, size_t size); +static inline void nccl_net_ofi_mem_create_mempool(void *handle, uintptr_t data, size_t size); /** * Destroy a memory allocator. @@ -150,7 +150,7 @@ static inline void nccl_net_ofi_mem_destroy_mempool(void *handle); * @param size * The size of the memory area. */ -static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, void *data, size_t size); +static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, uintptr_t data, size_t size); /** * Indicate that a deallocate has occured to a memory allocator. The @@ -167,7 +167,7 @@ static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, void *data, size * @param size * The size of the memory area. */ -static inline void nccl_net_ofi_mem_mempool_free(void *handle, void *data, size_t size); +static inline void nccl_net_ofi_mem_mempool_free(void *handle, uintptr_t data, size_t size); #ifdef __cplusplus } // End extern "C" diff --git a/include/nccl_ofi_memcheck_asan.h b/include/nccl_ofi_memcheck_asan.h index baab829aa..b99142b68 100644 --- a/include/nccl_ofi_memcheck_asan.h +++ b/include/nccl_ofi_memcheck_asan.h @@ -36,7 +36,7 @@ static inline void nccl_net_ofi_mem_noaccess(void *data, size_t size) __asan_poison_memory_region(data, size); } -static inline void nccl_net_ofi_mem_create_mempool(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_create_mempool(void *handle, uintptr_t data, size_t size) { nccl_net_ofi_mem_noaccess(data, size); } @@ -46,12 +46,12 @@ static inline void nccl_net_ofi_mem_destroy_mempool(void *handle) /* Cannot posion without knowing mempool data and size */ } -static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, uintptr_t data, size_t size) { nccl_net_ofi_mem_undefined(data, size); } -static inline void nccl_net_ofi_mem_mempool_free(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_mempool_free(void *handle, uintptr_t data, size_t size) { nccl_net_ofi_mem_noaccess(data, size); } diff --git a/include/nccl_ofi_memcheck_nop.h b/include/nccl_ofi_memcheck_nop.h index 17e4d1e50..88e0f096a 100644 --- a/include/nccl_ofi_memcheck_nop.h +++ b/include/nccl_ofi_memcheck_nop.h @@ -16,19 +16,19 @@ extern "C" { * By including this module, calls to the interface will result in nops. */ -static inline void nccl_net_ofi_mem_defined(void *data, size_t size) +static inline void nccl_net_ofi_mem_defined(uintptr_t data, size_t size) { } -static inline void nccl_net_ofi_mem_undefined(void *data, size_t size) +static inline void nccl_net_ofi_mem_undefined(uintptr_t data, size_t size) { } -static inline void nccl_net_ofi_mem_noaccess(void *data, size_t size) +static inline void nccl_net_ofi_mem_noaccess(uintptr_t data, size_t size) { } -static inline void nccl_net_ofi_mem_create_mempool(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_create_mempool(void *handle, uintptr_t data, size_t size) { } @@ -36,11 +36,11 @@ static inline void nccl_net_ofi_mem_destroy_mempool(void *handle) { } -static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, uintptr_t data, size_t size) { } -static inline void nccl_net_ofi_mem_mempool_free(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_mempool_free(void *handle, uintptr_t data, size_t size) { } diff --git a/include/nccl_ofi_memcheck_valgrind.h b/include/nccl_ofi_memcheck_valgrind.h index dfd64a62c..d83625c3a 100644 --- a/include/nccl_ofi_memcheck_valgrind.h +++ b/include/nccl_ofi_memcheck_valgrind.h @@ -12,22 +12,22 @@ extern "C" { #include #include -static inline void nccl_net_ofi_mem_defined(void *data, size_t size) +static inline void nccl_net_ofi_mem_defined(uintptr_t data, size_t size) { VALGRIND_MAKE_MEM_DEFINED(data, size); } -static inline void nccl_net_ofi_mem_undefined(void *data, size_t size) +static inline void nccl_net_ofi_mem_undefined(uintptr_t data, size_t size) { VALGRIND_MAKE_MEM_UNDEFINED(data, size); } -static inline void nccl_net_ofi_mem_noaccess(void *data, size_t size) +static inline void nccl_net_ofi_mem_noaccess(uintptr_t data, size_t size) { VALGRIND_MAKE_MEM_NOACCESS(data, size); } -static inline void nccl_net_ofi_mem_create_mempool(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_create_mempool(void *handle, uintptr_t data, size_t size) { nccl_net_ofi_mem_noaccess(data, size); VALGRIND_CREATE_MEMPOOL(handle, 0, 0); @@ -38,12 +38,12 @@ static inline void nccl_net_ofi_mem_destroy_mempool(void *handle) VALGRIND_DESTROY_MEMPOOL(handle); } -static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_mempool_alloc(void *handle, uintptr_t data, size_t size) { VALGRIND_MEMPOOL_ALLOC(handle, data, size); } -static inline void nccl_net_ofi_mem_mempool_free(void *handle, void *data, size_t size) +static inline void nccl_net_ofi_mem_mempool_free(void *handle, uintptr_t data, size_t size) { VALGRIND_MEMPOOL_FREE(handle, data); } diff --git a/src/nccl_ofi_freelist.c b/src/nccl_ofi_freelist.c index 55a60e254..e71705836 100644 --- a/src/nccl_ofi_freelist.c +++ b/src/nccl_ofi_freelist.c @@ -167,7 +167,7 @@ int nccl_ofi_freelist_fini(nccl_ofi_freelist_t *freelist) while (freelist->blocks) { struct nccl_ofi_freelist_block_t *block = freelist->blocks; - nccl_net_ofi_mem_defined(block, sizeof(struct nccl_ofi_freelist_block_t)); + nccl_net_ofi_mem_defined((uintptr_t)block, sizeof(struct nccl_ofi_freelist_block_t)); void *memory = block->memory; size_t size = block->memory_size; freelist->blocks = block->next; @@ -188,7 +188,7 @@ int nccl_ofi_freelist_fini(nccl_ofi_freelist_t *freelist) * needs to be performed manually since reallocation * of the same memory via mmap() is invisible to * ASAN. */ - nccl_net_ofi_mem_undefined(memory, size); + nccl_net_ofi_mem_undefined((uintptr_t)memory, size); ret = nccl_net_ofi_dealloc_mr_buffer(memory, size); if (ret != 0) { NCCL_OFI_WARN("Unable to deallocate MR buffer(%d)", ret); @@ -248,9 +248,9 @@ int nccl_ofi_freelist_add(nccl_ofi_freelist_t *freelist, char *b_end = (char *)(block + 1); char *b_end_aligned = (char *)NCCL_OFI_ROUND_DOWN((uintptr_t)b_end, (uintptr_t)MEMCHECK_GRANULARITY); - nccl_net_ofi_mem_noaccess(b_end_aligned, + nccl_net_ofi_mem_noaccess((uintptr_t)b_end_aligned, block_mem_size - (b_end_aligned - buffer)); - nccl_net_ofi_mem_undefined(b_end_aligned, b_end - b_end_aligned); + nccl_net_ofi_mem_undefined((uintptr_t)b_end_aligned, b_end - b_end_aligned); if (freelist->regmr_fn) { /* @@ -270,7 +270,7 @@ int nccl_ofi_freelist_add(nccl_ofi_freelist_t *freelist, * needs to be performed manually since reallocation * of the same memory via mmap() is invisible to * ASAN. */ - nccl_net_ofi_mem_undefined(block->memory, block_mem_size); + nccl_net_ofi_mem_undefined((uintptr_t)block->memory, block_mem_size); int dret = nccl_net_ofi_dealloc_mr_buffer(block->memory, block_mem_size); if (dret != 0) { NCCL_OFI_WARN("Unable to deallocate MR buffer(%d)", ret); @@ -288,7 +288,7 @@ int nccl_ofi_freelist_add(nccl_ofi_freelist_t *freelist, size_t user_entry_size = freelist->entry_size - freelist->memcheck_redzone_size; /* Add redzone before entry */ - nccl_net_ofi_mem_noaccess(buffer, freelist->memcheck_redzone_size); + nccl_net_ofi_mem_noaccess((uintptr_t)buffer, freelist->memcheck_redzone_size); buffer += freelist->memcheck_redzone_size; if (freelist->have_reginfo) { @@ -306,13 +306,13 @@ int nccl_ofi_freelist_add(nccl_ofi_freelist_t *freelist, freelist->entries = entry; freelist->num_allocated_entries++; - nccl_net_ofi_mem_noaccess(entry->ptr, user_entry_size); + nccl_net_ofi_mem_noaccess((uintptr_t)entry->ptr, user_entry_size); buffer += user_entry_size; } /* Block structure will not be accessed until freelist is destroyed */ - nccl_net_ofi_mem_noaccess(block, sizeof(struct nccl_ofi_freelist_block_t)); + nccl_net_ofi_mem_noaccess((uintptr_t)block, sizeof(struct nccl_ofi_freelist_block_t)); return 0; } diff --git a/src/nccl_ofi_rdma.c b/src/nccl_ofi_rdma.c index dee120ecf..c1179fa1d 100644 --- a/src/nccl_ofi_rdma.c +++ b/src/nccl_ofi_rdma.c @@ -4313,7 +4313,7 @@ static int post_bounce_buffer(nccl_net_ofi_rdma_req_t *req, * gets re-posted */ nccl_net_ofi_rdma_ep_t *ep = bounce_data->ep; nccl_ofi_freelist_entry_set_undefined(ep->bounce_buff_fl, - bounce_fl_item); + (uintptr_t)bounce_fl_item); req->state = NCCL_OFI_RDMA_REQ_CREATED; ssize_t rc =