aclrtMalloc
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Description
Allocates linear memory of the size bytes on the device and returns the allocated memory pointer through *devPtr. The start address of the memory is 64-byte aligned. The memory allocated by this API must be freed by calling aclrtFree or aclrtFreeWithDevSync.
The memory allocated by this API is byte-aligned. The size bytes requested by users are rounded up to the nearest multiple of 32 bytes, with an additional 32 bytes added. However, for huge page memory with the memory allocation granularity of 1 GB, to save huge page memory, this API only rounds the input size up to the nearest multiple of 32 bytes, but does not add an extra 32 bytes.
Prototype
1
|
aclError aclrtMalloc(void **devPtr, size_t size, aclrtMemMallocPolicy policy) |
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
devPtr |
Output |
Pointer to the pointer to the allocated device memory. |
|
size |
Input |
Requested allocation size in bytes. Must not be 0. |
|
policy |
Input |
Memory allocation policy. For details about the type definition, see aclrtMemMallocPolicy. If the configured memory allocation policy is not within the value range of aclrtMemMallocPolicy, and the size is greater than or equal to 2 MB, the huge page memory is allocated; otherwise, the common page memory is allocated. |
Returns
0 on success; else, failure. For details, see aclError.
Restrictions
- The memory allocated by this API is not initialized. Before using the memory, call aclrtMemset to initialize it and clear its random numbers.
- This API does not perform implicit device synchronization or stream synchronization. The result is returned immediately no matter whether memory application succeeds or fails.
- Performance deterioration will be caused by too frequent calls to aclrtMalloc and aclrtFree. You are advised to allocate or manage memory in advance to avoid unnecessary memory allocation and deallocation.
- If you need to allocate a large memory block and divide and manage the memory, each memory segment must meet the requirements listed below. len indicates the size of a memory segment. ALIGN_UP[len,k] indicates rounding up to a multiple of k bytes as in this formula: ((len – 1)/k + 1) x k.
- The memory size is rounded up to the nearest multiple of 32 plus 32 bytes (m = ALIGN_UP[len,32] + 32 bytes).
- The memory start address must be 64-byte aligned (ALIGN_UP[m,64]).