ttir_builder.apis

class ttir_builder.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.GoldenCheckLevel(value)

Bases: Enum

An enumeration.

DISABLED = 1

GRAPH_LEVEL = 3

OP_LEVEL = 2

class ttir_builder.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.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.

  • Parameters:
    • operand (Operand) – The operand to generate and store a golden for
    • dtype (Union[torch.dtype, TypeInfo], optional) – Data type of the golden tensor (default: torch.float32)
  • Returns: The generated golden tensor
  • Return type: Golden

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.

  • Parameters:
    • operand (Operand) – The input operand to generate a golden for
    • dtype (Union[torch.dtype, TypeInfo]) – Data type of the golden tensor
    • index (int) – Index to use for mapping the golden
    • override (bool , optional) – Whether to override existing golden (default: False)
  • Returns: The generated golden tensor
  • Return type: Golden

get_context()

Gets MLIR context.

  • Returns: The MLIR context
  • Return type: Context

get_golden_map()

Gets the golden tensor mapping.

  • Returns: Mapping of golden tensor names to their GoldenTensor objects
  • Return type: Dict

get_shape(input)

Gets tensor shape.

  • Parameters: input (Operand) – The operand whose shape to retrieve
  • Returns: The shape of the operand
  • Return type: Shape

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, tiled=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.

  • Parameters:
    • shape (Shape) – The shape of the tensor
    • grid (Union[List, Tuple, ttcore.ir.GridAttr]) – Grid specification for the layout
    • tiled (bool , optional) – Whether the layout is tiled (default: False)
    • memorySpace (ttcore.MemorySpace , optional) – Memory space for the tensor (default: DeviceL1)
    • collapseIntervals (List[Tuple[int, int]], optional) – Intervals to collapse (default: [(0, -1)])
    • oobVal (ttcore.OOBVal , optional) – Out-of-bounds value handling (default: Undef)
  • Returns: Tensor type with metal layout attributes
  • Return type: RankedTensorType

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

  • Parameters:
    • shape (Shape) – The shape of the tensor type
    • data_type (Optional[Type], optional) – The data type of the tensor (default: None)
    • encoding (Optional[Attribute], optional) – Optional encoding attribute (default: None)
  • Returns: The created ranked tensor type
  • Return type: RankedTensorType

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.

  • Parameters:
    • inputs (List[torch.Tensor]) – List of input tensors for the graph
    • outputs (Optional[List[torch.Tensor]], optional) – List of output tensors for the graph (default: None)
    • override (bool , optional) – Whether to override existing golden tensors (default: False)
  • Return type: None