cuda.bindings._v2.driver.mem_discard_and_prefetch_batch_async#

cuda.bindings._v2.driver.mem_discard_and_prefetch_batch_async(
dptrs,
sizes,
prefetch_locs,
prefetch_loc_idxs,
unsigned long long flags,
intptr_t h_stream,
)#

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 CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS otherwise the API will return an error. Calling cuMemDiscardAndPrefetchBatchAsync is semantically equivalent to calling cuMemDiscardBatchAsync followed by cuMemPrefetchBatchAsync, but is more optimal. For more details on what discarding and prefetching imply, please refer to cuMemDiscardBatchAsync and cuMemPrefetchBatchAsync 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 len(dptrs). Each memory range specified must refer to managed memory allocated via cuMemAllocManaged or declared via managed variables or it may also refer to system-allocated memory when all devices have a non-zero value for 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 prefetch_locs array. Each entry in this array can apply to more than one operation. This can be done by specifying in the prefetch_loc_idxs array, the index of the first operation that the corresponding entry in the prefetch_locs array applies to. Both prefetch_locs and prefetch_loc_idxs must be of the same length as specified by len(prefetch_locs). 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 len(prefetch_locs) will be 2, prefetch_loc_idxs will be {0, 6} and prefetch_locs will contain the two set of locations. Note the first entry in prefetch_loc_idxs must always be 0. Also, each entry must be greater than the previous entry and the last entry should be less than len(dptrs). Furthermore, len(prefetch_locs) must be lesser than or equal to len(dptrs).

Parameters:
  • dptrs (object) –

    Array of pointers to be discarded. It must be:

    • a Python sequence of unsigned long long, or

    • None for NULL.

  • sizes (object) –

    Array of sizes for memory discard operations. It must be:

    • a Python sequence of size_t, or

    • None for NULL.

  • prefetch_locs (MemLocation_v1) –

    Array of locations to prefetch to. It must be:

  • prefetch_loc_idxs (object) –

    Array of indices to specify which operands each entry in the prefetch_locs array applies to. The locations specified in prefetch_locs[k] will be applied to operations starting from prefetch_loc_idxs[k] through prefetch_loc_idxs[k+1] - 1. Also prefetch_locs[len(prefetch_locs) - 1] will apply to copies starting from prefetch_loc_idxs[len(prefetch_locs) - 1] through len(dptrs) - 1. It must be:

    • a Python sequence of size_t, or

    • None for NULL.

  • flags (unsigned long long) – Flags reserved for future use. Must be zero.

  • h_stream (intptr_t) – The stream to enqueue the operations in. Must not be legacy NULL stream.

See also

cuMemDiscardAndPrefetchBatchAsync