MemoryOperatorsType

public protocol MemoryOperatorsType

Memory manager for a device

  • Undocumented

    Declaration

    Swift

    associatedtype Device : DeviceType where Self == Self.Device.Memory
  • Undocumented

    Declaration

    Swift

    associatedtype RawBuffer : Hashable
  • Allocates a buffer with capacity for the given amount of elements of the given type.

    Declaration

    Swift

    static func allocateBuffer<Element>(withCapacity: Int, type: Element.Type) -> Buffer<Element, Device>

    Parameters

    withCapacity

    Capacity to reserve

    type

    Type of elements in the buffer

  • Allocates a buffer with capacity for the amount of elements in the given shape

    Declaration

    Swift

    static func allocateBuffer<Element>(withShape shape: [Int], type: Element.Type) -> ShapedBuffer<Element, Device>

    Parameters

    shape

    Shape of the buffer to allocate

    type

    Type of elements in the buffer

  • Releases all resources associated with the given buffer

    Declaration

    Swift

    static func free<Element>(_ buffer: Buffer<Element, Device>)

    Parameters

    buffer

    Buffer to release

  • Releases all resources associated with the given buffer

    Declaration

    Swift

    static func free<Element>(_ buffer: ShapedBuffer<Element, Device>)

    Parameters

    buffer

    Buffer to release

  • Copies values from the given host buffer to the memory of the device

    Declaration

    Swift

    static func assign<Element>(from source: UnsafeBufferPointer<Element>, to destination: Buffer<Element, Device>, count: Int)

    Parameters

    source

    Source buffer

    destination

    Device buffer

    count

    Number of elements to copy

  • Copies values between two device buffers

    Declaration

    Swift

    static func assign<Element>(from source: Buffer<Element, Device>, to destination: Buffer<Element, Device>, count: Int)

    Parameters

    source

    Source device buffer

    destination

    Target device buffer

    count

    Number of elements to copy

  • Copies values from the given device buffer to the given host buffer

    Declaration

    Swift

    static func assign<Element>(from source: Buffer<Element, Device>, to destination: UnsafeMutableBufferPointer<Element>, count: Int)

    Parameters

    source

    Device buffer

    destination

    Host buffer

    count

    Number of elements to copy

  • Returns the first value in the buffer

    Declaration

    Swift

    static func getValue<Element>(from source: Buffer<Element, Device>) -> Element

    Parameters

    source

    Buffer to return the first value of

  • Returns the number of elements in the buffer

    Declaration

    Swift

    static func getSize<Element>(of buffer: Buffer<Element, Device>) -> Int

    Parameters

    buffer

    Number of elements in the buffer

  • Retrieves a slice of values from the given buffer

    Declaration

    Swift

    static func get<Element>(slice: [Int?], of buffer: Buffer<Element, Device>, with shape: [Int]) -> (Buffer<Element, Device>, Bool, [Int])

    Parameters

    slice

    Index

    buffer

    Buffer to read from

    shape

    Shape of the buffer

    Return Value

    The result buffer, a boolean indicating whether the result buffer is a copy (true) or a pointer in the same memory region (false) and the shape of the result.

  • Retrieves a slice of values from the given buffer

    Declaration

    Swift

    static func get<Element>(slice: [(CountableRange<Int>)?], of buffer: Buffer<Element, Device>, with shape: [Int]) -> (Buffer<Element, Device>, Bool, [Int])

    Parameters

    slice

    Index

    buffer

    Buffer to read from

    shape

    Shape of the buffer

    Return Value

    The result buffer, a boolean indicating whether the result buffer is a copy (true) or a pointer in the same memory region (false) and the shape of the result.

  • Writes a slice into a target buffer

    Declaration

    Swift

    static func set<Element>(slice: [Int?], of buffer: Buffer<Element, Device>, with dstShape: [Int], from source: Buffer<Element, Device>, with sourceShape: [Int])

    Parameters

    slice

    Slice index

    buffer

    Buffer to write to

    dstShape

    Shape of the destination buffer

    source

    Buffer to read from

    sourceShape

    Shape of the source buffer

  • Writes a slice into a target buffer

    Declaration

    Swift

    static func set<Element>(slice: [Range<Int>?], of buffer: Buffer<Element, Device>, with dstShape: [Int], from source: Buffer<Element, Device>, with sourceShape: [Int])

    Parameters

    slice

    Slice index

    buffer

    Buffer to write to

    dstShape

    Shape of the destination buffer

    source

    Buffer to read from

    sourceShape

    Shape of the source buffer

  • Sets the first element of the device buffer

    Declaration

    Swift

    static func setPointee<Element>(of buffer: Buffer<Element, Device>, to newValue: Element)

    Parameters

    buffer

    Target buffer

    newValue

    Value to set the first slot of the target to

  • Returns a buffer that uses the same region of memory but is advanced by the given number of elements

    Declaration

    Swift

    static func advance<Element>(buffer: Buffer<Element, Device>, by advancement: Int) -> Buffer<Element, Device>

    Parameters

    buffer

    Parent buffer

    advancement

    Number of elements to advance the start index by