Merged
add AIN readme && basic example #80
Li-JianAdd on Aug 6
add AIN readme && basic example #80
Merged
Merged fromliragnarosf/asc-commmasterintocann/asc-commmaster
Total: 33 files changed+1909-0
| @@ -13,11 +13,37 @@ | |||
| 13 | | [Commit](./aicore/hcomm/Commit.md) | Explicitly submit pending communication tasks on the channel. | | 13 | | [Commit](./aicore/hcomm/Commit.md) | Explicitly submit pending communication tasks on the channel. | |
| 14 | | [Drain](./aicore/hcomm/Drain.md) | Wait for all communication tasks on the channel to complete. | | 14 | | [Drain](./aicore/hcomm/Drain.md) | Wait for all communication tasks on the channel to complete. | |
| 15 | 15 | ||
| 16 | +## AICore Ain | ||
| 17 | + | ||
| 18 | +### Ain Class | ||
| 19 | + | ||
| 20 | +| Document | Description | | ||
| 21 | +| --- | --- | | ||
| 22 | +| [Ain](./aicore/ain/Ain.md) | Overview of the AICore-side AIN one-sided communication interface template, protocol capabilities and usage constraints. | | ||
| 23 | +| [Put](./aicore/ain/Put.md) | Write data from a local symmetric window to a peer symmetric window. | | ||
| 24 | +| [PutValue](./aicore/ain/PutValue.md) | Write an immediate value to a peer symmetric window. | | ||
| 25 | +| [Get](./aicore/ain/Get.md) | Read data from a peer symmetric window to a local symmetric window. | | ||
| 26 | +| [Flush](./aicore/ain/Flush.md) | Wait for communication tasks on all peer channels in the team to complete. | | ||
| 27 | +| [FlushAsync](./aicore/ain/FlushAsync.md) | Get the communication channel handle of a specified peer for subsequent asynchronous waiting. | | ||
| 28 | +| [Wait](./aicore/ain/Wait.md) | Wait for tasks on a specified communication channel to complete. | | ||
| 29 | +| [Signal](./aicore/ain/Signal.md) | Perform an atomic add operation on a remote signal. | | ||
| 30 | +| [ReadSignal](./aicore/ain/ReadSignal.md) | Read a local signal value. | | ||
| 31 | +| [WaitSignal](./aicore/ain/WaitSignal.md) | Wait until a local signal reaches the specified threshold. | | ||
| 32 | + | ||
| 33 | +### AinBarrierSession Class | ||
| 34 | + | ||
| 35 | +| Document | Description | | ||
| 36 | +| --- | --- | | ||
| 37 | +| [AinBarrierSession](./aicore/ain/AinBarrierSession.md) | Overview of the AICore-side AIN barrier synchronization session. | | ||
| 38 | +| [Sync](./aicore/ain/Sync.md) | Perform in-team barrier synchronization. | | ||
| 39 | + | ||
| 16 | ## Header File | 40 | ## Header File |
| 17 | ```cpp | 41 | ```cpp |
| 18 | #include "hcomm/hcomm.h" | 42 | #include "hcomm/hcomm.h" |
| 43 | +#include "ain/ain.h" | ||
| 19 | ``` | 44 | ``` |
| 20 | 45 | ||
| 21 | ## Related Documents | 46 | ## Related Documents |
| 22 | - [Hcomm Usage Guide](../guide/hcomm_usage.md) | 47 | - [Hcomm Usage Guide](../guide/hcomm_usage.md) |
| 23 | - [AIV Direct-driven URMA WriteNbi/ReadNbi Sample](../../../examples/hcomm_write_read_nbi/README_en.md) | 48 | - [AIV Direct-driven URMA WriteNbi/ReadNbi Sample](../../../examples/hcomm_write_read_nbi/README_en.md) |
| 49 | +- [Ain Basic Ring Sample](../../../examples/ain/basic_ring/README_en.md) | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | +# Ain | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Header file: | ||
| 6 | + | ||
| 7 | +```cpp | ||
| 8 | +#include "ain/ain.h" | ||
| 9 | +``` | ||
| 10 | + | ||
| 11 | +`AscendC::Ain` is an AICore-side one-sided communication interface template. It provides one-sided communication and synchronization capabilities such as `Put`/`Get`/`Signal`/`Flush`. `Ain` resolves communication channels and GM addresses from the communication team, peer rank and symmetric window handles, so the Kernel side does not need to maintain remote addresses directly. | ||
| 12 | + | ||
| 13 | +## Template Parameters | ||
| 14 | + | ||
| 15 | +```cpp | ||
| 16 | +template <unsigned CommEngineMask = AscendC::AIN_MASK_DEFAULT> | ||
| 17 | +class Ain; | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +| Parameter | Description | | ||
| 21 | +| --- | --- | | ||
| 22 | +| `CommEngineMask` | Communication engine selection mask. Default value: `AIN_MASK_DEFAULT`. This parameter is currently reserved. | | ||
| 23 | + | ||
| 24 | +## Constructor | ||
| 25 | + | ||
| 26 | +```cpp | ||
| 27 | +__aicore__ inline Ain(uint32_t contextIndex = 0); | ||
| 28 | +``` | ||
| 29 | + | ||
| 30 | +| Parameter | Input/Output | Description | | ||
| 31 | +| --- | --- | --- | | ||
| 32 | +| `contextIndex` | Input | Communication context index. Default value: 0. | | ||
| 33 | + | ||
| 34 | +## Common APIs | ||
| 35 | + | ||
| 36 | +| API | Description | | ||
| 37 | +| --- | --- | | ||
| 38 | +| [Put](./Put.md) | Write data from a local symmetric window to a peer symmetric window. | | ||
| 39 | +| [PutValue](./PutValue.md) | Write an immediate value to a peer symmetric window. | | ||
| 40 | +| [Get](./Get.md) | Read data from a peer symmetric window to a local symmetric window. | | ||
| 41 | +| [Flush](./Flush.md) | Wait for communication tasks on all peer channels in the team to complete. | | ||
| 42 | +| [FlushAsync](./FlushAsync.md) | Get the communication channel handle of a specified peer for subsequent asynchronous waiting. | | ||
| 43 | +| [Wait](./Wait.md) | Wait for tasks on a specified communication channel to complete. | | ||
| 44 | +| [Signal](./Signal.md) | Perform an atomic add operation on a remote signal. | | ||
| 45 | +| [ReadSignal](./ReadSignal.md) | Read a local signal value. | | ||
| 46 | +| [WaitSignal](./WaitSignal.md) | Wait until a local signal reaches the specified threshold. | | ||
| 47 | + | ||
| 48 | +## Usage Constraints | ||
| 49 | + | ||
| 50 | +- The Host side shall create the team and register symmetric windows before invocation. | ||
| 51 | +- The passed `HcommTeamHandle` and `HcommWindowHandle` must be valid device-side handles. | ||
| 52 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| 53 | +- `Put`, `PutValue`, `Get` and `Signal` initialize the underlying Hcomm internally. A valid `AinDescriptorUbuf` must be provided when invoking these APIs. | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | +# AinBarrierSession | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Header file: | ||
| 6 | + | ||
| 7 | +```cpp | ||
| 8 | +#include "ain/ain.h" | ||
| 9 | +``` | ||
| 10 | + | ||
| 11 | +`AscendC::AinBarrierSession` is an AICore-side in-team synchronization session implemented based on AIN signals. The constructor binds an `Ain` instance, a communication team and a barrier resource index. When `Sync` is called, it sends signals to other ranks in the team and waits until the corresponding signals from other ranks reach the threshold. | ||
| 12 | + | ||
| 13 | +## Template Parameters | ||
| 14 | + | ||
| 15 | +```cpp | ||
| 16 | +template <unsigned CommEngineMask = AscendC::AIN_MASK_DEFAULT> | ||
| 17 | +class AinBarrierSession; | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +| Parameter | Description | | ||
| 21 | +| --- | --- | | ||
| 22 | +| `CommEngineMask` | Communication engine selection mask. Default value: `AIN_MASK_DEFAULT`. This parameter is currently reserved. | | ||
| 23 | + | ||
| 24 | +## Constructor | ||
| 25 | + | ||
| 26 | +```cpp | ||
| 27 | +__aicore__ inline AinBarrierSession( | ||
| 28 | + AscendC::Ain<CommEngineMask>* ain, | ||
| 29 | + AscendC::HcommTeamHandle team, | ||
| 30 | + uint32_t index); | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +## Parameter Description | ||
| 34 | + | ||
| 35 | +| Parameter | Input/Output | Description | | ||
| 36 | +| --- | --- | --- | | ||
| 37 | +| `ain` | Input | Pointer to an `Ain` instance. | | ||
| 38 | +| `team` | Input | Communication team handle. | | ||
| 39 | +| `index` | Input | Barrier resource index. Different indexes isolate different barrier sessions. | | ||
| 40 | + | ||
| 41 | +## Common APIs | ||
| 42 | + | ||
| 43 | +| API | Description | | ||
| 44 | +| --- | --- | | ||
| 45 | +| [Sync](./Sync.md) | Perform in-team barrier synchronization. Both no-timeout and timeout overloads are supported. | | ||
| 46 | + | ||
| 47 | +## Usage Constraints | ||
| 48 | + | ||
| 49 | +- The Host side shall create the team and prepare the synchronization memory used by barrier before invocation. | ||
| 50 | +- `ain` must not be nullptr. `team` must be a valid device-side handle. | ||
| 51 | +- `index` must correspond to an available barrier resource. Different concurrent barriers should use different `index` values for isolation. | ||
| 52 | +- `Sync` updates remote signals through underlying Hcomm atomic add operations, and polls local signals to wait until other ranks arrive. | ||
| 53 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,30 @@ | |||
| 1 | +# Flush | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Wait for communication tasks on all peer channels in the specified communication team to complete. | ||
| 6 | + | ||
| 7 | +`Flush` traverses all ranks in the team except the current rank, resolves the corresponding communication channel based on the `contextIndex` of the `Ain` instance, and invokes the underlying Hcomm completion-wait API on each channel. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void Flush(AscendC::HcommTeamHandle team); | ||
| 13 | +``` | ||
| 14 | + | ||
| 15 | +## Parameter Description | ||
| 16 | + | ||
| 17 | +| Parameter | Input/Output | Description | | ||
| 18 | +| --- | --- | --- | | ||
| 19 | +| `team` | Input | Communication team handle. | | ||
| 20 | + | ||
| 21 | +## Return Value | ||
| 22 | + | ||
| 23 | +No return value. | ||
| 24 | + | ||
| 25 | +## Usage Constraints | ||
| 26 | + | ||
| 27 | +- The Host side shall create the team before invocation. | ||
| 28 | +- `team` must be a valid device-side handle. | ||
| 29 | +- `Flush` waits for submitted tasks on all peer channels in the team to complete. To wait for a single peer channel, call `FlushAsync` to obtain the channel handle and then call `Wait`. | ||
| 30 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,36 @@ | |||
| 1 | +# FlushAsync | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Get the communication channel handle corresponding to a specified peer for subsequent `Wait` calls to wait for communication tasks on that channel to complete. | ||
| 6 | + | ||
| 7 | +`FlushAsync` itself does not block waiting for communication task completion. It only resolves the channel handle based on `team`, `peer` and the `contextIndex` of the `Ain` instance, and writes it to `outChannelHandle`. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void FlushAsync( | ||
| 13 | + AscendC::HcommTeamHandle team, | ||
| 14 | + uint32_t peer, | ||
| 15 | + AscendC::ChannelHandle* outChannelHandle); | ||
| 16 | +``` | ||
| 17 | + | ||
| 18 | +## Parameter Description | ||
| 19 | + | ||
| 20 | +| Parameter | Input/Output | Description | | ||
| 21 | +| --- | --- | --- | | ||
| 22 | +| `team` | Input | Communication team handle. | | ||
| 23 | +| `peer` | Input | Peer rank ID in the team. | | ||
| 24 | +| `outChannelHandle` | Output | Returned communication channel handle. | | ||
| 25 | + | ||
| 26 | +## Return Value | ||
| 27 | + | ||
| 28 | +No return value. | ||
| 29 | + | ||
| 30 | +## Usage Constraints | ||
| 31 | + | ||
| 32 | +- The Host side shall create the team before invocation. | ||
| 33 | +- `team` must be a valid device-side handle. `peer` must be a valid rank ID in the team. | ||
| 34 | +- `outChannelHandle` must point to a valid writable address. | ||
| 35 | +- `FlushAsync` does not wait for task completion. The caller needs to call `Wait` to wait for tasks on the channel corresponding to `outChannelHandle` to complete. | ||
| 36 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,60 @@ | |||
| 1 | +# Get | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Submit a one-sided read task via the specified communication team and peer rank, reading data from a peer symmetric window to a local symmetric window. | ||
| 6 | + | ||
| 7 | +`Get` resolves the communication channel based on `team`, `peer` and the `contextIndex` of the `Ain` instance, resolves local/remote GM addresses from `dstWin`, `srcWin` and offsets, and submits the communication task through the underlying Hcomm read API. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 14 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 15 | + auto const& Config = URMA_DEFAULT_CFG> | ||
| 16 | +__aicore__ inline void Get( | ||
| 17 | + AscendC::HcommTeamHandle team, | ||
| 18 | + uint32_t peer, | ||
| 19 | + AscendC::HcommWindowHandle dstWin, | ||
| 20 | + uint64_t dstOffset, | ||
| 21 | + AscendC::HcommWindowHandle srcWin, | ||
| 22 | + uint64_t srcOffset, | ||
| 23 | + uint64_t bytes, | ||
| 24 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 25 | +``` | ||
| 26 | + | ||
| 27 | +## Parameter Description | ||
| 28 | + | ||
| 29 | +| Parameter | Input/Output | Description | | ||
| 30 | +| --- | --- | --- | | ||
| 31 | +| `team` | Input | Communication team handle. | | ||
| 32 | +| `peer` | Input | Peer rank ID in the team. | | ||
| 33 | +| `dstWin` | Input | Destination symmetric window handle of the local rank. | | ||
| 34 | +| `dstOffset` | Input | Byte offset in the destination symmetric window. | | ||
| 35 | +| `srcWin` | Input | Source symmetric window handle of the peer. | | ||
| 36 | +| `srcOffset` | Input | Byte offset in the source symmetric window. | | ||
| 37 | +| `bytes` | Input | Read length in bytes. | | ||
| 38 | +| `ubuf` | Input | UBuf temporary workspace descriptor used by the underlying Hcomm. | | ||
| 39 | + | ||
| 40 | +## Template Parameters | ||
| 41 | + | ||
| 42 | +| Parameter | Description | | ||
| 43 | +| --- | --- | | ||
| 44 | +| `DescriptorUbuf` | UBuf temporary workspace descriptor type. Default: `AinDescriptorUbuf`. | | ||
| 45 | +| `CommitFlags` | Task submission mode. `AIN_COMMIT_IMMED` means assembling the WQE and ringing the doorbell immediately. `AIN_COMMIT_DELAYED` means assembling only the WQE, and requires a subsequent `AIN_COMMIT_IMMED` task to be called to trigger submission. | | ||
| 46 | +| `Config` | URMA WQE control configuration. Default: `URMA_DEFAULT_CFG`(strong ordering / FenceOn / CqeOn). | | ||
| 47 | + | ||
| 48 | +## Return Value | ||
| 49 | + | ||
| 50 | +No return value. | ||
| 51 | + | ||
| 52 | +## Usage Constraints | ||
| 53 | + | ||
| 54 | +- The Host side shall create the team and register symmetric windows before invocation. | ||
| 55 | +- `team`, `dstWin` and `srcWin` must be valid device-side handles. `peer` must be a valid rank ID in the team. | ||
| 56 | +- `dstOffset + bytes` must fall within the registered memory range of `dstWin` corresponding to the local rank. `srcOffset + bytes` must fall within the registered memory range of `srcWin` corresponding to `peer`. | ||
| 57 | +- `ubuf.addr` and `ubuf.bytes` must provide a UBuf temporary workspace for underlying Hcomm initialization. `DescriptorUbuf` currently must provide a UBuf temporary workspace no smaller than 512 B. | ||
| 58 | +- When `AIN_COMMIT_DELAYED` is used, this task does not ring the doorbell immediately. At least one subsequent `AIN_COMMIT_IMMED` task must be submitted to ensure that previous tasks are submitted. | ||
| 59 | +- `Get` submits a non-blocking communication task. Call `Flush` to wait for tasks on all peer channels in the team to complete, or call `FlushAsync` to get a specified peer channel and then call `Wait`. | ||
| 60 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. Due to underlying protocol restrictions, the maximum data transfer length of a single `Get` call is 256 MB, that is, the input parameter `bytes` must be no greater than 256 * 1024 * 1024. | ||
| @@ -0,0 +1,73 @@ | |||
| 1 | +# Put | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Submit a one-sided write task via the specified communication team and peer rank, writing data from a local symmetric window to a peer symmetric window. | ||
| 6 | + | ||
| 7 | +`Put` resolves the communication channel based on `team`, `peer` and the `contextIndex` of the `Ain` instance, resolves remote/local GM addresses from `dstWin`, `srcWin` and offsets, and submits the communication task through the underlying Hcomm write API. `AinSignalInc` or `AinSignalAdd` can optionally be configured as a remote action, which appends a remote signal atomic add operation after the write task. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename RemoteAction = AscendC::AinRemoteNone, | ||
| 14 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 15 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 16 | + auto const& Config = URMA_DEFAULT_CFG> | ||
| 17 | +__aicore__ inline void Put( | ||
| 18 | + AscendC::HcommTeamHandle team, | ||
| 19 | + uint32_t peer, | ||
| 20 | + AscendC::HcommWindowHandle dstWin, | ||
| 21 | + uint64_t dstOffset, | ||
| 22 | + AscendC::HcommWindowHandle srcWin, | ||
| 23 | + uint64_t srcOffset, | ||
| 24 | + uint64_t bytes, | ||
| 25 | + RemoteAction remoteAction = RemoteAction{}, | ||
| 26 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 27 | +``` | ||
| 28 | + | ||
| 29 | +## Parameter Description | ||
| 30 | + | ||
| 31 | +| Parameter | Input/Output | Description | | ||
| 32 | +| --- | --- | --- | | ||
| 33 | +| `team` | Input | Communication team handle. | | ||
| 34 | +| `peer` | Input | Peer rank ID in the team. | | ||
| 35 | +| `dstWin` | Input | Destination symmetric window handle of the peer. | | ||
| 36 | +| `dstOffset` | Input | Byte offset in the destination symmetric window. | | ||
| 37 | +| `srcWin` | Input | Source symmetric window handle of the local rank. | | ||
| 38 | +| `srcOffset` | Input | Byte offset in the source symmetric window. | | ||
| 39 | +| `bytes` | Input | Write length in bytes. | | ||
| 40 | +| `remoteAction` | Input | Remote action after the write task. Default: `AinRemoteNone`, which does not trigger a remote signal operation. | | ||
| 41 | +| `ubuf` | Input | UBuf temporary workspace descriptor used by the underlying Hcomm. | | ||
| 42 | + | ||
| 43 | +## Template Parameters | ||
| 44 | + | ||
| 45 | +| Parameter | Description | | ||
| 46 | +| --- | --- | | ||
| 47 | +| `RemoteAction` | Remote action type. Supports `AinRemoteNone`, `AinSignalInc` and `AinSignalAdd`. | | ||
| 48 | +| `DescriptorUbuf` | UBuf temporary workspace descriptor type. Default: `AinDescriptorUbuf`. | | ||
| 49 | +| `CommitFlags` | Task submission mode. `AIN_COMMIT_IMMED` means assembling the WQE and ringing the doorbell immediately. `AIN_COMMIT_DELAYED` means assembling only the WQE, and requires a subsequent `AIN_COMMIT_IMMED` task to be called to trigger submission. | | ||
| 50 | +| `Config` | URMA WQE control configuration. Default: `URMA_DEFAULT_CFG`(strong ordering / FenceOn / CqeOn). | | ||
| 51 | + | ||
| 52 | +## Remote Actions | ||
| 53 | + | ||
| 54 | +| Type | Description | | ||
| 55 | +| --- | --- | | ||
| 56 | +| `AinRemoteNone` | Do not append a remote action. | | ||
| 57 | +| `AinSignalInc` | After the write task, atomically add 1 to the remote signal corresponding to `remoteAction.signalWindow` and `remoteAction.signalOffset`. | | ||
| 58 | +| `AinSignalAdd` | After the write task, atomically add `remoteAction.value` to the remote signal corresponding to `remoteAction.signalWindow` and `remoteAction.signalOffset`. | | ||
| 59 | + | ||
| 60 | +## Return Value | ||
| 61 | + | ||
| 62 | +No return value. | ||
| 63 | + | ||
| 64 | +## Usage Constraints | ||
| 65 | + | ||
| 66 | +- The Host side shall create the team and register symmetric windows before invocation. | ||
| 67 | +- `team`, `dstWin` and `srcWin` must be valid device-side handles. `peer` must be a valid rank ID in the team. | ||
| 68 | +- `dstOffset + bytes` must fall within the registered memory range of `dstWin` corresponding to `peer`. `srcOffset + bytes` must fall within the registered memory range of `srcWin` corresponding to the local rank. | ||
| 69 | +- `ubuf.addr` and `ubuf.bytes` must provide a UBuf temporary workspace for underlying Hcomm initialization. `DescriptorUbuf` currently must provide a UBuf temporary workspace no smaller than 512 B. | ||
| 70 | +- When `AIN_COMMIT_DELAYED` is used, this task does not ring the doorbell immediately. At least one subsequent `AIN_COMMIT_IMMED` task must be submitted to ensure that previous tasks are submitted. | ||
| 71 | +- `Put` submits a non-blocking communication task. Call `Flush` to wait for tasks on all peer channels in the team to complete, or call `FlushAsync` to get a specified peer channel and then call `Wait`. | ||
| 72 | +- `AinSignalInc` and `AinSignalAdd` are implemented through underlying Hcomm atomic add. The signal address shall be prepared according to `uint64_t` access requirements. | ||
| 73 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. Due to underlying protocol restrictions, the maximum data transfer length of a single `Put` call is 256 MB, that is, the input parameter `bytes` must be no greater than 256 * 1024 * 1024. | ||
| @@ -0,0 +1,71 @@ | |||
| 1 | +# PutValue | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Submit a point-to-point immediate-value write task via the specified communication team and peer rank, writing `value` to a peer symmetric window. | ||
| 6 | + | ||
| 7 | +`PutValue` resolves the communication channel based on `team`, `peer` and the `contextIndex` of the `Ain` instance, resolves the remote GM address from `dstWin` and `dstOffset`, and submits the communication task through the underlying Hcomm immediate-value write API. `AinSignalInc` or `AinSignalAdd` can optionally be configured as a remote action, which appends a remote signal atomic add operation after the write task. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename T, | ||
| 14 | + typename RemoteAction = AscendC::AinRemoteNone, | ||
| 15 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 16 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 17 | + auto const& Config = URMA_INLINE_CFG> | ||
| 18 | +__aicore__ inline void PutValue( | ||
| 19 | + AscendC::HcommTeamHandle team, | ||
| 20 | + uint32_t peer, | ||
| 21 | + AscendC::HcommWindowHandle dstWin, | ||
| 22 | + uint64_t dstOffset, | ||
| 23 | + T value, | ||
| 24 | + RemoteAction remoteAction = RemoteAction{}, | ||
| 25 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 26 | +``` | ||
| 27 | + | ||
| 28 | +## Parameter Description | ||
| 29 | + | ||
| 30 | +| Parameter | Input/Output | Description | | ||
| 31 | +| --- | --- | --- | | ||
| 32 | +| `team` | Input | Communication team handle. | | ||
| 33 | +| `peer` | Input | Peer rank ID in the team. | | ||
| 34 | +| `dstWin` | Input | Destination symmetric window handle of the peer. | | ||
| 35 | +| `dstOffset` | Input | Byte offset in the destination symmetric window. | | ||
| 36 | +| `value` | Input | Immediate value to write to the peer. | | ||
| 37 | +| `remoteAction` | Input | Remote action after the write task. Default: `AinRemoteNone`, which does not trigger a remote signal operation. | | ||
| 38 | +| `ubuf` | Input | UBuf temporary workspace descriptor used by the underlying Hcomm. | | ||
| 39 | + | ||
| 40 | +## Template Parameters | ||
| 41 | + | ||
| 42 | +| Parameter | Description | | ||
| 43 | +| --- | --- | | ||
| 44 | +| `T` | Immediate value type. | | ||
| 45 | +| `RemoteAction` | Remote action type. Supports `AinRemoteNone`, `AinSignalInc` and `AinSignalAdd`. | | ||
| 46 | +| `DescriptorUbuf` | UBuf temporary workspace descriptor type. Default: `AinDescriptorUbuf`. | | ||
| 47 | +| `CommitFlags` | Task submission mode. `AIN_COMMIT_IMMED` means assembling the WQE and ringing the doorbell immediately. `AIN_COMMIT_DELAYED` means assembling only the WQE, and requires a subsequent `AIN_COMMIT_IMMED` task to be called to trigger submission. | | ||
| 48 | +| `Config` | URMA WQE control configuration. Default: `URMA_INLINE_CFG`(strong ordering / FenceOn / CqeOn / Inline mode). | | ||
| 49 | + | ||
| 50 | +## Remote Actions | ||
| 51 | + | ||
| 52 | +| Type | Description | | ||
| 53 | +| --- | --- | | ||
| 54 | +| `AinRemoteNone` | Do not append a remote action. | | ||
| 55 | +| `AinSignalInc` | After the write task, atomically add 1 to the remote signal corresponding to `remoteAction.signalWindow` and `remoteAction.signalOffset`. | | ||
| 56 | +| `AinSignalAdd` | After the write task, atomically add `remoteAction.value` to the remote signal corresponding to `remoteAction.signalWindow` and `remoteAction.signalOffset`. | | ||
| 57 | + | ||
| 58 | +## Return Value | ||
| 59 | + | ||
| 60 | +No return value. | ||
| 61 | + | ||
| 62 | +## Usage Constraints | ||
| 63 | + | ||
| 64 | +- The Host side shall create the team and register symmetric windows before invocation. | ||
| 65 | +- `team` and `dstWin` must be valid device-side handles. `peer` must be a valid rank ID in the team. | ||
| 66 | +- `dstOffset + sizeof(T)` must fall within the registered memory range of `dstWin` corresponding to `peer`. | ||
| 67 | +- `ubuf.addr` and `ubuf.bytes` must provide a UBuf temporary workspace for underlying Hcomm initialization. `DescriptorUbuf` currently must provide a UBuf temporary workspace no smaller than 512 B. | ||
| 68 | +- When `AIN_COMMIT_DELAYED` is used, this task does not ring the doorbell immediately. At least one subsequent `AIN_COMMIT_IMMED` task must be submitted to ensure that previous tasks are submitted. | ||
| 69 | +- `PutValue` submits a non-blocking communication task. Call `Flush` to wait for tasks on all peer channels in the team to complete, or call `FlushAsync` to get a specified peer channel and then call `Wait`. | ||
| 70 | +- `AinSignalInc` and `AinSignalAdd` are implemented through underlying Hcomm atomic add. The signal address shall be prepared according to `uint64_t` access requirements. | ||
| 71 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | +# ReadSignal | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Read the local signal value of the current rank, and return the value masked to the low-order width specified by `bits`. | ||
| 6 | + | ||
| 7 | +`ReadSignal` resolves the signal address corresponding to the current rank based on `team`, `signalWindow` and `signalOffset`, and reads the `uint64_t` signal value through a device-side read operation. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline uint64_t ReadSignal( | ||
| 13 | + AscendC::HcommTeamHandle team, | ||
| 14 | + AscendC::HcommWindowHandle signalWindow, | ||
| 15 | + size_t signalOffset, | ||
| 16 | + uint32_t bits = 64, | ||
| 17 | + AscendC::AinMemoryOrder order = AscendC::AIN_MEMORY_ORDER_RELAX) const; | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +## Parameter Description | ||
| 21 | + | ||
| 22 | +| Parameter | Input/Output | Description | | ||
| 23 | +| --- | --- | --- | | ||
| 24 | +| `team` | Input | Communication team handle. | | ||
| 25 | +| `signalWindow` | Input | Symmetric window handle containing the signal. | | ||
| 26 | +| `signalOffset` | Input | Byte offset of the signal in the symmetric window. | | ||
| 27 | +| `bits` | Input | Number of low-order bits to read. Valid range: 1-64. Default: 64. | | ||
| 28 | +| `order` | Input | Memory order for signal read. Default: `AIN_MEMORY_ORDER_RELAX`. | | ||
| 29 | + | ||
| 30 | +## Return Value | ||
| 31 | + | ||
| 32 | +| Return Value | Description | | ||
| 33 | +| --- | --- | | ||
| 34 | +| `uint64_t` | Local signal value of the current rank after masking to the low `bits` bits. | | ||
| 35 | + | ||
| 36 | +## Usage Constraints | ||
| 37 | + | ||
| 38 | +- The Host side shall create the team and register the symmetric window containing the signal before invocation. | ||
| 39 | +- `team` and `signalWindow` must be valid device-side handles. | ||
| 40 | +- The address corresponding to `signalOffset` must fall within the registered memory range of the signal window corresponding to the local rank. | ||
| 41 | +- The signal address shall be prepared according to `uint64_t` access requirements. | ||
| 42 | +- `bits` is used to generate the low-order mask. Valid range: 1-64. When `bits` is 64, the complete 64-bit signal value is read. | ||
| 43 | +- Currently, only `AIN_MEMORY_ORDER_RELAX` is supported. This memory order only guarantees signal atomic read/write and threshold checking, and does not guarantee memory ordering for ordinary data accesses before and after signal operations. | ||
| 44 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,62 @@ | |||
| 1 | +# Signal | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Perform an atomic add operation on a remote signal via the specified communication team and peer rank. | ||
| 6 | + | ||
| 7 | +`Signal` resolves the communication channel based on `team`, `peer` and the `contextIndex` of the `Ain` instance, resolves the remote signal address from `action.signalWindow` and `action.signalOffset`, and submits an atomic add task through the underlying Hcomm. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename RemoteAction, | ||
| 14 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 15 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 16 | + auto const& Config = URMA_DEFAULT_CFG> | ||
| 17 | +__aicore__ inline void Signal( | ||
| 18 | + AscendC::HcommTeamHandle team, | ||
| 19 | + uint32_t peer, | ||
| 20 | + RemoteAction action, | ||
| 21 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 22 | +``` | ||
| 23 | + | ||
| 24 | +## Parameter Description | ||
| 25 | + | ||
| 26 | +| Parameter | Input/Output | Description | | ||
| 27 | +| --- | --- | --- | | ||
| 28 | +| `team` | Input | Communication team handle. | | ||
| 29 | +| `peer` | Input | Peer rank ID in the team. | | ||
| 30 | +| `action` | Input | Signal action. Supports `AinSignalInc` and `AinSignalAdd`. | | ||
| 31 | +| `ubuf` | Input | UBuf temporary workspace descriptor used by the underlying Hcomm. | | ||
| 32 | + | ||
| 33 | +## Template Parameters | ||
| 34 | + | ||
| 35 | +| Parameter | Description | | ||
| 36 | +| --- | --- | | ||
| 37 | +| `RemoteAction` | Signal action type. Supports `AinSignalInc` and `AinSignalAdd`. | | ||
| 38 | +| `DescriptorUbuf` | UBuf temporary workspace descriptor type. Default: `AinDescriptorUbuf`. | | ||
| 39 | +| `CommitFlags` | Task submission mode. `AIN_COMMIT_IMMED` means assembling the WQE and ringing the doorbell immediately. `AIN_COMMIT_DELAYED` means assembling only the WQE, and requires a subsequent `AIN_COMMIT_IMMED` task to be called to trigger submission. | | ||
| 40 | +| `Config` | URMA WQE control configuration. Default: `URMA_DEFAULT_CFG`(strong ordering / FenceOn / CqeOn). | | ||
| 41 | + | ||
| 42 | +## Signal Actions | ||
| 43 | + | ||
| 44 | +| Type | Description | | ||
| 45 | +| --- | --- | | ||
| 46 | +| `AinSignalInc` | Atomically add 1 to the remote signal corresponding to `action.signalWindow` and `action.signalOffset`. | | ||
| 47 | +| `AinSignalAdd` | Atomically add `action.value` to the remote signal corresponding to `action.signalWindow` and `action.signalOffset`. | | ||
| 48 | + | ||
| 49 | +## Return Value | ||
| 50 | + | ||
| 51 | +No return value. | ||
| 52 | + | ||
| 53 | +## Usage Constraints | ||
| 54 | + | ||
| 55 | +- The Host side shall create the team and register the symmetric window containing the signal before invocation. | ||
| 56 | +- `team` and `action.signalWindow` must be valid device-side handles. `peer` must be a valid rank ID in the team. | ||
| 57 | +- The address corresponding to `action.signalOffset` must fall within the registered memory range of the signal window corresponding to `peer`. | ||
| 58 | +- The signal address shall be prepared according to `uint64_t` access requirements. | ||
| 59 | +- `ubuf.addr` and `ubuf.bytes` must provide a UBuf temporary workspace for underlying Hcomm initialization. `DescriptorUbuf` currently must provide a UBuf temporary workspace no smaller than 512 B. | ||
| 60 | +- When `AIN_COMMIT_DELAYED` is used, this task does not ring the doorbell immediately. At least one subsequent `AIN_COMMIT_IMMED` task must be submitted to ensure that previous tasks are submitted. | ||
| 61 | +- `Signal` submits a non-blocking communication task. Call `Flush` to wait for tasks on all peer channels in the team to complete, or call `FlushAsync` to get a specified peer channel and then call `Wait`. | ||
| 62 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,59 @@ | |||
| 1 | +# Sync | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Perform barrier synchronization within the team bound to `AinBarrierSession`. | ||
| 6 | + | ||
| 7 | +`Sync` first sends barrier signals to other ranks in the team, and then waits for other ranks to write the barrier signal of the current rank. The no-timeout overload waits until synchronization completes. The timeout overload returns failure when the number of polling attempts exceeds `timeoutCycles`. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template <typename DescriptorUbuf = AscendC::AinDescriptorUbuf> | ||
| 13 | +__aicore__ inline void Sync( | ||
| 14 | + AscendC::AinMemoryOrder order, | ||
| 15 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 16 | +``` | ||
| 17 | + | ||
| 18 | +```cpp | ||
| 19 | +template <typename DescriptorUbuf = AscendC::AinDescriptorUbuf> | ||
| 20 | +__aicore__ inline int32_t Sync( | ||
| 21 | + AscendC::AinMemoryOrder order, | ||
| 22 | + uint64_t timeoutCycles, | ||
| 23 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 24 | +``` | ||
| 25 | + | ||
| 26 | +## Parameter Description | ||
| 27 | + | ||
| 28 | +| Parameter | Input/Output | Description | | ||
| 29 | +| --- | --- | --- | | ||
| 30 | +| `order` | Input | Memory order for barrier signal wait. Currently supports `AIN_MEMORY_ORDER_RELAX`. | | ||
| 31 | +| `timeoutCycles` | Input | Maximum number of polling attempts. Used only by the timeout overload. | | ||
| 32 | +| `ubuf` | Input | UBuf temporary workspace descriptor used by the underlying Hcomm. | | ||
| 33 | + | ||
| 34 | +## Template Parameters | ||
| 35 | + | ||
| 36 | +| Parameter | Description | | ||
| 37 | +| --- | --- | | ||
| 38 | +| `DescriptorUbuf` | UBuf temporary workspace descriptor type. Default: `AinDescriptorUbuf`. | | ||
| 39 | + | ||
| 40 | +## Return Value | ||
| 41 | + | ||
| 42 | +The no-timeout overload has no return value. | ||
| 43 | + | ||
| 44 | +The timeout overload returns: | ||
| 45 | + | ||
| 46 | +| Return Value | Description | | ||
| 47 | +| --- | --- | | ||
| 48 | +| `0` | Synchronization succeeded. | | ||
| 49 | +| `-1` | Waiting exceeded `timeoutCycles`; synchronization failed. | | ||
| 50 | + | ||
| 51 | +## Usage Constraints | ||
| 52 | + | ||
| 53 | +- A valid `AinBarrierSession` must be constructed before invocation. | ||
| 54 | +- The Host side shall create the team and prepare the synchronization memory used by barrier before invocation. | ||
| 55 | +- `ubuf.addr` and `ubuf.bytes` must provide a UBuf temporary workspace for underlying Hcomm initialization. `DescriptorUbuf` currently must provide a UBuf temporary workspace no smaller than 512 B. | ||
| 56 | +- Currently, only `AIN_MEMORY_ORDER_RELAX` is supported. This memory order only guarantees signal atomic read/write and threshold checking, and does not guarantee memory ordering for ordinary data accesses before and after signal operations. | ||
| 57 | +- The no-timeout overload keeps polling until all other ranks arrive at the barrier. The caller must ensure that ranks in the team call it symmetrically to avoid permanent Kernel waiting. | ||
| 58 | +- For the timeout overload, `timeoutCycles` indicates the number of polling attempts. Returning `-1` only indicates that the current rank timed out while waiting, and does not roll back signals that have already been sent. | ||
| 59 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,29 @@ | |||
| 1 | +# Wait | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Wait for communication tasks on a specified communication channel to complete. | ||
| 6 | + | ||
| 7 | +Typically, call `FlushAsync` first to obtain the communication channel handle of a specified peer, and then call `Wait` to wait for submitted tasks on that channel to complete. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void Wait(AscendC::ChannelHandle& channelHandle); | ||
| 13 | +``` | ||
| 14 | + | ||
| 15 | +## Parameter Description | ||
| 16 | + | ||
| 17 | +| Parameter | Input/Output | Description | | ||
| 18 | +| --- | --- | --- | | ||
| 19 | +| `channelHandle` | Input | Communication channel handle, usually returned by `FlushAsync`. | | ||
| 20 | + | ||
| 21 | +## Return Value | ||
| 22 | + | ||
| 23 | +No return value. | ||
| 24 | + | ||
| 25 | +## Usage Constraints | ||
| 26 | + | ||
| 27 | +- `channelHandle` must be a valid communication channel handle. | ||
| 28 | +- `Wait` blocks and waits for submitted tasks on this channel to complete through the underlying Hcomm completion-wait API. | ||
| 29 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -0,0 +1,45 @@ | |||
| 1 | +# WaitSignal | ||
| 2 | + | ||
| 3 | +## Function Description | ||
| 4 | + | ||
| 5 | +Block and wait until the local signal value of the current rank reaches the specified threshold. | ||
| 6 | + | ||
| 7 | +`WaitSignal` resolves the signal address corresponding to the current rank based on `team`, `signalWindow` and `signalOffset`, and repeatedly reads the signal value masked to the low `bits` bits until the value is greater than or equal to `least`. | ||
| 8 | + | ||
| 9 | +## Function Prototype | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void WaitSignal( | ||
| 13 | + AscendC::HcommTeamHandle team, | ||
| 14 | + AscendC::HcommWindowHandle signalWindow, | ||
| 15 | + size_t signalOffset, | ||
| 16 | + uint64_t least, | ||
| 17 | + uint32_t bits = 64, | ||
| 18 | + AscendC::AinMemoryOrder order = AscendC::AIN_MEMORY_ORDER_RELAX) const; | ||
| 19 | +``` | ||
| 20 | + | ||
| 21 | +## Parameter Description | ||
| 22 | + | ||
| 23 | +| Parameter | Input/Output | Description | | ||
| 24 | +| --- | --- | --- | | ||
| 25 | +| `team` | Input | Communication team handle. | | ||
| 26 | +| `signalWindow` | Input | Symmetric window handle containing the signal. | | ||
| 27 | +| `signalOffset` | Input | Byte offset of the signal in the symmetric window. | | ||
| 28 | +| `least` | Input | Wait threshold. | | ||
| 29 | +| `bits` | Input | Number of low-order bits to compare. Valid range: 1-64. Default: 64. | | ||
| 30 | +| `order` | Input | Memory order for signal wait. Default: `AIN_MEMORY_ORDER_RELAX`. | | ||
| 31 | + | ||
| 32 | +## Return Value | ||
| 33 | + | ||
| 34 | +No return value. | ||
| 35 | + | ||
| 36 | +## Usage Constraints | ||
| 37 | + | ||
| 38 | +- The Host side shall create the team and register the symmetric window containing the signal before invocation. | ||
| 39 | +- `team` and `signalWindow` must be valid device-side handles. | ||
| 40 | +- The address corresponding to `signalOffset` must fall within the registered memory range of the signal window corresponding to the local rank. | ||
| 41 | +- The signal address shall be prepared according to `uint64_t` access requirements. | ||
| 42 | +- `bits` is used to generate the low-order mask. Valid range: 1-64. When `bits` is 64, the complete 64-bit signal value is compared. | ||
| 43 | +- Currently, only `AIN_MEMORY_ORDER_RELAX` is supported. This memory order only guarantees signal atomic read/write and threshold checking, and does not guarantee memory ordering for ordinary data accesses before and after signal operations. | ||
| 44 | +- `WaitSignal` keeps polling until the condition is satisfied. The caller must ensure that the remote side will update this signal to avoid permanent Kernel waiting. | ||
| 45 | +- Currently, only the `COMM_PROTOCOL_UBC_CTP` protocol path is supported. | ||
| @@ -14,13 +14,39 @@ | |||
| 14 | | [Commit](./aicore/hcomm/Commit.md) | 显式提交通道上的待执行通信任务。 | | 14 | | [Commit](./aicore/hcomm/Commit.md) | 显式提交通道上的待执行通信任务。 | |
| 15 | | [Drain](./aicore/hcomm/Drain.md) | 等待通道上的通信任务完成。 | | 15 | | [Drain](./aicore/hcomm/Drain.md) | 等待通道上的通信任务完成。 | |
| 16 | 16 | ||
| 17 | +## AICore Ain | ||
| 18 | + | ||
| 19 | +### Ain类 | ||
| 20 | + | ||
| 21 | +| 文档 | 内容 | | ||
| 22 | +| --- | --- | | ||
| 23 | +| [Ain](./aicore/ain/Ain.md) | AICore侧AIN单边通信接口模板总览、协议能力和使用约束。 | | ||
| 24 | +| [Put](./aicore/ain/Put.md) | 将本端对称window中的数据写入对端对称window。 | | ||
| 25 | +| [PutValue](./aicore/ain/PutValue.md) | 将立即数写入对端对称window。 | | ||
| 26 | +| [Get](./aicore/ain/Get.md) | 从对端对称window读取数据到本端对称window。 | | ||
| 27 | +| [Flush](./aicore/ain/Flush.md) | 等待team内所有peer通道上的通信任务完成。 | | ||
| 28 | +| [FlushAsync](./aicore/ain/FlushAsync.md) | 获取指定peer的通信通道句柄,用于后续异步等待。 | | ||
| 29 | +| [Wait](./aicore/ain/Wait.md) | 等待指定通信通道上的任务完成。 | | ||
| 30 | +| [Signal](./aicore/ain/Signal.md) | 对远端signal执行原子加操作。 | | ||
| 31 | +| [ReadSignal](./aicore/ain/ReadSignal.md) | 读取本端signal值。 | | ||
| 32 | +| [WaitSignal](./aicore/ain/WaitSignal.md) | 等待本端signal达到指定阈值。 | | ||
| 33 | + | ||
| 34 | +### AinBarrierSession类 | ||
| 35 | + | ||
| 36 | +| 文档 | 内容 | | ||
| 37 | +| --- | --- | | ||
| 38 | +| [AinBarrierSession](./aicore/ain/AinBarrierSession.md) | AICore侧AIN barrier同步会话总览。 | | ||
| 39 | +| [Sync](./aicore/ain/Sync.md) | 执行team内barrier同步。 | | ||
| 40 | + | ||
| 17 | ## 头文件 | 41 | ## 头文件 |
| 18 | 42 | ||
| 19 | ```cpp | 43 | ```cpp |
| 20 | #include "hcomm/hcomm.h" | 44 | #include "hcomm/hcomm.h" |
| 45 | +#include "ain/ain.h" | ||
| 21 | ``` | 46 | ``` |
| 22 | 47 | ||
| 23 | ## 相关文档 | 48 | ## 相关文档 |
| 24 | 49 | ||
| 25 | - [Hcomm使用说明](../guide/hcomm_usage.md) | 50 | - [Hcomm使用说明](../guide/hcomm_usage.md) |
| 26 | - [AIV直驱URMA WriteNbi/ReadNbi样例](../../../examples/hcomm_write_read_nbi/README.md) | 51 | - [AIV直驱URMA WriteNbi/ReadNbi样例](../../../examples/hcomm_write_read_nbi/README.md) |
| 52 | +- [Ain Basic Ring样例](../../../examples/ain/basic_ring/README.md) | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | +# Ain | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +头文件为: | ||
| 6 | + | ||
| 7 | +```cpp | ||
| 8 | +#include "ain/ain.h" | ||
| 9 | +``` | ||
| 10 | + | ||
| 11 | +`AscendC::Ain`是AICore侧单边通信接口模板,提供`Put`/`Get`/`Signal`/`Flush`等单边通信及同步能力。`Ain`会根据通信team、对端rank和对称window句柄解析通信通道及GM地址,Kernel侧无需直接维护远端地址。 | ||
| 12 | + | ||
| 13 | +## 模板参数 | ||
| 14 | + | ||
| 15 | +```cpp | ||
| 16 | +template <unsigned CommEngineMask = AscendC::AIN_MASK_DEFAULT> | ||
| 17 | +class Ain; | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +| 参数 | 说明 | | ||
| 21 | +| --- | --- | | ||
| 22 | +| `CommEngineMask` | 通信引擎选择掩码,默认值为`AIN_MASK_DEFAULT`。当前为预留参数。 | | ||
| 23 | + | ||
| 24 | +## 构造函数 | ||
| 25 | + | ||
| 26 | +```cpp | ||
| 27 | +__aicore__ inline Ain(uint32_t contextIndex = 0); | ||
| 28 | +``` | ||
| 29 | + | ||
| 30 | +| 参数 | 输入/输出 | 说明 | | ||
| 31 | +| --- | --- | --- | | ||
| 32 | +| `contextIndex` | 输入 | 通信上下文索引,默认值为0。 | | ||
| 33 | + | ||
| 34 | +## 常用接口 | ||
| 35 | + | ||
| 36 | +| 接口 | 说明 | | ||
| 37 | +| --- | --- | | ||
| 38 | +| [Put](./Put.md) | 将本端对称window中的数据写入对端对称window。 | | ||
| 39 | +| [PutValue](./PutValue.md) | 将立即数写入对端对称window。 | | ||
| 40 | +| [Get](./Get.md) | 从对端对称window读取数据到本端对称window。 | | ||
| 41 | +| [Flush](./Flush.md) | 等待team内所有peer通道上的通信任务完成。 | | ||
| 42 | +| [FlushAsync](./FlushAsync.md) | 获取指定peer的通信通道句柄,用于后续异步等待。 | | ||
| 43 | +| [Wait](./Wait.md) | 等待指定通信通道上的任务完成。 | | ||
| 44 | +| [Signal](./Signal.md) | 对远端signal执行原子加操作。 | | ||
| 45 | +| [ReadSignal](./ReadSignal.md) | 读取本端signal值。 | | ||
| 46 | +| [WaitSignal](./WaitSignal.md) | 等待本端signal达到指定阈值。 | | ||
| 47 | + | ||
| 48 | +## 约束说明 | ||
| 49 | + | ||
| 50 | +- 调用前Host侧需完成team创建、对称window注册。 | ||
| 51 | +- 传入的`HcommTeamHandle`和`HcommWindowHandle`需要是有效的device侧句柄。 | ||
| 52 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| 53 | +- `Put`、`PutValue`、`Get`和`Signal`内部会初始化底层Hcomm,调用时需要提供有效的`AinDescriptorUbuf`。 | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | +# AinBarrierSession | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +头文件为: | ||
| 6 | + | ||
| 7 | +```cpp | ||
| 8 | +#include "ain/ain.h" | ||
| 9 | +``` | ||
| 10 | + | ||
| 11 | +`AscendC::AinBarrierSession`是AICore侧基于AIN signal实现的team内同步会话。构造时绑定`Ain`实例、通信team和barrier资源索引;调用`Sync`时对team内其他rank发送signal,并等待其他rank对应signal达到阈值。 | ||
| 12 | + | ||
| 13 | +## 模板参数 | ||
| 14 | + | ||
| 15 | +```cpp | ||
| 16 | +template <unsigned CommEngineMask = AscendC::AIN_MASK_DEFAULT> | ||
| 17 | +class AinBarrierSession; | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +| 参数 | 说明 | | ||
| 21 | +| --- | --- | | ||
| 22 | +| `CommEngineMask` | 通信引擎选择掩码,默认值为`AIN_MASK_DEFAULT`。当前为预留参数。 | | ||
| 23 | + | ||
| 24 | +## 构造函数 | ||
| 25 | + | ||
| 26 | +```cpp | ||
| 27 | +__aicore__ inline AinBarrierSession( | ||
| 28 | + AscendC::Ain<CommEngineMask>* ain, | ||
| 29 | + AscendC::HcommTeamHandle team, | ||
| 30 | + uint32_t index); | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +## 参数说明 | ||
| 34 | + | ||
| 35 | +| 参数 | 输入/输出 | 说明 | | ||
| 36 | +| --- | --- | --- | | ||
| 37 | +| `ain` | 输入 | `Ain`实例指针。 | | ||
| 38 | +| `team` | 输入 | 通信team句柄。 | | ||
| 39 | +| `index` | 输入 | barrier资源索引,不同索引用于隔离不同barrier会话。 | | ||
| 40 | + | ||
| 41 | +## 常用接口 | ||
| 42 | + | ||
| 43 | +| 接口 | 说明 | | ||
| 44 | +| --- | --- | | ||
| 45 | +| [Sync](./Sync.md) | 执行team内barrier同步,支持无超时和带超时两种重载。 | | ||
| 46 | + | ||
| 47 | +## 约束说明 | ||
| 48 | + | ||
| 49 | +- 调用前Host侧需完成team创建,并准备barrier使用的同步内存。 | ||
| 50 | +- `ain`不能为nullptr;`team`需要是有效的device侧句柄。 | ||
| 51 | +- `index`需要对应可用的barrier资源,不同并发barrier应使用不同`index`隔离。 | ||
| 52 | +- `Sync`内部会通过底层Hcomm原子加更新远端signal,并轮询本端signal等待其他rank到达。 | ||
| 53 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,30 @@ | |||
| 1 | +# Flush | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +等待指定通信team内所有peer通道上的通信任务完成。 | ||
| 6 | + | ||
| 7 | +`Flush`会遍历team内除本rank外的所有rank,根据`Ain`实例的`contextIndex`解析对应通信通道,并对每个通道调用底层Hcomm完成等待接口。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void Flush(AscendC::HcommTeamHandle team); | ||
| 13 | +``` | ||
| 14 | + | ||
| 15 | +## 参数说明 | ||
| 16 | + | ||
| 17 | +| 参数 | 输入/输出 | 说明 | | ||
| 18 | +| --- | --- | --- | | ||
| 19 | +| `team` | 输入 | 通信team句柄。 | | ||
| 20 | + | ||
| 21 | +## 返回值 | ||
| 22 | + | ||
| 23 | +无返回值。 | ||
| 24 | + | ||
| 25 | +## 约束说明 | ||
| 26 | + | ||
| 27 | +- 调用前Host侧需完成team创建。 | ||
| 28 | +- `team`需要是有效的device侧句柄。 | ||
| 29 | +- `Flush`会等待team内所有peer通道上的已提交任务完成;如只需要等待单个peer通道,可通过`FlushAsync`获取通道句柄后调用`Wait`。 | ||
| 30 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,36 @@ | |||
| 1 | +# FlushAsync | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +获取指定peer对应的通信通道句柄,用于后续调用`Wait`等待该通道上的通信任务完成。 | ||
| 6 | + | ||
| 7 | +`FlushAsync`本身不阻塞等待通信任务完成,只根据`team`、`peer`和`Ain`实例的`contextIndex`解析通道句柄并写入`outChannelHandle`。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void FlushAsync( | ||
| 13 | + AscendC::HcommTeamHandle team, | ||
| 14 | + uint32_t peer, | ||
| 15 | + AscendC::ChannelHandle* outChannelHandle); | ||
| 16 | +``` | ||
| 17 | + | ||
| 18 | +## 参数说明 | ||
| 19 | + | ||
| 20 | +| 参数 | 输入/输出 | 说明 | | ||
| 21 | +| --- | --- | --- | | ||
| 22 | +| `team` | 输入 | 通信team句柄。 | | ||
| 23 | +| `peer` | 输入 | team内的对端rank ID。 | | ||
| 24 | +| `outChannelHandle` | 输出 | 返回解析出的通信通道句柄。 | | ||
| 25 | + | ||
| 26 | +## 返回值 | ||
| 27 | + | ||
| 28 | +无返回值。 | ||
| 29 | + | ||
| 30 | +## 约束说明 | ||
| 31 | + | ||
| 32 | +- 调用前Host侧需完成team创建。 | ||
| 33 | +- `team`需要是有效的device侧句柄;`peer`需要是team内有效rank ID。 | ||
| 34 | +- `outChannelHandle`需要指向有效可写地址。 | ||
| 35 | +- `FlushAsync`不会等待任务完成,调用方需要继续调用`Wait`等待`outChannelHandle`对应通道上的任务完成。 | ||
| 36 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,60 @@ | |||
| 1 | +# Get | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +通过指定通信team和对端rank,提交单边读任务,将对端对称window中的数据读取到本端对称window。 | ||
| 6 | + | ||
| 7 | +`Get`会根据`team`、`peer`和`Ain`实例的`contextIndex`解析通信通道,根据`dstWin`、`srcWin`及offset解析本端/远端GM地址,并通过底层Hcomm读接口提交通信任务。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 14 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 15 | + auto const& Config = URMA_DEFAULT_CFG> | ||
| 16 | +__aicore__ inline void Get( | ||
| 17 | + AscendC::HcommTeamHandle team, | ||
| 18 | + uint32_t peer, | ||
| 19 | + AscendC::HcommWindowHandle dstWin, | ||
| 20 | + uint64_t dstOffset, | ||
| 21 | + AscendC::HcommWindowHandle srcWin, | ||
| 22 | + uint64_t srcOffset, | ||
| 23 | + uint64_t bytes, | ||
| 24 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 25 | +``` | ||
| 26 | + | ||
| 27 | +## 参数说明 | ||
| 28 | + | ||
| 29 | +| 参数 | 输入/输出 | 说明 | | ||
| 30 | +| --- | --- | --- | | ||
| 31 | +| `team` | 输入 | 通信team句柄。 | | ||
| 32 | +| `peer` | 输入 | team内的对端rank ID。 | | ||
| 33 | +| `dstWin` | 输入 | 本端目的对称window句柄。 | | ||
| 34 | +| `dstOffset` | 输入 | 目的对称window内的字节偏移。 | | ||
| 35 | +| `srcWin` | 输入 | 对端源对称window句柄。 | | ||
| 36 | +| `srcOffset` | 输入 | 源对称window内的字节偏移。 | | ||
| 37 | +| `bytes` | 输入 | 读取长度,单位为字节。 | | ||
| 38 | +| `ubuf` | 输入 | 底层Hcomm使用的UBuf临时工作区描述。 | | ||
| 39 | + | ||
| 40 | +## 模板参数 | ||
| 41 | + | ||
| 42 | +| 参数 | 说明 | | ||
| 43 | +| --- | --- | | ||
| 44 | +| `DescriptorUbuf` | UBuf临时工作区描述类型,默认`AinDescriptorUbuf`。 | | ||
| 45 | +| `CommitFlags` | 任务提交方式。`AIN_COMMIT_IMMED`表示组装WQE后立即响铃提交;`AIN_COMMIT_DELAYED`表示只组装WQE,需后续调用一个`AIN_COMMIT_IMMED`任务统一触发提交。 | | ||
| 46 | +| `Config` | URMA WQE控制配置,默认`URMA_DEFAULT_CFG`(强保序/FenceOn/CqeOn)。 | | ||
| 47 | + | ||
| 48 | +## 返回值 | ||
| 49 | + | ||
| 50 | +无返回值。 | ||
| 51 | + | ||
| 52 | +## 约束说明 | ||
| 53 | + | ||
| 54 | +- 调用前Host侧需完成team创建及对称window注册。 | ||
| 55 | +- `team`、`dstWin`和`srcWin`需要是有效的device侧句柄;`peer`需要是team内有效rank ID。 | ||
| 56 | +- `dstOffset + bytes`需要落在本rank对应的`dstWin`注册内存范围内,`srcOffset + bytes`需要落在`peer`对应的`srcWin`注册内存范围内。 | ||
| 57 | +- `ubuf.addr`和`ubuf.bytes`需要提供可供底层Hcomm初始化使用的UBuf临时工作区;`DescriptorUbuf`当前必须提供不小于512B的UBuf临时工作区。 | ||
| 58 | +- 使用`AIN_COMMIT_DELAYED`时,本次任务不会立即响铃提交,需要后续至少提交一次`AIN_COMMIT_IMMED`的任务来保证之前任务已被提交。 | ||
| 59 | +- `Get`提交的是非阻塞通信任务;需要调用`Flush`等待team内所有peer通道任务完成,或通过`FlushAsync`获取指定peer通道后调用`Wait`等待完成。 | ||
| 60 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径,由于底层协议限制,单次调用`Get`数据传输长度最大不超过256MB,即入参bytes需要小于等于256 * 1024 * 1024。 | ||
| @@ -0,0 +1,73 @@ | |||
| 1 | +# Put | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +通过指定通信team和对端rank,提交单边写任务,将本端对称window中的数据写入对端对称window。 | ||
| 6 | + | ||
| 7 | +`Put`会根据`team`、`peer`和`Ain`实例的`contextIndex`解析通信通道,根据`dstWin`、`srcWin`及offset解析远端/本端GM地址,并通过底层Hcomm写接口提交通信任务。可选配置`AinSignalInc`或`AinSignalAdd`作为远端动作,在写任务后追加一次远端signal原子加操作。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename RemoteAction = AscendC::AinRemoteNone, | ||
| 14 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 15 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 16 | + auto const& Config = URMA_DEFAULT_CFG> | ||
| 17 | +__aicore__ inline void Put( | ||
| 18 | + AscendC::HcommTeamHandle team, | ||
| 19 | + uint32_t peer, | ||
| 20 | + AscendC::HcommWindowHandle dstWin, | ||
| 21 | + uint64_t dstOffset, | ||
| 22 | + AscendC::HcommWindowHandle srcWin, | ||
| 23 | + uint64_t srcOffset, | ||
| 24 | + uint64_t bytes, | ||
| 25 | + RemoteAction remoteAction = RemoteAction{}, | ||
| 26 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 27 | +``` | ||
| 28 | + | ||
| 29 | +## 参数说明 | ||
| 30 | + | ||
| 31 | +| 参数 | 输入/输出 | 说明 | | ||
| 32 | +| --- | --- | --- | | ||
| 33 | +| `team` | 输入 | 通信team句柄。 | | ||
| 34 | +| `peer` | 输入 | team内的对端rank ID。 | | ||
| 35 | +| `dstWin` | 输入 | 对端目的对称window句柄。 | | ||
| 36 | +| `dstOffset` | 输入 | 目的对称window内的字节偏移。 | | ||
| 37 | +| `srcWin` | 输入 | 本端源对称window句柄。 | | ||
| 38 | +| `srcOffset` | 输入 | 源对称window内的字节偏移。 | | ||
| 39 | +| `bytes` | 输入 | 写入长度,单位为字节。 | | ||
| 40 | +| `remoteAction` | 输入 | 写任务后的远端动作,默认`AinRemoteNone`,不触发远端signal操作。 | | ||
| 41 | +| `ubuf` | 输入 | 底层Hcomm使用的UBuf临时工作区描述。 | | ||
| 42 | + | ||
| 43 | +## 模板参数 | ||
| 44 | + | ||
| 45 | +| 参数 | 说明 | | ||
| 46 | +| --- | --- | | ||
| 47 | +| `RemoteAction` | 远端动作类型,支持`AinRemoteNone`、`AinSignalInc`和`AinSignalAdd`。 | | ||
| 48 | +| `DescriptorUbuf` | UBuf临时工作区描述类型,默认`AinDescriptorUbuf`。 | | ||
| 49 | +| `CommitFlags` | 任务提交方式。`AIN_COMMIT_IMMED`表示组装WQE后立即响铃提交;`AIN_COMMIT_DELAYED`表示只组装WQE,需后续调用一个`AIN_COMMIT_IMMED`任务统一触发提交。 | | ||
| 50 | +| `Config` | URMA WQE控制配置,默认`URMA_DEFAULT_CFG`(强保序/FenceOn/CqeOn)。 | | ||
| 51 | + | ||
| 52 | +## 远端动作 | ||
| 53 | + | ||
| 54 | +| 类型 | 说明 | | ||
| 55 | +| --- | --- | | ||
| 56 | +| `AinRemoteNone` | 不追加远端动作。 | | ||
| 57 | +| `AinSignalInc` | 写任务后对`remoteAction.signalWindow`中`remoteAction.signalOffset`对应的远端signal执行原子加1。 | | ||
| 58 | +| `AinSignalAdd` | 写任务后对`remoteAction.signalWindow`中`remoteAction.signalOffset`对应的远端signal执行原子加`remoteAction.value`。 | | ||
| 59 | + | ||
| 60 | +## 返回值 | ||
| 61 | + | ||
| 62 | +无返回值。 | ||
| 63 | + | ||
| 64 | +## 约束说明 | ||
| 65 | + | ||
| 66 | +- 调用前Host侧需完成team创建及对称window注册。 | ||
| 67 | +- `team`、`dstWin`和`srcWin`需要是有效的device侧句柄;`peer`需要是team内有效rank ID。 | ||
| 68 | +- `dstOffset + bytes`需要落在`peer`对应的`dstWin`注册内存范围内,`srcOffset + bytes`需要落在本rank对应的`srcWin`注册内存范围内。 | ||
| 69 | +- `ubuf.addr`和`ubuf.bytes`需要提供可供底层Hcomm初始化使用的UBuf临时工作区;`DescriptorUbuf`当前必须提供不小于512B的UBuf临时工作区。 | ||
| 70 | +- 使用`AIN_COMMIT_DELAYED`时,本次任务不会立即响铃提交,需要后续至少提交一次`AIN_COMMIT_IMMED`的任务来保证之前任务已被提交。 | ||
| 71 | +- `Put`提交的是非阻塞通信任务;需要调用`Flush`等待team内所有peer通道任务完成,或通过`FlushAsync`获取指定peer通道后调用`Wait`等待完成。 | ||
| 72 | +- `AinSignalInc`和`AinSignalAdd`通过底层Hcomm原子加实现,signal地址应按`uint64_t`访问要求准备。 | ||
| 73 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径,由于底层协议限制,单次调用`Put`数据传输长度最大不超过256MB,即入参bytes需要小于等于256 * 1024 * 1024。 | ||
| @@ -0,0 +1,71 @@ | |||
| 1 | +# PutValue | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +通过指定通信team和对端rank,提交点对点立即数写任务,将`value`写入对端对称window。 | ||
| 6 | + | ||
| 7 | +`PutValue`会根据`team`、`peer`和`Ain`实例的`contextIndex`解析通信通道,根据`dstWin`及`dstOffset`解析远端GM地址,并通过底层Hcomm立即数写接口提交通信任务。可选配置`AinSignalInc`或`AinSignalAdd`作为远端动作,在写任务后追加一次远端signal原子加操作。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename T, | ||
| 14 | + typename RemoteAction = AscendC::AinRemoteNone, | ||
| 15 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 16 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 17 | + auto const& Config = URMA_INLINE_CFG> | ||
| 18 | +__aicore__ inline void PutValue( | ||
| 19 | + AscendC::HcommTeamHandle team, | ||
| 20 | + uint32_t peer, | ||
| 21 | + AscendC::HcommWindowHandle dstWin, | ||
| 22 | + uint64_t dstOffset, | ||
| 23 | + T value, | ||
| 24 | + RemoteAction remoteAction = RemoteAction{}, | ||
| 25 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 26 | +``` | ||
| 27 | + | ||
| 28 | +## 参数说明 | ||
| 29 | + | ||
| 30 | +| 参数 | 输入/输出 | 说明 | | ||
| 31 | +| --- | --- | --- | | ||
| 32 | +| `team` | 输入 | 通信team句柄。 | | ||
| 33 | +| `peer` | 输入 | team内的对端rank ID。 | | ||
| 34 | +| `dstWin` | 输入 | 对端目的对称window句柄。 | | ||
| 35 | +| `dstOffset` | 输入 | 目的对称window内的字节偏移。 | | ||
| 36 | +| `value` | 输入 | 需要写入对端的立即数。 | | ||
| 37 | +| `remoteAction` | 输入 | 写任务后的远端动作,默认`AinRemoteNone`,不触发远端signal操作。 | | ||
| 38 | +| `ubuf` | 输入 | 底层Hcomm使用的UBuf临时工作区描述。 | | ||
| 39 | + | ||
| 40 | +## 模板参数 | ||
| 41 | + | ||
| 42 | +| 参数 | 说明 | | ||
| 43 | +| --- | --- | | ||
| 44 | +| `T` | 立即数类型。 | | ||
| 45 | +| `RemoteAction` | 远端动作类型,支持`AinRemoteNone`、`AinSignalInc`和`AinSignalAdd`。 | | ||
| 46 | +| `DescriptorUbuf` | UBuf临时工作区描述类型,默认`AinDescriptorUbuf`。 | | ||
| 47 | +| `CommitFlags` | 任务提交方式。`AIN_COMMIT_IMMED`表示组装WQE后立即响铃提交;`AIN_COMMIT_DELAYED`表示只组装WQE,需后续调用一个`AIN_COMMIT_IMMED`任务统一触发提交。 | | ||
| 48 | +| `Config` | URMA WQE控制配置,默认`URMA_INLINE_CFG`(强保序/FenceOn/CqeOn/Inline模式)。 | | ||
| 49 | + | ||
| 50 | +## 远端动作 | ||
| 51 | + | ||
| 52 | +| 类型 | 说明 | | ||
| 53 | +| --- | --- | | ||
| 54 | +| `AinRemoteNone` | 不追加远端动作。 | | ||
| 55 | +| `AinSignalInc` | 写任务后对`remoteAction.signalWindow`中`remoteAction.signalOffset`对应的远端signal执行原子加1。 | | ||
| 56 | +| `AinSignalAdd` | 写任务后对`remoteAction.signalWindow`中`remoteAction.signalOffset`对应的远端signal执行原子加`remoteAction.value`。 | | ||
| 57 | + | ||
| 58 | +## 返回值 | ||
| 59 | + | ||
| 60 | +无返回值。 | ||
| 61 | + | ||
| 62 | +## 约束说明 | ||
| 63 | + | ||
| 64 | +- 调用前Host侧需完成team创建及对称window注册。 | ||
| 65 | +- `team`和`dstWin`需要是有效的device侧句柄;`peer`需要是team内有效rank ID。 | ||
| 66 | +- `dstOffset + sizeof(T)`需要落在`peer`对应的`dstWin`注册内存范围内。 | ||
| 67 | +- `ubuf.addr`和`ubuf.bytes`需要提供可供底层Hcomm初始化使用的UBuf临时工作区;`DescriptorUbuf`当前必须提供不小于512B的UBuf临时工作区。 | ||
| 68 | +- 使用`AIN_COMMIT_DELAYED`时,本次任务不会立即响铃提交,需要后续至少提交一次`AIN_COMMIT_IMMED`的任务来保证之前任务已被提交。 | ||
| 69 | +- `PutValue`提交的是非阻塞通信任务;需要调用`Flush`等待team内所有peer通道任务完成,或通过`FlushAsync`获取指定peer通道后调用`Wait`等待完成。 | ||
| 70 | +- `AinSignalInc`和`AinSignalAdd`通过底层Hcomm原子加实现,signal地址应按`uint64_t`访问要求准备。 | ||
| 71 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | +# ReadSignal | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +读取本rank本地signal值,并按`bits`指定的低位宽度返回掩码后的结果。 | ||
| 6 | + | ||
| 7 | +`ReadSignal`会根据`team`、`signalWindow`和`signalOffset`解析本rank对应的signal地址,并通过device侧读操作读取`uint64_t` signal值。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline uint64_t ReadSignal( | ||
| 13 | + AscendC::HcommTeamHandle team, | ||
| 14 | + AscendC::HcommWindowHandle signalWindow, | ||
| 15 | + size_t signalOffset, | ||
| 16 | + uint32_t bits = 64, | ||
| 17 | + AscendC::AinMemoryOrder order = AscendC::AIN_MEMORY_ORDER_RELAX) const; | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +## 参数说明 | ||
| 21 | + | ||
| 22 | +| 参数 | 输入/输出 | 说明 | | ||
| 23 | +| --- | --- | --- | | ||
| 24 | +| `team` | 输入 | 通信team句柄。 | | ||
| 25 | +| `signalWindow` | 输入 | signal所在对称window句柄。 | | ||
| 26 | +| `signalOffset` | 输入 | signal在对称window内的字节偏移。 | | ||
| 27 | +| `bits` | 输入 | 读取低位bit数,取值范围为1-64,默认64。 | | ||
| 28 | +| `order` | 输入 | signal读内存序,默认`AIN_MEMORY_ORDER_RELAX`。 | | ||
| 29 | + | ||
| 30 | +## 返回值 | ||
| 31 | + | ||
| 32 | +| 返回值 | 说明 | | ||
| 33 | +| --- | --- | | ||
| 34 | +| `uint64_t` | 本rank本地signal低`bits`位掩码后的值。 | | ||
| 35 | + | ||
| 36 | +## 约束说明 | ||
| 37 | + | ||
| 38 | +- 调用前Host侧需完成team创建及signal所在对称window注册。 | ||
| 39 | +- `team`和`signalWindow`需要是有效的device侧句柄。 | ||
| 40 | +- `signalOffset`对应地址需要落在本rank对应的signal window注册内存范围内。 | ||
| 41 | +- signal地址应按`uint64_t`访问要求准备。 | ||
| 42 | +- `bits`用于生成低位掩码;取值范围为1-64,当`bits`为64时读取完整64位signal值。 | ||
| 43 | +- 当前仅支持`AIN_MEMORY_ORDER_RELAX`。该内存序只保证signal原子读写及阈值检查,不保证signal操作前后普通数据访问的内存序。 | ||
| 44 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,62 @@ | |||
| 1 | +# Signal | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +通过指定通信team和对端rank,对远端signal执行原子加操作。 | ||
| 6 | + | ||
| 7 | +`Signal`会根据`team`、`peer`和`Ain`实例的`contextIndex`解析通信通道,根据`action.signalWindow`及`action.signalOffset`解析远端signal地址,并通过底层Hcomm提交原子加任务。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template < | ||
| 13 | + typename RemoteAction, | ||
| 14 | + typename DescriptorUbuf = AscendC::AinDescriptorUbuf, | ||
| 15 | + AscendC::AinCommitFlags CommitFlags = AscendC::AIN_COMMIT_IMMED, | ||
| 16 | + auto const& Config = URMA_DEFAULT_CFG> | ||
| 17 | +__aicore__ inline void Signal( | ||
| 18 | + AscendC::HcommTeamHandle team, | ||
| 19 | + uint32_t peer, | ||
| 20 | + RemoteAction action, | ||
| 21 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 22 | +``` | ||
| 23 | + | ||
| 24 | +## 参数说明 | ||
| 25 | + | ||
| 26 | +| 参数 | 输入/输出 | 说明 | | ||
| 27 | +| --- | --- | --- | | ||
| 28 | +| `team` | 输入 | 通信team句柄。 | | ||
| 29 | +| `peer` | 输入 | team内的对端rank ID。 | | ||
| 30 | +| `action` | 输入 | signal动作,支持`AinSignalInc`和`AinSignalAdd`。 | | ||
| 31 | +| `ubuf` | 输入 | 底层Hcomm使用的UBuf临时工作区描述。 | | ||
| 32 | + | ||
| 33 | +## 模板参数 | ||
| 34 | + | ||
| 35 | +| 参数 | 说明 | | ||
| 36 | +| --- | --- | | ||
| 37 | +| `RemoteAction` | signal动作类型,支持`AinSignalInc`和`AinSignalAdd`。 | | ||
| 38 | +| `DescriptorUbuf` | UBuf临时工作区描述类型,默认`AinDescriptorUbuf`。 | | ||
| 39 | +| `CommitFlags` | 任务提交方式。`AIN_COMMIT_IMMED`表示组装WQE后立即响铃提交;`AIN_COMMIT_DELAYED`表示只组装WQE,需后续调用一个`AIN_COMMIT_IMMED`任务统一触发提交。 | | ||
| 40 | +| `Config` | URMA WQE控制配置,默认`URMA_DEFAULT_CFG`(强保序/FenceOn/CqeOn)。 | | ||
| 41 | + | ||
| 42 | +## Signal动作 | ||
| 43 | + | ||
| 44 | +| 类型 | 说明 | | ||
| 45 | +| --- | --- | | ||
| 46 | +| `AinSignalInc` | 对`action.signalWindow`中`action.signalOffset`对应的远端signal执行原子加1。 | | ||
| 47 | +| `AinSignalAdd` | 对`action.signalWindow`中`action.signalOffset`对应的远端signal执行原子加`action.value`。 | | ||
| 48 | + | ||
| 49 | +## 返回值 | ||
| 50 | + | ||
| 51 | +无返回值。 | ||
| 52 | + | ||
| 53 | +## 约束说明 | ||
| 54 | + | ||
| 55 | +- 调用前Host侧需完成team创建及signal所在对称window注册。 | ||
| 56 | +- `team`和`action.signalWindow`需要是有效的device侧句柄;`peer`需要是team内有效rank ID。 | ||
| 57 | +- `action.signalOffset`对应地址需要落在`peer`对应的signal window注册内存范围内。 | ||
| 58 | +- signal地址应按`uint64_t`访问要求准备。 | ||
| 59 | +- `ubuf.addr`和`ubuf.bytes`需要提供可供底层Hcomm初始化使用的UBuf临时工作区;`DescriptorUbuf`当前必须提供不小于512B的UBuf临时工作区。 | ||
| 60 | +- 使用`AIN_COMMIT_DELAYED`时,本次任务不会立即响铃提交,需要后续至少提交一次`AIN_COMMIT_IMMED`的任务来保证之前任务已被提交。 | ||
| 61 | +- `Signal`提交的是非阻塞通信任务;需要调用`Flush`等待team内所有peer通道任务完成,或通过`FlushAsync`获取指定peer通道后调用`Wait`等待完成。 | ||
| 62 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,59 @@ | |||
| 1 | +# Sync | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +执行`AinBarrierSession`绑定team内的barrier同步。 | ||
| 6 | + | ||
| 7 | +`Sync`会先向team内其他rank发送barrier signal,再等待其他rank写入本rank的barrier signal。无超时重载会一直等待直到同步完成;带超时重载在轮询次数超过`timeoutCycles`后返回失败。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +template <typename DescriptorUbuf = AscendC::AinDescriptorUbuf> | ||
| 13 | +__aicore__ inline void Sync( | ||
| 14 | + AscendC::AinMemoryOrder order, | ||
| 15 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 16 | +``` | ||
| 17 | + | ||
| 18 | +```cpp | ||
| 19 | +template <typename DescriptorUbuf = AscendC::AinDescriptorUbuf> | ||
| 20 | +__aicore__ inline int32_t Sync( | ||
| 21 | + AscendC::AinMemoryOrder order, | ||
| 22 | + uint64_t timeoutCycles, | ||
| 23 | + const DescriptorUbuf& ubuf = DescriptorUbuf{}); | ||
| 24 | +``` | ||
| 25 | + | ||
| 26 | +## 参数说明 | ||
| 27 | + | ||
| 28 | +| 参数 | 输入/输出 | 说明 | | ||
| 29 | +| --- | --- | --- | | ||
| 30 | +| `order` | 输入 | barrier signal等待内存序,当前支持`AIN_MEMORY_ORDER_RELAX`。 | | ||
| 31 | +| `timeoutCycles` | 输入 | 最大轮询次数,仅带超时重载使用。 | | ||
| 32 | +| `ubuf` | 输入 | 底层Hcomm使用的UBuf临时工作区描述。 | | ||
| 33 | + | ||
| 34 | +## 模板参数 | ||
| 35 | + | ||
| 36 | +| 参数 | 说明 | | ||
| 37 | +| --- | --- | | ||
| 38 | +| `DescriptorUbuf` | UBuf临时工作区描述类型,默认`AinDescriptorUbuf`。 | | ||
| 39 | + | ||
| 40 | +## 返回值 | ||
| 41 | + | ||
| 42 | +无超时重载无返回值。 | ||
| 43 | + | ||
| 44 | +带超时重载返回值如下: | ||
| 45 | + | ||
| 46 | +| 返回值 | 说明 | | ||
| 47 | +| --- | --- | | ||
| 48 | +| `0` | 同步成功。 | | ||
| 49 | +| `-1` | 等待超过`timeoutCycles`,同步失败。 | | ||
| 50 | + | ||
| 51 | +## 约束说明 | ||
| 52 | + | ||
| 53 | +- 调用前需要先构造有效的`AinBarrierSession`。 | ||
| 54 | +- 调用前Host侧需完成team创建,并准备barrier使用的同步内存。 | ||
| 55 | +- `ubuf.addr`和`ubuf.bytes`需要提供可供底层Hcomm初始化使用的UBuf临时工作区;`DescriptorUbuf`当前必须提供不小于512B的UBuf临时工作区。 | ||
| 56 | +- 当前仅支持`AIN_MEMORY_ORDER_RELAX`。该内存序只保证signal原子读写及阈值检查,不保证signal操作前后普通数据访问的内存序。 | ||
| 57 | +- 无超时重载会持续轮询直到所有其他rank到达barrier,调用方需要保证team内rank对称调用,避免Kernel永久等待。 | ||
| 58 | +- 带超时重载的`timeoutCycles`表示轮询次数,返回`-1`时只表示本rank等待超时,不会回滚已经发出的signal。 | ||
| 59 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,29 @@ | |||
| 1 | +# Wait | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +等待指定通信通道上的通信任务完成。 | ||
| 6 | + | ||
| 7 | +通常先调用`FlushAsync`获取指定peer的通信通道句柄,再调用`Wait`等待该通道上的已提交任务完成。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void Wait(AscendC::ChannelHandle& channelHandle); | ||
| 13 | +``` | ||
| 14 | + | ||
| 15 | +## 参数说明 | ||
| 16 | + | ||
| 17 | +| 参数 | 输入/输出 | 说明 | | ||
| 18 | +| --- | --- | --- | | ||
| 19 | +| `channelHandle` | 输入 | 通信通道句柄,通常由`FlushAsync`返回。 | | ||
| 20 | + | ||
| 21 | +## 返回值 | ||
| 22 | + | ||
| 23 | +无返回值。 | ||
| 24 | + | ||
| 25 | +## 约束说明 | ||
| 26 | + | ||
| 27 | +- `channelHandle`需要是有效通信通道句柄。 | ||
| 28 | +- `Wait`通过底层Hcomm完成等待接口阻塞等待该通道上已提交的任务完成。 | ||
| 29 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -0,0 +1,45 @@ | |||
| 1 | +# WaitSignal | ||
| 2 | + | ||
| 3 | +## 功能说明 | ||
| 4 | + | ||
| 5 | +阻塞等待本rank本地signal值达到指定阈值。 | ||
| 6 | + | ||
| 7 | +`WaitSignal`会根据`team`、`signalWindow`和`signalOffset`解析本rank对应的signal地址,循环读取低`bits`位掩码后的signal值,直到该值大于等于`least`。 | ||
| 8 | + | ||
| 9 | +## 函数原型 | ||
| 10 | + | ||
| 11 | +```cpp | ||
| 12 | +__aicore__ inline void WaitSignal( | ||
| 13 | + AscendC::HcommTeamHandle team, | ||
| 14 | + AscendC::HcommWindowHandle signalWindow, | ||
| 15 | + size_t signalOffset, | ||
| 16 | + uint64_t least, | ||
| 17 | + uint32_t bits = 64, | ||
| 18 | + AscendC::AinMemoryOrder order = AscendC::AIN_MEMORY_ORDER_RELAX) const; | ||
| 19 | +``` | ||
| 20 | + | ||
| 21 | +## 参数说明 | ||
| 22 | + | ||
| 23 | +| 参数 | 输入/输出 | 说明 | | ||
| 24 | +| --- | --- | --- | | ||
| 25 | +| `team` | 输入 | 通信team句柄。 | | ||
| 26 | +| `signalWindow` | 输入 | signal所在对称window句柄。 | | ||
| 27 | +| `signalOffset` | 输入 | signal在对称window内的字节偏移。 | | ||
| 28 | +| `least` | 输入 | 等待阈值。 | | ||
| 29 | +| `bits` | 输入 | 比较低位bit数,取值范围为1-64,默认64。 | | ||
| 30 | +| `order` | 输入 | signal等待内存序,默认`AIN_MEMORY_ORDER_RELAX`。 | | ||
| 31 | + | ||
| 32 | +## 返回值 | ||
| 33 | + | ||
| 34 | +无返回值。 | ||
| 35 | + | ||
| 36 | +## 约束说明 | ||
| 37 | + | ||
| 38 | +- 调用前Host侧需完成team创建及signal所在对称window注册。 | ||
| 39 | +- `team`和`signalWindow`需要是有效的device侧句柄。 | ||
| 40 | +- `signalOffset`对应地址需要落在本rank对应的signal window注册内存范围内。 | ||
| 41 | +- signal地址应按`uint64_t`访问要求准备。 | ||
| 42 | +- `bits`用于生成低位掩码;取值范围为1-64,当`bits`为64时比较完整64位signal值。 | ||
| 43 | +- 当前仅支持`AIN_MEMORY_ORDER_RELAX`。该内存序只保证signal原子读写及阈值检查,不保证signal操作前后普通数据访问的内存序。 | ||
| 44 | +- `WaitSignal`会持续轮询直到条件满足,调用方需要确保远端会更新该signal,避免Kernel永久等待。 | ||
| 45 | +- 当前只支持`COMM_PROTOCOL_UBC_CTP`协议路径。 | ||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | | 样例 | 说明 | 支持产品 | | 7 | | 样例 | 说明 | 支持产品 | |
| 8 | | --- | --- | --- | | 8 | | --- | --- | --- | |
| 9 | +| [ain/basic_ring](./ain/basic_ring/README.md) | 演示多卡环形场景下AIV Kernel通过AIN接口调用`Put`/`Get`进行点对点单边通信,并通过`AinBarrierSession`完成同步与结果校验。 | Ascend 950PR/Ascend 950DT | | ||
| 9 | | [hcomm_write_read_nbi](./hcomm_write_read_nbi/README.md) | 演示多卡场景下AIV Kernel通过URMA路径调用`Hcomm::WriteNbi`和`Hcomm::ReadNbi`,并校验通信结果。 | Ascend 950PR/Ascend 950DT | | 10 | | [hcomm_write_read_nbi](./hcomm_write_read_nbi/README.md) | 演示多卡场景下AIV Kernel通过URMA路径调用`Hcomm::WriteNbi`和`Hcomm::ReadNbi`,并校验通信结果。 | Ascend 950PR/Ascend 950DT | |
| 10 | | [one_multi_path](./one_multi_path/README.md) | 查询`UB_MEM`链路,为每个peer创建one path/multi path Channel,逐个处理peer,并通过双Stream并发搬运和校验该peer的远端数据。 | Ascend 950PR/Ascend 950DT | | 11 | | [one_multi_path](./one_multi_path/README.md) | 查询`UB_MEM`链路,为每个peer创建one path/multi path Channel,逐个处理peer,并通过双Stream并发搬运和校验该peer的远端数据。 | Ascend 950PR/Ascend 950DT | |
| 11 | 12 | ||
| @@ -3,8 +3,10 @@ | |||
| 3 | This directory contains usage samples for asc-comm APIs. | 3 | This directory contains usage samples for asc-comm APIs. |
| 4 | 4 | ||
| 5 | ## Sample List | 5 | ## Sample List |
| 6 | + | ||
| 6 | | Sample | Description | Supported Products | | 7 | | Sample | Description | Supported Products | |
| 7 | | --- | --- | --- | | 8 | | --- | --- | --- | |
| 9 | +| [ain/basic_ring](./ain/basic_ring/README_en.md) | Demonstrates AIV Kernel invoking `Put`/`Get` over the AIN interface for point-to-point one-sided communication in a multi-card ring scenario, with synchronization and result verification through `AinBarrierSession`. | Ascend 950PR / Ascend 950DT | | ||
| 8 | | [hcomm_write_read_nbi](./hcomm_write_read_nbi/README_en.md) | Demonstrates AIV Kernel invoking `Hcomm::WriteNbi` and `Hcomm::ReadNbi` over the URMA path in a multi-card scenario, with communication result verification. | Ascend 950PR / Ascend 950DT | | 10 | | [hcomm_write_read_nbi](./hcomm_write_read_nbi/README_en.md) | Demonstrates AIV Kernel invoking `Hcomm::WriteNbi` and `Hcomm::ReadNbi` over the URMA path in a multi-card scenario, with communication result verification. | Ascend 950PR / Ascend 950DT | |
| 9 | | [one_multi_path](./one_multi_path/README_en.md) | Queries a `UB_MEM` link, creates one path/multi path channels for every peer, processes peers serially, and concurrently moves and verifies each peer's remote data over two streams. | Ascend 950PR / Ascend 950DT | | 11 | | [one_multi_path](./one_multi_path/README_en.md) | Queries a `UB_MEM` link, creates one path/multi path channels for every peer, processes peers serially, and concurrently moves and verifies each peer's remote data over two streams. | Ascend 950PR / Ascend 950DT | |
| 10 | 12 | ||
| @@ -0,0 +1,60 @@ | |||
| 1 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +cmake_minimum_required(VERSION 3.16) | ||
| 12 | + | ||
| 13 | +set(CMAKE_ASC_ARCHITECTURES "dav-3510" CACHE STRING "NPU architecture") | ||
| 14 | + | ||
| 15 | +if(NOT CMAKE_ASC_ARCHITECTURES STREQUAL "dav-3510") | ||
| 16 | + message(FATAL_ERROR "ain_basic_ring_sample only supports dav-3510, but got ${CMAKE_ASC_ARCHITECTURES}") | ||
| 17 | +endif() | ||
| 18 | + | ||
| 19 | +find_package(ASC REQUIRED) | ||
| 20 | + | ||
| 21 | +project(ain_basic_ring_sample LANGUAGES ASC CXX) | ||
| 22 | + | ||
| 23 | +set(CMAKE_CXX_STANDARD 17) | ||
| 24 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| 25 | + | ||
| 26 | +set_source_files_properties( | ||
| 27 | + basic_ring.asc | ||
| 28 | + PROPERTIES LANGUAGE ASC | ||
| 29 | +) | ||
| 30 | + | ||
| 31 | +add_executable(basic_ring_demo | ||
| 32 | + basic_ring.asc | ||
| 33 | +) | ||
| 34 | + | ||
| 35 | +target_include_directories(basic_ring_demo PRIVATE | ||
| 36 | + ${ASCEND_CANN_PACKAGE_LINUX_PATH}/pkg_inc | ||
| 37 | + ${ASCEND_CANN_PACKAGE_LINUX_PATH}/include | ||
| 38 | + ${ASCEND_CANN_PACKAGE_LINUX_PATH}/include/hcomm | ||
| 39 | + ${ASCEND_CANN_PACKAGE_LINUX_PATH}/asc/include/comm_api/aicore | ||
| 40 | +) | ||
| 41 | + | ||
| 42 | +target_link_directories(basic_ring_demo PRIVATE | ||
| 43 | + ${ASCEND_CANN_PACKAGE_PATH}/lib64 | ||
| 44 | + ${ASCEND_CANN_PACKAGE_LINUX_PATH}/lib64 | ||
| 45 | +) | ||
| 46 | + | ||
| 47 | +target_link_libraries(basic_ring_demo PRIVATE | ||
| 48 | + -Wl,--no-as-needed | ||
| 49 | + hccl | ||
| 50 | + hcomm | ||
| 51 | + -Wl,--as-needed | ||
| 52 | + ascendcl | ||
| 53 | + runtime | ||
| 54 | + stdc++ | ||
| 55 | + dl | ||
| 56 | +) | ||
| 57 | + | ||
| 58 | +set_target_properties(basic_ring_demo PROPERTIES | ||
| 59 | + BUILD_RPATH "${ASCEND_CANN_PACKAGE_PATH}/lib64;${ASCEND_CANN_PACKAGE_LINUX_PATH}/lib64" | ||
| 60 | +) | ||
| @@ -0,0 +1,111 @@ | |||
| 1 | +# AIN Basic Ring Sample | ||
| 2 | + | ||
| 3 | +## Overview | ||
| 4 | + | ||
| 5 | +This sample demonstrates how to use basic AIN communication capabilities from an AscendC AIV Kernel through the `ain/ain.h` interface. The sample runs symmetrically across multiple ranks: each rank issues `Put` to the next rank, issues `Get` to the previous rank, and finally synchronizes through `AinBarrierSession`. | ||
| 6 | + | ||
| 7 | +The Host side allocates memory, initializes the HCCL communicator, creates the HCCL Team, registers symmetric windows, and creates AIV communication channels. The Kernel side only submits data-plane communication tasks through the AIN interface. | ||
| 8 | + | ||
| 9 | +## Supported Scope | ||
| 10 | + | ||
| 11 | +| Item | Description | | ||
| 12 | +| --- | --- | | ||
| 13 | +| Product | `Ascend 950PR / Ascend 950DT` | | ||
| 14 | +| NPU architecture | `dav-3510` | | ||
| 15 | +| Communication protocol | `COMM_PROTOCOL_UBC_CTP` | | ||
| 16 | +| Communication engine | `COMM_ENGINE_AIV` | | ||
| 17 | +| Deployment mode | Single-node multi-card | | ||
| 18 | +| CANN package | The CANN package selected by the current `set_env.sh` environment | | ||
| 19 | + | ||
| 20 | +> A single-card environment only supports build verification. Running this sample requires at least two NPUs. | ||
| 21 | + | ||
| 22 | +## Directory Structure | ||
| 23 | + | ||
| 24 | +```text | ||
| 25 | +basic_ring | ||
| 26 | +├── CMakeLists.txt // Build project file | ||
| 27 | +├── README.md // Chinese README | ||
| 28 | +├── README_en.md // English README | ||
| 29 | +├── basic_ring.asc // Host-side setup, AICore-side AIN calls, and shared definitions | ||
| 30 | +└── run.sh // Multi-rank launch script | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +## Sample Flow | ||
| 34 | + | ||
| 35 | +### Host-Side Resource Setup | ||
| 36 | + | ||
| 37 | +1. Call `aclInit`, `aclrtSetDevice`, and `aclrtCreateStream` to initialize the runtime environment. | ||
| 38 | +2. Create the multi-rank HCCL communicator through `HcclGetRootInfo` and `HcclCommInitRootInfo`. | ||
| 39 | +3. Configure `barrierCount` and call `HcclWorldTeamCreate` to create the world team. | ||
| 40 | +4. Register `sendBuf` and `recvBuf` as symmetric windows through `HcclTeamWindowRegister`. | ||
| 41 | +5. Call `HcclTeamChannelsCreate` to create AIV + UBC_CTP communication channels. | ||
| 42 | +6. Pass `worldTeam`, `sendWin`, and `recvWin` to the Kernel. | ||
| 43 | + | ||
| 44 | +### Kernel-Side AIN Communication | ||
| 45 | + | ||
| 46 | +The Kernel side performs the following steps: | ||
| 47 | + | ||
| 48 | +1. Construct an `AscendC::Ain` object and initialize the Hcomm UB temporary workspace. | ||
| 49 | +2. The current rank uses `Put` to write its rank id to `recvWindow[rankId]` on the next rank. | ||
| 50 | +3. The current rank uses `Get` to read `sendWindow[0]` from the previous rank into local `recvWindow[rankNum + rankId]`. | ||
| 51 | +4. Call `Flush` to wait for AIN communication tasks to complete. | ||
| 52 | +5. Call `AinBarrierSession::Sync` to synchronize ranks. | ||
| 53 | + | ||
| 54 | +## Build | ||
| 55 | + | ||
| 56 | +Run the following commands in this sample directory: | ||
| 57 | + | ||
| 58 | +```bash | ||
| 59 | +# If CANN is installed in the default path, for example as root. | ||
| 60 | +# For a non-root user, replace /usr/local with ${HOME}. | ||
| 61 | +source /usr/local/Ascend/cann/set_env.sh | ||
| 62 | +# If CANN is installed in a custom path: | ||
| 63 | +# source ${install_path}/cann/set_env.sh | ||
| 64 | + | ||
| 65 | +rm -rf build | ||
| 66 | +mkdir -p build | ||
| 67 | +cd build | ||
| 68 | +cmake -DCMAKE_ASC_ARCHITECTURES=dav-3510 .. | ||
| 69 | +make -j | ||
| 70 | +``` | ||
| 71 | + | ||
| 72 | +## Run | ||
| 73 | + | ||
| 74 | +After the build completes, run the following command in the sample directory: | ||
| 75 | + | ||
| 76 | +```bash | ||
| 77 | +./run.sh <nranks> | ||
| 78 | +``` | ||
| 79 | + | ||
| 80 | +For example, run with two cards: | ||
| 81 | + | ||
| 82 | +```bash | ||
| 83 | +./run.sh 2 | ||
| 84 | +``` | ||
| 85 | + | ||
| 86 | +`run.sh` starts one `basic_ring_demo` process for each rank and uses a temporary file to exchange the HCCL root info. The default script timeout is 300 seconds. | ||
| 87 | + | ||
| 88 | +## Expected Result | ||
| 89 | + | ||
| 90 | +Each rank reads back `recvBuf` and prints the `Put` and `Get` results, for example: | ||
| 91 | + | ||
| 92 | +```text | ||
| 93 | +PUT RES rank 0 recvBuf[1]=1 expect=1 | ||
| 94 | +GET RES rank 0 recvBuf[2]=1 expect=1 | ||
| 95 | +rank 0 test pass | ||
| 96 | +``` | ||
| 97 | + | ||
| 98 | +The sample succeeds when all ranks print `test pass`. | ||
| 99 | + | ||
| 100 | +## Build Option | ||
| 101 | + | ||
| 102 | +| Option | Default | Description | | ||
| 103 | +| --- | --- | --- | | ||
| 104 | +| `CMAKE_ASC_ARCHITECTURES` | `dav-3510` | This sample only supports `dav-3510`, which corresponds to Ascend 950PR / Ascend 950DT. | | ||
| 105 | + | ||
| 106 | +## Notes | ||
| 107 | + | ||
| 108 | +- Load the CANN environment variables before building to ensure `ASCEND_CANN_PACKAGE_PATH` and ASC CMake modules are available. | ||
| 109 | +- This sample depends on CANN `hccl`, `hcomm`, `ascendcl`, and `runtime` libraries. | ||
| 110 | +- The number of ranks must not exceed the number of available NPUs. | ||
| 111 | +- This sample supports only single-node multi-card execution and does not support multi-node execution. | ||
| @@ -0,0 +1,72 @@ | |||
| 1 | +#!/usr/bin/env bash | ||
| 2 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 11 | + | ||
| 12 | +set -euo pipefail | ||
| 13 | + | ||
| 14 | +if [ "$#" -ne 1 ]; then | ||
| 15 | + echo "Usage: $0 <nranks>" | ||
| 16 | + exit 1 | ||
| 17 | +fi | ||
| 18 | + | ||
| 19 | +nranks="$1" | ||
| 20 | +timeout_seconds=300 | ||
| 21 | + | ||
| 22 | +if ! [[ "$nranks" =~ ^[0-9]+$ ]] || [ "$nranks" -lt 2 ]; then | ||
| 23 | + echo "nranks must be an integer greater than or equal to 2" | ||
| 24 | + exit 1 | ||
| 25 | +fi | ||
| 26 | + | ||
| 27 | +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 28 | +binary="${script_dir}/build/basic_ring_demo" | ||
| 29 | + | ||
| 30 | +if [ ! -x "$binary" ]; then | ||
| 31 | + echo "binary does not exist or is not executable: $binary" | ||
| 32 | + exit 1 | ||
| 33 | +fi | ||
| 34 | + | ||
| 35 | +root_info_dir="$(mktemp -d "${TMPDIR:-/tmp}/ain_basic_ring_root_info.XXXXXX")" | ||
| 36 | +root_info_file="${root_info_dir}/root_info.bin" | ||
| 37 | + | ||
| 38 | +pids=() | ||
| 39 | + | ||
| 40 | +cleanup() { | ||
| 41 | + status=$? | ||
| 42 | + trap - EXIT INT TERM | ||
| 43 | + | ||
| 44 | + if [ "$status" -ne 0 ] && [ "${#pids[@]}" -gt 0 ]; then | ||
| 45 | + kill "${pids[@]}" 2>/dev/null || true | ||
| 46 | + wait "${pids[@]}" 2>/dev/null || true | ||
| 47 | + fi | ||
| 48 | + | ||
| 49 | + if [ -n "${root_info_dir:-}" ]; then | ||
| 50 | + rm -rf "$root_info_dir" | ||
| 51 | + fi | ||
| 52 | + exit "$status" | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +trap cleanup EXIT INT TERM | ||
| 56 | + | ||
| 57 | +for ((rank = 0; rank < nranks; ++rank)); do | ||
| 58 | + timeout --foreground --kill-after=5s "${timeout_seconds}s" \ | ||
| 59 | + "$binary" "$rank" "$nranks" "$root_info_file" & | ||
| 60 | + pids+=("$!") | ||
| 61 | +done | ||
| 62 | + | ||
| 63 | +remaining="${#pids[@]}" | ||
| 64 | +while [ "$remaining" -gt 0 ]; do | ||
| 65 | + if wait -n; then | ||
| 66 | + remaining=$((remaining - 1)) | ||
| 67 | + else | ||
| 68 | + status=$? | ||
| 69 | + echo "a rank process failed with status ${status}" | ||
| 70 | + exit "$status" | ||
| 71 | + fi | ||
| 72 | +done | ||


🤖 GitCode 检视意见
严重性: Low 置信度: 较确定 问题类别: 文档接入 / 样例入口缺失 问题详情: 这个新样例已经有独立中英文 README,但 PR 没有把它登记到仓库的
examples/README.md和examples/README_en.md样例列表。用户从仓库约定的样例总入口浏览时仍只能看到hcomm_write_read_nbi,无法发现本样例。 证据: 仓库docs/doc_contributing.md与英文版都明确要求“新增样例”同步更新对应examples/README*,并将其列为提交前自检项;当前三点 diff 的 31 个文件不包含这两个入口文件。 修改建议: 在中英文examples/README*的 Sample List 中各增加ain/basic_ring条目,写明 AIN Put/Get/Flush/Barrier、dav-3510、单机多卡和 UBC_CTP 支持范围;必要时补一段简短流程说明。