Function: host_register

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

Maps and registers host memory as the memory address that can be accessed by devices, and obtains the mapped device memory address. This address can only be accessed on devices, for example, as a parameter of a kernel function for the device AI Core to access. If host memory processing is involved, use the original host memory address.

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

Prototype

  • C Prototype
    1
    aclError aclrtHostRegister(void *ptr, uint64_t size, aclrtHostRegisterType type, void **devPtr)
    
  • Python Function
    1
    dev_ptr, ret = acl.rt.host_register(ptr, size, type)
    

Parameters

Parameter

Description

ptr

Int, host memory address. The host memory address must be 4K-page-aligned. If the OS kernel version is 5.10 or earlier, using non-lock page memory will cause exceptions. In this case, you must call acl.rt.malloc_host to allocate the host memory. If the OS kernel version is later than 5.10, non-lock page memory can be used, so acl.rt.malloc_host is not required for allocating the host memory.

size

Int, memory size, in bytes.

type

Int, memory registration type. For details about the type definition, see aclrtHostRegisterType.

Return Values

Return Value

Description

dev_ptr

Int, memory address mapped from the host and accessible to the device.

ret

Int, 0 on success; else failure.