cupy.cuda.MemoryPointer

class cupy.cuda.MemoryPointer(BaseMemory mem, ptrdiff_t offset)

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:
  • device (Device) – Device whose memory the pointer refers to.
  • mem (BaseMemory) – The device memory buffer.
  • 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:
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:
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:
  • mem (ctypes.c_void_p) – Source memory pointer.
  • size (int) – Size of the sequence in bytes.
copy_from_host_async(self, mem, size_t size, stream=None)

Copies a memory sequence from the host memory asynchronously.

Parameters:
  • mem (ctypes.c_void_p) – Source memory pointer. It must be a 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:
  • mem (ctypes.c_void_p) – Target memory pointer.
  • size (int) – Size of the sequence in bytes.
copy_to_host_async(self, mem, size_t size, stream=None)

Copies a memory sequence to the host memory asynchronously.

Parameters:
  • mem (ctypes.c_void_p) – Target memory pointer. It must be a 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.
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.

Attributes

device
device_id
mem
ptr