Skip to main content

cudaMemDiscardAndPrefetchBatchAsync

Function cudaMemDiscardAndPrefetchBatchAsync 

Source
pub unsafe extern "C" fn cudaMemDiscardAndPrefetchBatchAsync(
    dptrs: *mut *mut c_void,
    sizes: *mut size_t,
    count: size_t,
    prefetchLocs: *mut cudaMemLocation,
    prefetchLocIdxs: *mut size_t,
    numPrefetchLocs: size_t,
    flags: c_ulonglong,
    stream: cudaStream_t,
) -> cudaError_t
Expand description

Performs a batch of memory discards and prefetches asynchronously.

Performs a batch of memory discards followed by prefetches. The batch as a whole executes in stream order but operations within a batch are not guaranteed to execute in any specific order. All devices in the system must have a non-zero value for the device attribute cudaDeviceAttr::CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS otherwise the API will return an error.

Calling cudaMemDiscardAndPrefetchBatchAsync is semantically equivalent to calling cudaMemDiscardBatchAsync followed by cudaMemPrefetchBatchAsync, but is more optimal. For more details on what discarding and prefetching imply, please refer to cudaMemDiscardBatchAsync and cudaMemPrefetchBatchAsync respectively. Note that any reads, writes or prefetches to any part of the memory range that occur simultaneously with this combined discard+prefetch operation result in undefined behavior.

Performs memory discard and prefetch on address ranges specified in dptrs and sizes. Both arrays must be of the same length as specified by count. Each memory range specified must refer to managed memory allocated via cudaMallocManaged or declared via managed variables or it may also refer to system-allocated memory when all devices have a non-zero value for cudaDeviceAttr::CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. Every operation in the batch has to be associated with a valid location to prefetch the address range to and specified in the prefetchLocs array. Each entry in this array can apply to more than one operation. This can be done by specifying in the prefetchLocIdxs array, the index of the first operation that the corresponding entry in the prefetchLocs array applies to. Both prefetchLocs and prefetchLocIdxs must be of the same length as specified by numPrefetchLocs. For example, if a batch has 10 operations listed in dptrs/sizes, the first 6 of which are to be prefetched to one location and the remaining 4 are to be prefetched to another, then numPrefetchLocs will be 2, prefetchLocIdxs will be {0, 6} and prefetchLocs will contain the two set of locations. Note the first entry in prefetchLocIdxs must always be 0. Also, each entry must be greater than the previous entry and the last entry should be less than count. Furthermore, numPrefetchLocs must be lesser than or equal to count.

ยงParameters

  • dptrs: Array of pointers to be discarded.
  • sizes: Array of sizes for memory discard operations.
  • count: Size of dptrs and sizes arrays.
  • prefetchLocs: Array of locations to prefetch to.
  • prefetchLocIdxs: Array of indices to specify which operands each entry in the prefetchLocs array applies to. The locations specified in prefetchLocs[k] will be applied to operations starting from prefetchLocIdxs[k] through prefetchLocIdxs[k+1] - 1. Also prefetchLocs[numPrefetchLocs - 1] will apply to copies starting from prefetchLocIdxs[numPrefetchLocs - 1] through count - 1.
  • numPrefetchLocs: Size of prefetchLocs and prefetchLocIdxs arrays.
  • flags: Flags reserved for future use. Must be zero.
  • stream: The stream to enqueue the operations in. Must not be legacy NULL stream.