Skip to content

Shard

shard

ShardAxis: TypeAlias = I16 module-attribute

The type used to represent numbers on a grid axis.

See the MLIR definition.

ShardAxesAttr: TypeAlias = DenseArrayBase[ShardAxis] module-attribute

The type used to represent a list of grid axes.

See the MLIR definition.

Shard = Dialect('shard', [AllReduceOp, BroadcastOp, GatherOp, RecvOp, ReduceOp, SendOp, ScatterOp, ShiftOp, GridOp, ShardingOp, ShardOp], [ReductionKindAttr, ShardingType, ShardAxesArrayAttr]) module-attribute

ShardAxesArrayAttr dataclass

Bases: ParametrizedAttribute, OpaqueSyntaxAttribute

ShardAxesArrayAttr attribute for representing multiple grid axes.

Reflects the MLIR attribute.

Source code in xdsl/dialects/shard.py
@irdl_attr_definition
class ShardAxesArrayAttr(ParametrizedAttribute, OpaqueSyntaxAttribute):
    """
    ShardAxesArrayAttr attribute for representing multiple grid axes.

    Reflects [the MLIR attribute](https://github.com/llvm/llvm-project/blob/fef02d48c08db859ef83f84232ed78bd9d1c323a/mlir/include/mlir/Dialect/Shard/IR/ShardBase.td#L83).
    """

    name = "shard.axisarray"

    axes: ArrayAttr[ShardAxesAttr]

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
        """
        Parses a ShardAxesArrayAttr, which has the syntax of a list
        of lists, e.g.:

        [[1, 2, 3], [], [4, 5]]
        """
        axes = parser.parse_comma_separated_list(
            parser.Delimiter.SQUARE,
            lambda: _parse_grid_axes_attr(parser),
        )

        return (ArrayAttr(axes),)

    def print_parameters(self, printer: Printer) -> None:
        """
        Prints a ShardAxesArrayAttr, which has the syntax of a list
        of lists, e.g.:

        [[1, 2, 3], [], [4, 5]]
        """
        with printer.in_square_brackets():
            printer.print_list(
                self.axes.data,
                lambda x: _print_sublist(printer, x),
            )

name = 'shard.axisarray' class-attribute instance-attribute

axes: ArrayAttr[ShardAxesAttr] instance-attribute

parse_parameters(parser: AttrParser) -> Sequence[Attribute] classmethod

Parses a ShardAxesArrayAttr, which has the syntax of a list of lists, e.g.:

[[1, 2, 3], [], [4, 5]]

Source code in xdsl/dialects/shard.py
@classmethod
def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
    """
    Parses a ShardAxesArrayAttr, which has the syntax of a list
    of lists, e.g.:

    [[1, 2, 3], [], [4, 5]]
    """
    axes = parser.parse_comma_separated_list(
        parser.Delimiter.SQUARE,
        lambda: _parse_grid_axes_attr(parser),
    )

    return (ArrayAttr(axes),)

print_parameters(printer: Printer) -> None

Prints a ShardAxesArrayAttr, which has the syntax of a list of lists, e.g.:

[[1, 2, 3], [], [4, 5]]

Source code in xdsl/dialects/shard.py
def print_parameters(self, printer: Printer) -> None:
    """
    Prints a ShardAxesArrayAttr, which has the syntax of a list
    of lists, e.g.:

    [[1, 2, 3], [], [4, 5]]
    """
    with printer.in_square_brackets():
        printer.print_list(
            self.axes.data,
            lambda x: _print_sublist(printer, x),
        )

ReductionKind

Bases: StrEnum

Reduction kind for grid dialect

Source code in xdsl/dialects/shard.py
class ReductionKind(StrEnum):
    "Reduction kind for grid dialect"

    SUM = auto()
    MAX = auto()
    MIN = auto()
    PRODUCT = auto()
    AVERAGE = auto()
    BITWISE_AND = auto()
    BITWISE_OR = auto()
    BITWISE_XOR = auto()
    GENERIC = auto()

SUM = auto() class-attribute instance-attribute

MAX = auto() class-attribute instance-attribute

MIN = auto() class-attribute instance-attribute

PRODUCT = auto() class-attribute instance-attribute

AVERAGE = auto() class-attribute instance-attribute

