InitDetermineComputeWorkspace
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
√ |
|
x |
|
√ |
|
x |
|
x |
Function Usage
Initializes the value of the GM shared memory. WaitPreBlock and NotifyNextBlock can be called only after the initialization is complete.
Prototype
1 | __aicore__ inline void InitDetermineComputeWorkspace(GlobalTensor<int32_t>& gmWorkspace, LocalTensor<int32_t>& ubWorkspace) |
Parameters
Parameter |
Input/Output |
Meaning |
|---|---|---|
gmWorkspace |
Input |
Temporary space, which is used to initialize the shared memory for inter-core synchronization. The type is GlobalTensor. |
ubWorkspace |
Input |
Temporary space, which is used to operate gmWorkspace. The type is LocalTensor. |
Returns
None
Constraints
- The minimum space allocated to gmWorkspace is (blockNum × 32) bytes. The minimum space allocated to ubWorkspace is (blockNum × 32 + 32) bytes. blockNum indicates the number of called cores, which can be obtained by calling GetBlockNum.
- When this API is used for multi-core control, the logical numBlocks specified during operator calling must be less than or equal to the number of cores for running the operator. Otherwise, the framework inserts abnormal synchronization during multi-round scheduling, causing the kernel to stop responding.
Example
The following example simulates eight cores for data processing. The deterministic computing API is used to ensure the inter-core running sequence and perform atomic accumulation.
// m_gmWorkspace is the shared memory for initializing inter-core synchronization. Its type is GlobalTensor. ubWorkspace is the temporary space for operating m_gmWorkspace. Its type is LocalTensor. int64_t m_tileCount = 256 * sizeof(int32_t); // Space occupied by the total number of elements involved in computation, in bytes. // Initialize the value of the shared global memory. AscendC::InitDetermineComputeWorkspace(m_gmWorkspace, ubWorkspace); // copy in // srcLocal is a LocalTensor of the int32_t type, and m_srcGlobal is a GlobalTensor of the int32_t type. AscendC::DataCopy(srcLocal, m_srcGlobal[m_tileCount], m_tileCount); // copy out // Call WaitPreBlock to read the value at the global memory address and check whether to continue waiting. AscendC::WaitPreBlock(m_gmWorkspace, ubWorkspace); // Enable atomic accumulation. AscendC::SetAtomicAdd<int32_t>(); // m_dstGlobal is a GlobalTensor of the int32_t type. AscendC::DataCopy(m_dstGlobal[m_tileCount], srcLocal, m_tileCount); AscendC::DisableDmaAtomic(); // Call NotifyNextBlock to write the global memory address and notify the next core that the operation of the current core is completed and the next core can perform the operation. AscendC::NotifyNextBlock(m_gmWorkspace, ubWorkspace);
// Input data of each core: [1,1,1,1,1,...,1] // 1 × 256 // Final output data: [8,8,8,8,8,...,8] // 8 × 256