cupy.cuda.MemoryPointer#

class cupy.cuda.MemoryPointer(BaseMemory mem, ptrdiff_t offset)[source]#

Pointer to a point on a device memory.

An instance of this class holds a reference to the original memory buffer and a pointer to a place within this buffer.

Parameters:
  • mem (BaseMemory) – The device memory buffer.

  • offset (int) – An offset from the head of the buffer to the place this pointer refers.

Variables:
  • ~MemoryPointer.device (Device) – Device whose memory the pointer refers to.

  • ~MemoryPointer.mem (BaseMemory) – The device memory buffer.

  • ~MemoryPointer.ptr (int) – Pointer to the place within the buffer.

Methods

copy_from(self, mem, size_t size)#

Copies a memory sequence from a (possibly different) device or host.

This function is a useful interface that selects appropriate one from copy_from_device() and copy_from_host().

Parameters:

Warning

This function always uses the legacy default stream and does not honor the current stream. Use copy_from_async instead if you are using streams in your code, or have PTDS enabled.

copy_from_async(self, mem, size_t size, stream=None)#

Copies a memory sequence from an arbitrary place asynchronously.

This function is a useful interface that selects appropriate one from copy_from_device_async() and copy_from_host_async().

Parameters:
copy_from_device(self, MemoryPointer src, size_t size)#

Copies a memory sequence from a (possibly different) device.

Parameters:

Warning

This function always uses the legacy default stream and does not honor the current stream. Use copy_from_device_async instead if you are using streams in your code, or have PTDS enabled.

copy_from_device_async(self, MemoryPointer src, size_t size, stream=None)#

Copies a memory from a (possibly different) device asynchronously.

Parameters:
copy_from_host(self, mem, size_t size)#

Copies a memory sequence from the host memory.

Parameters:

Warning

This function always uses the legacy default stream and does not honor the current stream. Use copy_from_host_async instead if you are using streams in your code, or have PTDS enabled.

copy_from_host_async(self, mem, size_t size, stream=None)#

Copies a memory sequence from the host memory asynchronously.

Parameters:
  • mem (int or ctypes.c_void_p) – Source memory pointer. It must point to pinned memory.

  • size (int) – Size of the sequence in bytes.

  • stream (cupy.cuda.Stream) – CUDA stream. The default uses CUDA stream of the current context.

copy_to_host(self, mem, size_t size)#

Copies a memory sequence to the host memory.

Parameters:

Warning

This function always uses the legacy default stream and does not honor the current stream. Use copy_to_host_async instead if you are using streams in your code, or have PTDS enabled.

copy_to_host_async(self, mem, size_t size, stream=None)#

Copies a memory sequence to the host memory asynchronously.

Parameters:
  • mem (int or ctypes.c_void_p) – Target memory pointer. It must point to pinned memory.

  • size (int) – Size of the sequence in bytes.

  • stream (cupy.cuda.Stream) – CUDA stream. The default uses CUDA stream of the current context.

memset(self, int value, size_t size)#

Fills a memory sequence by constant byte value.

Parameters:
  • value (int) – Value to fill.

  • size (int) – Size of the sequence in bytes.

Warning

This function always uses the legacy default stream and does not honor the current stream. Use memset_async instead if you are using streams in your code, or have PTDS enabled.

memset_async(self, int value, size_t size, stream=None)#

Fills a memory sequence by constant byte value asynchronously.

Parameters:
  • value (int) – Value to fill.

  • size (int) – Size of the sequence in bytes.

  • stream (cupy.cuda.Stream) – CUDA stream. The default uses CUDA stream of the current context.

__eq__(value, /)#

Return self==value.

__ne__(value, /)#

Return self!=value.

__lt__(value, /)#

Return self<value.

__le__(value, /)#

Return self<=value.

__gt__(value, /)#

Return self>value.

__ge__(value, /)#

Return self>=value.

Attributes

device#
device_id#
mem#
ptr#