Function: host_register_v2

Applicable Products

Product

Supported (√/x)

Ascend 950PR/Ascend 950DT

√

Atlas A3 training products/Atlas A3 inference products

√

Atlas A2 training products/Atlas A2 inference products

√

Atlas training products

x

Atlas inference products

x

Atlas 200I/500 A2 inference products

x

Description

Registers a host memory address.

To unregister the memory, call acl.rt.host_unregister.

Prototype

  • C Prototype
    1
    aclError aclrtHostRegisterV2(void *ptr, uint64_t size, uint32_t flag)
    
  • Python Function
    1
    ret = acl.rt.host_register_v2 (ptr, size, flag)
    

Parameters

Parameter

Description

ptr

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

Buffer size in bytes.

flag

Memory registration type.

  • 0x2: ACL_HOST_REG_MAPPED: Maps and registers host memory as a memory address that can be accessed by the device, and then calls acl.rt.host_get_device_pointer to obtain the mapped device memory address.
  • 0x4: ACL_HOST_REG_IOMEMORY: Maps and registers the I/O space (registers and cache) of a third-party PCIe device on the host as accessible to the device, including read and write operations. Reserved. Not supported yet.
  • 0x8: ACL_HOST_REG_READONLY: Maps and registers host memory as read-only to the device. This reserved option is not supported currently.
  • 0x10000000: ACL_HOST_REG_PINNED: Registers host non-page-locked memory as page-locked memory.

Return Values

Return Value

Description

ret

Int, 0 on success; else failure.

Constraints

For the Atlas A3 training products/Atlas A3 inference products, if flag is set to ACL_HOST_REG_IOMEMORY, only the x86 architecture is supported.