aclrtHostRegister

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

x

Atlas inference product

x

Atlas training product

x

Description

Maps and registers the host memory as a memory address that can be accessed by the device, and obtains the mapped device memory address. This address cannot be used for memory operations, such as memory copy.

If the registered ptr is allocated by aclrtMallocHostWithCfg with the attr type set to ACL_RT_MEM_ATTR_VA_FLAG and the value of vaFlag set to 1, the mapped device address is the same as the host address and can be used for memory operations.

To unregister the host memory, call the aclrtHostUnregister API.

Prototype

1
aclError aclrtHostRegister(void *ptr, uint64_t size, aclrtHostRegisterType type, void **devPtr)

Parameters

Parameter

Input/Output

Description

ptr

Input

Host memory address.

The host memory address must be 4K-page-aligned.

If the OS kernel version is 5.10 or earlier, using non-page-locked memory will cause exceptions. Therefore, you must call aclrtMallocHost to allocate page-locked host memory.

If the OS kernel version is later than 5.10, non-page-locked host memory can be used. Therefore, you can either call aclrtMallocHost to allocate page-locked host memory, or call malloc to allocate non-page-locked host memory.

size

Input

Memory size, in bytes

type

Input

Memory registration type. For details about the type definition, see aclrtHostRegisterType.

devPtr

Output

Memory address mapped from the host memory. This address is accessible to the device.

Returns

0 on success; otherwise, failure. For details, see aclError.