BITWISE_AND = auto() class-attribute instance-attribute

BITWISE_OR = auto() class-attribute instance-attribute

BITWISE_XOR = auto() class-attribute instance-attribute

GENERIC = auto() class-attribute instance-attribute

ReductionKindAttr dataclass

Bases: EnumAttribute[ReductionKind], SpacedOpaqueSyntaxAttribute

Source code in xdsl/dialects/shard.py
@irdl_attr_definition
class ReductionKindAttr(EnumAttribute[ReductionKind], SpacedOpaqueSyntaxAttribute):
    name = "shard.partial"

    assembly_format = "$value"

name = 'shard.partial' class-attribute instance-attribute

assembly_format = '$value' class-attribute instance-attribute

ShardingType dataclass

Bases: ParametrizedAttribute, TypeAttribute

Source code in xdsl/dialects/shard.py
@irdl_attr_definition
class ShardingType(ParametrizedAttribute, TypeAttribute):
    name = "shard.sharding"

name = 'shard.sharding' class-attribute instance-attribute

CollectiveCommunicationOp dataclass

Bases: IRDLOperation, ABC

Base class for collective communication ops.

Source code in xdsl/dialects/shard.py
class CollectiveCommunicationOp(IRDLOperation, ABC):
    """
    Base class for collective communication ops.
    """

    grid = prop_def(FlatSymbolRefAttr)
    grid_axes = prop_def(
        ShardAxesAttr, default_value=ShardAxesAttr(i16, BytesAttr(b""))
    )

grid = prop_def(FlatSymbolRefAttr) class-attribute instance-attribute

grid_axes = prop_def(ShardAxesAttr, default_value=ShardAxesAttr(i16, BytesAttr(b''))) class-attribute instance-attribute

AllReduceOp dataclass

Bases: CollectiveCommunicationOp

All-reduce over a device grid.

Within each device group reduce the input using the reduction method. Each device in a group receives a replicated copy of the reduction result. The accumulation element type is determined by the result type.

See external documentation.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class AllReduceOp(CollectiveCommunicationOp):
    """
    All-reduce over a device grid.

    Within each device group reduce the input using the `reduction` method.
    Each device in a group receives a replicated copy of the reduction result.
    The accumulation element type is determined by the result type.

    See [external documentation](https://mlir.llvm.org/docs/Dialects/Shard/#shardall_reduce-shardallreduceop).
    """

    name = "shard.all_reduce"

    input = operand_def(MemRefType.constr() | TensorType.constr())
    reduction = prop_def(
        ReductionKindAttr, default_value=ReductionKindAttr(ReductionKind.SUM)
    )

    result = result_def(MemRefType.constr() | TensorType.constr())

    traits = traits_def(Pure())

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "(`reduction` `=` $reduction^)? "
        + "attr-dict `:` type($input) `->` type($result)"
    )

name = 'shard.all_reduce' class-attribute instance-attribute

input = operand_def(MemRefType.constr() | TensorType.constr()) class-attribute instance-attribute

reduction = prop_def(ReductionKindAttr, default_value=ReductionKindAttr(ReductionKind.SUM)) class-attribute instance-attribute

result = result_def(MemRefType.constr() | TensorType.constr()) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '(`reduction` `=` $reduction^)? ' + 'attr-dict `:` type($input) `->` type($result)' class-attribute instance-attribute

BroadcastOp dataclass

Bases: CollectiveCommunicationOp

Broadcast tensor from one device to many devices.

See external documentation.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class BroadcastOp(CollectiveCommunicationOp):
    """
    Broadcast tensor from one device to many devices.

    See [external documentation](https://mlir.llvm.org/docs/Dialects/Shard/#shardbroadcast-shardbroadcastop).
    """

    name = "shard.broadcast"

    input = operand_def(TensorType)
    root = prop_def(DenseArrayBase[I64])
    root_dynamic = var_operand_def(IndexType)

    result = result_def(TensorType)

    traits = traits_def(Pure())

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "`root` `=` custom<DynamicIndexList>($root_dynamic, $root) "
        + "attr-dict `:` functional-type(operands, results)"
    )

    custom_directives = (DynamicIndexList,)

name = 'shard.broadcast' class-attribute instance-attribute

