cuda.bindings._v2.driver.mem_alloc_pitch_v2#

cuda.bindings._v2.driver.mem_alloc_pitch_v2(
size_t width_in_bytes,
size_t height,
unsigned int element_size_bytes,
) → tuple#

Allocates pitched device memory.

Allocates at least width_in_bytes * height bytes of linear memory on the device and returns in *dptr a pointer to the allocated memory. The function may pad the allocation to ensure that corresponding pointers in any given row will continue to meet the alignment requirements for coalescing as the address is updated from row to row. element_size_bytes specifies the size of the largest reads and writes that will be performed on the memory range. element_size_bytes may be 4, 8 or 16 (since coalesced memory transactions are not possible on other data sizes). If element_size_bytes is smaller than the actual read/write size of a kernel, the kernel will run correctly, but possibly at reduced speed. The pitch returned in *p_pitch by cuMemAllocPitch() is the width in bytes of the allocation. The intended usage of pitch is as a separate parameter of the allocation, used to compute addresses within the 2D array. Given the row and column of an array element of type T, the address is computed as:. **View CUDA Toolkit Documentation for a C++ code example**. The pitch returned by cuMemAllocPitch() is guaranteed to work with cuMemcpy2D() under all circumstances. For allocations of 2D arrays, it is recommended that programmers consider performing pitch allocations using cuMemAllocPitch(). Due to alignment restrictions in the hardware, this is especially true if the application will be performing 2D memory copies between different regions of device memory (whether linear memory or CUDA arrays). The byte alignment of the pitch returned by cuMemAllocPitch() is guaranteed to match or exceed the alignment requirement for texture binding with cuTexRefSetAddress2D().

Parameters:
  • width_in_bytes (size_t) – Requested allocation width in bytes.

  • height (size_t) – Requested allocation height in rows.

  • element_size_bytes (unsigned int) – Size of largest reads/writes for range.

Returns:

  • uint64_t: Returned device pointer.

  • size_t: Returned pitch of allocation in bytes.

Return type:

A 2-tuple containing

See also

cuMemAllocPitch_v2