Mojo struct
DynamicRankBuffer
DynamicRankBuffer represents a buffer with unknown rank, shapes and dtype.
It is not as efficient as the statically ranked buffer, but is useful when interacting with external functions. In particular the shape is represented as a fixed (ie _MAX_RANK) array of dimensions to simplify the ABI.
Fieldsβ
- βdata (
UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): The pointer to the buffer. - βrank (
Int
): The buffer rank. Has a max value of_MAX_RANK
. - βshape (
StaticIntTuple[8]
): The dynamic shape of the buffer. - βtype (
DType
): The dynamic dtype of the buffer.
Implemented traitsβ
AnyType
Methodsβ
__init__
β
__init__(inout self: Self, data: UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1], rank: Int, shape: StaticIntTuple[8], type: DType)
Construct DynamicRankBuffer.
Args:
- βdata (
UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): Pointer to the underlying data. - βrank (
Int
): Rank of the buffer. - βshape (
StaticIntTuple[8]
): Shapes of the buffer. - βtype (
DType
):dtype
of the buffer.
to_buffer
β
to_buffer[type: DType](self: Self) -> Buffer[$0, -31337, 0]
Casts DynamicRankBuffer to Buffer.
Parameters:
- βtype (
DType
):dtype
of the buffer.
Returns:
Constructed Buffer.
to_ndbuffer
β
to_ndbuffer[type: DType, rank: Int](self: Self) -> NDBuffer[$0, $1, create_unknown[::Int](), create_unknown[::Int](), 0]
Casts the buffer to NDBuffer.
Constraints:
Rank of DynamicRankBuffer must equal rank of NDBuffer.
Parameters:
- βtype (
DType
):dtype
of the buffer. - βrank (
Int
): Rank of the buffer.
Returns:
Constructed NDBuffer.
to_ndbuffer[type: DType, rank: Int](self: Self, stride: StaticIntTuple[rank]) -> NDBuffer[$0, $1, create_unknown[::Int](), create_unknown[::Int](), 0]
Casts the buffer to NDBuffer.
Constraints:
Rank of DynamicRankBuffer must equal rank of NDBuffer.
Parameters:
- βtype (
DType
):dtype
of the buffer. - βrank (
Int
): Rank of the buffer.
Args:
- βstride (
StaticIntTuple[rank]
): Strides of the buffer.
Returns:
Constructed NDBuffer.
rank_dispatch
β
rank_dispatch[func: fn[Int]() capturing -> None](self: Self)
Dispatches the function call based on buffer rank.
Constraints:
Rank must be positive and less or equal to 8.
Parameters:
- βfunc (
fn[Int]() capturing -> None
): Function to dispatch. The function should be parametrized on an index parameter, which will be used for rank when the function will be called.
num_elements
β
num_elements(self: Self) -> Int
Gets number of elements in the buffer.
Returns:
The number of elements in the buffer.
get_shape
β
get_shape[rank: Int](self: Self) -> StaticIntTuple[$0]
Gets a static tuple representing the buffer shape.
Parameters:
- βrank (
Int
): Rank of the buffer.
Returns:
A static tuple of size 'Rank' filled with buffer shapes.
dim
β
dim(self: Self, idx: Int) -> Int
Gets given dimension.
Args:
- βidx (
Int
): The dimension index.
Returns:
The buffer size on the given dimension.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?