Skip to content

Commit 69e9b6e

Browse files
amd-hsongassistant-librarian[bot]
authored andcommitted
[rocm-libraries] ROCm/rocm-libraries#4905 (commit 2b42a42)
[rocthrust] Fix unqualified swap calls in contiguous_storage.inl (#4905) ## Motivation <!-- Explain the purpose of this PR and the goals it aims to achieve. --> This PR fixes a couple of unqualified swap calls caused ADL ambiguity with libhipcxx 3.0.2. ## Technical Details <!-- Explain the changes along with any relevant GitHub links. --> Unqualified swap() calls in thrust/detail/contiguous_storage.inl cause compilation failures when used with cuda::std namespace types due to ADL ambiguity between thrust::swap and cuda::std::swap. The ambiguity is removed by explicit calls to thrust::swap when _THRUST_HAS_DEVICE_SYSTEM_STD is not defined. When _THRUST_HAS_DEVICE_SYSTEM_STD is defined, std::swap provides a fallback while allowing customized swap implementation via ADL - this is to be consistent with CCCL. ## Test Plan <!-- Explain any relevant testing done to verify this PR. --> Build a reproducer that uses cuda::std namespace types in host_vector. ## Test Result <!-- Briefly summarize test outcomes. --> The compilation is successful. ## Submission Checklist - [ ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent d2001b0 commit 69e9b6e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

thrust/detail/contiguous_storage.inl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2008-2018 NVIDIA Corporation
3-
* Modifications Copyright© 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
3+
* Modifications Copyright© 2023-2026 Advanced Micro Devices, Inc. All rights reserved.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -39,7 +39,6 @@
3939
#endif
4040

4141
#include <stdexcept> // for std::runtime_error
42-
#include <utility> // for use of std::swap in the WAR below
4342

4443
THRUST_NAMESPACE_BEGIN
4544

@@ -199,16 +198,21 @@ THRUST_HOST_DEVICE void contiguous_storage<T, Alloc>::swap(contiguous_storage& x
199198
{
200199
#if _THRUST_HAS_DEVICE_SYSTEM_STD
201200
using _THRUST_STD::swap;
202-
#else
203-
using thrust::swap;
204-
#endif
205201
swap(m_begin, x.m_begin);
206202
swap(m_size, x.m_size);
203+
#else
204+
thrust::swap(m_begin, x.m_begin);
205+
thrust::swap(m_size, x.m_size);
206+
#endif
207207

208208
// FIXME(bgruber): swap_allocators already swaps m_allocator, so we are swapping twice here !!
209209
swap_allocators(integral_constant<bool, allocator_traits<Alloc>::propagate_on_container_swap::value>(),
210210
x.m_allocator);
211+
#if _THRUST_HAS_DEVICE_SYSTEM_STD
211212
swap(m_allocator, x.m_allocator);
213+
#else
214+
thrust::swap(m_allocator, x.m_allocator);
215+
#endif
212216
} // end contiguous_storage::swap()
213217

214218
template <typename T, typename Alloc>
@@ -357,10 +361,10 @@ THRUST_HOST_DEVICE void contiguous_storage<T, Alloc>::swap_allocators(false_type
357361
(if (is_allocator_not_equal(other)) { throw allocator_mismatch_on_swap(); }));
358362
#if _THRUST_HAS_DEVICE_SYSTEM_STD
359363
using _THRUST_STD::swap;
364+
swap(m_allocator, other);
360365
#else
361-
using thrust::swap;
366+
thrust::swap(m_allocator, other);
362367
#endif
363-
swap(m_allocator, other);
364368
} // end contiguous_storage::swap_allocators()
365369

366370
template <typename T, typename Alloc>

0 commit comments

Comments
 (0)