HcclThreadAcquire
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
For
Function
Obtains the communication thread based on the communicator.
Prototype
1 | HcclResult HcclThreadAcquire(HcclComm comm, CommEngine engine, uint32_t threadNum, uint32_t notifyNumPerThread, ThreadHandle *threads) |
Parameters
Parameter |
Input/Output |
Description |
||
|---|---|---|---|---|
comm |
Input |
Communicator. The HcclComm type is defined as follows:
|
||
engine |
Input |
Communication engine type. For the definition of the CommEngine type, see CommEngine. |
||
threadNum |
Input |
Number of communication threads. A maximum of 40 threads can be allocated in a communicator. |
||
notifyNumPerThread |
Input |
Number of synchronization resources (Notify) in each communication thread. A maximum of 64 synchronization resources can be allocated in a communicator. |
||
threads |
Output |
Returned communication thread handles. An array of the ThreadHandle type with a size of threadNum needs to be passed. For the definition of the ThreadHandle type, see ThreadHandle. |
Returns
HcclResult: HCCL_SUCCESS on success, or else failure.
Restrictions
The returned communication threads and synchronization resources are managed by the library and cannot be released by the caller.
Example
The following is an example of creating thread resources:
1 2 3 4 5 | HcclComm comm; CommEngine engine = COMM_ENGINE_AICPU_TS; ThreadHandle threads[5]; // Allocate five threads, each with two Notify resources. HcclThreadAcquire(comm, engine, 5, 2, threads); |
The following is an example of synchronizing host thread resources:
// Allocate one host stream. aclrtStream stream; aclrtCreateStream(&stream); // Create a thread of the CPU_TS type based on the allocated stream. ThreadHandle cpuThread; HcclThreadAcquireWithStream(comm, COMM_ENGINE_CPU_TS, streams, 1, &cpuThread); // Task orchestration // ... // Stream synchronization aclrtSynchronizeStream(stream);
The following is an example of synchronizing AICPU thread resources:
// --Host-side call process-- // Allocate one host stream. aclrtStream stream; aclrtCreateStream(&stream); // Create a thread of the CPU_TS type based on the allocated stream. ThreadHandle cpuThread; HcclThreadAcquireWithStream(comm, COMM_ENGINE_CPU_TS, streams, 1, &cpuThread); // Create a thread of the AICPU_TS type. ThreadHandle aicpuThread; HcclThreadAcquire(comm, COMM_ENGINE_AICPU_TS, 1, 1, &aicpuThread); // Export the created thread of the AICPU_TS type as a thread available on the CPU. ThreadHandle exportedCpuThread; HcclThreadExportToCommEngine(comm, 1, &aicpuThread, COMM_ENGINE_CPU_TS, &exportedCpuThread); // Export the created thread of the CPU type as a thread available on the AICPU. ThreadHandle exportedAicpuThread; HcclThreadExportToCommEngine(comm, 1, &cpuThread, COMM_ENGINE_AICPU_TS, &exportedAicpuThread); // Send a synchronization signal. HcommThreadNotifyRecordOnThread(cpuThread, exportedCpuThread, 0); // Launch the kernel and export the exportedAicpuThread and aicpuThread to the AICPU. // ... uint32_t timeout = 1; // Wait for a synchronization signal. HcommThreadNotifyWaitOnThread(cpuThread, 0, timeout); // --Call process on the AICPU-- // Wait for a synchronization signal. uint32_t timeout = 1; HcommThreadNotifyWaitOnThread(aicpuThread, 0, timeout); // Orchestrate the task and dispatch it to the aicpuThread. // ... // Send a synchronization signal. HcommThreadNotifyRecordOnThread(aicpuThread, exportedAicpuThread, 0); // Stream synchronization aclrtSynchronizeStream(stream);