Repository navigation
Add cuda::device::barrier_arrive tx #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
miscco
merged 68 commits into
NVIDIA:main
from
ahendriksen:add-barrier-arrive-tx-method
Sep 12, 2023
Merged
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
5747b51
Add barrier::arrive_tx
ahendriksen dcb64a8
Implement review feedback
ahendriksen 8df2664
Add test
ahendriksen b007800
arrive_tx: Trap on older architectures
ahendriksen 8f88451
Implement review feedback
ahendriksen 4ed5686
Remove includes that are unavailable in nvrtc
ahendriksen 01edfd2
Update libcudacxx/.upstream-tests/test/cuda/barrier_arrive_tx.pass.cpp
ahendriksen 4a0ae94
Update libcudacxx/.upstream-tests/test/cuda/barrier_arrive_tx.pass.cpp
ahendriksen 89b8a33
Update libcudacxx/.upstream-tests/test/cuda/barrier_arrive_tx.pass.cpp
ahendriksen 7c91f12
Update libcudacxx/.upstream-tests/test/cuda/barrier_arrive_tx.pass.cpp
ahendriksen 889bea5
Saved by [no_discard](!)
ahendriksen 2769530
Move barrier tests into their own subfolder
miscco 3f36503
Split arrive_tx test up
miscco fe358cd
Ensure that we silence "unused variable" warnings
miscco 104d739
Add a feature test macro for cp_async_exposure
miscco 7f06ca4
Change feature test macro name
ahendriksen edfbba4
Actually change the macro name
ahendriksen 6d4a7c7
Fix typo in feature test macro
ahendriksen c97f318
Implement review feedback
ahendriksen e04db94
Fix feature flag test
ahendriksen 4107b77
Invert feature test macro availability
ahendriksen 1756350
Fix license headers
ahendriksen 9447f36
Update libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx.h
ahendriksen 3cc5f24
Update libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx.h
ahendriksen 6f2bcdf
Use more descriptive header guard
ahendriksen 61744ce
Address more review feedback
miscco f35972b
Make tests work on the host
ahendriksen 1b647c0
Add arrive_tx to non-thread-scoped barriers
ahendriksen a9026b5
Cleanup `_LIBCUDACXX_DEBUG_ASSERT`
miscco a045347
Fix asserts
ahendriksen 4d4c1ea
Fix nvrtc tests
ahendriksen c2fec0c
Revert to _LIBCUDACXX_DEBUG_ASSERT
ahendriksen 228e072
Remove debug assert from constexpr init
ahendriksen 0e0c661
Add and test cuda::device::arrive_tx
ahendriksen f83e7ca
Remove barrier::arrive_tx
ahendriksen c092f56
Add docs
ahendriksen 3bff8e9
Update CC sentence
ahendriksen 7fa3ad2
Run arrive_tx tests from SM90 onwards
ahendriksen 4eb18f9
Document feature flag
ahendriksen 6e7d312
Make feature flag available in host compilation trajectory
ahendriksen 3b9a184
Add pre-conditions, effects discussion
ahendriksen c0513bf
Improve architecture checking
ahendriksen 514e330
Add back assert for expected unit
ahendriksen f96f20a
Add __syncthreads() to example
ahendriksen 901ab2a
arrive_tx: disallow arrive_count == 0
ahendriksen 3407e30
Simplify state space handling
ahendriksen 31b0de9
Check arrive_count_update upper limit
ahendriksen ee9db4a
Update arch check test
ahendriksen d56cd4e
Add completion function template parameter for ABI
ahendriksen c7c4484
Test that arrive_tx fails on cluster and device memory
ahendriksen db23c52
Test that arrive_tx fails with completion function
ahendriksen c280a68
Remove expected unit assert again
ahendriksen 1401d4a
Hide arrive_tx on older architectures
ahendriksen 3b8503f
Pull out barrier_native_handle into variable
ahendriksen c6535a2
Fix hiding of arrive_tx
ahendriksen f2b38e7
Rename arrive_tx => barrier_arrive_tx
ahendriksen 490b166
Add docs for barrier with transaction count
ahendriksen 1739496
Markup cluster test
ahendriksen 53403d2
Remove completion function template param
ahendriksen c17b3ed
Trap in complete_tx in arrive_tx tests
ahendriksen c41fd9e
Exclude failing nvrtc test
ahendriksen 1443a90
Remove ref to UB in effects section
ahendriksen 331ed7c
Update docs
ahendriksen 8e2f2ef
Replace phase completion section
ahendriksen 41303da
Pull out __cvta_generic_to_shared
ahendriksen ce919a2
Add back debug assert in constexpr
ahendriksen 2040fa6
Disable debug assert on C++11
ahendriksen bb989b1
[skip-tests] Use same format for standard lib text modification
ahendriksen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef TEST_ARRIVE_TX_H_ | ||
| #define TEST_ARRIVE_TX_H_ | ||
|
|
||
| #include <cuda/barrier> | ||
|
|
||
| #include <cuda/std/utility> | ||
|
|
||
| #include "concurrent_agents.h" | ||
| #include "cuda_space_selector.h" | ||
| #include "test_macros.h" | ||
|
|
||
| // Suppress warning about barrier in shared memory | ||
| TEST_NV_DIAG_SUPPRESS(static_var_with_dynamic_init) | ||
|
|
||
| template<typename Barrier> | ||
| inline __device__ | ||
| void mbarrier_complete_tx( | ||
| Barrier &b, int transaction_count) | ||
| { | ||
| NV_DISPATCH_TARGET( | ||
| NV_PROVIDES_SM_90, ( | ||
| if (__isShared(cuda::device::barrier_native_handle(b))) { | ||
| asm volatile( | ||
| "mbarrier.complete_tx.relaxed.cta.shared::cta.b64 [%0], %1;" | ||
| : | ||
| : "r"((unsigned int) __cvta_generic_to_shared(cuda::device::barrier_native_handle(b))), | ||
| "r"(transaction_count) | ||
| : "memory"); | ||
| } else { | ||
| __trap(); | ||
| } | ||
| ), NV_ANY_TARGET, ( | ||
| // On architectures pre-SM90 (and on host), we drop the transaction count | ||
| // update. The barriers do not keep track of transaction counts. | ||
| __trap(); | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| template<typename Barrier> | ||
| __device__ | ||
| void thread(Barrier& b, int arrives_per_thread) | ||
| { | ||
| constexpr int tx_count = 1; | ||
| auto tok = cuda::device::barrier_arrive_tx(b, arrives_per_thread, tx_count); | ||
| // Manually increase the transaction count of the barrier. | ||
| mbarrier_complete_tx(b, tx_count); | ||
|
|
||
| b.wait(cuda::std::move(tok)); | ||
| } | ||
|
|
||
| __device__ | ||
| void test() | ||
| { | ||
| NV_DISPATCH_TARGET( | ||
| NV_IS_DEVICE, ( | ||
| // Run all threads, each arriving with arrival count 1 | ||
| constexpr auto block = cuda::thread_scope_block; | ||
|
|
||
| __shared__ cuda::barrier<block> bar_1; | ||
| init(&bar_1, (int) blockDim.x); | ||
| __syncthreads(); | ||
| thread(bar_1, 1); | ||
|
|
||
| // Run all threads, each arriving with arrival count 2 | ||
| __shared__ cuda::barrier<block> bar_2; | ||
| init(&bar_2, (int) 2 * blockDim.x); | ||
| __syncthreads(); | ||
| thread(bar_2, 2); | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| #endif // TEST_ARRIVE_TX_H_ | ||
50 changes: 50 additions & 0 deletions
50
libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx_cluster.runfail.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // UNSUPPORTED: libcpp-has-no-threads | ||
| // UNSUPPORTED: pre-sm-90 | ||
|
|
||
| // <cuda/barrier> | ||
|
|
||
| #include <cooperative_groups.h> | ||
| #include <cuda/barrier> | ||
| #include "test_macros.h" | ||
|
|
||
| // Suppress warning about barrier in shared memory | ||
| TEST_NV_DIAG_SUPPRESS(static_var_with_dynamic_init) | ||
|
|
||
| int main(int, char**){ | ||
| NV_DISPATCH_TARGET( | ||
| NV_IS_HOST, ( | ||
| // When PR #416 is merged, uncomment this line: | ||
| // cuda_cluster_size = 2; | ||
| ), | ||
| NV_IS_DEVICE, ( | ||
| __shared__ cuda::barrier<cuda::thread_scope_block> bar; | ||
|
|
||
| if (threadIdx.x == 0) { | ||
| init(&bar, blockDim.x); | ||
| } | ||
| namespace cg = cooperative_groups; | ||
| auto cluster = cg::this_cluster(); | ||
|
|
||
| cluster.sync(); | ||
|
|
||
| // This test currently fails at this point because support for | ||
| // clusters has not yet been added. | ||
| cuda::barrier<cuda::thread_scope_block> *remote_bar; | ||
| remote_bar = cluster.map_shared_rank(&bar, cluster.block_rank() ^ 1); | ||
|
|
||
| // When PR #416 is merged, this should fail here because the barrier | ||
| // is in device memory. | ||
| auto token = cuda::device::barrier_arrive_tx(*remote_bar, 1, 0); | ||
| )); | ||
| return 0; | ||
| } |
33 changes: 33 additions & 0 deletions
33
libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx_cta.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // UNSUPPORTED: libcpp-has-no-threads | ||
| // UNSUPPORTED: pre-sm-90 | ||
|
|
||
| // <cuda/barrier> | ||
|
|
||
| #include "arrive_tx.h" | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| NV_DISPATCH_TARGET( | ||
| NV_IS_HOST, ( | ||
| // Required by concurrent_agents_launch to know how many we're | ||
| // launching. This can only be an int, because the nvrtc tests use grep | ||
| // to figure out how many threads to launch. | ||
| cuda_thread_count = 256; | ||
| ), | ||
| NV_IS_DEVICE, ( | ||
| test(); | ||
| ) | ||
| ); | ||
|
|
||
| return 0; | ||
| } |
39 changes: 39 additions & 0 deletions
39
libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx_device.runfail.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // UNSUPPORTED: libcpp-has-no-threads | ||
| // UNSUPPORTED: pre-sm-90 | ||
|
ahendriksen marked this conversation as resolved.
Resolved
|
||
|
|
||
| // <cuda/barrier> | ||
|
|
||
| #include <cuda/barrier> | ||
| #include "test_macros.h" | ||
|
|
||
| // Suppress warning about barrier in shared memory | ||
| TEST_NV_DIAG_SUPPRESS(static_var_with_dynamic_init) | ||
|
|
||
| __device__ uint64_t bar_storage; | ||
|
|
||
| int main(int, char**){ | ||
| NV_IF_TARGET( | ||
| NV_IS_DEVICE, ( | ||
| cuda::barrier<cuda::thread_scope_block> *bar_ptr; | ||
| bar_ptr = reinterpret_cast<cuda::barrier<cuda::thread_scope_block> *>(bar_storage); | ||
|
|
||
| if (threadIdx.x == 0) { | ||
| init(bar_ptr, blockDim.x); | ||
| } | ||
| __syncthreads(); | ||
|
|
||
| // Should fail because the barrier is in device memory. | ||
| auto token = cuda::device::barrier_arrive_tx(*bar_ptr, 1, 0); | ||
| )); | ||
| return 0; | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx_feature_test.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // UNSUPPORTED: libcpp-has-no-threads | ||
| // UNSUPPORTED: pre-sm-90 | ||
|
|
||
| // <cuda/barrier> | ||
|
|
||
| #include <cuda/barrier> | ||
|
|
||
| #ifndef __cccl_lib_local_barrier_arrive_tx | ||
| static_assert(false, "should define __cccl_lib_local_barrier_arrive_tx"); | ||
| #endif // __cccl_lib_local_barrier_arrive_tx | ||
|
|
||
| int main(int, char**){ | ||
| return 0; | ||
| } |
36 changes: 36 additions & 0 deletions
36
libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx_static_asserts_pre_sm90.fail.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // UNSUPPORTED: libcpp-has-no-threads | ||
| // UNSUPPORTED: nvrtc | ||
| // UNSUPPORTED: pre-sm-70 | ||
|
|
||
| // <cuda/barrier> | ||
|
|
||
| #include <cuda/barrier> | ||
|
|
||
| int main(int, char**){ | ||
| NV_IF_TARGET( | ||
| NV_IS_DEVICE, ( | ||
| __shared__ cuda::barrier<cuda::thread_scope_block> bar; | ||
| if (threadIdx.x == 0) { | ||
| init(&bar, blockDim.x); | ||
| } | ||
| __syncthreads(); | ||
|
|
||
| // barrier_arrive_tx should fail on SM70 and SM80, because it is hidden. | ||
| auto token = cuda::device::barrier_arrive_tx(bar, 1, 0); | ||
|
|
||
| #if defined(__CUDA_MINIMUM_ARCH__) && 900 <= __CUDA_MINIMUM_ARCH__ | ||
| static_assert(false, "Fail manually for SM90 and up."); | ||
| #endif // __CUDA_MINIMUM_ARCH__ | ||
| )); | ||
| return 0; | ||
| } |
33 changes: 33 additions & 0 deletions
33
libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx_thread.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // UNSUPPORTED: libcpp-has-no-threads | ||
| // UNSUPPORTED: pre-sm-90 | ||
|
|
||
| // <cuda/barrier> | ||
|
|
||
| #include "arrive_tx.h" | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| NV_DISPATCH_TARGET( | ||
| NV_IS_HOST, ( | ||
| // Required by concurrent_agents_launch to know how many we're | ||
| // launching. This can only be an int, because the nvrtc tests use grep | ||
| // to figure out how many threads to launch. | ||
| cuda_thread_count = 2; | ||
| ), | ||
| NV_IS_DEVICE, ( | ||
| test(); | ||
| ) | ||
| ); | ||
|
|
||
| return 0; | ||
| } |
33 changes: 33 additions & 0 deletions
33
libcudacxx/.upstream-tests/test/cuda/barrier/arrive_tx_warp.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // UNSUPPORTED: libcpp-has-no-threads | ||
| // UNSUPPORTED: pre-sm-90 | ||
|
|
||
| // <cuda/barrier> | ||
|
|
||
| #include "arrive_tx.h" | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| NV_DISPATCH_TARGET( | ||
| NV_IS_HOST, ( | ||
| // Required by concurrent_agents_launch to know how many we're | ||
| // launching. This can only be an int, because the nvrtc tests use grep | ||
| // to figure out how many threads to launch. | ||
| cuda_thread_count = 32; | ||
| ), | ||
| NV_IS_DEVICE, ( | ||
| test(); | ||
| ) | ||
| ); | ||
|
|
||
| return 0; | ||
| } |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.