input = operand_def(TensorType) class-attribute instance-attribute

root = prop_def(DenseArrayBase[I64]) class-attribute instance-attribute

root_dynamic = var_operand_def(IndexType) class-attribute instance-attribute

result = result_def(TensorType) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '`root` `=` custom<DynamicIndexList>($root_dynamic, $root) ' + 'attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

custom_directives = (DynamicIndexList,) class-attribute instance-attribute

GatherOp dataclass

Bases: CollectiveCommunicationOp

Gather tensor shards from many devices to a single device.

See external documentation.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class GatherOp(CollectiveCommunicationOp):
    """
    Gather tensor shards from many devices to a single device.

    See [external documentation](https://mlir.llvm.org/docs/Dialects/Shard/#shardgather-shardgatherop).
    """

    name = "shard.gather"

    input = operand_def(TensorType)
    gather_axis = prop_def(IntegerAttr.constr(IndexTypeConstr))
    root = prop_def(DenseArrayBase[I64])
    root_dynamic = var_operand_def(IndexType)

    result = result_def(TensorType)

    traits = traits_def(Pure())

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "`gather_axis` `=` $gather_axis "
        + "`root` `=` custom<DynamicIndexList>($root_dynamic, $root) "
        + "attr-dict `:` functional-type(operands, results)"
    )

    custom_directives = (DynamicIndexList,)

name = 'shard.gather' class-attribute instance-attribute

input = operand_def(TensorType) class-attribute instance-attribute

gather_axis = prop_def(IntegerAttr.constr(IndexTypeConstr)) class-attribute instance-attribute

root = prop_def(DenseArrayBase[I64]) class-attribute instance-attribute

root_dynamic = var_operand_def(IndexType) class-attribute instance-attribute

result = result_def(TensorType) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '`gather_axis` `=` $gather_axis ' + '`root` `=` custom<DynamicIndexList>($root_dynamic, $root) ' + 'attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

custom_directives = (DynamicIndexList,) class-attribute instance-attribute

ScatterOp dataclass

Bases: CollectiveCommunicationOp

Scatter tensor over a device shard.

For each device group split the input tensor on the root device along axis scatter_axis and scatter the parts across the group devices.

See external documentation.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class ScatterOp(CollectiveCommunicationOp):
    """
    Scatter tensor over a device shard.

    For each device group split the input tensor on the `root` device along
    axis `scatter_axis` and scatter the parts across the group devices.

    See [external documentation](https://mlir.llvm.org/docs/Dialects/Shard/#shardscatter-shardscatterop).
    """

    name = "shard.scatter"

    input = operand_def(TensorType)
    scatter_axis = prop_def(IntegerAttr.constr(IndexTypeConstr))

    root = prop_def(DenseArrayBase[I64])
    root_dynamic = var_operand_def(IndexType)

    result = result_def(TensorType)

    traits = traits_def(
        Pure(),
    )

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "`scatter_axis` `=` $scatter_axis "
        + "`root` `=` custom<DynamicIndexList>($root_dynamic, $root) "
        + "attr-dict `:` functional-type(operands, results)"
    )

    custom_directives = (DynamicIndexList,)

name = 'shard.scatter' class-attribute instance-attribute

input = operand_def(TensorType) class-attribute instance-attribute

scatter_axis = prop_def(IntegerAttr.constr(IndexTypeConstr)) class-attribute instance-attribute

root = prop_def(DenseArrayBase[I64]) class-attribute instance-attribute

root_dynamic = var_operand_def(IndexType) class-attribute instance-attribute

result = result_def(TensorType) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '`scatter_axis` `=` $scatter_axis ' + '`root` `=` custom<DynamicIndexList>($root_dynamic, $root) ' + 'attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

custom_directives = (DynamicIndexList,) class-attribute instance-attribute

RecvOp dataclass

Bases: CollectiveCommunicationOp

Receive from a device within a device group.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class RecvOp(CollectiveCommunicationOp):
    """
    Receive from a device within a device group.
    """

    name = "shard.recv"

    input = operand_def(TensorType)
    source = opt_prop_def(DenseArrayBase[I64])
    source_dynamic = var_operand_def(IndexType)

    result = result_def(TensorType)

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "(`source` `=` custom<DynamicIndexList>($source_dynamic, $source)^)? "
        + "attr-dict `:` functional-type(operands, results)"
    )

    custom_directives = (DynamicIndexList,)

