|
| 1 | + |
| 2 | +//===- DLTITransformOps.cpp - Implementation of DLTI transform ops --------===// |
| 3 | +// |
| 4 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#include "mlir/Dialect/DLTI/TransformOps/DLTITransformOps.h" |
| 11 | + |
| 12 | +#include "mlir/Dialect/DLTI/DLTI.h" |
| 13 | +#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h" |
| 14 | +#include "mlir/Dialect/Transform/Utils/Utils.h" |
| 15 | +#include "mlir/Interfaces/DataLayoutInterfaces.h" |
| 16 | + |
| 17 | +using namespace mlir; |
| 18 | +using namespace mlir::transform; |
| 19 | + |
| 20 | +#define DEBUG_TYPE "dlti-transforms" |
| 21 | + |
| 22 | +//===----------------------------------------------------------------------===// |
| 23 | +// QueryOp |
| 24 | +//===----------------------------------------------------------------------===// |
| 25 | + |
| 26 | +void transform::QueryOp::getEffects( |
| 27 | + SmallVectorImpl<MemoryEffects::EffectInstance> &effects) { |
| 28 | + onlyReadsHandle(getTargetMutable(), effects); |
| 29 | + producesHandle(getOperation()->getOpResults(), effects); |
| 30 | + onlyReadsPayload(effects); |
| 31 | +} |
| 32 | + |
| 33 | +DiagnosedSilenceableFailure transform::QueryOp::applyToOne( |
| 34 | + transform::TransformRewriter &rewriter, Operation *target, |
| 35 | + transform::ApplyToEachResultList &results, TransformState &state) { |
| 36 | + StringAttr deviceId = getDeviceAttr(); |
| 37 | + StringAttr key = getKeyAttr(); |
| 38 | + |
| 39 | + DataLayoutEntryInterface entry; |
| 40 | + if (deviceId) { |
| 41 | + TargetSystemSpecInterface sysSpec = dlti::getTargetSystemSpec(target); |
| 42 | + if (!sysSpec) |
| 43 | + return mlir::emitDefiniteFailure(target->getLoc()) |
| 44 | + << "no target system spec associated to: " << target; |
| 45 | + |
| 46 | + if (auto targetSpec = sysSpec.getDeviceSpecForDeviceID(deviceId)) |
| 47 | + entry = targetSpec->getSpecForIdentifier(key); |
| 48 | + else |
| 49 | + return mlir::emitDefiniteFailure(target->getLoc()) |
| 50 | + << "no " << deviceId << " target device spec found"; |
| 51 | + } else { |
| 52 | + DataLayoutSpecInterface dlSpec = dlti::getDataLayoutSpec(target); |
| 53 | + if (!dlSpec) |
| 54 | + return mlir::emitDefiniteFailure(target->getLoc()) |
| 55 | + << "no data layout spec associated to: " << target; |
| 56 | + |
| 57 | + entry = dlSpec.getSpecForIdentifier(key); |
| 58 | + } |
| 59 | + |
| 60 | + if (!entry) |
| 61 | + return mlir::emitDefiniteFailure(target->getLoc()) |
| 62 | + << "no DLTI entry for key: " << key; |
| 63 | + |
| 64 | + results.push_back(entry.getValue()); |
| 65 | + |
| 66 | + return DiagnosedSilenceableFailure::success(); |
| 67 | +} |
| 68 | + |
| 69 | +//===----------------------------------------------------------------------===// |
| 70 | +// Transform op registration |
| 71 | +//===----------------------------------------------------------------------===// |
| 72 | + |
| 73 | +namespace { |
| 74 | +class DLTITransformDialectExtension |
| 75 | + : public transform::TransformDialectExtension< |
| 76 | + DLTITransformDialectExtension> { |
| 77 | +public: |
| 78 | + using Base::Base; |
| 79 | + |
| 80 | + void init() { |
| 81 | + registerTransformOps< |
| 82 | +#define GET_OP_LIST |
| 83 | +#include "mlir/Dialect/DLTI/TransformOps/DLTITransformOps.cpp.inc" |
| 84 | + >(); |
| 85 | + } |
| 86 | +}; |
| 87 | +} // namespace |
| 88 | + |
| 89 | +#define GET_OP_CLASSES |
| 90 | +#include "mlir/Dialect/DLTI/TransformOps/DLTITransformOps.cpp.inc" |
| 91 | + |
| 92 | +void mlir::dlti::registerTransformDialectExtension(DialectRegistry ®istry) { |
| 93 | + registry.addExtensions<DLTITransformDialectExtension>(); |
| 94 | +} |
0 commit comments