aclrtMalloc

Applicable Products

Product

Supported

Ascend 950PR/Ascend 950DT

√

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

√

Function

Allocates size bytes of linear memory on the device and returns the pointer to the allocated memory through *devPtr. The start address of the memory is 64-byte aligned.

The memory allocated by this API can only be freed by calling aclrtFree or aclrtFreeWithDevSync.

This is an encapsulated API that applies only to C++ programs. It internally calls the C API aclrtMallocWithCfg.

Prototype

1
2
3
4
5
template <typename T>
aclError aclrtMalloc(T **devPtr, size_t size, aclrtMallocConfig *cfg = nullptr)

template <typename T>
aclError aclrtMalloc(T **devPtr, size_t size, aclrtMemMallocPolicy policy, aclrtMallocConfig *cfg = nullptr)

Parameters

Parameter

Input/Output

Description

devPtr

Output

Pointer to the pointer to the allocated device memory.

size

Input

Allocated memory size, in bytes.

size cannot be 0.

policy

Input

Memory allocation policy. For details about the type definition, see aclrtMemMallocPolicy.

If the configured memory allocation policy is beyond the value range of aclrtMemMallocPolicy, and size is greater than or equal to 2 MB, huge page memory is allocated; otherwise, common page memory is allocated.

cfg

Input

Memory configuration. For details about the type definition, see aclrtMallocConfig.

Returns

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