aclrtHostRegister

Applicability

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference products

Atlas training products

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

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 or aclrtMallocHostWithCfg 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 or aclrtMallocHostWithCfg 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.

devPtr

Output

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

Returns

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