Skip to content

Dlti

dlti

The Data Layout and Target Information (DLTI) dialect is intended to hold attributes and other components pertaining to descriptions of in-memory data layout and compilation targets.

https://mlir.llvm.org/docs/Dialects/DLTIDialect/

DictValueType: TypeAlias = Mapping[StringAttr | TypeAttribute | str, 'Attribute | str | int | DictValueType'] module-attribute

DLTI = Dialect('dlti', [], [DataLayoutEntryAttr, DataLayoutSpecAttr, MapAttr, TargetDeviceSpecAttr, TargetSystemSpecAttr]) module-attribute

DLTITypeConverters

Type converter for DLTIEntryMap and DataLayoutEntryAttr parameters

Source code in xdsl/dialects/dlti.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class DLTITypeConverters:
    """
    Type converter for DLTIEntryMap and DataLayoutEntryAttr parameters
    """

    @staticmethod
    def convert_entry_map_type(
        contents: ArrayAttr[DataLayoutEntryAttr] | DictValueType,
    ) -> ArrayAttr[DataLayoutEntryAttr]:
        if isinstance(contents, Mapping):
            return ArrayAttr([DataLayoutEntryAttr(k, v) for k, v in contents.items()])
        else:
            return contents

    @staticmethod
    def convert_entry_attr_key_type(
        key: StringAttr | TypeAttribute | str,
    ) -> Attribute:
        if isinstance(key, str):
            return StringAttr(key)
        else:
            return key

    @staticmethod
    def convert_entry_attr_value_type(
        value: Attribute | str | int | DictValueType,
    ) -> Attribute:
        if isinstance(value, str):
            return StringAttr(value)
        elif isinstance(value, int):
            return IntAttr(value)
        elif isinstance(value, Mapping):
            return MapAttr(value)
        else:
            return value

convert_entry_map_type(contents: ArrayAttr[DataLayoutEntryAttr] | DictValueType) -> ArrayAttr[DataLayoutEntryAttr] staticmethod

Source code in xdsl/dialects/dlti.py
36
37
38
39
40
41
42
43
@staticmethod
def convert_entry_map_type(
    contents: ArrayAttr[DataLayoutEntryAttr] | DictValueType,
) -> ArrayAttr[DataLayoutEntryAttr]:
    if isinstance(contents, Mapping):
        return ArrayAttr([DataLayoutEntryAttr(k, v) for k, v in contents.items()])
    else:
        return contents

convert_entry_attr_key_type(key: StringAttr | TypeAttribute | str) -> Attribute staticmethod

Source code in xdsl/dialects/dlti.py
45
46
47
48
49
50
51
52
@staticmethod
def convert_entry_attr_key_type(
    key: StringAttr | TypeAttribute | str,
) -> Attribute:
    if isinstance(key, str):
        return StringAttr(key)
    else:
        return key

convert_entry_attr_value_type(value: Attribute | str | int | DictValueType) -> Attribute staticmethod

Source code in xdsl/dialects/dlti.py
54
55
56
57
58
59
60
61
62
63
64
65
@staticmethod
def convert_entry_attr_value_type(
    value: Attribute | str | int | DictValueType,
) -> Attribute:
    if isinstance(value, str):
        return StringAttr(value)
    elif isinstance(value, int):
        return IntAttr(value)
    elif isinstance(value, Mapping):
        return MapAttr(value)
    else:
        return value

DataLayoutEntryAttr dataclass

Bases: ParametrizedAttribute

An attribute to represent an entry of a data layout specification. https://mlir.llvm.org/docs/Dialects/DLTIDialect/#datalayoutentryattr

Source code in xdsl/dialects/dlti.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@irdl_attr_definition
class DataLayoutEntryAttr(ParametrizedAttribute):
    """
    An attribute to represent an entry of a data layout specification.
    https://mlir.llvm.org/docs/Dialects/DLTIDialect/#datalayoutentryattr
    """

    name = "dlti.dl_entry"

    key: Attribute = param_def(converter=DLTITypeConverters.convert_entry_attr_key_type)
    value: Attribute = param_def(
        converter=DLTITypeConverters.convert_entry_attr_value_type
    )

    def verify(self) -> None:
        if not isinstance(self.key, StringAttr | TypeAttribute):
            raise VerifyException("key must be a string or a type attribute")
        if isinstance(self.key, StringAttr) and not self.key.data:
            raise VerifyException("empty string as DLTI key is not allowed")

