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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@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
119
120
121
122
123
124
125
126
127
128
129
130
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
133
134
135
136
137
138
139
140
141
142
143
144
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
147
148
149
150
151
@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
154
155
156
@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
164
165
166
167
168
169
170
171
172
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
@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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
@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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
@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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
@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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
@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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
@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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
@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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
@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
430
431
432
433
434
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
@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
484
485
486
487
488
489
490
491
492
493
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
@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
520
521
522
523
524
525
526
527
528
529
530
531
532
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,
        },
    )