Skip to content

Snitch

snitch

This dialect provides operations to target features of the Snitch[1] streaming architecture based on custom extensions to the RISC-V ISA. This dialect works on 'riscv' types directly as all arguments are of 'riscv.reg<>' type and it is meant to be as close as possible to the asm that aims at generating.

[1] https://pulp-platform.github.io/snitch/publications

Snitch = Dialect('snitch', [SsrSetDimensionBoundOp, SsrSetDimensionStrideOp, SsrSetDimensionSourceOp, SsrSetDimensionDestinationOp, SsrSetStreamRepetitionOp, SsrEnableOp, SsrDisableOp], [ReadableStreamType, WritableStreamType]) module-attribute

ReadableStreamType dataclass

Bases: ParametrizedAttribute, TypeAttribute, ContainerType[_StreamTypeElement], Generic[_StreamTypeElement]

Source code in xdsl/dialects/snitch.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@irdl_attr_definition
class ReadableStreamType(
    ParametrizedAttribute,
    TypeAttribute,
    ContainerType[_StreamTypeElement],
    Generic[_StreamTypeElement],
):
    name = "snitch.readable"

    element_type: _StreamTypeElement

    def get_element_type(self) -> _StreamTypeElement:
        return self.element_type

    @staticmethod
    def constr(
        element_type: AttrConstraint[_StreamTypeElement] = AnyAttr(),
    ) -> ParamAttrConstraint[ReadableStreamType[_StreamTypeElement]]:
        return ParamAttrConstraint[ReadableStreamType[_StreamTypeElement]](
            ReadableStreamType, (element_type,)
        )

name = 'snitch.readable' class-attribute instance-attribute

element_type: _StreamTypeElement instance-attribute

get_element_type() -> _StreamTypeElement

Source code in xdsl/dialects/snitch.py
59
60
def get_element_type(self) -> _StreamTypeElement:
    return self.element_type

constr(element_type: AttrConstraint[_StreamTypeElement] = AnyAttr()) -> ParamAttrConstraint[ReadableStreamType[_StreamTypeElement]] staticmethod

Source code in xdsl/dialects/snitch.py
62
63
64
65
66
67
68
@staticmethod
def constr(
    element_type: AttrConstraint[_StreamTypeElement] = AnyAttr(),
) -> ParamAttrConstraint[ReadableStreamType[_StreamTypeElement]]:
    return ParamAttrConstraint[ReadableStreamType[_StreamTypeElement]](
        ReadableStreamType, (element_type,)
    )

WritableStreamType dataclass

Bases: ParametrizedAttribute, TypeAttribute, ContainerType[_StreamTypeElement], Generic[_StreamTypeElement]

Source code in xdsl/dialects/snitch.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@irdl_attr_definition
class WritableStreamType(
    ParametrizedAttribute,
    TypeAttribute,
    ContainerType[_StreamTypeElement],
    Generic[_StreamTypeElement],
):
    name = "snitch.writable"

    element_type: _StreamTypeElement

    def get_element_type(self) -> _StreamTypeElement:
        return self.element_type

    @staticmethod
    def constr(
        element_type: AttrConstraint[_StreamTypeElement] = AnyAttr(),
    ) -> ParamAttrConstraint[WritableStreamType[_StreamTypeElement]]:
        return ParamAttrConstraint[WritableStreamType[_StreamTypeElement]](
            WritableStreamType, (element_type,)
        )

name = 'snitch.writable' class-attribute instance-attribute

element_type: _StreamTypeElement instance-attribute

get_element_type() -> _StreamTypeElement

Source code in xdsl/dialects/snitch.py
82
83
def get_element_type(self) -> _StreamTypeElement:
    return self.element_type

constr(element_type: AttrConstraint[_StreamTypeElement] = AnyAttr()) -> ParamAttrConstraint[WritableStreamType[_StreamTypeElement]] staticmethod

Source code in xdsl/dialects/snitch.py
85
86
87
88
89
90
91
@staticmethod
def constr(
    element_type: AttrConstraint[_StreamTypeElement] = AnyAttr(),
) -> ParamAttrConstraint[WritableStreamType[_StreamTypeElement]]:
    return ParamAttrConstraint[WritableStreamType[_StreamTypeElement]](
        WritableStreamType, (element_type,)
    )

