This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge remote-tracking branch 'origin/main' into type-traits-b…
- Loading branch information
Showing
26 changed files
with
334 additions
and
434 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,9 +1,3 @@ | ||
--- | ||
has_children: true | ||
has_toc: false | ||
nav_order: 2 | ||
--- | ||
|
||
# API | ||
|
||
Any header not listed below is omitted. | ||
|
This file contains 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 |
---|---|---|
@@ -1,23 +1,10 @@ | ||
--- | ||
parent: API | ||
has_children: true | ||
has_toc: false | ||
nav_order: 0 | ||
--- | ||
|
||
# Synchronization Library | ||
|
||
Most synchronization primitives have an additional thread scope template | ||
parameter, which defines the set of threads that may interact with the object. | ||
Most synchronization primitives have an additional thread scope template parameter, | ||
which defines the set of threads that may interact with the object. | ||
Please see the [thread scope section] for more details. | ||
|
||
Any header not listed below is omitted. | ||
|
||
*: Some the Standard C++ facilities in this header are omitted, see the libcu++ | ||
Addendum for details. | ||
|
||
{% include_relative synchronization_library/header_table.md %} | ||
|
||
|
||
[thread scope section]: ./synchronization_library/thread_scopes.md | ||
|
This file contains 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 |
---|---|---|
@@ -1,75 +1,56 @@ | ||
--- | ||
grand_parent: API | ||
parent: Synchronization Library | ||
nav_order: 1 | ||
--- | ||
|
||
# `<cuda/std/atomic>`, `<cuda/atomic>` | ||
|
||
## Extensions | ||
## Extensions in the `cuda::` namespace | ||
|
||
The class template `atomic` takes an additional [thread scope] argument, | ||
defaulted to `thread_scope_system`. | ||
The class template `atomic` takes an additional scope argument, defaulted to `thread_scope_system`. | ||
|
||
```c++ | ||
// This atomic is suitable for all threads in the system. | ||
cuda::atomic<int, cuda::thread_scope_system> a; | ||
// This object is atomic for all threads in the system | ||
cuda::atomic<int> a; | ||
|
||
// This atomic has the same type as the previous one (`a`). | ||
cuda::atomic<int> b; | ||
// This object has the same type as the previous | ||
cuda::atomic<int, cuda::thread_scope_system> b; | ||
|
||
// This atomic is suitable for threads in the same thread block. | ||
cuda::atomic<int, cuda::thread_scope_block> c; | ||
// This object is atomic for threads in the same thread block | ||
cuda::atomic<int, cuda::thread_scope_block> c; | ||
``` | ||
|
||
The `atomic` class template specializations for integral and pointer types are | ||
extended with members `fetch_min` and `fetch_max`. | ||
These conform to the requirements in section [atomics.types.int] and | ||
[atomics.types.pointer] of ISO/IEC IS 14882 (the C++ Standard), | ||
with keys _min_ and _max_, and operations `min` and `max`, respectively. | ||
The `atomic` class template specializations for integral and pointer types are extended with members `fetch_min` and `fetch_max`. These conform to the requirements in `[atomics.types.int]` and `[atomics.types.pointer]`, with keys _min_ and _max_, and operations `min` and `max`, respectively. | ||
|
||
Note that conformance to these requirements include implicit conversions to | ||
unsigned types, if applicable. | ||
Note that conformance to these requirements include implicit conversions to unsigned types, if applicable. | ||
|
||
```c++ | ||
cuda::atomic<int> a(1); | ||
auto x = a.fetch_min(0); // Operates as if unsigned. | ||
cuda::atomic<int> a(1); | ||
auto x = a.fetch_min(0); // operates as if unsigned | ||
auto y = a.load(); | ||
assert(x == 1 && y == 0); | ||
``` | ||
## Restrictions | ||
## Omissions | ||
An object of type `atomic` shall not be accessed concurrently by CPU and GPU | ||
threads unless: | ||
- it is in unified memory and the [`concurrentManagedAccess` property] is 1, or | ||
- it is in CPU memory and the [`hostNativeAtomicSupported` property] is 1. | ||
None relative to libcxx. | ||
Note, for objects of scopes other than `thread_scope_system` this is a | ||
data-race, and thefore also prohibited regardless of memory characteristics. | ||
## Restrictions | ||
Under CUDA Compute Capability 6 (Pascal), an object of type `atomic` may not be | ||
used: | ||
- with automatic storage duration, or | ||
- if `is_always_lock_free()` is `false`. | ||
An object of type `atomic` shall not be accessed concurrently by CPU and GPU threads unless: | ||
1. it is in managed memory, with `concurrentManagedAccess==1`, or | ||
2. it is in host memory, with `hostNativeAtomicSupported==1`. | ||
Under CUDA Compute Capability prior to 6 (Pascal), objects of type `atomic` may | ||
not be used. | ||
(Note, for objects of scopes other than `thread_scope_system` this is a data-race, and thefore also prohibited regardless of memory characteristics.) | ||
## Implementation-Defined Behavior | ||
Under Compute Capability 6, an object of type `atomic` may not be used: | ||
1. with automatic storage duration, or | ||
2. if `is_always_lock_free()` returns `false`. | ||
For each type `T` and [thread scope] `S`, the value of | ||
`atomic<T, S>::is_always_lock_free()` is as follows: | ||
Under Compute Capability prior to 6, objects of type `atomic` may not be used. | ||
|Type `T`|Thread Scope `S`|`atomic<T, S>::is_always_lock_free()`| | ||
|--------|----------------|-------------------------------------| | ||
|Any |Any |`sizeof(T) <= 8` | | ||
## Implementation-Defined Behavior | ||
For each type `T` and scope `S`, the value of `atomic<T,S>::is_always_lock_free()` is as follows: | ||
[thread scope]: ./thread_scopes.md | ||
|Type `T`|Scope `S`|`atomic<T,S>::is_always_lock_free()`| | ||
|-|-|-| | ||
|Any|Any|`sizeof(T) <= 8`| | ||
[atomics.types.int]: https://eel.is/c++draft/atomics.types.int | ||
[atomics.types.pointer]: https://eel.is/c++draft/atomics.types.pointer | ||
[`concurrentManagedAccess` property]: https://docs.nvidia.com/cuda/cuda-runtime-api/structcudaDeviceProp.html#structcudaDeviceProp_116f9619ccc85e93bc456b8c69c80e78b | ||
[`hostNativeAtomicSupported` property]: https://docs.nvidia.com/cuda/cuda-runtime-api/structcudaDeviceProp.html#structcudaDeviceProp_1ef82fd7d1d0413c7d6f33287e5b6306f | ||
Objects in namespace `cuda::std::` have the same behavior as corresponding objects in namespace `cuda::` when instantiated with a scope of `cuda::thread_scope_system`. |
Oops, something went wrong.