Pointer
Module
Implements classes for working with pointers.
DTypePointer
Defines a DTypePointer
struct that contains an address of the given dtype.
Parameters:
- type (
DType
): DType of the underlying data.
Aliases:
element_type = scalar<#lit.struct.extract<:@"$DType"::@DType type, "value">>
pointer_type = pointer<scalar<#lit.struct.extract<:@"$DType"::@DType type, "value">>>
Fields:
address
The pointed-to address.
Functions:
__init__
__init__() -> Self
Construct a null DTypePointer
from the given type.
Returns:
Constructed DTypePointer
object.
__init__(address: pointer<scalar<#lit.struct.extract<:_"$DType"::_DType type, "value">>>) -> Self
Construct a DTypePointer
from the given address.
Args:
- address (
pointer<scalar<#lit.struct.extract<:_"$DType"::_DType type, "value">>>
): The input pointer.
Returns:
Constructed DTypePointer
object.
__init__(value: Pointer[SIMD[type, 1]]) -> Self
Construct a DTypePointer
from a scalar pointer of the same type.
Args:
- value (
Pointer[SIMD[type, 1]]
): The scalar pointer.
Returns:
Constructed DTypePointer
.
__init__(value: SIMD[address, 1]) -> Self
Construct a DTypePointer
from the value of scalar address.
Args:
- value (
SIMD[address, 1]
): The input pointer index.
Returns:
Constructed DTypePointer
object.
__bool__
__bool__(self: Self) -> Bool
Checks if the pointer is null.
Returns:
Returns False if the pointer is null and True otherwise.
__lt__
__lt__(self: Self, rhs: Self) -> Bool
Returns True if this pointer represents a lower address than rhs.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if this pointer represents a lower address and False otherwise.
__eq__
__eq__(self: Self, rhs: Self) -> Bool
Returns True if the two pointers are equal.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if the two pointers are equal and False otherwise.
__ne__
__ne__(self: Self, rhs: Self) -> Bool
Returns True if the two pointers are not equal.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if the two pointers are not equal and False otherwise.
__add__
__add__(self: Self, rhs: Int) -> Self
Returns a new pointer shifted by the specified offset.
Args:
- rhs (
Int
): The offset.
Returns:
The new DTypePointer shifted by the offset.
__sub__
__sub__(self: Self, rhs: Int) -> Self
Returns a new pointer shifted back by the specified offset.
Args:
- rhs (
Int
): The offset.
Returns:
The new DTypePointer shifted by the offset.
__iadd__
__iadd__(self: Self&, rhs: Int)
Shift the current pointer by the specified offset.
Args:
- rhs (
Int
): The offset.
__isub__
__isub__(self: Self&, rhs: Int)
Shift back the current pointer by the specified offset.
Args:
- rhs (
Int
): The offset.
address_of
address_of(arg: scalar<#lit.struct.extract<:_"$DType"::_DType type, "value">>&) -> Self
Gets the address of the argument.
Args:
- arg (
scalar<#lit.struct.extract<:_"$DType"::_DType type, "value">>&
): The value to get the address of.
Returns:
A pointer struct which contains the address of the argument.
aligned_alloc
aligned_alloc(alignment: Int, count: Int) -> Self
Heap allocates count number of element of the specified type using the specified alignment.
Args:
- alignment (
Int
): The alignment used for the allocation. - count (
Int
): The number of elements to allocate (note that this is not the bytecount).
Returns:
A new DTypePointer
object which has been allocated on the heap.
aligned_simd_load
aligned_simd_load[width: Int, alignment: Int](self: Self, offset: Int) -> SIMD[type, width]
Load a SIMD vector of elements from the pointer at the specified offset with the guaranteed specified alignment.
Parameters:
- width (
Int
): The SIMD width. - alignment (
Int
): The minimal alignment of the address.
Args:
- offset (
Int
): The offset to load from.
Returns:
The loaded SIMD value.
aligned_simd_load[width: Int, alignment: Int](self: Self) -> SIMD[type, width]
Load a SIMD vector of elements from the pointer with the guaranteed specified alignment.
Parameters:
- width (
Int
): The SIMD width. - alignment (
Int
): The minimal alignment of the address.
Returns:
The loaded SIMD value.
aligned_simd_store
aligned_simd_store[width: Int, alignment: Int](self: Self, offset: Int, val: SIMD[type, width])
Store a SIMD vector at the given offset with a guaranteed alignment.
Parameters:
- width (
Int
): The SIMD width. - alignment (
Int
): The minimal alignment of the address.
Args:
- offset (
Int
): The offset to store to. - val (
SIMD[type, width]
): The SIMD value to store.
aligned_simd_store[width: Int, alignment: Int](self: Self, val: SIMD[type, width])
Store a SIMD vector with a guaranteed alignment.
Parameters:
- width (
Int
): The SIMD width. - alignment (
Int
): The minimal alignment of the address.
Args:
- val (
SIMD[type, width]
): The SIMD value to store.
alloc
alloc(count: Int) -> Self
Heap allocates count number of element of the specified type.
Args:
- count (
Int
): The number of elements to allocate (note that this is not the bytecount).
Returns:
A new DTypePointer
object which has been allocated on the heap.
as_scalar_pointer
as_scalar_pointer(self: Self) -> Pointer[SIMD[type, 1]]
Convert the DTypePointer
to a scalar pointer of the same dtype.
Returns:
A Pointer
to a scalar of the same dtype.
bitcast
bitcast[new_type: DType](self: Self) -> DTypePointer[new_type]
Bitcast DTypePointer
to a different dtype.
Parameters:
- new_type (
DType
): The target dtype.
Returns:
A new DTypePointer
object with the specified dtype and the same address, as the original DTypePointer
.
free
free(self: Self)
Frees the heap allocates memory.
get_null
get_null() -> Self
Construct a DTypePointer
representing nullptr.
Returns:
Constructed nullptr DTypePointer
object.
is_aligned
is_aligned[alignment: Int](self: Self) -> Bool
Check if the pointer is aligned.
Parameters:
- alignment (
Int
): The minimal desired alignment.
Returns:
True
if the pointer is at least alignment
-aligned or False
otherwise.
load
load(self: Self, offset: Int) -> SIMD[type, 1]
Load a single element (SIMD of size 1) from the pointer at the specified index.
Args:
- offset (
Int
): The offset to load from.
Returns:
The loaded value.
load(self: Self) -> SIMD[type, 1]
Load a single element (SIMD of size 1) from the pointer.
Returns:
The loaded value.
offset
offset(self: Self, idx: Int) -> Self
Returns a new pointer shifted by the specified offset.
Args:
- idx (
Int
): The offset of the new pointer.
Returns:
The new constructed DTypePointer.
prefetch
prefetch[params: PrefetchOptions](self: Self)
Prefetch memory at the underlying address.
Parameters:
- params (
PrefetchOptions
): Prefetch options (seePrefetchOptions
for details).
simd_load
simd_load[width: Int](self: Self, offset: Int) -> SIMD[type, width]
Load a SIMD vector of elements from the pointer at the specified offset.
Parameters:
- width (
Int
): The SIMD width.
Args:
- offset (
Int
): The offset to load from.
Returns:
The loaded value.
simd_load[width: Int](self: Self) -> SIMD[type, width]
Load a SIMD vector of elements from the pointer.
Parameters:
- width (
Int
): The SIMD width.
Returns:
The loaded SIMD value.
simd_nt_store
simd_nt_store[width: Int](self: Self, offset: Int, val: SIMD[type, width])
Store a SIMD vector using non-temporal store.
Parameters:
- width (
Int
): The SIMD width.
Args:
- offset (
Int
): The offset to store to. - val (
SIMD[type, width]
): The SIMD value to store.
simd_nt_store[width: Int](self: Self, val: SIMD[type, width])
Store a SIMD vector using non-temporal store.
The address must be properly aligned, 64B for avx512, 32B for avx2, and 16B for avx.
Parameters:
- width (
Int
): The SIMD width.
Args:
- val (
SIMD[type, width]
): The SIMD value to store.
simd_store
simd_store[width: Int](self: Self, offset: Int, val: SIMD[type, width])
Store a SIMD vector at the given offset.
Parameters:
- width (
Int
): The SIMD width.
Args:
- offset (
Int
): The offset to store to. - val (
SIMD[type, width]
): The SIMD value to store.
simd_store[width: Int](self: Self, val: SIMD[type, width])
Store a SIMD vector.
Parameters:
- width (
Int
): The SIMD width.
Args:
- val (
SIMD[type, width]
): The SIMD value to store.
simd_strided_load
simd_strided_load[width: Int](self: Self, stride: Int) -> SIMD[type, width]
Perform a strided load of the SIMD vector.
Parameters:
- width (
Int
): The SIMD width.
Args:
- stride (
Int
): The stride between loads.
Returns:
A vector which is stride loaded.
simd_strided_store
simd_strided_store[width: Int](self: Self, val: SIMD[type, width], stride: Int)
Perform a strided store of the SIMD vector.
Parameters:
- width (
Int
): The SIMD width.
Args:
- val (
SIMD[type, width]
): The SIMD value to store. - stride (
Int
): The stride between stores.
store
store(self: Self, offset: Int, val: SIMD[type, 1])
Store a single element value at the given offset.
Args:
- offset (
Int
): The offset to store to. - val (
SIMD[type, 1]
): The value to store.
store(self: Self, val: SIMD[type, 1])
Store a single element value.
Args:
- val (
SIMD[type, 1]
): The value to store.
Pointer
Defines a Pointer struct that contains an address of any mlirtype.
Parameters:
- type (
AnyType
): Type of the underlying data.
Aliases:
pointer_type = pointer<type>
Fields:
address
The pointed-to address.
Functions:
__init__
__init__() -> Self
Construct a null Pointer from the value of pop.pointer type.
Returns:
Constructed Pointer object.
__init__(address: pointer<type>) -> Self
Construct a Pointer from the address.
Args:
- address (
pointer<type>
): The input pointer address.
Returns:
Constructed Pointer object.
__init__(value: SIMD[address, 1]) -> Self
Construct a Pointer from the value of scalar address.
Args:
- value (
SIMD[address, 1]
): The input pointer index.
Returns:
Constructed Pointer object.
__bool__
__bool__(self: Self) -> Bool
Checks if the pointer is null.
Returns:
Returns False if the pointer is null and True otherwise.
__getitem__
__getitem__(self: Self, offset: Int) -> type
Load value the Pointer object points to with the given offset.
Args:
- offset (
Int
): The offset to load from.
Returns:
The loaded value.
__eq__
__eq__(self: Self, rhs: Self) -> Bool
Returns True if the two pointers are equal.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if the two pointers are equal and False otherwise.
__ne__
__ne__(self: Self, rhs: Self) -> Bool
Returns True if the two pointers are not equal.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if the two pointers are not equal and False otherwise.
__add__
__add__(self: Self, rhs: Int) -> Self
Returns a new pointer shifted by the specified offset.
Args:
- rhs (
Int
): The offset.
Returns:
The new Pointer shifted by the offset.
__sub__
__sub__(self: Self, rhs: Int) -> Self
Returns a new pointer shifted back by the specified offset.
Args:
- rhs (
Int
): The offset.
Returns:
The new Pointer shifted back by the offset.
__iadd__
__iadd__(self: Self&, rhs: Int)
Shift the current pointer by the specified offset.
Args:
- rhs (
Int
): The offset.
__isub__
__isub__(self: Self&, rhs: Int)
Shift back the current pointer by the specified offset.
Args:
- rhs (
Int
): The offset.
address_of
address_of(arg: type&) -> Self
Gets the address of the argument.
Args:
- arg (
type&
): The value to get the address of.
Returns:
A pointer struct which contains the address of the argument.
aligned_alloc
aligned_alloc(alignment: Int, count: Int) -> Self
Heap allocates count number of element of the specified type using the specified alignment.
Args:
- alignment (
Int
): The alignment used for the allocation. - count (
Int
): The number of elements to allocate (note that this is not the bytecount).
Returns:
A new Pointer object which has been allocated on the heap.
alloc
alloc(count: Int) -> Self
Heap allocates count number of element of the specified type.
Args:
- count (
Int
): The number of elements to allocate (note that this is not the bytecount).
Returns:
A new Pointer object which has been allocated on the heap.
bitcast
bitcast[new_type: AnyType](self: Self) -> Pointer[new_type]
Bitcast Pointer to a different type.
Parameters:
- new_type (
AnyType
): The target type.
Returns:
A new Pointer object with the specified type and the same address, as the original Pointer.
free
free(self: Self)
Frees the heap allocated memory.
get_null
get_null() -> Self
Construct a Pointer representing nullptr.
Returns:
Constructed nullptr Pointer object.
load
load(self: Self, offset: Int) -> type
Load value the Pointer object points to with the given offset.
Args:
- offset (
Int
): The offset to load from.
Returns:
The loaded value.
load(self: Self) -> type
Load value the Pointer object points to.
Returns:
The loaded value.
offset
offset(self: Self, idx: Int) -> Self
Returns a new pointer shifted by the specified offset.
Args:
- idx (
Int
): The offset.
Returns:
The new Pointer shifted by the offset.
store
store(self: Self, offset: Int, value: type)
Store the specified value to the location the Pointer object points to with the given offset.
Args:
- offset (
Int
): The offset to load from. - value (
type
): The value to store.
store(self: Self, value: type)
Store the specified value to the location the Pointer object points to.
Args:
- value (
type
): The value to store.