From 8b318e6cf0e701680f9657bd727c9b224ba057f8 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Fri, 18 Oct 2024 17:49:24 -0400 Subject: [PATCH] Prefer `expected == atomic_compare_exchange(ptr, expected, desired)` (#2387) * Prefer expected == atomic_compare_exchange(ptr, expected, desired) Signed-off-by: Damien L-G * Reintroduce break statement that was accidentally removed Signed-off-by: Damien L-G --------- Signed-off-by: Damien L-G --- .../src/KokkosKernels_HashmapAccumulator.hpp | 2 +- ...Kernels_Uniform_Initialized_MemoryPool.hpp | 2 +- .../KokkosGraph_ExplicitCoarsening_impl.hpp | 2 +- graph/src/KokkosGraph_CoarsenHeuristics.hpp | 18 ++++++------- .../impl/KokkosSparse_bspgemm_impl_kkmem.hpp | 14 +++++----- .../impl/KokkosSparse_partitioning_impl.hpp | 2 +- .../KokkosSparse_spgemm_impl_compression.hpp | 2 +- .../impl/KokkosSparse_spgemm_impl_kkmem.hpp | 14 +++++----- ...kosSparse_spgemm_jacobi_sparseacc_impl.hpp | 26 ++++++++++--------- 9 files changed, 44 insertions(+), 38 deletions(-) diff --git a/common/src/KokkosKernels_HashmapAccumulator.hpp b/common/src/KokkosKernels_HashmapAccumulator.hpp index 4e10ec8121..c5ea080e05 100644 --- a/common/src/KokkosKernels_HashmapAccumulator.hpp +++ b/common/src/KokkosKernels_HashmapAccumulator.hpp @@ -516,7 +516,7 @@ struct HashmapAccumulator { Kokkos::atomic_add(values + hash, value); return __insert_success; } else if (keys[hash] == -1) { - if (Kokkos::atomic_compare_exchange_strong(keys + hash, -1, key)) { + if (-1 == Kokkos::atomic_compare_exchange(keys + hash, -1, key)) { // should only be here if we used a new hash used_hashes[Kokkos::atomic_fetch_add(used_hash_size, size_type(1))] = hash; Kokkos::atomic_add(values + hash, value); diff --git a/common/src/KokkosKernels_Uniform_Initialized_MemoryPool.hpp b/common/src/KokkosKernels_Uniform_Initialized_MemoryPool.hpp index aa477815d6..caf8e6b307 100644 --- a/common/src/KokkosKernels_Uniform_Initialized_MemoryPool.hpp +++ b/common/src/KokkosKernels_Uniform_Initialized_MemoryPool.hpp @@ -294,7 +294,7 @@ class UniformMemoryPool { data_type *get_arbitrary_free_chunk(const size_t &thread_index, const size_t max_tries) const { size_t chunk_index = thread_index & modular_num_chunks; size_t num_try = 0; - while (!Kokkos::atomic_compare_exchange_strong(pchunk_locks + chunk_index, 0, 1)) { + while (0 != Kokkos::atomic_compare_exchange(pchunk_locks + chunk_index, 0, 1)) { chunk_index = (chunk_index + 1) & modular_num_chunks; ++num_try; if (num_try > max_tries) { diff --git a/graph/impl/KokkosGraph_ExplicitCoarsening_impl.hpp b/graph/impl/KokkosGraph_ExplicitCoarsening_impl.hpp index f41b01175c..7aff62f318 100644 --- a/graph/impl/KokkosGraph_ExplicitCoarsening_impl.hpp +++ b/graph/impl/KokkosGraph_ExplicitCoarsening_impl.hpp @@ -98,7 +98,7 @@ struct ExplicitGraphCoarsening { KOKKOS_INLINE_FUNCTION bool insert(lno_t cluster, lno_t nei, int* table) const { unsigned h = xorshiftHash(nei); for (unsigned i = h; i < h + 2; i++) { - if (Kokkos::atomic_compare_exchange_strong(&table[i % tableSize()], cluster, nei)) return true; + if (cluster == Kokkos::atomic_compare_exchange(&table[i % tableSize()], cluster, nei)) return true; } return false; } diff --git a/graph/src/KokkosGraph_CoarsenHeuristics.hpp b/graph/src/KokkosGraph_CoarsenHeuristics.hpp index f136882d89..3a6dfbda6d 100644 --- a/graph/src/KokkosGraph_CoarsenHeuristics.hpp +++ b/graph/src/KokkosGraph_CoarsenHeuristics.hpp @@ -86,7 +86,7 @@ class coarsen_heuristics { if (bucket >= t_buckets) bucket -= t_buckets; if (buckets(bucket) == ORD_MAX) { // attempt to insert into bucket - if (Kokkos::atomic_compare_exchange_strong(&buckets(bucket), ORD_MAX, i)) { + if (ORD_MAX == Kokkos::atomic_compare_exchange(&buckets(bucket), ORD_MAX, i)) { break; } } @@ -140,8 +140,8 @@ class coarsen_heuristics { // need to enforce an ordering condition to allow hard-stall // conditions to be broken if (condition ^ swap) { - if (Kokkos::atomic_compare_exchange_strong(&match(u), ORD_MAX, v)) { - if (u == v || Kokkos::atomic_compare_exchange_strong(&match(v), ORD_MAX, u)) { + if (ORD_MAX == Kokkos::atomic_compare_exchange(&match(u), ORD_MAX, v)) { + if (u == v || ORD_MAX == Kokkos::atomic_compare_exchange(&match(v), ORD_MAX, u)) { ordinal_t cv = Kokkos::atomic_fetch_add(&nvertices_coarse(), 1); vcmap(u) = cv; vcmap(v) = cv; @@ -201,8 +201,8 @@ class coarsen_heuristics { // need to enforce an ordering condition to allow hard-stall // conditions to be broken if (condition ^ swap) { - if (Kokkos::atomic_compare_exchange_strong(&match(u), ORD_MAX, v)) { - if (u == v || Kokkos::atomic_compare_exchange_strong(&match(v), ORD_MAX, u)) { + if (ORD_MAX == Kokkos::atomic_compare_exchange(&match(u), ORD_MAX, v)) { + if (u == v || ORD_MAX == Kokkos::atomic_compare_exchange(&match(v), ORD_MAX, u)) { ordinal_t cv = u; if (v < u) { cv = v; @@ -859,8 +859,8 @@ class coarsen_heuristics { // need to enforce an ordering condition to allow hard-stall // conditions to be broken if (condition ^ swap) { - if (Kokkos::atomic_compare_exchange_strong(&match(u), ORD_MAX, v)) { - if (u == v || Kokkos::atomic_compare_exchange_strong(&match(v), ORD_MAX, u)) { + if (ORD_MAX == Kokkos::atomic_compare_exchange(&match(u), ORD_MAX, v)) { + if (u == v || ORD_MAX == Kokkos::atomic_compare_exchange(&match(v), ORD_MAX, u)) { // u == v avoids problems if there is a self-loop edge ordinal_t cv = Kokkos::atomic_fetch_add(&nvertices_coarse(), 1); vcmap(u) = cv; @@ -1084,8 +1084,8 @@ class coarsen_heuristics { // need to enforce an ordering condition to allow hard-stall // conditions to be broken if (condition ^ swap) { - if (Kokkos::atomic_compare_exchange_strong(&match(u), ORD_MAX, v)) { - if (Kokkos::atomic_compare_exchange_strong(&match(v), ORD_MAX, u)) { + if (ORD_MAX == Kokkos::atomic_compare_exchange(&match(u), ORD_MAX, v)) { + if (ORD_MAX == Kokkos::atomic_compare_exchange(&match(v), ORD_MAX, u)) { ordinal_t cv = Kokkos::atomic_fetch_add(&nvertices_coarse(), 1); vcmap(u) = cv; vcmap(v) = cv; diff --git a/sparse/impl/KokkosSparse_bspgemm_impl_kkmem.hpp b/sparse/impl/KokkosSparse_bspgemm_impl_kkmem.hpp index 65ae66d6ec..b306c219f1 100644 --- a/sparse/impl/KokkosSparse_bspgemm_impl_kkmem.hpp +++ b/sparse/impl/KokkosSparse_bspgemm_impl_kkmem.hpp @@ -607,7 +607,7 @@ struct KokkosBSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -629,7 +629,7 @@ struct KokkosBSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -651,7 +651,8 @@ struct KokkosBSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -714,7 +714,7 @@ struct KokkosSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -737,7 +737,8 @@ struct KokkosSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -835,7 +835,7 @@ struct KokkosSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -856,7 +856,7 @@ struct KokkosSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -960,7 +961,7 @@ struct KokkosSPGEMM max_first_level_hash_size) insert_is_on = false; @@ -980,7 +981,7 @@ struct KokkosSPGEMM