The Iterate and IterateAll APIs of Matmul provide synchronous and asynchronous modes in the MIX scenario (including matrix computation and vector computation). In the CUBE_ONLY scenario (including matrix computation only), only the synchronous mode is supported.
In synchronous mode, the next operation can be performed only after the preceding operation finishes. In asynchronous mode, the next operation can be performed without waiting for the preceding operation to finish.

The key sample code for the synchronous mode of Iterate and GetTensorC is as follows:
1 2 3 |
while (mm.Iterate()) { mm.GetTensorC(gm_c); } |
1 2 3 4 5 6 7 8 9 |
mm.SetWorkspace(workspace, size); // workspace indicates the physical address of the temporary space, and size indicates the size of matrix C with the size of singleCoreM × singleCoreN. // Asynchronous mode mm.template Iterate<false>(); …… // Perform other operations. auto mIter = Ceil(singleCoreM, baseM); auto nIter = Ceil(singleCoreN, baseN); for (int i = 0; i < mIter * nIter ; ++i) { mm.GetTensorC<false> (gm_c); } |
The key sample code for the synchronous mode of IterateAll is as follows:
1 2 3 4 5 6 |
mm.SetTensorA(gm_a); // Set the left matrix A. mm.SetTensorB(gm_b); // Set the right matrix B. mm.SetBias(gm_bias); // Set the bias. mm.IterateAll(gm_c); // Follow-up operations ... |
1 2 3 4 5 6 7 8 9 |
AscendC::Matmul<aType, bType, cType, biasType> mm; mm.SetTensorA(queryGm[tensorACoreOffset]); mm.SetTensorB(keyGm[tensorBCoreOffset + sInnerStart * singleProcessSInnerSize * tilingData->attentionScoreOffsetStrideParams.matmulHead], true); mm.SetTail(singleProcessSOuterSize, mmNNum); mm.template IterateAll<false>(workspaceGm[tmp_block_idx * mmResUbSize * sInnerLoopTimes],0, false,true); // Perform other operations. mm.WaitIterateAll(); // Wait for IterateAll to complete. DataCopy(dstUB, GM); // Copy data from GM to UB. |