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.
NonZeroRankedTensorConstr = TensorType.constr(shape=_NonZeroRankShapeConstr)
module-attribute
¶
Constrains a ranked tensor to have a non-zero rank.
Reflects MLIR's AnyNon0RankedTensor.
NonZeroRankedMemRefConstr = MemRefType.constr(shape=_NonZeroRankShapeConstr)
module-attribute
¶
Constrains a memref to have a non-zero rank.
Reflects MLIR's AnyNon0RankedMemRef.
Shard = Dialect('shard', [AllGatherOp, AllReduceOp, AllSliceOp, BroadcastOp, GatherOp, RecvOp, ReduceOp, ReduceScatterOp, SendOp, ScatterOp, ShiftOp, GridOp, NeighborsLinearIndicesOp, ProcessLinearIndexOp, ProcessMultiIndexOp, ShardingOp, ShardShapeOp, ShardOp, UpdateHaloOp], [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
¶
GridSymbolUserOperation
dataclass
¶
Bases: IRDLOperation, ABC
Base class for ops referencing a shard.grid via their grid property.
Source code in xdsl/dialects/shard.py
grid = prop_def(FlatSymbolRefAttrConstr)
class-attribute
instance-attribute
¶
get_grid() -> GridOp
¶
Looks up the shard.grid referenced by grid, raising a
VerifyException if it is not found.
Source code in xdsl/dialects/shard.py
CollectiveCommunicationOperation
dataclass
¶
Bases: GridSymbolUserOperation, ABC
Base class for collective communication ops.
Source code in xdsl/dialects/shard.py
grid_axes = prop_def(ShardAxesAttr, default_value=ShardAxesAttr(i16, BytesAttr(b'')))
class-attribute
instance-attribute
¶
verify_() -> None
¶
collective_process_group_size(grid: GridOp) -> int
¶
Number of devices in each collective group, or DYNAMIC_INDEX if unknown.
Source code in xdsl/dialects/shard.py
AllGatherOp
dataclass
¶
Bases: CollectiveCommunicationOperation
All-gather over a device grid.
Concatenates all tensor slices from a device group defined by grid_axes
along the tensor dimension gather_axis and replicates the result across all
devices in the group.
Source code in xdsl/dialects/shard.py
name = 'shard.all_gather'
class-attribute
instance-attribute
¶
input = operand_def(NonZeroRankedTensorConstr)
class-attribute
instance-attribute
¶
gather_axis = prop_def(IntegerAttr.constr(IndexType))
class-attribute
instance-attribute
¶
result = result_def(NonZeroRankedTensorConstr)
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 ' + 'attr-dict `:` type($input) `->` type($result)'
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/shard.py
AllReduceOp
dataclass
¶
Bases: CollectiveCommunicationOperation
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
¶
AllSliceOp
dataclass
¶
Bases: CollectiveCommunicationOperation
All-slice over a device grid.
Within each device group defined by grid_axes, slices the input tensor
along the slice_axis dimension. It can be viewed as the inverse of an
all-gather if the input data is replicated along the slice_axis. Does not
involve any communication between devices.
Source code in xdsl/dialects/shard.py
name = 'shard.all_slice'
class-attribute
instance-attribute
¶
input = operand_def(NonZeroRankedTensorConstr)
class-attribute
instance-attribute
¶
slice_axis = prop_def(IntegerAttr.constr(IndexType))
class-attribute
instance-attribute
¶
result = result_def(NonZeroRankedTensorConstr)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '$input `on` $grid (`grid_axes` `=` $grid_axes^)? ' + '`slice_axis` `=` $slice_axis ' + 'attr-dict `:` type($input) `->` type($result)'
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/shard.py
BroadcastOp
dataclass
¶
Bases: CollectiveCommunicationOperation
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: CollectiveCommunicationOperation
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(IndexType))
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: CollectiveCommunicationOperation
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(IndexType))
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: CollectiveCommunicationOperation
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: CollectiveCommunicationOperation
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
¶
ReduceScatterOp
dataclass
¶
Bases: CollectiveCommunicationOperation
Reduce-scatter over a device grid.
Within each device group defined by grid_axes reduce the input tensor
element-wise using the reduction method, then scatter the result across
the group along scatter_axis.
Source code in xdsl/dialects/shard.py
name = 'shard.reduce_scatter'
class-attribute
instance-attribute
¶
input = operand_def(NonZeroRankedTensorConstr)
class-attribute
instance-attribute
¶
reduction = prop_def(ReductionKindAttr, default_value=ReductionKindAttr(ReductionKind.SUM))
class-attribute
instance-attribute
¶
scatter_axis = prop_def(IntegerAttr.constr(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^)? ' + '`scatter_axis` `=` $scatter_axis ' + 'attr-dict `:` type($input) `->` type($result)'
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/shard.py
SendOp
dataclass
¶
Bases: CollectiveCommunicationOperation
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: CollectiveCommunicationOperation
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(IndexType))
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
¶
ProcessMultiIndexOp
¶
Bases: GridSymbolUserOperation
Get the multi index of current device along specified grid axes.
If axes is empty, the index along all grid axes is returned.
When constructing, pass either the sequence of axes (one result per axis),
or the rank of the grid as an int.
Source code in xdsl/dialects/shard.py
name = 'shard.process_multi_index'
class-attribute
instance-attribute
¶
axes = prop_def(ShardAxesAttr, default_value=ShardAxesAttr(i16, BytesAttr(b'')))
class-attribute
instance-attribute
¶
result = var_result_def(IndexType)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '`on` $grid (`axes` `=` $axes^)? attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
__init__(grid: str | StringAttr | SymbolRefAttr, axes: Sequence[int] | int)
¶
Source code in xdsl/dialects/shard.py
verify_() -> None
¶
Source code in xdsl/dialects/shard.py
ProcessLinearIndexOp
¶
Bases: GridSymbolUserOperation
Get the linear index of the current device.
Source code in xdsl/dialects/shard.py
name = 'shard.process_linear_index'
class-attribute
instance-attribute
¶
result = result_def(IndexType)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '`on` $grid attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
NeighborsLinearIndicesOp
¶
Bases: GridSymbolUserOperation
For a given grid index, get the linear indices of the direct neighbor processes along the given split. A negative value is returned if there is no neighbor in the respective direction.
Source code in xdsl/dialects/shard.py
name = 'shard.neighbors_linear_indices'
class-attribute
instance-attribute
¶
device = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
split_axes = prop_def(ShardAxesAttr)
class-attribute
instance-attribute
¶
neighbor_down = result_def(IndexType)
class-attribute
instance-attribute
¶
neighbor_up = result_def(IndexType)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '`on` $grid `[` $device `]` `split_axes` `=` $split_axes ' + 'attr-dict `:` type(results)'
class-attribute
instance-attribute
¶
__init__(grid: str | StringAttr | SymbolRefAttr, device: Sequence[SSAValue | Operation], split_axes: Sequence[int])
¶
Source code in xdsl/dialects/shard.py
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(FlatSymbolRefAttrConstr)
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
ShardShapeOp
¶
Bases: IRDLOperation
Get the shard shape for a given process/device.
The device/process id is a multi-index of the device/process in the shard.
This operation might be used during partition when the shard shape depends
on (non-constant) values used in shard.sharding.
Source code in xdsl/dialects/shard.py
name = 'shard.shard_shape'
class-attribute
instance-attribute
¶
dims = prop_def(DenseArrayBase[I64])
class-attribute
instance-attribute
¶
dims_dynamic = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
sharding = operand_def(ShardingType)
class-attribute
instance-attribute
¶
device = prop_def(DenseArrayBase[I64])
class-attribute
instance-attribute
¶
device_dynamic = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
result = var_result_def(IndexType)
class-attribute
instance-attribute
¶
irdl_options = (AttrSizedOperandSegments(as_property=True),)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '`dims` `=` custom<DynamicIndexList>($dims_dynamic, $dims) ' + '`sharding` `=` $sharding ' + '`device` `=` custom<DynamicIndexList>($device_dynamic, $device) ' + 'attr-dict `:` type(results)'
class-attribute
instance-attribute
¶
custom_directives = (DynamicIndexList,)
class-attribute
instance-attribute
¶
__init__(dims: Sequence[SSAValue | int], sharding: SSAValue | Operation, device: Sequence[SSAValue | int])
¶
Source code in xdsl/dialects/shard.py
ShardOp
¶
Bases: IRDLOperation
Annotate on how a tensor is sharded across a shard.
Source code in xdsl/dialects/shard.py
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
UpdateHaloOp
¶
Bases: GridSymbolUserOperation
Update halo data.
This operation updates halo regions of shards, e.g. if their sharding specified halos and the actual tensor/memref data might have changed on the remote devices.
Destination is supposed to be initialized with the local data (not halos).
split_axes specifies for each tensor axis along which grid axes its halo
data is updated.
Source code in xdsl/dialects/shard.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |