diff options
| author | Lei Zhang <antiagainst@google.com> | 2019-12-27 16:24:33 -0500 |
|---|---|---|
| committer | Lei Zhang <antiagainst@google.com> | 2019-12-27 16:25:09 -0500 |
| commit | b30d87a90ba983d76f8a6cd334ac38244bbf9ded (patch) | |
| tree | 1de94d9458e552ff6c90dadb621f66521659ca1d /mlir/test/Dialect | |
| parent | c3dbd782f1e0578c7ebc342f2e92f54d9644cff7 (diff) | |
| download | bcm5719-llvm-b30d87a90ba983d76f8a6cd334ac38244bbf9ded.tar.gz bcm5719-llvm-b30d87a90ba983d76f8a6cd334ac38244bbf9ded.zip | |
[mlir][spirv] Add basic definitions for supporting availability
SPIR-V has a few mechanisms to control op availability: version,
extension, and capabilities. These mechanisms are considered as
different availability classes.
This commit introduces basic definitions for modelling SPIR-V
availability classes. Specifically, an `Availability` class is
added to SPIRVBase.td, along with two subclasses: MinVersion
and MaxVersion for versioning. SPV_Op is extended to take a
list of `Availability`. Each `Availability` instance carries
information for generating op interfaces for the corresponding
availability class and also the concrete availability
requirements.
With the availability spec on ops, we can now auto-generate the
op interfaces of all SPIR-V availability classes and also
synthesize the op's implementations of these interfaces. The
interface generation is done via new TableGen backends
-gen-avail-interface-{decls|defs}. The op's implementation is
done via -gen-spirv-avail-impls.
Differential Revision: https://reviews.llvm.org/D71930
Diffstat (limited to 'mlir/test/Dialect')
| -rw-r--r-- | mlir/test/Dialect/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | mlir/test/Dialect/SPIRV/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | mlir/test/Dialect/SPIRV/TestAvailability.cpp | 73 | ||||
| -rw-r--r-- | mlir/test/Dialect/SPIRV/availability.mlir | 31 |
4 files changed, 119 insertions, 0 deletions
diff --git a/mlir/test/Dialect/CMakeLists.txt b/mlir/test/Dialect/CMakeLists.txt new file mode 100644 index 00000000000..cc1766c6127 --- /dev/null +++ b/mlir/test/Dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(SPIRV) diff --git a/mlir/test/Dialect/SPIRV/CMakeLists.txt b/mlir/test/Dialect/SPIRV/CMakeLists.txt new file mode 100644 index 00000000000..25ea9625ae8 --- /dev/null +++ b/mlir/test/Dialect/SPIRV/CMakeLists.txt @@ -0,0 +1,14 @@ +add_llvm_library(MLIRSPIRVTestPasses + TestAvailability.cpp + + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SPIRV + ${MLIR_MAIN_INCLUDE_DIR}/mlir/IR + ) + +target_link_libraries(MLIRSPIRVTestPasses + MLIRIR + MLIRPass + MLIRSPIRV + MLIRSupport + ) diff --git a/mlir/test/Dialect/SPIRV/TestAvailability.cpp b/mlir/test/Dialect/SPIRV/TestAvailability.cpp new file mode 100644 index 00000000000..bb164215995 --- /dev/null +++ b/mlir/test/Dialect/SPIRV/TestAvailability.cpp @@ -0,0 +1,73 @@ +//===- TestAvailability.cpp - Pass to test SPIR-V op availability ---------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/SPIRV/SPIRVOps.h" +#include "mlir/Dialect/SPIRV/SPIRVTypes.h" +#include "mlir/IR/Function.h" +#include "mlir/Pass/Pass.h" + +using namespace mlir; + +namespace { +/// A pass for testing SPIR-V op availability. +struct TestAvailability : public FunctionPass<TestAvailability> { + void runOnFunction() override; +}; +} // end anonymous namespace + +void TestAvailability::runOnFunction() { + auto f = getFunction(); + llvm::outs() << f.getName() << "\n"; + + Dialect *spvDialect = getContext().getRegisteredDialect("spv"); + + f.getOperation()->walk([&](Operation *op) { + if (op->getDialect() != spvDialect) + return WalkResult::advance(); + + auto &os = llvm::outs(); + + if (auto minVersion = dyn_cast<spirv::QueryMinVersionInterface>(op)) + os << " min version: " + << spirv::stringifyVersion(minVersion.getMinVersion()) << "\n"; + + if (auto maxVersion = dyn_cast<spirv::QueryMaxVersionInterface>(op)) + os << " max version: " + << spirv::stringifyVersion(maxVersion.getMaxVersion()) << "\n"; + + if (auto extension = dyn_cast<spirv::QueryExtensionInterface>(op)) { + os << " extensions: ["; + for (const auto &exts : extension.getExtensions()) { + os << " ["; + interleaveComma(exts, os, [&](spirv::Extension ext) { + os << spirv::stringifyExtension(ext); + }); + os << "]"; + } + os << " ]\n"; + } + + if (auto capability = dyn_cast<spirv::QueryCapabilityInterface>(op)) { + os << " capabilities: ["; + for (const auto &caps : capability.getCapabilities()) { + os << " ["; + interleaveComma(caps, os, [&](spirv::Capability cap) { + os << spirv::stringifyCapability(cap); + }); + os << "]"; + } + os << " ]\n"; + } + os.flush(); + + return WalkResult::advance(); + }); +} + +static PassRegistration<TestAvailability> pass("test-spirv-op-availability", + "Test SPIR-V op availability"); diff --git a/mlir/test/Dialect/SPIRV/availability.mlir b/mlir/test/Dialect/SPIRV/availability.mlir new file mode 100644 index 00000000000..ed4d29cc51d --- /dev/null +++ b/mlir/test/Dialect/SPIRV/availability.mlir @@ -0,0 +1,31 @@ +// RUN: mlir-opt -disable-pass-threading -test-spirv-op-availability %s | FileCheck %s + +// CHECK-LABEL: iadd +func @iadd(%arg: i32) -> i32 { + // CHECK: min version: V_1_0 + // CHECK: max version: V_1_5 + // CHECK: extensions: [ ] + // CHECK: capabilities: [ ] + %0 = spv.IAdd %arg, %arg: i32 + return %0: i32 +} + +// CHECK: atomic_compare_exchange_weak +func @atomic_compare_exchange_weak(%ptr: !spv.ptr<i32, Workgroup>, %value: i32, %comparator: i32) -> i32 { + // CHECK: min version: V_1_0 + // CHECK: max version: V_1_3 + // CHECK: extensions: [ ] + // CHECK: capabilities: [ [Kernel] ] + %0 = spv.AtomicCompareExchangeWeak "Workgroup" "Release" "Acquire" %ptr, %value, %comparator: !spv.ptr<i32, Workgroup> + return %0: i32 +} + +// CHECK-LABEL: subgroup_ballot +func @subgroup_ballot(%predicate: i1) -> vector<4xi32> { + // CHECK: min version: V_1_3 + // CHECK: max version: V_1_5 + // CHECK: extensions: [ ] + // CHECK: capabilities: [ [GroupNonUniformBallot] ] + %0 = spv.GroupNonUniformBallot "Workgroup" %predicate : vector<4xi32> + return %0: vector<4xi32> +} |

