|
| 1 | +//===- DLTIAttrs.td - DLTI dialect attributes definition --*- tablegen -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef MLIR_DIALECT_DLTI_DLTIATTRS_TD |
| 10 | +#define MLIR_DIALECT_DLTI_DLTIATTRS_TD |
| 11 | + |
| 12 | +include "mlir/Dialect/DLTI/DLTI.td" |
| 13 | +include "mlir/IR/AttrTypeBase.td" |
| 14 | + |
| 15 | +class DLTIAttr<string name, list<Trait> traits = [], |
| 16 | + string baseCppClass = "::mlir::Attribute"> |
| 17 | + : AttrDef<DLTI_Dialect, name, traits, baseCppClass> { } |
| 18 | + |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +// DataLayoutEntryAttr |
| 21 | +//===----------------------------------------------------------------------===// |
| 22 | + |
| 23 | +def DataLayoutEntryTrait |
| 24 | + : NativeAttrTrait<"DataLayoutEntryInterface::Trait"> { |
| 25 | + let cppNamespace = "::mlir"; |
| 26 | +} |
| 27 | + |
| 28 | +def DLTI_DataLayoutEntryAttr : |
| 29 | + DLTIAttr<"DataLayoutEntry", [DataLayoutEntryTrait]> { |
| 30 | + let summary = [{ |
| 31 | + An attribute to represent an entry of a data layout specification. |
| 32 | + }]; |
| 33 | + let description = [{ |
| 34 | + A data layout entry attribute is a key-value pair where the key is a type or |
| 35 | + an identifier and the value is another attribute. These entries form a data |
| 36 | + layout specification. |
| 37 | + }]; |
| 38 | + let parameters = (ins |
| 39 | + "DataLayoutEntryKey":$key, "Attribute":$value |
| 40 | + ); |
| 41 | + // TODO: We do not generate storage class because llvm::PointerUnion |
| 42 | + // does not work with hash_key method. |
| 43 | + let genStorageClass = 0; |
| 44 | + let mnemonic = "dl_entry"; |
| 45 | + let genVerifyDecl = 0; |
| 46 | + let hasCustomAssemblyFormat = 1; |
| 47 | + let extraClassDeclaration = [{ |
| 48 | + /// Returns the entry with the given key and value. |
| 49 | + static DataLayoutEntryAttr get(StringAttr key, Attribute value); |
| 50 | + static DataLayoutEntryAttr get(MLIRContext *context, Type key, Attribute value); |
| 51 | + static DataLayoutEntryAttr get(Type key, Attribute value); |
| 52 | + }]; |
| 53 | +} |
| 54 | + |
| 55 | +//===----------------------------------------------------------------------===// |
| 56 | +// DataLayoutSpecAttr |
| 57 | +//===----------------------------------------------------------------------===// |
| 58 | +def DataLayoutSpecTrait |
| 59 | + : NativeAttrTrait<"DataLayoutSpecInterface::Trait"> { |
| 60 | + let cppNamespace = "::mlir"; |
| 61 | +} |
| 62 | + |
| 63 | +def DLTI_DataLayoutSpecAttr : |
| 64 | + DLTIAttr<"DataLayoutSpec", [DataLayoutSpecTrait]> { |
| 65 | + let summary = [{ |
| 66 | + An attribute to represent a data layout specification. |
| 67 | + }]; |
| 68 | + let description = [{ |
| 69 | + A data layout specification is a list of entries that specify (partial) data |
| 70 | + layout information. It is expected to be attached to operations that serve |
| 71 | + as scopes for data layout requests. |
| 72 | + }]; |
| 73 | + let parameters = (ins |
| 74 | + ArrayRefParameter<"DataLayoutEntryInterface", "">:$entries |
| 75 | + ); |
| 76 | + let mnemonic = "dl_spec"; |
| 77 | + let genVerifyDecl = 1; |
| 78 | + let hasCustomAssemblyFormat = 1; |
| 79 | + let extraClassDeclaration = [{ |
| 80 | + /// Combines this specification with `specs`, enclosing specifications listed |
| 81 | + /// from outermost to innermost. This overwrites the older entries with the |
| 82 | + /// same key as the newer entries if the entries are compatible. Returns null |
| 83 | + /// if the specifications are not compatible. |
| 84 | + DataLayoutSpecAttr combineWith(ArrayRef<DataLayoutSpecInterface> specs) const; |
| 85 | + |
| 86 | + /// Returns the endiannes identifier. |
| 87 | + StringAttr getEndiannessIdentifier(MLIRContext *context) const; |
| 88 | + |
| 89 | + /// Returns the alloca memory space identifier. |
| 90 | + StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const; |
| 91 | + |
| 92 | + /// Returns the program memory space identifier. |
| 93 | + StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const; |
| 94 | + |
| 95 | + /// Returns the global memory space identifier. |
| 96 | + StringAttr getGlobalMemorySpaceIdentifier(MLIRContext *context) const; |
| 97 | + |
| 98 | + /// Returns the stack alignment identifier. |
| 99 | + StringAttr getStackAlignmentIdentifier(MLIRContext *context) const; |
| 100 | + }]; |
| 101 | +} |
| 102 | + |
| 103 | +//===----------------------------------------------------------------------===// |
| 104 | +// TargetSystemSpecAttr |
| 105 | +//===----------------------------------------------------------------------===// |
| 106 | + |
| 107 | +def TargetSystemSpecTrait |
| 108 | + : NativeAttrTrait<"TargetSystemSpecInterface::Trait"> { |
| 109 | + let cppNamespace = "::mlir"; |
| 110 | +} |
| 111 | + |
| 112 | +def DLTI_TargetSystemSpecAttr : |
| 113 | + DLTIAttr<"TargetSystemSpec", [TargetSystemSpecTrait]> { |
| 114 | + let summary = [{ |
| 115 | + An attribute to represent target system specification. |
| 116 | + }]; |
| 117 | + let description = [{ |
| 118 | + A system specification describes the overall system containing |
| 119 | + multiple devices, with each device having a unique ID (string) |
| 120 | + and its corresponding TargetDeviceSpec object. |
| 121 | + |
| 122 | + Example: |
| 123 | + dlti.target_system_spec = |
| 124 | + #dlti.target_system_spec< |
| 125 | + "CPU": #dlti.target_device_spec< |
| 126 | + #dlti.dl_entry<"dlti.L1_cache_size_in_bytes", 4096: ui32>>, |
| 127 | + "GPU": #dlti.target_device_spec< |
| 128 | + #dlti.dl_entry<"dlti.max_vector_op_width", 64 : ui32>>, |
| 129 | + "XPU": #dlti.target_device_spec< |
| 130 | + #dlti.dl_entry<"dlti.max_vector_op_width", 4096 : ui32>>> |
| 131 | + }]; |
| 132 | + let parameters = (ins |
| 133 | + ArrayRefParameter<"DeviceIDTargetDeviceSpecPair", "">:$entries |
| 134 | + ); |
| 135 | + let mnemonic = "target_system_spec"; |
| 136 | + let genVerifyDecl = 1; |
| 137 | + let assemblyFormat = "`<` $entries `>`"; |
| 138 | + let extraClassDeclaration = [{ |
| 139 | + /// Return the device specification that matches the given device ID |
| 140 | + std::optional<TargetDeviceSpecInterface> |
| 141 | + getDeviceSpecForDeviceID( |
| 142 | + TargetSystemSpecInterface::DeviceID deviceID); |
| 143 | + }]; |
| 144 | + let extraClassDefinition = [{ |
| 145 | + std::optional<TargetDeviceSpecInterface> |
| 146 | + $cppClass::getDeviceSpecForDeviceID( |
| 147 | + TargetSystemSpecInterface::DeviceID deviceID) { |
| 148 | + for (const auto& entry : getEntries()) { |
| 149 | + if (entry.first == deviceID) |
| 150 | + return entry.second; |
| 151 | + } |
| 152 | + return std::nullopt; |
| 153 | + } |
| 154 | + }]; |
| 155 | +} |
| 156 | + |
| 157 | +//===----------------------------------------------------------------------===// |
| 158 | +// TargetDeviceSpecAttr |
| 159 | +//===----------------------------------------------------------------------===// |
| 160 | + |
| 161 | +def TargetDeviceSpecTrait |
| 162 | + : NativeAttrTrait<"TargetDeviceSpecInterface::Trait"> { |
| 163 | + let cppNamespace = "::mlir"; |
| 164 | +} |
| 165 | + |
| 166 | +def DLTI_TargetDeviceSpecAttr : |
| 167 | + DLTIAttr<"TargetDeviceSpec", [TargetDeviceSpecTrait]> { |
| 168 | + let summary = [{ |
| 169 | + An attribute to represent target device specification. |
| 170 | + }]; |
| 171 | + let description = [{ |
| 172 | + Each device specification describes a single device and its |
| 173 | + hardware properties. Each device specification can contain any number |
| 174 | + of optional hardware properties (e.g., max_vector_op_width below). |
| 175 | + |
| 176 | + Example: |
| 177 | + #dlti.target_device_spec< |
| 178 | + #dlti.dl_entry<"dlti.max_vector_op_width", 64 : ui32>> |
| 179 | + }]; |
| 180 | + let parameters = (ins |
| 181 | + ArrayRefParameter<"DataLayoutEntryInterface", "">:$entries |
| 182 | + ); |
| 183 | + let mnemonic = "target_device_spec"; |
| 184 | + let genVerifyDecl = 1; |
| 185 | + let assemblyFormat = "`<` $entries `>`"; |
| 186 | +} |
| 187 | + |
| 188 | +#endif // MLIR_DIALECT_DLTI_DLTIATTRS_TD |
0 commit comments