SnitchResources dataclass

Bounds for resources provided by the Snitch architecture.

Source code in xdsl/dialects/snitch.py
 94
 95
 96
 97
 98
 99
100
101
@dataclass(frozen=True)
class SnitchResources:
    """
    Bounds for resources provided by the Snitch architecture.
    """

    # Number of dimensions supported by each data mover.
    dimensions: int = 4

dimensions: int = 4 class-attribute instance-attribute

__init__(dimensions: int = 4) -> None

SsrSetDimensionConfigOperation

Bases: IRDLOperation, ABC

A base class for Snitch operations that set a configuration value for a specific dimension handled by a streamer.

Source code in xdsl/dialects/snitch.py
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
131
132
133
class SsrSetDimensionConfigOperation(IRDLOperation, ABC):
    """
    A base class for Snitch operations that set a
    configuration value for a specific dimension handled by a streamer.
    """

    value = operand_def(IntRegisterType)
    dm = attr_def(IntAttr)
    dimension = attr_def(IntAttr)

    def __init__(
        self,
        value: Operation | SSAValue,
        dm: IntAttr,
        dimension: IntAttr,
    ):
        super().__init__(
            operands=[value],
            attributes={
                "dm": dm,
                "dimension": dimension,
            },
        )

    def verify_(self) -> None:
        if self.dimension.data >= SnitchResources.dimensions:
            raise VerifyException(
                f"dimension attribute out of range [0..{SnitchResources.dimensions - 1}], "
                f"Snitch supports up to {SnitchResources.dimensions} dimensions per streamer"
            )

value = operand_def(IntRegisterType) class-attribute instance-attribute

dm = attr_def(IntAttr) class-attribute instance-attribute

dimension = attr_def(IntAttr) class-attribute instance-attribute

__init__(value: Operation | SSAValue, dm: IntAttr, dimension: IntAttr)

Source code in xdsl/dialects/snitch.py
114
115
116
117
118
119
120
121
122
123
124
125
126
def __init__(
    self,
    value: Operation | SSAValue,
    dm: IntAttr,
    dimension: IntAttr,
):
    super().__init__(
        operands=[value],
        attributes={
            "dm": dm,
            "dimension": dimension,
        },
    )

verify_() -> None

Source code in xdsl/dialects/snitch.py
128
129
130
131
132
133
def verify_(self) -> None:
    if self.dimension.data >= SnitchResources.dimensions:
        raise VerifyException(
            f"dimension attribute out of range [0..{SnitchResources.dimensions - 1}], "
            f"Snitch supports up to {SnitchResources.dimensions} dimensions per streamer"
        )

SsrSetStreamConfigOperation

Bases: IRDLOperation, ABC

A base class for Snitch operations that set a configuration value for a streamer.

Source code in xdsl/dialects/snitch.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
class SsrSetStreamConfigOperation(IRDLOperation, ABC):
    """
    A base class for Snitch operations that set a
    configuration value for a streamer.
    """

    value = operand_def(IntRegisterType)
    dm = attr_def(IntAttr)

    def __init__(self, value: Operation | SSAValue, dm: IntAttr):
        super().__init__(
            operands=[value],
            attributes={
                "dm": dm,
            },
        )

value = operand_def(IntRegisterType) class-attribute instance-attribute

dm = attr_def(IntAttr) class-attribute instance-attribute

__init__(value: Operation | SSAValue, dm: IntAttr)

Source code in xdsl/dialects/snitch.py
145
146
147
148
149
150
151
def __init__(self, value: Operation | SSAValue, dm: IntAttr):
    super().__init__(
        operands=[value],
        attributes={
            "dm": dm,
        },
    )

SsrSetDimensionBoundOp dataclass

Bases: SsrSetDimensionConfigOperation

Set the bound for one of the dimensions handled by a specific streamer.

