|
IRON 1.0
|
Public Member Functions | |
| __repr__ (self) | |
| __init__ (self, shape_or_data, dtype=np.uint32, device="npu") | |
| __array__ (self, dtype=None) | |
| __getitem__ (self, index) | |
| __setitem__ (self, index, value) | |
| to (self, str target_device) | |
| buffer_object (self) | |
| numpy (self) | |
| fill_ (self, value) | |
| numel (self) | |
| ones (cls, *size, out=None, dtype=None, device=None, **kwargs) | |
| zeros (cls, *size, out=None, dtype=None, device=None, **kwargs) | |
| randint (cls, low, high, size, *out=None, dtype=None, device=None, **kwargs) | |
| rand (cls, *size, out=None, dtype=None, device=None, **kwargs) | |
| arange (cls, start=0, end=None, step=1, *out=None, dtype=None, device=None, **kwargs) | |
| zeros_like (cls, other, dtype=None, device=None, **kwargs) | |
| __del__ (self) | |
Public Attributes | |
| device | |
| shape | |
| dtype | |
| data | |
| len_bytes | |
| xrt_device | |
| bo | |
Static Protected Member Functions | |
| _ctype_from_dtype (dtype) | |
Private Member Functions | |
| __sync_to_device (self) | |
| __sync_from_device (self) | |
Tensor object backed by NPU or CPU memory. The class provides commom tensor operations such as creation, filling with values, and accessing data.
| iron.tensor.Tensor.__init__ | ( | self, | |
| shape_or_data, | |||
dtype = np.uint32, |
|||
device = "npu" |
|||
| ) |
Initialize the tensor.
Parameters:
shape_or_data (tuple or array-like):
- If a tuple, creates a new tensor with the given shape and dtype.
- If array-like, wraps the data into a tensor with optional dtype casting.
dtype (np.dtype, optional): Data type of the tensor. Defaults to np.uint32.
device (str, optional): Device string identifier (e.g., 'npu', 'cpu'). Defaults to 'npu'.
| iron.tensor.Tensor.__del__ | ( | self | ) |
Destructor for Tensor. Releases associated device memory (e.g., XRT buffer object).
| iron.tensor.Tensor.__array__ | ( | self, | |
dtype = None |
|||
| ) |
NumPy protocol method to convert the tensor to a NumPy array.
This allows the tensor to be used in NumPy functions or explicitly converted via np.array(tensor).
Parameters:
dtype (np.dtype, optional): Desired NumPy dtype for the resulting array.
If None, returns with the tensor's current dtype.
Returns:
np.ndarray: A NumPy array containing the tensor's data.
Note: For NPU tensors, this method causes implicit data synchronization from device to host
to ensure the returned array reflects the current device state.
| iron.tensor.Tensor.__getitem__ | ( | self, | |
| index | |||
| ) |
Retrieves the value at a specific index in the tensor.
Parameters:
index (int): The index of the value to retrieve.
Returns:
The value at the specified index.
Note: For NPU tensors, this method causes implicit data synchronization from device to host
to ensure the retrieved value reflects the current device state.
| iron.tensor.Tensor.__repr__ | ( | self | ) |
Return a string representation of the tensor. Note: For NPU tensors, this method causes implicit data synchronization from device to host to ensure the string representation reflects the current device state.
| iron.tensor.Tensor.__setitem__ | ( | self, | |
| index, | |||
| value | |||
| ) |
Sets the value at a specific index in the tensor.
Parameters:
index (int): The index of the value to set.
value: The new value to assign.
Note: For NPU tensors, this method causes implicit data synchronization from device to host
before modification and back to device after modification to ensure
data consistency across device and host memory.
|
private |
Syncs the tensor data from the device to the host memory.
|
private |
Syncs the tensor data from the host to the device memory.
|
staticprotected |
Converts a NumPy data type to its corresponding ctypes type.
Parameters:
dtype (np.dtype): A NumPy data type (or a convertible type like np.float32).
Returns:
A ctypes type (e.g., ctypes.c_float).
| iron.tensor.Tensor.arange | ( | cls, | |
start = 0, |
|||
end = None, |
|||
step = 1, |
|||
| * | out = None, |
||
dtype = None, |
|||
device = None, |
|||
| ** | kwargs | ||
| ) |
Returns a 1-D tensor with values from the interval [start, end) with spacing `step`.
Parameters:
start (number): Start of interval. Defaults to 0.
end (number): End of interval (exclusive). Required if only one argument is given.
step (number): Gap between elements. Defaults to 1.
Keyword Arguments:
dtype (np.dtype, optional): Desired output data type. Inferred if not provided.
out (Tensor, optional): Optional tensor to write output to (must match shape and dtype).
device (str, optional): Target device (e.g., "npu", "cpu"). Defaults to "npu".
Returns:
Tensor: 1-D tensor containing the sequence.
| iron.tensor.Tensor.buffer_object | ( | self | ) |
Returns the XRT buffer object associated with this tensor. Returns: xrt.bo: The XRT buffer object associated with this tensor.
| iron.tensor.Tensor.fill_ | ( | self, | |
| value | |||
| ) |
Fills the tensor with a scalar value (in-place operation).
Parameters:
value: The scalar value to fill the tensor with.
Note: For NPU tensors, this method syncs the filled data to device after modification.
| iron.tensor.Tensor.numel | ( | self | ) |
Calculates the number of elements in the tensor.
Returns:
int: The total number of elements in the tensor.
| iron.tensor.Tensor.numpy | ( | self | ) |
Returns a NumPy view of the tensor data on host memory.
This method ensures that data is first synchronized from the device
(e.g., NPU) to the host before returning the array.
Returns:
np.ndarray: The tensor's data as a NumPy array.
Note: For NPU tensors, this method causes implicit data synchronization from device to host
to ensure the returned array reflects the current device state.
| iron.tensor.Tensor.ones | ( | cls, | |
| * | size, | ||
out = None, |
|||
dtype = None, |
|||
device = None, |
|||
| ** | kwargs | ||
| ) |
Returns a tensor filled with ones, with shape defined by size.
Parameters:
*size (int...): Shape of the tensor, passed as separate ints or a single tuple/list.
Keyword Arguments:
out (Tensor, optional): Optional output tensor to write into.
dtype (np.dtype, optional): Desired dtype. Defaults to np.float32.
device (str, optional): Target device. Defaults to "npu".
**kwargs: Additional keyword args.
Returns:
Tensor: A one-filled tensor.
| iron.tensor.Tensor.rand | ( | cls, | |
| * | size, | ||
out = None, |
|||
dtype = None, |
|||
device = None, |
|||
| ** | kwargs | ||
| ) |
Returns a tensor filled with random numbers from a uniform distribution on [0, 1).
Parameters:
*size (int...): Variable number of integers or a single tuple defining the shape.
Keyword Arguments:
out (Tensor, optional): Output tensor to write into.
dtype (np.dtype, optional): Desired data type. Defaults to np.float32.
device (str, optional): Target device. Defaults to "npu".
**kwargs: Additional arguments passed to constructor.
Returns:
Tensor: A tensor with random values in [0, 1).
| iron.tensor.Tensor.randint | ( | cls, | |
| low, | |||
| high, | |||
| size, | |||
| * | out = None, |
||
dtype = None, |
|||
device = None, |
|||
| ** | kwargs | ||
| ) |
Returns a tensor filled with random integers uniformly sampled from [low, high).
Parameters:
low (int): Lowest integer to be drawn (inclusive).
high (int): One above the highest integer to be drawn (exclusive).
size (tuple): Shape of the returned tensor.
Keyword Arguments:
out (Tensor, optional): Optional tensor to write the result into.
dtype (np.dtype, optional): Data type. Defaults to np.int64.
device (str, optional): Target device. Defaults to "npu".
**kwargs: Additional arguments passed to the constructor.
Returns:
Tensor: A tensor with random integers.
| iron.tensor.Tensor.to | ( | self, | |
| str | target_device | ||
| ) |
Moves the tensor to a specified target device (either "npu" or "cpu").
Parameters:
target_device (str): The target device ("npu" or "cpu").
Returns:
The tensor object on the target device.
| iron.tensor.Tensor.zeros | ( | cls, | |
| * | size, | ||
out = None, |
|||
dtype = None, |
|||
device = None, |
|||
| ** | kwargs | ||
| ) |
Returns a tensor filled with zeros, with shape defined by size.
Parameters:
*size (int...): Shape of the tensor, passed as separate ints or a single tuple/list.
Keyword Arguments:
out (Tensor, optional): Optional output tensor to write into.
dtype (np.dtype, optional): Desired dtype. Defaults to np.float32.
device (str, optional): Target device. Defaults to "npu".
**kwargs: Additional keyword args.
Returns:
Tensor: A zero-filled tensor.
| iron.tensor.Tensor.zeros_like | ( | cls, | |
| other, | |||
dtype = None, |
|||
device = None, |
|||
| ** | kwargs | ||
| ) |
Creates a new tensor with the same shape as `other`, filled with zeros.
Parameters:
other (Tensor): The reference tensor to copy shape from.
dtype (np.dtype, optional): Data type of the new tensor. Defaults to other's dtype.
device (str, optional): Target device. Defaults to other's device.
**kwargs: Additional keyword arguments forwarded to the constructor.
Returns:
Tensor: A new zero-filled tensor with the same shape.
| iron.tensor.Tensor.bo |
| iron.tensor.Tensor.data |
| iron.tensor.Tensor.device |
| iron.tensor.Tensor.dtype |
| iron.tensor.Tensor.len_bytes |
| iron.tensor.Tensor.shape |
| iron.tensor.Tensor.xrt_device |