name = 'shard.recv' class-attribute instance-attribute

input = operand_def(TensorType) class-attribute instance-attribute

source = opt_prop_def(DenseArrayBase[I64]) class-attribute instance-attribute

source_dynamic = var_operand_def(IndexType) class-attribute instance-attribute

result = result_def(TensorType) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '(`source` `=` custom<DynamicIndexList>($source_dynamic, $source)^)? ' + 'attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

custom_directives = (DynamicIndexList,) class-attribute instance-attribute

ReduceOp dataclass

Bases: CollectiveCommunicationOp

Reduce over a device grid.

Within each device group reduce the input tensor using the reduction method. The result is returned on the root device of each group and is undefined on all other devices.

See external documentation.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class ReduceOp(CollectiveCommunicationOp):
    """
    Reduce over a device grid.

    Within each device group reduce the input tensor using the `reduction`
    method. The result is returned on the `root` device of each group and is
    undefined on all other devices.

    See [external documentation](https://mlir.llvm.org/docs/Dialects/Shard/#shardreduce-shardreduceop).
    """

    name = "shard.reduce"

    input = operand_def(TensorType)
    reduction = prop_def(
        ReductionKindAttr, default_value=ReductionKindAttr(ReductionKind.SUM)
    )
    root = prop_def(DenseArrayBase[I64])
    root_dynamic = var_operand_def(IndexType)

    result = result_def(TensorType)

    traits = traits_def(Pure())

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "(`reduction` `=` $reduction^)? "
        + "`root` `=` custom<DynamicIndexList>($root_dynamic, $root) "
        + "attr-dict `:` functional-type(operands, results)"
    )

    custom_directives = (DynamicIndexList,)

name = 'shard.reduce' class-attribute instance-attribute

input = operand_def(TensorType) class-attribute instance-attribute

reduction = prop_def(ReductionKindAttr, default_value=ReductionKindAttr(ReductionKind.SUM)) class-attribute instance-attribute

root = prop_def(DenseArrayBase[I64]) class-attribute instance-attribute

root_dynamic = var_operand_def(IndexType) class-attribute instance-attribute

result = result_def(TensorType) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '(`reduction` `=` $reduction^)? ' + '`root` `=` custom<DynamicIndexList>($root_dynamic, $root) ' + 'attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

custom_directives = (DynamicIndexList,) class-attribute instance-attribute

SendOp dataclass

Bases: CollectiveCommunicationOp

Send from one device to another within a device group.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class SendOp(CollectiveCommunicationOp):
    """
    Send from one device to another within a device group.
    """

    name = "shard.send"

    input = operand_def(TensorType)

    destination = prop_def(DenseArrayBase[I64])
    destination_dynamic = var_operand_def(IndexType)

    result = result_def(TensorType)

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "`destination` `=` custom<DynamicIndexList>($destination_dynamic, $destination) "
        + "attr-dict `:` functional-type(operands, results)"
    )

    custom_directives = (DynamicIndexList,)

name = 'shard.send' class-attribute instance-attribute

input = operand_def(TensorType) class-attribute instance-attribute

destination = prop_def(DenseArrayBase[I64]) class-attribute instance-attribute

destination_dynamic = var_operand_def(IndexType) class-attribute instance-attribute

result = result_def(TensorType) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '`destination` `=` custom<DynamicIndexList>($destination_dynamic, $destination) ' + 'attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

custom_directives = (DynamicIndexList,) class-attribute instance-attribute

ShiftOp dataclass

Bases: CollectiveCommunicationOp

Shift over a device shard.

Within each device group shift along shift_axis by offset. If the rotate flag is present a rotation is performed instead of a shift.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class ShiftOp(CollectiveCommunicationOp):
    """
    Shift over a device shard.

    Within each device group shift along `shift_axis` by `offset`. If the
    `rotate` flag is present a rotation is performed instead of a shift.
    """

    name = "shard.shift"

    input = operand_def(TensorType)

    shift_axis = prop_def(IntegerAttr.constr(IndexTypeConstr))
    offset = prop_def(IntegerAttr[I64])
    rotate = prop_def(UnitAttr)

    result = result_def(TensorType)

    traits = traits_def(
        Pure(),
    )

    assembly_format = (
        "$input `on` $grid (`grid_axes` `=` $grid_axes^)? "
        + "`shift_axis` `=` $shift_axis "
        + "`offset` `=` $offset "
        + "(`rotate` $rotate^)? "
        + "attr-dict `:` type($input) `->` type($result)"
    )