Source code in xdsl/dialects/snitch.py
154
155
156
157
158
159
160
161
@irdl_op_definition
class SsrSetDimensionBoundOp(SsrSetDimensionConfigOperation):
    """
    Set the bound for one of the dimensions handled by a
    specific streamer.
    """

    name = "snitch.ssr_set_dimension_bound"

name = 'snitch.ssr_set_dimension_bound' class-attribute instance-attribute

SsrSetDimensionStrideOp dataclass

Bases: SsrSetDimensionConfigOperation

Set the stride for one of the dimensions handled by a specific streamer.

Source code in xdsl/dialects/snitch.py
164
165
166
167
168
169
170
171
@irdl_op_definition
class SsrSetDimensionStrideOp(SsrSetDimensionConfigOperation):
    """
    Set the stride for one of the dimensions handled by a
    specific streamer.
    """

    name = "snitch.ssr_set_dimension_stride"

name = 'snitch.ssr_set_dimension_stride' class-attribute instance-attribute

SsrSetDimensionSourceOp dataclass

Bases: SsrSetDimensionConfigOperation

Set the data source for one of the dimensions handled by a specific streamer.

Source code in xdsl/dialects/snitch.py
174
175
176
177
178
179
180
181
@irdl_op_definition
class SsrSetDimensionSourceOp(SsrSetDimensionConfigOperation):
    """
    Set the data source for one of the dimensions handled by a
    specific streamer.
    """

    name = "snitch.ssr_set_dimension_source"

name = 'snitch.ssr_set_dimension_source' class-attribute instance-attribute

SsrSetDimensionDestinationOp dataclass

Bases: SsrSetDimensionConfigOperation

Set the data destination for one of the dimensions handled by a specific streamer.

Source code in xdsl/dialects/snitch.py
184
185
186
187
188
189
190
191
@irdl_op_definition
class SsrSetDimensionDestinationOp(SsrSetDimensionConfigOperation):
    """
    Set the data destination for one of the dimensions handled by a
    specific streamer.
    """

    name = "snitch.ssr_set_dimension_destination"

name = 'snitch.ssr_set_dimension_destination' class-attribute instance-attribute

SsrSetStreamRepetitionOp dataclass

Bases: SsrSetStreamConfigOperation

Setup repetition count for a specific data mover.

Source code in xdsl/dialects/snitch.py
194
195
196
197
198
199
200
@irdl_op_definition
class SsrSetStreamRepetitionOp(SsrSetStreamConfigOperation):
    """
    Setup repetition count for a specific data mover.
    """

    name = "snitch.ssr_set_stream_repetition"

name = 'snitch.ssr_set_stream_repetition' class-attribute instance-attribute

SsrEnableOp

Bases: IRDLOperation

Enable stream semantics.

Source code in xdsl/dialects/snitch.py
203
204
205
206
207
208
209
210
211
212
213
214
@irdl_op_definition
class SsrEnableOp(IRDLOperation):
    """
    Enable stream semantics.
    """

    name = "snitch.ssr_enable"

    streams = var_result_def(ReadableStreamType.constr() | WritableStreamType.constr())

    def __init__(self, stream_types: Sequence[Attribute]):
        super().__init__(result_types=[stream_types])

name = 'snitch.ssr_enable' class-attribute instance-attribute

streams = var_result_def(ReadableStreamType.constr() | WritableStreamType.constr()) class-attribute instance-attribute

__init__(stream_types: Sequence[Attribute])

Source code in xdsl/dialects/snitch.py
213
214
def __init__(self, stream_types: Sequence[Attribute]):
    super().__init__(result_types=[stream_types])

SsrDisableOp

Bases: IRDLOperation

Disable stream semantics.

Source code in xdsl/dialects/snitch.py
217
218
219
220
221
222
223
224
225
226
@irdl_op_definition
class SsrDisableOp(IRDLOperation):
    """
    Disable stream semantics.
    """

    name = "snitch.ssr_disable"

    def __init__(self):
        super().__init__()

name = 'snitch.ssr_disable' class-attribute instance-attribute

__init__()

Source code in xdsl/dialects/snitch.py
225
226
def __init__(self):
    super().__init__()