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
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
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
ReductionKind
¶
Bases: StrEnum
Reduction kind for grid dialect
Source code in xdsl/dialects/shard.py
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
ShardingType
dataclass
¶
Bases: ParametrizedAttribute, TypeAttribute
Source code in xdsl/dialects/shard.py
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
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.
Source code in xdsl/dialects/shard.py
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.
Source code in xdsl/dialects/shard.py
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.
Source code in xdsl/dialects/shard.py
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.
Source code in xdsl/dialects/shard.py
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
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.
Source code in xdsl/dialects/shard.py
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
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
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
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
¶
ShardingOp
dataclass
¶
Bases: IRDLOperation
Define the sharding of a tensor.
Note: halo_sizes and sharded_dims_offsets are mutually exclusive.
Source code in xdsl/dialects/shard.py
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
ShardOp
¶
Bases: IRDLOperation
Annotate on how a tensor is sharded across a shard.