Mojo struct
DeviceBuffer
struct DeviceBuffer[type: DType, address_space: AddressSpace = AddressSpace(0), mut: Bool = True, origin: Origin[mut] = SomeAnyOrigin]
Represents a block of device-resident storage. For GPU devices, a device buffer is allocated in the device's global memory.
To allocate a DeviceBuffer
, use one of the methods provided by
DeviceContext
, such as
enqueue_create_buffer()
.
Parameters
- type (
DType
): Data type to be stored in the buffer. - address_space (
AddressSpace
): The address space of the underlying pointer. - mut (
Bool
): The mutability of the underlying pointer. - origin (
Origin[mut]
): The origin of the underlying pointer.
Implemented traits
AnyType
,
CollectionElement
,
Copyable
,
Movable
,
Sized
,
Stringable
,
UnknownDestructibility
,
Writable
Methods
__copyinit__
__copyinit__(out self, existing: Self)
__moveinit__
__moveinit__(out self, owned existing: Self)
__del__
__del__(owned self)
This function schedules an owned buffer free using the stream in the device context.
__getitem__
__getitem__(self, idx: Int) -> SIMD[type, 1]
__setitem__
__setitem__(self: DeviceBuffer[type], idx: Int, val: SIMD[type, 1])
copy
copy(self) -> Self
Explicitly construct a copy of self.
Returns:
A copy of this value.
__len__
__len__(self) -> Int
create_sub_buffer
create_sub_buffer[view_type: DType](self, offset: Int, size: Int) -> DeviceBuffer[view_type]
enqueue_copy_to
enqueue_copy_to(self, dst: DeviceBuffer[type, address_space, mut, origin])
enqueue_copy_to(self, dst_ptr: UnsafePointer[SIMD[type, 1]])
enqueue_copy_from
enqueue_copy_from(self, src: DeviceBuffer[type, address_space, mut, origin])
enqueue_copy_from(self, src_ptr: UnsafePointer[SIMD[type, 1]])
enqueue_fill
enqueue_fill(self, val: SIMD[type, 1]) -> Self
reassign_ownership_to
reassign_ownership_to(self, ctx: DeviceContext)
take_ptr
take_ptr(owned self) -> UnsafePointer[SIMD[type, 1], address_space=address_space, mut=mut, origin=origin]
unsafe_ptr
unsafe_ptr(self) -> UnsafePointer[SIMD[type, 1], address_space=address_space, mut=mut, origin=origin]
context
context(self) -> DeviceContext
map_to_host
map_to_host(self) -> _HostMappedBuffer[type, address_space, mut, origin]
write_to
write_to[W: Writer](self, mut writer: W)
__str__
__str__(self) -> String
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!