-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[mlir][spirv] Add support for SPV_ARM_graph extension - part 1 #151934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davidegrohmann
wants to merge
5
commits into
llvm:main
Choose a base branch
from
davidegrohmann:mlir-spv-arm-graphs-part-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3eb19f
[mlir][spirv] Add support for SPV_ARM_graph extension - part 1
davidegrohmann 101e674
Resolve code review comments
davidegrohmann 3cf2ee9
Fix one more comment
davidegrohmann 5ae57fe
Resolve more review comments and expand testing
davidegrohmann 1a4f0aa
Extract SPV_ARM_graph operations in its own file
davidegrohmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
//===- SPIRVGraphOps.td - Graph extended insts spec file -----*- tablegen -*-=// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is the op definition spec of Graph extension ops. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_SPIRV_IR_GRAPH_OPS | ||
#define MLIR_DIALECT_SPIRV_IR_GRAPH_OPS | ||
|
||
include "mlir/Dialect/SPIRV/IR/SPIRVBase.td" | ||
include "mlir/Interfaces/CallInterfaces.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
include "mlir/Interfaces/FunctionInterfaces.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// SPIR-V Graph opcode specification. | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Base class for all Graph ops. | ||
class SPIRV_GraphARMOp<string mnemonic, list<Trait> traits = []> : | ||
SPIRV_ArmVendorOp<mnemonic, traits> { | ||
|
||
let availability = [ | ||
MinVersion<SPIRV_V_1_0>, | ||
MaxVersion<SPIRV_V_1_6>, | ||
Extension<[SPV_ARM_graph, SPV_ARM_tensors]>, | ||
Capability<[SPIRV_C_GraphARM]> | ||
]; | ||
} | ||
|
||
def SPIRV_GraphARMOp : SPIRV_GraphARMOp<"Graph", [ | ||
AutomaticAllocationScope, DeclareOpInterfaceMethods<CallableOpInterface>, | ||
FunctionOpInterface, InModuleScope, IsolatedFromAbove | ||
]> { | ||
|
||
let summary = "Declare or define a SPIR-V graph"; | ||
|
||
let description = [{ | ||
This op declares or defines a SPIR-V graph using one region, which | ||
contains one or more blocks. | ||
|
||
Different from the SPIR-V binary format, this op is not allowed to | ||
implicitly capture global values, and all external references must use | ||
function arguments or symbol references. This op itself defines a symbol | ||
that is unique in the enclosing module op. | ||
|
||
This op itself takes no operands and generates no results. Its region | ||
can take zero or more arguments and return zero or more values. | ||
|
||
``` | ||
spv-graph-arm-op ::= `spirv.ARM.Graph` function-signature | ||
region | ||
``` | ||
|
||
#### Example: | ||
|
||
```mlir | ||
spirv.ARM.Graph @graph(%arg0 : !spirv.arm.tensor<14x19xi16>) -> !spirv.arm.tensor<14x19xi16> { | ||
spirv.ARM.GraphOutputs %arg0 : !spirv.arm.tensor<14x19xi16> | ||
} | ||
``` | ||
}]; | ||
|
||
let arguments = (ins | ||
TypeAttrOf<GraphType>:$function_type, | ||
OptionalAttr<DictArrayAttr>:$arg_attrs, | ||
OptionalAttr<DictArrayAttr>:$res_attrs, | ||
OptionalAttr<BoolAttr>:$entry_point, | ||
StrAttr:$sym_name | ||
); | ||
|
||
let results = (outs); | ||
|
||
let regions = (region AnyRegion:$body); | ||
|
||
let hasVerifier = 0; | ||
|
||
let builders = [ | ||
OpBuilder<(ins "StringRef":$name, "GraphType":$type, | ||
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs, CArg<"bool", "false">:$entry_point)>]; | ||
|
||
let hasOpcode = 0; | ||
|
||
let autogenSerialization = 0; | ||
|
||
let extraClassDeclaration = [{ | ||
/// Hook for FunctionOpInterface, called after verifying that the 'type' | ||
/// attribute is present and checks if it holds a function type. Ensures | ||
/// getType, getNumArguments, and getNumResults can be called safely | ||
LogicalResult verifyType(); | ||
|
||
/// Hook for FunctionOpInterface, called after verifying the function | ||
/// type and the presence of the (potentially empty) function body. | ||
/// Ensures SPIR-V specific semantics. | ||
LogicalResult verifyBody(); | ||
}]; | ||
} | ||
|
||
// ----- | ||
|
||
// Check that an op can only be used within the scope of a spirv.ARM.Graph op. | ||
def InGraphScope : PredOpTrait< | ||
"op must appear in a spirv.ARM.Graph op's block", | ||
CPred<"isNestedInGraphARMOpInterface($_op.getParentOp())">>; | ||
|
||
// ----- | ||
|
||
def SPIRV_GraphConstantARMOp : SPIRV_GraphARMOp<"GraphConstant", [InGraphScope, Pure, ConstantLike]> { | ||
let summary = "Declare a graph constant."; | ||
|
||
let description = [{ | ||
Declare a graph constant. | ||
Result Type must be an OpTypeTensorARM. | ||
GraphConstantID must be a 32-bit integer literal. | ||
|
||
``` | ||
spv-graph-constant-arm-op ::= `spirv.ARM.GraphConstant` { graph_constant_id = 42 : i32 } | ||
``` | ||
|
||
#### Example: | ||
|
||
```mlir | ||
%0 = spirv.ARM.GraphConstant { graph_constant_id = 42 : i32 } : !spirv.arm.tensor<2x3xi16> | ||
``` | ||
}]; | ||
|
||
let arguments = (ins | ||
I32Attr: $graph_constant_id | ||
); | ||
|
||
let results = (outs | ||
SPIRV_AnyTensorArm:$output | ||
); | ||
|
||
let hasVerifier = 0; | ||
|
||
let autogenSerialization = 0; | ||
|
||
let assemblyFormat = [{ | ||
attr-dict `:` type($output) | ||
}]; | ||
} | ||
|
||
// ----- | ||
|
||
def SPIRV_GraphEntryPointARMOp : SPIRV_GraphARMOp<"GraphEntryPoint", [InModuleScope]> { | ||
let summary = [{ | ||
Declare a graph entry point and its interface. | ||
}]; | ||
|
||
let description = [{ | ||
Graph Entry Point must be the Result <id> of an OpGraphARM instruction. | ||
|
||
Name is a name string for the graphentry point. A module cannot have two | ||
OpGraphEntryPointARM instructions with the same Name string. | ||
|
||
Interface is a list of symbol references to `spirv.GlobalVariable` | ||
operations. These declare the set of global variables from a | ||
module that form the interface of this entry point. The set of | ||
Interface symbols must be equal to or a superset of the | ||
`spirv.GlobalVariable`s referenced by the entry point’s static call | ||
tree, within the interface’s storage classes. | ||
|
||
``` | ||
entry-point-op ::= ssa-id `=` `spirv.ARM.GraphEntryPoint` | ||
symbol-reference (`, ` symbol-reference)* | ||
``` | ||
|
||
#### Example: | ||
|
||
```mlir | ||
spirv.GlobalVariable @arg_0 bind(0, 0) : !spirv.ptr<!spirv.arm.tensor<14x19xi16>, UniformConstant> | ||
spirv.GlobalVariable @res_0 bind(0, 1) : !spirv.ptr<!spirv.arm.tensor<14x19xi16>, UniformConstant> | ||
spirv.ARM.GraphEntryPoint @graph, @arg_0, @res_0 | ||
spirv.ARM.Graph @graph(%arg0 : !spirv.arm.tensor<14x19xi16>) -> !spirv.arm.tensor<14x19xi16> { | ||
... | ||
} | ||
``` | ||
}]; | ||
|
||
let arguments = (ins | ||
FlatSymbolRefAttr:$fn, | ||
SymbolRefArrayAttr:$interface | ||
); | ||
|
||
let results = (outs); | ||
|
||
// Checks for graph and interface symbol reference are done in spirv::ModuleOp verification. | ||
let hasVerifier = 0; | ||
|
||
let autogenSerialization = 0; | ||
|
||
let builders = [ | ||
OpBuilder<(ins "spirv::GraphARMOp":$graph, "ArrayRef<Attribute>":$interfaceVars)>]; | ||
} | ||
|
||
// ----- | ||
|
||
def SPIRV_GraphOutputsARMOp : SPIRV_GraphARMOp<"GraphOutputs", [InGraphScope, Pure, | ||
Terminator]> { | ||
|
||
let summary = "Define graph outputs."; | ||
|
||
let description = [{ | ||
Values are the graph outputs values and must match the GraphOutputs Type | ||
operand of the OpTypeGraphARM type of the OpGraphARM body this | ||
instruction is in. | ||
|
||
This instruction must be the last instruction in a block. | ||
|
||
``` | ||
graph-output-op ::= `spirv.ARM.GraphOutputs` ssa-use `:` type-list-no-parens | ||
``` | ||
|
||
#### Example: | ||
|
||
```mlir | ||
spirv.ARM.Graph @graph(%arg0 : !spirv.arm.tensor<14x19xi16>) -> !spirv.arm.tensor<14x19xi16> { | ||
spirv.ARM.GraphOutputs %arg0 : !spirv.arm.tensor<14x19xi16> | ||
} | ||
``` | ||
}]; | ||
|
||
let arguments = (ins | ||
Variadic<SPIRV_AnyTensorArm>:$value | ||
); | ||
|
||
let results = (outs); | ||
|
||
let autogenSerialization = 0; | ||
|
||
let hasOpcode = 0; | ||
|
||
let assemblyFormat = "$value attr-dict `:` type($value)"; | ||
} | ||
|
||
#endif // MLIR_DIALECT_SPIRV_IR_GRAPH_OPS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.