From dfe076dc73f427357ed28c29aa23d12e0a088c2f Mon Sep 17 00:00:00 2001 From: Akihiro Nitta Date: Mon, 18 May 2026 16:04:49 +0000 Subject: [PATCH 1/3] empty From 9c242cf6a4fbaeb80f0a02c94419f2d39d3554ee Mon Sep 17 00:00:00 2001 From: Akihiro Nitta Date: Mon, 18 May 2026 16:36:17 +0000 Subject: [PATCH 2/3] update --- pyg_lib/csrc/ops/cuda/atomics.cuh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pyg_lib/csrc/ops/cuda/atomics.cuh b/pyg_lib/csrc/ops/cuda/atomics.cuh index 945456457..65e850f47 100644 --- a/pyg_lib/csrc/ops/cuda/atomics.cuh +++ b/pyg_lib/csrc/ops/cuda/atomics.cuh @@ -453,9 +453,11 @@ static inline __device__ int16_t atomicMin(int16_t* address, int16_t val) { // where `int32_t` is `int`.) // // `int64_t` is `long int` on Linux x86_64 (LP64); CUDA's native -// `atomicMin(long long int*, long long int)` covers a *different* type, so -// we provide our own CAS loop. The comparison is done in signed space on the -// reinterpreted 64-bit word. +// `atomicMin(long long int*, long long int)` covers a *different* type there, +// so we provide our own CAS loop. On Windows MSVC (LLP64), `int64_t` *is* +// `long long int`, so the same CUDA intrinsic already participates in +// overload resolution and defining a wrapper here would be a redefinition. +#if !defined(_MSC_VER) static inline __device__ int64_t atomicMin(int64_t* address, int64_t val) { unsigned long long int* address_as_ull = (unsigned long long int*)address; unsigned long long int old = *address_as_ull; @@ -469,6 +471,7 @@ static inline __device__ int64_t atomicMin(int64_t* address, int64_t val) { } while (assumed != old); return (int64_t)old; } +#endif // Floating-point overloads. static inline __device__ at::Half atomicMin(at::Half* address, at::Half val) { @@ -607,9 +610,11 @@ static inline __device__ int16_t atomicMax(int16_t* address, int16_t val) { // Linux x86_64 where `int32_t` is `int`). // // `int64_t` is `long int` on Linux x86_64 (LP64); CUDA's native -// `atomicMax(long long int*, long long int)` covers a *different* type, so -// we provide our own CAS loop. The comparison is done in signed space on the -// reinterpreted 64-bit word. +// `atomicMax(long long int*, long long int)` covers a *different* type there, +// so we provide our own CAS loop. On Windows MSVC (LLP64), `int64_t` *is* +// `long long int`, so the same CUDA intrinsic already participates in +// overload resolution and defining a wrapper here would be a redefinition. +#if !defined(_MSC_VER) static inline __device__ int64_t atomicMax(int64_t* address, int64_t val) { unsigned long long int* address_as_ull = (unsigned long long int*)address; unsigned long long int old = *address_as_ull; @@ -623,6 +628,7 @@ static inline __device__ int64_t atomicMax(int64_t* address, int64_t val) { } while (assumed != old); return (int64_t)old; } +#endif // Floating-point overloads. static inline __device__ at::Half atomicMax(at::Half* address, at::Half val) { From 9e1b532bf49c04b03a3517f5d69e6b27e1ea3f96 Mon Sep 17 00:00:00 2001 From: Akihiro Nitta Date: Mon, 18 May 2026 20:14:20 +0000 Subject: [PATCH 3/3] update --- pyg_lib/csrc/ops/cuda/atomics.cuh | 32 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pyg_lib/csrc/ops/cuda/atomics.cuh b/pyg_lib/csrc/ops/cuda/atomics.cuh index 65e850f47..a79afc7a1 100644 --- a/pyg_lib/csrc/ops/cuda/atomics.cuh +++ b/pyg_lib/csrc/ops/cuda/atomics.cuh @@ -34,6 +34,8 @@ // `atomicAdd(float*, float)`, etc. Defining them inside `pyg::ops` would // shadow the built-ins for any unqualified call site inside that namespace. +#include + #include #include @@ -457,21 +459,24 @@ static inline __device__ int16_t atomicMin(int16_t* address, int16_t val) { // so we provide our own CAS loop. On Windows MSVC (LLP64), `int64_t` *is* // `long long int`, so the same CUDA intrinsic already participates in // overload resolution and defining a wrapper here would be a redefinition. -#if !defined(_MSC_VER) -static inline __device__ int64_t atomicMin(int64_t* address, int64_t val) { +// The SFINAE constraint keys directly on the *type relationship* rather than +// a platform macro, so it stays correct under any future ABI change. +template && + !std::is_same_v>> +static inline __device__ T atomicMin(T* address, T val) { unsigned long long int* address_as_ull = (unsigned long long int*)address; unsigned long long int old = *address_as_ull; unsigned long long int assumed; do { assumed = old; - const int64_t cur = (int64_t)assumed; - const int64_t new_val = val < cur ? val : cur; + const T cur = (T)assumed; + const T new_val = val < cur ? val : cur; old = atomicCAS(address_as_ull, assumed, (unsigned long long int)new_val); } while (assumed != old); - return (int64_t)old; + return (T)old; } -#endif // Floating-point overloads. static inline __device__ at::Half atomicMin(at::Half* address, at::Half val) { @@ -614,21 +619,24 @@ static inline __device__ int16_t atomicMax(int16_t* address, int16_t val) { // so we provide our own CAS loop. On Windows MSVC (LLP64), `int64_t` *is* // `long long int`, so the same CUDA intrinsic already participates in // overload resolution and defining a wrapper here would be a redefinition. -#if !defined(_MSC_VER) -static inline __device__ int64_t atomicMax(int64_t* address, int64_t val) { +// The SFINAE constraint keys directly on the *type relationship* rather than +// a platform macro, so it stays correct under any future ABI change. +template && + !std::is_same_v>> +static inline __device__ T atomicMax(T* address, T val) { unsigned long long int* address_as_ull = (unsigned long long int*)address; unsigned long long int old = *address_as_ull; unsigned long long int assumed; do { assumed = old; - const int64_t cur = (int64_t)assumed; - const int64_t new_val = val > cur ? val : cur; + const T cur = (T)assumed; + const T new_val = val > cur ? val : cur; old = atomicCAS(address_as_ull, assumed, (unsigned long long int)new_val); } while (assumed != old); - return (int64_t)old; + return (T)old; } -#endif // Floating-point overloads. static inline __device__ at::Half atomicMax(at::Half* address, at::Half val) {