name = 'dlti.dl_entry' class-attribute instance-attribute

key: Attribute = param_def(converter=(DLTITypeConverters.convert_entry_attr_key_type)) class-attribute instance-attribute

value: Attribute = param_def(converter=(DLTITypeConverters.convert_entry_attr_value_type)) class-attribute instance-attribute

verify() -> None

Source code in xdsl/dialects/dlti.py
82
83
84
85
86
def verify(self) -> None:
    if not isinstance(self.key, StringAttr | TypeAttribute):
        raise VerifyException("key must be a string or a type attribute")
    if isinstance(self.key, StringAttr) and not self.key.data:
        raise VerifyException("empty string as DLTI key is not allowed")

DLTIEntryMap dataclass

Bases: ParametrizedAttribute, ABC

Many DLTI dialect operations contain arrays of DataLayoutEntryInterface, with these representing different things such as data layout or information about the target hardware. This is the base class that these operations extend.

Source code in xdsl/dialects/dlti.py
 89
 90
 91
 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
131
132
133
134
135
class DLTIEntryMap(ParametrizedAttribute, ABC):
    """
    Many DLTI dialect operations contain arrays of DataLayoutEntryInterface,
    with these representing different things such as data layout or information
    about the target hardware. This is the base class that these operations extend.
    """

    # In MLIR, this is a DataLayoutEntryInterface.
    entries: ArrayAttr[DataLayoutEntryAttr] = param_def(
        converter=DLTITypeConverters.convert_entry_map_type
    )

    def __getitem__(self, key: StringAttr | TypeAttribute | str) -> Attribute:
        if isinstance(key, str):
            key = StringAttr(key)
        for entry in self.entries:
            if entry.key == key:
                return entry.value

        raise KeyError

    @classmethod
    def parse_parameters(
        cls, parser: AttrParser
    ) -> tuple[ArrayAttr[DataLayoutEntryAttr]]:
        def parse_entry() -> DataLayoutEntryAttr:
            entry = parser.parse_attribute()
            parser.parse_punctuation("=")
            value = parser.parse_attribute()
            return DataLayoutEntryAttr.new((entry, value))

        entries = parser.parse_comma_separated_list(parser.Delimiter.ANGLE, parse_entry)

        return (ArrayAttr(entries),)

    def print_parameters(self, printer: Printer):
        def print_entry(entry: DataLayoutEntryAttr):
            printer.print_attribute(entry.key)
            printer.print_string(" = ")
            printer.print_attribute(entry.value)

        with printer.in_angle_brackets():
            printer.print_list(self.entries, print_entry)

    def verify(self) -> None:
        if len({entry.key for entry in self.entries}) != len(self.entries):
            raise VerifyException("duplicate DLTI entry key")

entries: ArrayAttr[DataLayoutEntryAttr] = param_def(converter=(DLTITypeConverters.convert_entry_map_type)) class-attribute instance-attribute

__getitem__(key: StringAttr | TypeAttribute | str) -> Attribute

Source code in xdsl/dialects/dlti.py
101
102
103
104
105
106
107
108
def __getitem__(self, key: StringAttr | TypeAttribute | str) -> Attribute:
    if isinstance(key, str):
        key = StringAttr(key)
    for entry in self.entries:
        if entry.key == key:
            return entry.value

    raise KeyError

parse_parameters(parser: AttrParser) -> tuple[ArrayAttr[DataLayoutEntryAttr]] classmethod

Source code in xdsl/dialects/dlti.py
110
111
112
113
114
115
116
117
118
119
120
121
122
@classmethod
def parse_parameters(
    cls, parser: AttrParser
) -> tuple[ArrayAttr[DataLayoutEntryAttr]]:
    def parse_entry() -> DataLayoutEntryAttr:
        entry = parser.parse_attribute()
        parser.parse_punctuation("=")
        value = parser.parse_attribute()
        return DataLayoutEntryAttr.new((entry, value))

    entries = parser.parse_comma_separated_list(parser.Delimiter.ANGLE, parse_entry)

    return (ArrayAttr(entries),)

print_parameters(printer: Printer)