name = 'shard.shift' class-attribute instance-attribute

input = operand_def(TensorType) class-attribute instance-attribute

shift_axis = prop_def(IntegerAttr.constr(IndexTypeConstr)) class-attribute instance-attribute

offset = prop_def(IntegerAttr[I64]) class-attribute instance-attribute

rotate = prop_def(UnitAttr) class-attribute instance-attribute

result = result_def(TensorType) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '`shift_axis` `=` $shift_axis ' + '`offset` `=` $offset ' + '(`rotate` $rotate^)? ' + 'attr-dict `:` type($input) `->` type($result)' class-attribute instance-attribute

GridOp dataclass

Bases: IRDLOperation

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class GridOp(IRDLOperation):
    name = "shard.grid"

    sym_name = prop_def(SymbolNameConstraint())
    shape = prop_def(DenseArrayBase[I64])

    traits = traits_def(SymbolOpInterface(), Pure())

    assembly_format = (
        "$sym_name `(` `shape` `=` custom<DimensionList>($shape) `)` attr-dict"
    )

    custom_directives = (DimensionList,)

    def verify_(self):
        if not self.shape.get_values():
            raise VerifyException(
                "'shard.grid' op rank of grid is expected to be a positive integer"
            )

name = 'shard.grid' class-attribute instance-attribute

sym_name = prop_def(SymbolNameConstraint()) class-attribute instance-attribute

shape = prop_def(DenseArrayBase[I64]) class-attribute instance-attribute

traits = traits_def(SymbolOpInterface(), Pure()) class-attribute instance-attribute

assembly_format = '$sym_name `(` `shape` `=` custom<DimensionList>($shape) `)` attr-dict' class-attribute instance-attribute

custom_directives = (DimensionList,) class-attribute instance-attribute

verify_()

Source code in xdsl/dialects/shard.py
def verify_(self):
    if not self.shape.get_values():
        raise VerifyException(
            "'shard.grid' op rank of grid is expected to be a positive integer"
        )

ShardingOp dataclass

Bases: IRDLOperation

Define the sharding of a tensor.

Note: halo_sizes and sharded_dims_offsets are mutually exclusive.

See external documentation

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class ShardingOp(IRDLOperation):
    """
    Define the sharding of a tensor.

    Note: `halo_sizes` and `sharded_dims_offsets` are mutually exclusive.

    See [external documentation](https://mlir.llvm.org/docs/Dialects/Shard/#shardsharding-shardshardingop)
    """

    name = "shard.sharding"

    grid = prop_def(FlatSymbolRefAttr)
    split_axes = prop_def(ShardAxesArrayAttr)
    static_sharded_dims_offsets = prop_def(
        DenseArrayBase[I64], default_value=DenseArrayBase[I64](i64, BytesAttr(b""))
    )
    dynamic_sharded_dims_offsets = var_operand_def(I64)
    static_halo_sizes = prop_def(
        DenseArrayBase[I64], default_value=DenseArrayBase[I64](i64, BytesAttr(b""))
    )
    dynamic_halo_sizes = var_operand_def(I64)

    result = result_def(ShardingType)

    irdl_options = (AttrSizedOperandSegments(as_property=True),)

    traits = traits_def(
        Pure(),
    )

    assembly_format = (
        "$grid "
        + "`split_axes` `=` $split_axes "
        + "(`halo_sizes` `=` custom<DynamicIndexList>($dynamic_halo_sizes, $static_halo_sizes)^)? "
        + "(`sharded_dims_offsets` `=` "
        + "custom<DynamicIndexList>($dynamic_sharded_dims_offsets, $static_sharded_dims_offsets)^)? "
        + "attr-dict `:` type($result)"
    )

    custom_directives = (DynamicIndexList,)

    def verify_(self) -> None:
        dims_offsets = (
            self.static_sharded_dims_offsets or self.dynamic_sharded_dims_offsets
        )
        halo_sizes = self.static_halo_sizes or self.dynamic_halo_sizes

        if dims_offsets and halo_sizes:
            raise VerifyException(
                "'shard.sharding' op halo sizes and shard offsets are mutually exclusive"
            )

