diff options
| author | Lei Zhang <antiagainst@google.com> | 2020-01-14 18:23:25 -0500 |
|---|---|---|
| committer | Lei Zhang <antiagainst@google.com> | 2020-01-14 19:18:42 -0500 |
| commit | 47c6ab2b97773ee5fb360fc093a5824be64b8c68 (patch) | |
| tree | 7d9562e97714b1ac42d4579b9cbfae4a3ed130ef /mlir/docs/Dialects | |
| parent | 60d39479221d6bc09060f7816bcd7c54eb286603 (diff) | |
| download | bcm5719-llvm-47c6ab2b97773ee5fb360fc093a5824be64b8c68.tar.gz bcm5719-llvm-47c6ab2b97773ee5fb360fc093a5824be64b8c68.zip | |
[mlir][spirv] Properly support SPIR-V conversion target
This commit defines a new SPIR-V dialect attribute for specifying
a SPIR-V target environment. It is a dictionary attribute containing
the SPIR-V version, supported extension list, and allowed capability
list. A SPIRVConversionTarget subclass is created to take in the
target environment and sets proper dynmaically legal ops by querying
the op availability interface of SPIR-V ops to make sure they are
available in the specified target environment. All existing conversions
targeting SPIR-V is changed to use this SPIRVConversionTarget. It
probes whether the input IR has a `spv.target_env` attribute,
otherwise, it uses the default target environment: SPIR-V 1.0 with
Shader capability and no extra extensions.
Differential Revision: https://reviews.llvm.org/D72256
Diffstat (limited to 'mlir/docs/Dialects')
| -rw-r--r-- | mlir/docs/Dialects/SPIR-V.md | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/mlir/docs/Dialects/SPIR-V.md b/mlir/docs/Dialects/SPIR-V.md index ed02b1609f2..502f100cfaf 100644 --- a/mlir/docs/Dialects/SPIR-V.md +++ b/mlir/docs/Dialects/SPIR-V.md @@ -725,6 +725,28 @@ func @foo() -> () { } ``` +## Target environment + +SPIR-V aims to support multiple execution environments as specified by client +APIs. These execution environments affect the availability of certain SPIR-V +features. For example, a [Vulkan 1.1][VulkanSpirv] implementation must support +the 1.0, 1.1, 1.2, and 1.3 versions of SPIR-V and the 1.0 version of the SPIR-V +extended instructions for GLSL. Further Vulkan extensions may enable more SPIR-V +instructions. + +SPIR-V compilation should also take into consideration of the execution +environment, so we generate SPIR-V modules valid for the target environment. +This is conveyed by the `spv.target_env` attribute. It is a triple of + +* `version`: a 32-bit integer indicating the target SPIR-V version. +* `extensions`: a string array attribute containing allowed extensions. +* `capabilities`: a 32-bit integer array attribute containing allowed + capabilities. + +Dialect conversion framework will utilize the information in `spv.target_env` +to properly filter out patterns and ops not available in the target execution +environment. + ## Shader interface (ABI) SPIR-V itself is just expressing computation happening on GPU device. SPIR-V @@ -852,12 +874,18 @@ classes are provided. additional rules are imposed by [Vulkan execution environment][VulkanSpirv]. The lowering described below implements both these requirements.) +### `SPIRVConversionTarget` + +The `mlir::spirv::SPIRVConversionTarget` class derives from the +`mlir::ConversionTarget` class and serves as a utility to define a conversion +target satisfying a given [`spv.target_env`](#target-environment). It registers +proper hooks to check the dynamic legality of SPIR-V ops. Users can further +register other legality constraints into the returned `SPIRVConversionTarget`. -### SPIRVTypeConverter +### `SPIRVTypeConverter` -The `mlir::spirv::SPIRVTypeConverter` derives from -`mlir::TypeConverter` and provides type conversion for standard -types to SPIR-V types: +The `mlir::SPIRVTypeConverter` derives from `mlir::TypeConverter` and provides +type conversion for standard types to SPIR-V types: * [Standard Integer][MlirIntegerType] -> Standard Integer * [Standard Float][MlirFloatType] -> Standard Float @@ -874,11 +902,11 @@ supported in SPIR-V. Currently the `index` type is converted to `i32`. (TODO: Allow for configuring the integer width to use for `index` types in the SPIR-V dialect) -### SPIRVOpLowering +### `SPIRVOpLowering` -`mlir::spirv::SPIRVOpLowering` is a base class that can be used to define the -patterns used for implementing the lowering. For now this only provides derived -classes access to an instance of `mlir::spirv::SPIRVTypeLowering` class. +`mlir::SPIRVOpLowering` is a base class that can be used to define the patterns +used for implementing the lowering. For now this only provides derived classes +access to an instance of `mlir::SPIRVTypeLowering` class. ### Utility functions for lowering |

