MLIR 22.0.0git
TensorToSPIRVPass.cpp
Go to the documentation of this file.
1//===- TensorToSPIRVPass.cpp - Tensor to SPIR-V Passes ----------------===//
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 file implements a pass to convert Tensor dialect to SPIR-V dialect.
10//
11//===----------------------------------------------------------------------===//
12
14
20
21namespace mlir {
22#define GEN_PASS_DEF_CONVERTTENSORTOSPIRVPASS
23#include "mlir/Conversion/Passes.h.inc"
24} // namespace mlir
25
26using namespace mlir;
27
28namespace {
29/// A pass converting MLIR Tensor operations into the SPIR-V dialect.
30class ConvertTensorToSPIRVPass
31 : public impl::ConvertTensorToSPIRVPassBase<ConvertTensorToSPIRVPass> {
32 using Base::Base;
33
34 void runOnOperation() override {
35 MLIRContext *context = &getContext();
36 Operation *op = getOperation();
37
38 auto targetAttr = spirv::lookupTargetEnvOrDefault(op);
39 std::unique_ptr<ConversionTarget> target =
41
42 SPIRVConversionOptions options;
43 options.emulateLT32BitScalarTypes = this->emulateLT32BitScalarTypes;
44 options.emulateUnsupportedFloatTypes = this->emulateUnsupportedFloatTypes;
45 SPIRVTypeConverter typeConverter(targetAttr, options);
46
47 RewritePatternSet patterns(context);
48 arith::populateArithToSPIRVPatterns(typeConverter, patterns);
50 populateTensorToSPIRVPatterns(typeConverter, /*byteCountThreshold=*/64,
51 patterns);
53
54 if (failed(applyPartialConversion(op, *target, std::move(patterns))))
55 return signalPassFailure();
56 }
57};
58} // namespace
b getContext())
static llvm::ManagedStatic< PassManagerOptions > options
static std::unique_ptr< SPIRVConversionTarget > get(spirv::TargetEnvAttr targetAttr)
Creates a SPIR-V conversion target for the given target environment.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:561
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
Include the generated interface declarations.
void populateTensorToSPIRVPatterns(const SPIRVTypeConverter &typeConverter, int64_t byteCountThreshold, RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating tensor ops to SPIR-V ops.
void populateBuiltinFuncToSPIRVPatterns(const SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating the builtin func op to the SPIR-V diale...
void populateFuncToSPIRVPatterns(const SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating Func ops to SPIR-V ops.
const FrozenRewritePatternSet & patterns