name = 'shard.sharding' class-attribute instance-attribute

grid = prop_def(FlatSymbolRefAttr) class-attribute instance-attribute

split_axes = prop_def(ShardAxesArrayAttr) class-attribute instance-attribute

static_sharded_dims_offsets = prop_def(DenseArrayBase[I64], default_value=DenseArrayBase[I64](i64, BytesAttr(b''))) class-attribute instance-attribute

dynamic_sharded_dims_offsets = var_operand_def(I64) class-attribute instance-attribute

static_halo_sizes = prop_def(DenseArrayBase[I64], default_value=DenseArrayBase[I64](i64, BytesAttr(b''))) class-attribute instance-attribute

dynamic_halo_sizes = var_operand_def(I64) class-attribute instance-attribute

result = result_def(ShardingType) class-attribute instance-attribute

irdl_options = (AttrSizedOperandSegments(as_property=True),) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$grid ' + '`split_axes` `=` $split_axes ' + '(`halo_sizes` `=` custom<DynamicIndexList>($dynamic_halo_sizes, $static_halo_sizes)^)? ' + '(`sharded_dims_offsets` `=` ' + 'custom<DynamicIndexList>($dynamic_sharded_dims_offsets, $static_sharded_dims_offsets)^)? ' + 'attr-dict `:` type($result)' class-attribute instance-attribute

custom_directives = (DynamicIndexList,) class-attribute instance-attribute

verify_() -> None

Source code in xdsl/dialects/shard.py
def verify_(self) -> None:
    dims_offsets = (
        self.static_sharded_dims_offsets or self.dynamic_sharded_dims_offsets
    )
    halo_sizes = self.static_halo_sizes or self.dynamic_halo_sizes

    if dims_offsets and halo_sizes:
        raise VerifyException(
            "'shard.sharding' op halo sizes and shard offsets are mutually exclusive"
        )

ShardOp

Bases: IRDLOperation

Annotate on how a tensor is sharded across a shard.

See external documentation.

Source code in xdsl/dialects/shard.py
@irdl_op_definition
class ShardOp(IRDLOperation):
    """
    Annotate on how a tensor is sharded across a shard.

    See [external documentation](https://mlir.llvm.org/docs/Dialects/Shard/#shardshard-shardshardop).
    """

    name = "shard.shard"

    T: ClassVar = VarConstraint("T", TensorType.constr())

    src = operand_def(T)
    sharding = operand_def(ShardingType)
    annotate_for_users = opt_prop_def(UnitAttr)

    result = result_def(T)

    traits = traits_def(
        Pure(),
    )

    assembly_format = "$src `to` $sharding (`annotate_for_users` $annotate_for_users^)? attr-dict `:` type($result)"

    def __init__(
        self,
        src: SSAValue,
        sharding: SSAValue,
        annotate_for_users: UnitAttr | None,
    ):
        return super().__init__(
            operands=[src, sharding],
            result_types=[src.type],
            properties={
                "annotate_for_users": annotate_for_users,
            },
        )

name = 'shard.shard' class-attribute instance-attribute

T: ClassVar = VarConstraint('T', TensorType.constr()) class-attribute instance-attribute

src = operand_def(T) class-attribute instance-attribute

sharding = operand_def(ShardingType) class-attribute instance-attribute

annotate_for_users = opt_prop_def(UnitAttr) class-attribute instance-attribute

result = result_def(T) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$src `to` $sharding (`annotate_for_users` $annotate_for_users^)? attr-dict `:` type($result)' class-attribute instance-attribute

__init__(src: SSAValue, sharding: SSAValue, annotate_for_users: UnitAttr | None)

Source code in xdsl/dialects/shard.py
def __init__(
    self,
    src: SSAValue,
    sharding: SSAValue,
    annotate_for_users: UnitAttr | None,
):
    return super().__init__(
        operands=[src, sharding],
        result_types=[src.type],
        properties={
            "annotate_for_users": annotate_for_users,
        },
    )