GroupBarrier Instructions

When two AIV tasks in the same CubeResGroupHandle object depend on each other, control synchronization by calling GroupBarrier. Assume that AIV B can start subsequent services only after AIV A completes task x. Here, AIV A is referred to as the Arrive group, and AIV B is referred to as the Wait group.

To use GroupBarrier-based group synchronization, perform the following steps:

  1. Create a GroupBarrier object.
  2. Call Arrive by the AIV to be waited for, and call Wait by the AIV that needs to wait.

The following lists only code snippets. For details about a complete example, see GroupBarrier sample.

  1. Create a GroupBarrier object.
    1
    2
    3
    constexpr int32_t ARRIVE_NUM = 2; // Number of AIVs in the Arrive group
    constexpr int32_t WAIT_NUM = 6; // Number of AIVs in the Wait group
    AscendC::GroupBarrier<AscendC::PipeMode::MTE3_MODE> barA(workspace, ARRIVE_NUM, WAIT_NUM);  // Create a GroupBarrier object. Users manage and clear the workspace.
    
  2. Call Arrive by the AIV to be waited for, and call Wait by the AIV that needs to wait.
    1
    2
    3
    4
    5
    6
    7
    8
    auto id = AscendC::GetBlockIdx();
    if (id > 0 && id < ARRIVE_NUM) {
     //Various Vector compute logic, which is implemented by users.
      barA.Arrive(id);
    } else(id >= ARRIVE_NUM && id < ARRIVE_NUM + WAIT_NUM){
      barA.Wait(id - ARRIVE_NUM);
      // Various Vector compute logic, which is implemented by users.
    }