Source code in xdsl/dialects/dlti.py
124
125
126
127
128
129
130
131
def print_parameters(self, printer: Printer):
    def print_entry(entry: DataLayoutEntryAttr):
        printer.print_attribute(entry.key)
        printer.print_string(" = ")
        printer.print_attribute(entry.value)

    with printer.in_angle_brackets():
        printer.print_list(self.entries, print_entry)

verify() -> None

Source code in xdsl/dialects/dlti.py
133
134
135
def verify(self) -> None:
    if len({entry.key for entry in self.entries}) != len(self.entries):
        raise VerifyException("duplicate DLTI entry key")

DataLayoutSpecAttr dataclass

Bases: DLTIEntryMap

An attribute to represent a data layout specification.

A data layout specification is a list of entries that specify (partial) data layout information. It is expected to be attached to operations that serve as scopes for data layout requests.

https://mlir.llvm.org/docs/Dialects/DLTIDialect/#datalayoutspecattr

Source code in xdsl/dialects/dlti.py
138
139
140
141
142
143
144
145
146
147
148
149
150
@irdl_attr_definition(init=False)
class DataLayoutSpecAttr(DLTIEntryMap):
    """
    An attribute to represent a data layout specification.

    A data layout specification is a list of entries that specify (partial) data
    layout information. It is expected to be attached to operations that serve as
    scopes for data layout requests.

    https://mlir.llvm.org/docs/Dialects/DLTIDialect/#datalayoutspecattr
    """

    name = "dlti.dl_spec"

name = 'dlti.dl_spec' class-attribute instance-attribute

TargetDeviceSpecAttr dataclass

Bases: DLTIEntryMap

An attribute to represent target device specification.

Each device specification describes a single device and its hardware properties. Each device specification can contain any number of optional hardware properties (e.g., max_vector_op_width below).

https://mlir.llvm.org/docs/Dialects/DLTIDialect/#targetdevicespecattr

Source code in xdsl/dialects/dlti.py
153
154
155
156
157
158
159
160
161
162
163
164
165
@irdl_attr_definition(init=False)
class TargetDeviceSpecAttr(DLTIEntryMap):
    """
    An attribute to represent target device specification.

    Each device specification describes a single device and its hardware properties.
    Each device specification can contain any number of optional hardware properties
    (e.g., max_vector_op_width below).

    https://mlir.llvm.org/docs/Dialects/DLTIDialect/#targetdevicespecattr
    """

    name = "dlti.target_device_spec"

name = 'dlti.target_device_spec' class-attribute instance-attribute

TargetSystemSpecAttr dataclass

Bases: DLTIEntryMap

An attribute to represent target system specification.

A system specification describes the overall system containing multiple devices, with each device having a unique ID (string) and its corresponding TargetDeviceSpec object.

https://mlir.llvm.org/docs/Dialects/DLTIDialect/#targetsystemspecattr

Source code in xdsl/dialects/dlti.py
168
169
170
171
172
173
174
175
176
177
178
179
180
@irdl_attr_definition(init=False)
class TargetSystemSpecAttr(DLTIEntryMap):
    """
    An attribute to represent target system specification.

    A system specification describes the overall system containing multiple devices,
    with each device having a unique ID (string) and its corresponding
    TargetDeviceSpec object.

    https://mlir.llvm.org/docs/Dialects/DLTIDialect/#targetsystemspecattr
    """

    name = "dlti.target_system_spec"

name = 'dlti.target_system_spec' class-attribute instance-attribute

MapAttr dataclass

Bases: DLTIEntryMap

A mapping of DLTI-information by way of key-value pairs

A Data Layout and Target Information map is a list of entries effectively encoding a dictionary, mapping DLTI-related keys to DLTI-related values.

https://mlir.llvm.org/docs/Dialects/DLTIDialect/#mapattr

Source code in xdsl/dialects/dlti.py
183
184
185
186
187
188
189
190
191
192
193
194
@irdl_attr_definition(init=False)
class MapAttr(DLTIEntryMap):
    """
    A mapping of DLTI-information by way of key-value pairs

    A Data Layout and Target Information map is a list of entries effectively
    encoding a dictionary, mapping DLTI-related keys to DLTI-related values.

    https://mlir.llvm.org/docs/Dialects/DLTIDialect/#mapattr
    """

    name = "dlti.map"

name = 'dlti.map' class-attribute instance-attribute