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
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
@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
@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
@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
@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
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
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:
            pos = parser.pos
            entry = parser.parse_attribute()
            parser.parse_punctuation("=")
            value = parser.parse_attribute()
            try:
                return DataLayoutEntryAttr.new((entry, value))
            except ValueError as e:
                parser.raise_error(str(e), pos)

        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
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
@classmethod
def parse_parameters(
    cls, parser: AttrParser
) -> tuple[ArrayAttr[DataLayoutEntryAttr]]:
    def parse_entry() -> DataLayoutEntryAttr:
        pos = parser.pos
        entry = parser.parse_attribute()
        parser.parse_punctuation("=")
        value = parser.parse_attribute()
        try:
            return DataLayoutEntryAttr.new((entry, value))
        except ValueError as e:
            parser.raise_error(str(e), pos)

    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
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
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
@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
@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
@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
@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