aclrtMemManagedPrefetchBatchAsync

Function

Prefetches the unified virtual memory (UVM) in a batch.

The memory operated on by this API must be allocated using aclrtMemAllocManaged. This is an asynchronous API. A successful call only indicates that the task is successfully issued, not executed. After calling this API, call the synchronization API (for example, aclrtSynchronizeStream) to ensure that the memory prefetch task is complete.

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

Prototype

1
2
3
4
5
6
7
# Use the location information of the same physical memory for all memory to be prefetched.
template <typename T>
aclError aclrtMemManagedPrefetchBatchAsync(const T **ptrs, size_t *sizes, size_t count, aclrtMemManagedLocation prefetchLoc, uint64_t flags, aclrtStream stream)

# Use the location information of the corresponding physical memory for each memory segment to be prefetched.
template <typename T>
aclError aclrtMemManagedPrefetchBatchAsync(const T **ptrs, size_t *sizes, size_t count, aclrtMemManagedLocation *prefetchLocs, size_t *prefetchLocIdxs, size_t numPrefetchLocs, uint64_t flags, aclrtStream stream)

Parameters

Parameter

Input/Output

Description

ptrs

Input

Array of memory addresses to be prefetched. Each address must fall within the UVM memory range: [0x90000000000ULL, 0x90000000000ULL+3TB).

sizes

Input

Length array of the memory to be prefetched. This array stores the size of each memory segment to be prefetched. The unit is bytes. The length of each segment must be aligned to 2 MB. Value range: (0, 3TB]

count

Input

Length of the ptrs and sizes arrays.

prefetchLoc

Input

Physical memory location information, where each entry contains an ID and type. For all memory to be prefetched, use the location information of the same physical memory.

For details about the type definition, see aclrtMemManagedLocation.

prefetchLocs

Input

Physical memory location information array, where each entry contains an ID and type. For each memory segment to be prefetched, use the location information of the corresponding physical memory.

For details about the type definition, see aclrtMemManagedLocation.

prefetchLocIdxs

Input

Index array of the physical memory prefetch information. It specifies the prefetch range applicable to each physical address in the prefetchLocs array. For the physical address specified by prefetchLocs[k], the UVM memory addresses of the elements pointed to by the subscript from prefetchLocIdxs[k] to prefetchLocIdxs[k+1] – 1 in the ptrs array are prefetched. For the physical address specified by prefetchLocs[numPrefetchLocs -1], the UVM memory addresses of the elements pointed to by the subscript from prefetchLocIdxs[numPrefetchLocs -1] to count - 1 in the ptrs array are prefetched.

numPrefetchLocs

Input

Length of the prefetchLocs and prefetchLocIdxs arrays.

flags

Input

Reserved. The value is fixed at 0.

stream

Input

Stream for executing the memory prefetch task. For details about the type definition, see aclrtStream.

Returns

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

Restrictions

  • This API prefetches the data specified in ptrs to the physical memory region specified in prefetchLocs. The size of each prefetch operation is specified by sizes. The ptrs and sizes arrays must have the same length specified by count.
  • In a batch prefetch operation, each entry in the prefetchLocs array can be applied to multiple prefetch operations. The prefetchLocIdxs array specifies the start UVM address index to be prefetched for the corresponding physical memory region. The prefetchLocs and prefetchLocIdxs arrays must have the same length specified by numPrefetchLocs. For example, if the batch processing contains 10 prefetch operations listed in ptrs/sizes, where the first six need to be prefetched to one physical memory region and the last four need to be prefetched to another physical memory region, then numPrefetchLocs is 2, prefetchLocIdxs is {0,6}, and prefetchLocs contains two groups of physical memory location information. Note that the first entry of prefetchLocIdxs must be 0. Each entry must be greater than the previous one, and the last entry must be less than count. In addition, numPrefetchLocs must be less than or equal to count.