HcclCommSymWinGet

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

Function

Obtains the corresponding window resource handle and its offset within the window based on the virtual address pointer of the registered symmetric memory.

Prototype

1
HcclResult HcclCommSymWinGet(HcclComm comm, void *ptr, size_t size, HcclCommSymWindow *winHandle, size_t *offset)

Parameters

Parameter

Input/Output

Description

comm

Input

HCCL communicator.

ptr

Input

Virtual address pointer. The memory must have been registered by calling the HcclCommSymWinRegister API.

size

Input

Size of the symmetric memory window.

Assume that the size of the symmetric memory window is symSize and the virtual address pointer of the registered symmetric memory is addr. The size must meet the following conditions:
  • size > 0
  • ptr+size <= addr + symSize

winHandle

Output

Pointer to the symmetric memory window resource handle.

offset

Output

Pointer to the offset.

Assume that the virtual address pointer of the registered symmetric memory is addr. Then, *offset = ptraddr.

Returns

HcclResult: HCCL_SUCCESS on success, or else failure.

Constraints

  • Only intra-SuperPoD communication of the Atlas A3 training product/Atlas A3 inference product is supported.
  • The communication operator can be expanded only on AICPU.

Call Example

// Create and initialize the configuration items of the communicator.
HcclCommConfig config;
HcclCommConfigInit(&config);
// Modify the communicator configuration as required.
config.hcclSymWinMaxMemSizePerRank = 10; // The default value is 16, in GB.

// Obtain the communicator parameters.
uint32_t rankSize = 4;
uint32_t rankId = 0;
int32_t deviceId;
ACLCHECK(aclrtGetDevice(&deviceId));
HcclRootInfo rootInfo;
HCCLCHECK(HcclGetRootInfo(&rootInfo));

// Initialize the collective communicator.
HcclComm hcclComm;
HCCLCHECK(HcclCommInitRootInfoConfig(rankSize, &rootInfo, rankId, &config, &hcclComm));

// Create a task flow.
aclrtStream stream;
ACLCHECK(aclrtCreateStream(&stream));

// Configure the physical memory attributes.
aclrtPhysicalMemProp prop;
prop.handleType = ACL_MEM_HANDLE_TYPE_NONE;
prop.allocationType = ACL_MEM_ALLOCATION_TYPE_PINNED;
prop.memAttr = ACL_HBM_MEM_HUGE;
prop.location.id = deviceId;
prop.location.type = ACL_MEM_LOCATION_TYPE_DEVICE;
prop.reserve = 0;

// Obtain the alignment granularity, which is usually 2 MB.
size_t granularity;
ACLCHECK(aclrtMemGetAllocationGranularity(&prop, ACL_RT_MEM_ALLOC_GRANULARITY_RECOMMENDED, &granularity));

// Align the size based on the granularity.
size_t size = 2 * 1024 * 1024;
size_t allocSize = (size + granularity - 1) / granularity * granularity;

// Reserve virtual memory.
void *virPtr;
ACLCHECK(aclrtReserveMemAddress(&virPtr, allocSize, 0, nullptr, 1));

// Allocate physical memory.
aclrtDrvMemHandle memHandle;
ACLCHECK(aclrtMallocPhysical(&memHandle, allocSize, &prop, 0));

// Establish the mapping from physical memory to virtual memory.
ACLCHECK(aclrtMapMem(virPtr, allocSize, 0, memHandle, 0));

HcclCommSymWindow symWin;
// Register symmetric memory.
HCCLCHECK(HcclCommSymWinRegister(hcclComm, virPtr, allocSize, &symWin, 1));

// Use HcclCommSymWinGet to obtain symmetric memory resources.
HcclCommSymWindow tempWin;
size_t offset = 0;
HCCLCHECK(HcclCommSymWinGet(hcclComm, virPtr, allocSize, &tempWin, &offset));

// Deregister symmetric memory.
HCCLCHECK(HcclCommSymWinDeregister(symWin));

// Free memory.
ACLCHECK(aclrtUnmapMem(virPtr));
ACLCHECK(aclrtFreePhysical(memHandle));
ACLCHECK(aclrtReleaseMemAddress(virPtr));

 // Destroy the task flow.
ACLCHECK(aclrtDestroyStream(stream));

// Destroy the communicator.
HCCLCHECK(HcclCommDestroy(hcclComm));