ttir_builder.apis

class ttir_builder.apis.Golden(tensor, seed=None)

Bases: object

Dataclass used to store information about golden tensor which will be used for comparison with TT device output.

Each TTIR op should have a matching torch op, and for same inputs, they should generate same outputs.

  • Parameters:
    • tensor (Tensor)
    • seed (int | None)

contiguous()

seed : int | None = None

tensor : Tensor

class ttir_builder.apis.GoldenCheckLevel(value)

Bases: Enum

An enumeration.

DISABLED = 1

GRAPH_LEVEL = 3

OP_LEVEL = 2

class ttir_builder.apis.TypeInfo(dtype, scale=None, zero_point=None)

Bases: object

Encapsulates type information for quantized tensors.

  • Parameters:
    • dtype (torch.dtype) – Base PyTorch data type (e.g. torch.float32, torch.qint32).
    • scale (Optional[float]) – Scaling factor for quantization. Required for quantized types.
    • zero_point (Optional[int]) – Zero point offset for quantization. Required for quantized types.

dtype : dtype

scale : float | None = None

zero_point : int | None = None

class ttir_builder.apis.TTIRBuilder(ctx, location)

Bases: TTIRBuilderOps

Builder class providing APIs for creating TTIR ops.

  • Parameters:
    • ctx (Context)
    • location (Location)

generate_and_store_random_golden(operand, dtype=torch.float32)

Creates and stores a random golden tensor. :param operand: The operand to generate and store a golden for :type operand: Operand :param dtype: Data type of the golden tensor (default: torch.float32) :type dtype: Union[torch.dtype, TypeInfo], optional

  • Returns: The generated golden tensor
  • Return type: Golden
  • Parameters:
    • operand (Value | OpView | Operation)
    • dtype (dtype | TypeInfo)

generate_input_golden(operand, dtype, index, override=False)

Generates random tensor of dtype`s of `input`s shape, assigns it to a golden, and maps `input to that golden. :param operand: The input operand to generate a golden for :type operand: Operand :param dtype: Data type of the golden tensor :type dtype: Union[torch.dtype, TypeInfo] :param index: Index to use for mapping the golden :type index: int :param override: Whether to override existing golden (default: False) :type override: bool, optional

  • Returns: The generated golden tensor
  • Return type: Golden
  • Parameters:
    • operand (Value | OpView | Operation)
    • dtype (dtype | TypeInfo)
    • index (int)
    • override (bool)

get_context()

Gets MLIR context. :returns: The MLIR context :rtype: Context

  • Return type: Context

get_golden_map()

Gets the golden tensor mapping. :returns: Mapping of golden tensor names to their GoldenTensor objects :rtype: Dict

  • Return type: Dict

get_shape(input)

Gets tensor shape. :param input: The operand whose shape to retrieve :type input: Operand

  • Returns: The shape of the operand
  • Return type: Shape
  • Parameters: input (Value | OpView | Operation)

property golden_check_level : GoldenCheckLevel

returns: Current golden check level :rtype: GoldenCheckLevel

property goldens : Dict

returns: Dictionary mapping operands to their golden tensors :rtype: Dict

metal_tensor_layout(shape, tilize=False, oobVal=OOBVal.Undef, memorySpace=MemorySpace.DeviceL1)

Creates a metal tensor layout with attributes including grid, tiling, memory space, collapse intervals, and out-of-bounds value handling.. :param shape: The shape of the tensor :type shape: Shape :param grid: Grid specification for the layout :type grid: Union[List, Tuple, ttcore.ir.GridAttr] :param tiled: Whether the layout is tiled (default: False) :type tiled: bool, optional :param memorySpace: Memory space for the tensor (default: DeviceL1) :type memorySpace: ttcore.MemorySpace, optional :param collapseIntervals: Intervals to collapse (default: [(0, -1)]) :type collapseIntervals: List[Tuple[int, int]], optional :param oobVal: Out-of-bounds value handling (default: Undef) :type oobVal: ttcore.OOBVal, optional

  • Returns: Tensor type with metal layout attributes
  • Return type: RankedTensorType
  • Parameters: shape (List *[*int ] | Tuple *[*int , ... ])

Prints saved operands and their respective goldens in descriptive form which follows SSA ordering from MLIR graph.

  • Return type: None

ranked_tensor_type(shape, data_type=None, encoding=None)

Convenience wrapper constructing RankedTensorType :param shape: The shape of the tensor type :type shape: Shape :param data_type: The data type of the tensor (default: None) :type data_type: Optional[Type], optional :param encoding: Optional encoding attribute (default: None) :type encoding: Optional[Attribute], optional

  • Returns: The created ranked tensor type
  • Return type: RankedTensorType
  • Parameters:
    • shape (List *[*int ] | Tuple *[*int , ... ])
    • data_type (Type | None)
    • encoding (Attribute | None)

set_graph_input_output(inputs, outputs=None, override=False)

Records the input and output tensors for the graph. Creates golden tensors for inputs and optionally for outputs. Can override existing golden tensors if specified. :param inputs: List of input tensors for the graph :type inputs: List[torch.Tensor] :param outputs: List of output tensors for the graph (default: None) :type outputs: Optional[List[torch.Tensor]], optional :param override: Whether to override existing golden tensors (default: False) :type override: bool, optional

  • Parameters:
    • inputs (List *[*Tensor ])
    • outputs (List *[*Tensor ] | None)
    • override (bool)
  • Return type: None