From c9eabadc5e964678556a6bfcde455a5e11dc0785 Mon Sep 17 00:00:00 2001 From: "Yu, Guangye" Date: Mon, 27 Oct 2025 18:08:18 +0000 Subject: [PATCH] Suppress std::hardware_destructive_interference_size warning on GCC 13+ (#166297) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Motivation In https://github.com/pytorch/pytorch/pull/145591, `std::hardware_destructive_interference_size` was introduced in CUDACachingAllocator. Later, https://github.com/pytorch/pytorch/pull/160067 moved it to `c10/core/alignment.h` for code reuse. However, on **GCC 13+** using `std::hardware_destructive_interference_size` triggers the following warning: ```bash warning: use of ‘std::hardware_destructive_interference_size’ [-Winterference-size] /home/pt-gpu/4T-4652/guangyey/stock-pytorch/aten/src/ATen/core/CachingHostAllocator.h:42:16: note: its value can vary between compiler versions or with different ‘-mtune’ or ‘-mcpu’ flags /home/pt-gpu/4T-4652/guangyey/stock-pytorch/aten/src/ATen/core/CachingHostAllocator.h:42:16: note: if this use is part of a public ABI, change it to instead use a constant variable you define /home/pt-gpu/4T-4652/guangyey/stock-pytorch/aten/src/ATen/core/CachingHostAllocator.h:42:16: note: the default value for the current CPU tuning is 64 bytes /home/pt-gpu/4T-4652/guangyey/stock-pytorch/aten/src/ATen/core/CachingHostAllocator.h:42:16: note: you can stabilize this value with ‘--param hardware_destructive_interference_size=64’, or disable this warning with ‘-Wno-interference-size’ ``` # Solution - Solution 1: Replace `c10::hardware_destructive_interference_size` with a constant 64. ```cpp constexpr std::size_t hardware_destructive_interference_size = 64; ``` - Solution 2: adding `-Wno-interference-size’ to https://github.com/pytorch/pytorch/blob/8d4e48831e5abb6cbca8d97a2df6c47b770c303b/cmake/public/utils.cmake#L386 to suppress the warning. # Additional Context The current implementation uses the second approach. If the reviewers prefer the first approach, I am happy to update it accordingly. Pull Request resolved: https://github.com/pytorch/pytorch/pull/166297 Approved by: https://github.com/ezyang --- aten/src/ATen/core/CachingHostAllocator.h | 4 ++-- cmake/public/utils.cmake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aten/src/ATen/core/CachingHostAllocator.h b/aten/src/ATen/core/CachingHostAllocator.h index ce3f4429778..603e7e73bc1 100644 --- a/aten/src/ATen/core/CachingHostAllocator.h +++ b/aten/src/ATen/core/CachingHostAllocator.h @@ -677,8 +677,8 @@ struct CachingHostAllocatorImpl { // size. This allows us to quickly find a free block of the right size. // We use deque to store per size free list and guard the list with its own // mutex. - alignas(hardware_destructive_interference_size) std::vector> free_list_ = - std::vector>(MAX_SIZE_INDEX); + alignas(hardware_destructive_interference_size) std::vector> + free_list_{MAX_SIZE_INDEX}; alignas(hardware_destructive_interference_size) std::mutex events_mutex_; std::deque> events_; // event queue paired with block diff --git a/cmake/public/utils.cmake b/cmake/public/utils.cmake index bccd09690e2..efc39f2bc14 100644 --- a/cmake/public/utils.cmake +++ b/cmake/public/utils.cmake @@ -383,7 +383,7 @@ function(torch_compile_options libname) -Wno-strict-aliasing ) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - list(APPEND private_compile_options -Wredundant-move) + list(APPEND private_compile_options -Wredundant-move -Wno-interference-size) endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") list(APPEND private_compile_options -Wextra-semi -Wmove)