Function: malloc

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

√

Atlas inference products

√

Atlas 200I/500 A2 inference products

√

Description

Allocates linear memory of the size on the device and returns the pointer to the allocated memory through dev_ptr. The start address of the memory is 64-byte aligned. The memory allocated by this API needs to be freed by calling acl.rt.free.

The allocated memory is byte-aligned. The alignment policy varies depending on the product model.

Prototype

Parameters

Parameter

Description

size

Int, size of the memory to be allocated, in bytes. The value cannot be 0.

policy

Int, memory allocation policy.

If the configured memory allocation rule exceeds the value range of aclrtMemMallocPolicy and size is greater than or equal to 2 MB, memory is allocated based on huge pages. Otherwise, memory is allocated based on normal pages.

Return Values

Return Value

Description

dev_ptr

Int, address of the pointer to the allocated device memory.

ret

Int, error code. 0 on success; else, failure.

Restrictions