|
| 1 | +//===- SPIRVGraphOps.td - Graph extended insts spec file -----*- 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 | +// This is the op definition spec of Graph extension ops. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef MLIR_DIALECT_SPIRV_IR_GRAPH_OPS |
| 14 | +#define MLIR_DIALECT_SPIRV_IR_GRAPH_OPS |
| 15 | + |
| 16 | +include "mlir/Dialect/SPIRV/IR/SPIRVBase.td" |
| 17 | +include "mlir/Interfaces/CallInterfaces.td" |
| 18 | +include "mlir/Interfaces/SideEffectInterfaces.td" |
| 19 | +include "mlir/Interfaces/FunctionInterfaces.td" |
| 20 | + |
| 21 | +//===----------------------------------------------------------------------===// |
| 22 | +// SPIR-V Graph opcode specification. |
| 23 | +//===----------------------------------------------------------------------===// |
| 24 | + |
| 25 | +// Base class for all Graph ops. |
| 26 | +class SPIRV_GraphARMOp<string mnemonic, list<Trait> traits = []> : |
| 27 | + SPIRV_ArmVendorOp<mnemonic, traits> { |
| 28 | + |
| 29 | + let availability = [ |
| 30 | + MinVersion<SPIRV_V_1_0>, |
| 31 | + MaxVersion<SPIRV_V_1_6>, |
| 32 | + Extension<[SPV_ARM_graph, SPV_ARM_tensors]>, |
| 33 | + Capability<[SPIRV_C_GraphARM]> |
| 34 | + ]; |
| 35 | +} |
| 36 | + |
| 37 | +def SPIRV_GraphARMOp : SPIRV_GraphARMOp<"Graph", [ |
| 38 | + AutomaticAllocationScope, DeclareOpInterfaceMethods<CallableOpInterface>, |
| 39 | + FunctionOpInterface, InModuleScope, IsolatedFromAbove |
| 40 | + ]> { |
| 41 | + |
| 42 | + let summary = "Declare or define a SPIR-V graph"; |
| 43 | + |
| 44 | + let description = [{ |
| 45 | + This op declares or defines a SPIR-V graph using one region, which |
| 46 | + contains one or more blocks. |
| 47 | + |
| 48 | + This op is not allowed to implicitly capture global values, and all external |
| 49 | + references must use function arguments or symbol references. This op itself |
| 50 | + defines a symbol that is unique in the enclosing module op. |
| 51 | + |
| 52 | + Note that this op does not have a 1:1 mapping to the SPIR-V ops representing |
| 53 | + a graph. Indeed during serialization a single GraphARMOp is serialized into |
| 54 | + several different SPIR-V ops: OpGraphARM, OpGraphInputARM and OpGraphEndARM. |
| 55 | + There are as many occurences of OpGraphInputARM ops as many inputs in the |
| 56 | + graph. Deserialization maps that set of operations into a single GraphARMOp. |
| 57 | + |
| 58 | + This op itself takes no operands and generates no results. Its region |
| 59 | + can take zero or more arguments and return one or more values. |
| 60 | + |
| 61 | + ``` |
| 62 | + spv-graph-arm-op ::= `spirv.ARM.Graph` function-signature |
| 63 | + region |
| 64 | + ``` |
| 65 | + |
| 66 | + #### Example: |
| 67 | + |
| 68 | + ```mlir |
| 69 | + spirv.ARM.Graph @graph(%arg0: !spirv.arm.tensor<14x19xi16>) -> !spirv.arm.tensor<14x19xi16> { |
| 70 | + spirv.ARM.GraphOutputs %arg0 : !spirv.arm.tensor<14x19xi16> |
| 71 | + } |
| 72 | + ``` |
| 73 | + }]; |
| 74 | + |
| 75 | + let arguments = (ins |
| 76 | + TypeAttrOf<GraphType>:$function_type, |
| 77 | + OptionalAttr<DictArrayAttr>:$arg_attrs, |
| 78 | + OptionalAttr<DictArrayAttr>:$res_attrs, |
| 79 | + OptionalAttr<BoolAttr>:$entry_point, |
| 80 | + StrAttr:$sym_name |
| 81 | + ); |
| 82 | + |
| 83 | + let results = (outs); |
| 84 | + |
| 85 | + let regions = (region AnyRegion:$body); |
| 86 | + |
| 87 | + let hasVerifier = 0; |
| 88 | + |
| 89 | + let builders = [ |
| 90 | + OpBuilder<(ins "StringRef":$name, "GraphType":$type, |
| 91 | + CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs, CArg<"bool", "false">:$entry_point)>]; |
| 92 | + |
| 93 | + let hasOpcode = 0; |
| 94 | + |
| 95 | + let autogenSerialization = 0; |
| 96 | + |
| 97 | + let extraClassDeclaration = [{ |
| 98 | + /// Hook for FunctionOpInterface, called after verifying that the 'type' |
| 99 | + /// attribute is present and checks if it holds a function type. Ensures |
| 100 | + /// getType, getNumArguments, and getNumResults can be called safely |
| 101 | + LogicalResult verifyType(); |
| 102 | + |
| 103 | + /// Hook for FunctionOpInterface, called after verifying the function |
| 104 | + /// type and the presence of the (potentially empty) function body. |
| 105 | + /// Ensures SPIR-V specific semantics. |
| 106 | + LogicalResult verifyBody(); |
| 107 | + }]; |
| 108 | +} |
| 109 | + |
| 110 | +// ----- |
| 111 | + |
| 112 | +// Check that an op can only be used within the scope of a spirv.ARM.Graph op. |
| 113 | +def InGraphScope : PredOpTrait< |
| 114 | + "op must appear in a spirv.ARM.Graph op's block", |
| 115 | + CPred<"isNestedInGraphARMOpInterface($_op.getParentOp())">>; |
| 116 | + |
| 117 | +// ----- |
| 118 | + |
| 119 | +def SPIRV_GraphConstantARMOp : SPIRV_GraphARMOp<"GraphConstant", [InGraphScope, Pure, ConstantLike]> { |
| 120 | + let summary = "Declare a graph constant."; |
| 121 | + |
| 122 | + let description = [{ |
| 123 | + Declare a graph constant. |
| 124 | + Result Type must be an OpTypeTensorARM. |
| 125 | + GraphConstantID must be a 32-bit integer literal. |
| 126 | + |
| 127 | + #### Example: |
| 128 | + |
| 129 | + ```mlir |
| 130 | + %0 = spirv.ARM.GraphConstant { graph_constant_id = 42 : i32 } : !spirv.arm.tensor<2x3xi16> |
| 131 | + ``` |
| 132 | + |
| 133 | + GraphConstantID is a unique identifier which is use to map the contants |
| 134 | + defined by GraphConstantARM in the SPIRV module with the one provided at |
| 135 | + shader creation time via the VkDataGraphPipelineShaderModuleCreateInfoARM. |
| 136 | + That Vulkan structure provides a list of VkDataGraphPipelineConstantARM |
| 137 | + which contains the bindings from id to data. (For more details see |
| 138 | + https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#graphs) |
| 139 | + }]; |
| 140 | + |
| 141 | + let arguments = (ins |
| 142 | + I32Attr: $graph_constant_id |
| 143 | + ); |
| 144 | + |
| 145 | + let results = (outs |
| 146 | + SPIRV_AnyTensorArm:$output |
| 147 | + ); |
| 148 | + |
| 149 | + let hasVerifier = 0; |
| 150 | + |
| 151 | + let autogenSerialization = 0; |
| 152 | + |
| 153 | + let assemblyFormat = [{ |
| 154 | + attr-dict `:` type($output) |
| 155 | + }]; |
| 156 | +} |
| 157 | + |
| 158 | +// ----- |
| 159 | + |
| 160 | +def SPIRV_GraphEntryPointARMOp : SPIRV_GraphARMOp<"GraphEntryPoint", [InModuleScope]> { |
| 161 | + let summary = [{ |
| 162 | + Declare a graph entry point and its interface. |
| 163 | + }]; |
| 164 | + |
| 165 | + let description = [{ |
| 166 | + Graph Entry Point must be the Result <id> of an OpGraphARM instruction. |
| 167 | + |
| 168 | + Name is a name string for the graphentry point. A module cannot have two |
| 169 | + OpGraphEntryPointARM instructions with the same Name string. |
| 170 | + |
| 171 | + Interface is a list of symbol references to `spirv.GlobalVariable` |
| 172 | + operations. These declare the set of global variables from a |
| 173 | + module that form the interface of this entry point. The set of |
| 174 | + Interface symbols must be equal to or a superset of the |
| 175 | + `spirv.GlobalVariable`s referenced by the entry point’s static call |
| 176 | + tree, within the interface’s storage classes. |
| 177 | + |
| 178 | + #### Example: |
| 179 | + |
| 180 | + ```mlir |
| 181 | + spirv.GlobalVariable @arg_0 bind(0, 0) : !spirv.ptr<!spirv.arm.tensor<14x19xi16>, UniformConstant> |
| 182 | + spirv.GlobalVariable @res_0 bind(0, 1) : !spirv.ptr<!spirv.arm.tensor<14x19xi16>, UniformConstant> |
| 183 | + spirv.ARM.GraphEntryPoint @graph, @arg_0, @res_0 |
| 184 | + spirv.ARM.Graph @graph(%arg0 : !spirv.arm.tensor<14x19xi16>) -> !spirv.arm.tensor<14x19xi16> { |
| 185 | + ... |
| 186 | + } |
| 187 | + ``` |
| 188 | + }]; |
| 189 | + |
| 190 | + let arguments = (ins |
| 191 | + FlatSymbolRefAttr:$fn, |
| 192 | + SymbolRefArrayAttr:$interface |
| 193 | + ); |
| 194 | + |
| 195 | + let results = (outs); |
| 196 | + |
| 197 | + // Checks for graph and interface symbol reference are done in spirv::ModuleOp verification. |
| 198 | + let hasVerifier = 0; |
| 199 | + |
| 200 | + let autogenSerialization = 0; |
| 201 | + |
| 202 | + let builders = [ |
| 203 | + OpBuilder<(ins "spirv::GraphARMOp":$graph, "ArrayRef<Attribute>":$interfaceVars)>]; |
| 204 | +} |
| 205 | + |
| 206 | +// ----- |
| 207 | + |
| 208 | +def SPIRV_GraphOutputsARMOp : SPIRV_GraphARMOp<"GraphOutputs", [InGraphScope, Pure, |
| 209 | + Terminator]> { |
| 210 | + |
| 211 | + let summary = "Define graph outputs."; |
| 212 | + |
| 213 | + let description = [{ |
| 214 | + Values are the graph outputs values and must match the GraphOutputs Type |
| 215 | + operand of the OpTypeGraphARM type of the OpGraphARM body this |
| 216 | + instruction is in. |
| 217 | + |
| 218 | + This instruction must be the last instruction in a block. |
| 219 | + |
| 220 | + #### Example: |
| 221 | + |
| 222 | + ```mlir |
| 223 | + spirv.ARM.Graph @graph(%arg0 : !spirv.arm.tensor<14x19xi16>) -> !spirv.arm.tensor<14x19xi16> { |
| 224 | + spirv.ARM.GraphOutputs %arg0 : !spirv.arm.tensor<14x19xi16> |
| 225 | + } |
| 226 | + ``` |
| 227 | + }]; |
| 228 | + |
| 229 | + let arguments = (ins |
| 230 | + Variadic<SPIRV_AnyTensorArm>:$value |
| 231 | + ); |
| 232 | + |
| 233 | + let results = (outs); |
| 234 | + |
| 235 | + let autogenSerialization = 0; |
| 236 | + |
| 237 | + let hasOpcode = 0; |
| 238 | + |
| 239 | + let assemblyFormat = "$value attr-dict `:` type($value)"; |
| 240 | +} |
| 241 | + |
| 242 | +#endif // MLIR_DIALECT_SPIRV_IR_GRAPH_OPS |
0 commit comments