aclrtHostRegisterV2

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

Registers the host memory address.

To unregister the memory, call the aclrtHostUnregister API.

Prototype

1
aclError aclrtHostRegisterV2(void *ptr, uint64_t size, uint32_t flag)

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

flag

Input

Memory registration type.

The value can be a single macro or multiple macros, for example, ACL_HOST_REG_MAPPED | ACL_HOST_REG_PINNED.

  • ACL_HOST_REG_MAPPED: Maps and registers the host memory as a memory address that can be accessed by the device, and then calls aclrtHostGetDevicePointer to obtain the mapped device memory address.
  • ACL_HOST_REG_IOMEMORY: Maps and registers the I/O space (registers and caches) of a third-party PCIe device on the host as accessible to the device, including read and write operations. Reserved, not supported currently.
  • ACL_HOST_REG_READONLY: Maps and registers the host memory as read-only to the device. Reserved option, which is not supported currently.
  • ACL_HOST_REG_PINNED: Registers the host memory as pinned memory. The host memory here refers only to the non-pinned memory allocated by using the C/C++ standard library function (such as malloc).

The macros are defined as follows:

#define ACL_HOST_REG_MAPPED 0x2UL
#define ACL_HOST_REG_IOMEMORY 0x4UL
#define ACL_HOST_REG_READONLY 0x8UL
#define ACL_HOST_REG_PINNED 0X10000000UL

Returns

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