MLIR 24.0.0git
Promotion.cpp
Go to the documentation of this file.
1//===- Promotion.cpp - Implementation of linalg Promotion -----------------===//
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 the linalg dialect Promotion pass.
10//
11//===----------------------------------------------------------------------===//
12
21#include "mlir/IR/AffineMap.h"
23#include "mlir/Support/LLVM.h"
25#include "llvm/ADT/MapVector.h"
26#include "llvm/ADT/SmallBitVector.h"
27#include "llvm/ADT/SmallSet.h"
28#include "llvm/ADT/TypeSwitch.h"
29#include "llvm/Support/Debug.h"
30
31using namespace mlir;
32using namespace mlir::linalg;
33using namespace mlir::scf;
34
35#define DEBUG_TYPE "linalg-promotion"
36
37/// Alloc a new buffer of `size` * `width` i8; where `width` is given by the
38/// data `layout` for `elementType`.
39/// Use AllocOp or AllocaOp depending on `options`.
40/// Take an optional alignment.
43 Type elementType, Value allocSize, DataLayout &layout,
44 std::optional<unsigned> alignment = std::nullopt) {
45 llvm::TypeSize width = layout.getTypeSize(elementType);
46 assert(!width.isScalable() && "cannot allocate buffer for a scalable vector");
47
48 IntegerAttr alignmentAttr;
49 if (alignment.has_value())
50 alignmentAttr = b.getI64IntegerAttr(alignment.value());
51
52 Attribute memorySpaceAttr;
53 if (options.memorySpace.has_value())
54 memorySpaceAttr = *options.memorySpace;
55
56 // Static buffer.
57 if (std::optional<int64_t> cst = getConstantIntValue(allocSize)) {
58 auto staticBufferType = MemRefType::get(width.getFixedValue() * cst.value(),
59 b.getIntegerType(8));
60 staticBufferType =
61 MemRefType::Builder(staticBufferType).setMemorySpace(memorySpaceAttr);
62 if (options.useAlloca) {
63 return memref::AllocaOp::create(b, staticBufferType, ValueRange{},
64 alignmentAttr);
65 }
66 return memref::AllocOp::create(b, staticBufferType, ValueRange{},
67 alignmentAttr);
68 }
69
70 // Fallback dynamic buffer.
71 auto dynamicBufferType =
72 MemRefType::get(ShapedType::kDynamic, b.getIntegerType(8));
73 dynamicBufferType =
74 MemRefType::Builder(dynamicBufferType).setMemorySpace(memorySpaceAttr);
75 Value mul = b.createOrFold<arith::MulIOp>(
76 arith::ConstantIndexOp::create(b, width), allocSize);
77 if (options.useAlloca)
78 return memref::AllocaOp::create(b, dynamicBufferType, mul, alignmentAttr);
79 return memref::AllocOp::create(b, dynamicBufferType, mul, alignmentAttr);
80}
81
82/// Default allocation callback function. This allocates a promoted buffer when
83/// no call back to do so is provided. The default is to allocate a
84/// memref<..xi8> and return a view to get a memref type of shape
85/// boundingSubViewSize.
86static std::optional<Value> defaultAllocBufferCallBack(
88 memref::SubViewOp subView, ArrayRef<Value> boundingSubViewSize,
89 std::optional<unsigned> alignment, DataLayout &layout) {
90 ShapedType viewType = subView.getType();
91 ImplicitLocOpBuilder b(subView.getLoc(), builder);
92 auto zero = arith::ConstantIndexOp::create(b, 0);
93 auto one = arith::ConstantIndexOp::create(b, 1);
94
95 Attribute memorySpaceAttr;
96 if (options.memorySpace.has_value())
97 memorySpaceAttr = *options.memorySpace;
98
99 Value allocSize = one;
100 for (const auto &size : llvm::enumerate(boundingSubViewSize))
101 allocSize = b.createOrFold<arith::MulIOp>(allocSize, size.value());
102 Value buffer = allocBuffer(b, options, viewType.getElementType(), allocSize,
103 layout, alignment);
104 SmallVector<int64_t, 4> dynSizes(boundingSubViewSize.size(),
105 ShapedType::kDynamic);
106
107 auto viewMemRefType = MemRefType::get(dynSizes, viewType.getElementType());
108 viewMemRefType =
109 MemRefType::Builder(viewMemRefType).setMemorySpace(memorySpaceAttr);
110 Value view = b.createOrFold<memref::ViewOp>(viewMemRefType, buffer, zero,
111 boundingSubViewSize);
112 return view;
113}
114
115/// Default implementation of deallocation of the buffer use for promotion. It
116/// expects to get the same value that the default allocation method returned,
117/// i.e. result of a ViewOp.
118static LogicalResult
120 OpBuilder &b, Value fullLocalView) {
121 if (!options.useAlloca) {
122 auto viewOp = cast<memref::ViewOp>(fullLocalView.getDefiningOp());
123 memref::DeallocOp::create(b, viewOp.getSource().getLoc(),
124 viewOp.getSource());
125 }
126 return success();
127}
128
129namespace {
130
131/// Helper struct that captures the information required to apply the
132/// transformation on each op. This bridges the abstraction gap with the
133/// user-facing API which exposes positional arguments to control which operands
134/// are promoted.
135struct LinalgOpInstancePromotionOptions {
136 LinalgOpInstancePromotionOptions(LinalgOp op,
137 const LinalgPromotionOptions &options);
138 /// SubViews to promote.
140 /// Subviews operand numbers to copy in using copyInFn.
141 llvm::SmallSet<int64_t, 4> operandsNumbersToCopyIn;
142 /// True if the full view should be used for the promoted buffer.
143 DenseMap<Value, bool> useFullTileBuffers;
144 /// True if the original subview size should be used. This means the full tile
145 /// buffer is the same size as the partial view.
146 bool useOriginalSubviewSize;
147
148 /// Callback functions for allocation and deallocation of promoted buffers, as
149 /// well as to copy the data into and out of these buffers.
150 AllocBufferCallbackFn allocationFn;
151 DeallocBufferCallbackFn deallocationFn;
152 CopyCallbackFn copyInFn;
153 CopyCallbackFn copyOutFn;
154
155 /// Alignment of promoted buffer.
156 std::optional<unsigned> alignment;
157};
158} // namespace
159
160LinalgOpInstancePromotionOptions::LinalgOpInstancePromotionOptions(
161 LinalgOp linalgOp, const LinalgPromotionOptions &options)
162 : subViews(), alignment(options.alignment) {
163 assert(linalgOp.hasPureBufferSemantics() &&
164 "revisit usage of shaped operand");
165 auto vUseFullTileBuffers =
166 options.useFullTileBuffers.value_or(llvm::SmallBitVector());
167 vUseFullTileBuffers.resize(linalgOp->getNumOperands(),
168 options.useFullTileBuffersDefault);
169 useOriginalSubviewSize = options.useOriginalSubviewSize;
170
171 for (OpOperand &opOperand : linalgOp->getOpOperands()) {
172 int64_t operandNumber = opOperand.getOperandNumber();
173 if (options.operandsToPromote &&
174 !options.operandsToPromote->count(operandNumber))
175 continue;
176 Operation *op = opOperand.get().getDefiningOp();
177 if (auto sv = dyn_cast_or_null<memref::SubViewOp>(op)) {
178 subViews[operandNumber] = sv;
179 // In case of linalg generic, copy in only if subview is used in linalg
180 // payload.
181 if (!isa<linalg::GenericOp>(linalgOp) ||
182 linalgOp.payloadUsesValueFromOperand(&opOperand))
183 operandsNumbersToCopyIn.insert(operandNumber);
184 useFullTileBuffers[sv] = vUseFullTileBuffers[operandNumber];
185 }
186 }
187
188 if (options.allocationFn) {
189 allocationFn = *options.allocationFn;
190 } else {
191 allocationFn = [&](OpBuilder &b, memref::SubViewOp subViewOp,
192 ArrayRef<Value> boundingSubViewSize,
193 DataLayout &layout) -> std::optional<Value> {
194 return defaultAllocBufferCallBack(options, b, subViewOp,
195 boundingSubViewSize, alignment, layout);
196 };
197 }
198
199 if (options.deallocationFn) {
200 deallocationFn = *options.deallocationFn;
201 } else {
202 deallocationFn = [&](OpBuilder &b, Value buffer) {
203 return defaultDeallocBufferCallBack(options, b, buffer);
204 };
205 }
206
207 // Save the loc because `linalgOp` goes out of scope.
208 Location loc = linalgOp.getLoc();
209 auto defaultCopyCallBack = [loc](OpBuilder &b, Value src,
210 Value dst) -> LogicalResult {
211 linalg::CopyOp::create(b, loc, src, dst);
212 return success();
213 };
214 copyInFn = (options.copyInFn ? *(options.copyInFn) : defaultCopyCallBack);
215 copyOutFn = (options.copyOutFn ? *(options.copyOutFn) : defaultCopyCallBack);
216}
217
218// Performs promotion of a `subView` into a local buffer of the size of the
219// *ranges* of the `subView`. This produces a buffer whose size may be bigger
220// than the actual size of the `subView` at the boundaries.
221// This is related to the full/partial tile problem.
222// Returns a PromotionInfo containing a `buffer`, `fullLocalView` and
223// `partialLocalView` such that:
224// * `buffer` is always the size of the full tile.
225// * `fullLocalView` is a dense contiguous view into that buffer.
226// * `partialLocalView` is a dense non-contiguous slice of `fullLocalView`
227// that corresponds to the size of `subView` and accounting for boundary
228// effects.
229// The point of the full tile buffer is that constant static tile sizes are
230// folded and result in a buffer type with statically known size and alignment
231// properties.
232// To account for general boundary effects, padding must be performed on the
233// boundary tiles. For now this is done with an unconditional `fill` op followed
234// by a partial `copy` op.
236 OpBuilder &b, Location loc, memref::SubViewOp subView,
237 bool useOriginalSubviewSize, const AllocBufferCallbackFn &allocationFn,
238 DataLayout &layout) {
239 auto viewType = subView.getType();
240 auto rank = viewType.getRank();
241 SmallVector<Value, 4> fullSizes;
242 SmallVector<OpFoldResult> partialSizes;
243 fullSizes.reserve(rank);
244 partialSizes.reserve(rank);
245 llvm::SmallBitVector droppedDims = subView.getDroppedDims();
246 int64_t resultDimIdx = 0;
247 for (const auto &en : llvm::enumerate(subView.getOrCreateRanges(b, loc))) {
248 if (droppedDims[en.index()])
249 continue;
250 auto rangeValue = en.value();
251 // Try to extract a tight constant. If the size is known statically, no need
252 // to look for the bound.
253 LLVM_DEBUG(llvm::dbgs() << "Extract tightest: " << rangeValue.size << "\n");
254 Value size;
255 if (llvm::isa_and_present<Attribute>(rangeValue.size) ||
256 useOriginalSubviewSize) {
257 size = getValueOrCreateConstantIndexOp(b, loc, rangeValue.size);
258 } else {
259 FailureOr<int64_t> upperBound =
261 presburger::BoundType::UB, rangeValue.size,
262 /*stopCondition=*/nullptr, ValueBoundsOptions{/*closedUB=*/true});
263 size = failed(upperBound)
264 ? getValueOrCreateConstantIndexOp(b, loc, rangeValue.size)
265 : arith::ConstantIndexOp::create(b, loc, *upperBound);
266 }
267 LLVM_DEBUG(llvm::dbgs() << "Extracted tightest: " << size << "\n");
268 fullSizes.push_back(size);
269 partialSizes.push_back(
270 b.createOrFold<memref::DimOp>(loc, subView, resultDimIdx++));
271 }
272 // If a callback is not specified, then use the default implementation for
273 // allocating the promoted buffer.
274 std::optional<Value> fullLocalView =
275 allocationFn(b, subView, fullSizes, layout);
276 if (!fullLocalView)
277 return failure();
278 SmallVector<OpFoldResult, 4> zeros(fullSizes.size(), b.getIndexAttr(0));
279 SmallVector<OpFoldResult, 4> ones(fullSizes.size(), b.getIndexAttr(1));
280 auto partialLocalView = b.createOrFold<memref::SubViewOp>(
281 loc, *fullLocalView, zeros, partialSizes, ones);
282 return PromotionInfo{*fullLocalView, partialLocalView};
283}
284
285static FailureOr<MapVector<int64_t, PromotionInfo>>
287 LinalgOpInstancePromotionOptions options, DataLayout &layout) {
288 if (options.subViews.empty())
289 return failure();
290
291 MapVector<int64_t, PromotionInfo> promotionInfoMap;
292
293 for (auto v : options.subViews) {
294 memref::SubViewOp subView =
295 cast<memref::SubViewOp>(v.second.getDefiningOp());
296 auto promotionInfo = promoteSubviewAsNewBuffer(
297 b, b.getLoc(), subView, options.useOriginalSubviewSize,
298 options.allocationFn, layout);
299 if (failed(promotionInfo))
300 return failure();
301 promotionInfoMap[v.first] = *promotionInfo;
302
303 // Only fill the buffer if the full local view is used
304 if (!options.useFullTileBuffers[v.second])
305 continue;
306 Type subviewEltType = subView.getType().getElementType();
307 Value fillVal =
308 llvm::TypeSwitch<Type, Value>(subviewEltType)
309 .Case([&](FloatType t) {
310 return arith::ConstantOp::create(b, FloatAttr::get(t, 0.0));
311 })
312 .Case([&](IntegerType t) {
313 return arith::ConstantOp::create(b, IntegerAttr::get(t, 0));
314 })
315 .Case([&](ComplexType t) {
316 Value tmp;
317 if (auto et = dyn_cast<FloatType>(t.getElementType()))
318 tmp = arith::ConstantOp::create(b, FloatAttr::get(et, 0.0));
319 else if (auto et = cast<IntegerType>(t.getElementType()))
320 tmp = arith::ConstantOp::create(b, IntegerAttr::get(et, 0));
321 return complex::CreateOp::create(b, t, tmp, tmp);
322 })
323 .Default(nullptr);
324 if (!fillVal)
325 return failure();
326 linalg::FillOp::create(b, fillVal, promotionInfo->fullLocalView);
327 }
328
329 // Copy data into the promoted buffers. Use callback if provided.
330 for (auto v : options.subViews) {
331 auto *info = promotionInfoMap.find(v.first);
332 if (info == promotionInfoMap.end())
333 continue;
334 if (options.operandsNumbersToCopyIn.count(v.first) == 0)
335 continue;
336 if (failed(options.copyInFn(
337 b, cast<memref::SubViewOp>(v.second.getDefiningOp()),
338 info->second.partialLocalView)))
339 return failure();
340 }
341 return promotionInfoMap;
342}
343
344static FailureOr<LinalgOp>
346 LinalgOpInstancePromotionOptions options, DataLayout &layout) {
347 assert(op.hasPureBufferSemantics() &&
348 "expected linalg op with buffer semantics");
349
350 // 1. Promote the specified views and use them in the new op.
351 auto promotedBuffersAndViews = promoteSubViews(b, options, layout);
352 if (failed(promotedBuffersAndViews) ||
353 promotedBuffersAndViews->size() != options.subViews.size())
354 return failure();
355
356 // 2. Append all other operands as they appear, this enforces that such
357 // operands are not views. This is to support cases such as FillOp taking
358 // extra scalars etc. Keep a reference to output buffers;
359 SmallVector<Value, 8> opViews;
360 opViews.reserve(op->getNumOperands());
361 SmallVector<std::pair<Value, Value>, 8> writebackViews;
362 writebackViews.reserve(promotedBuffersAndViews->size());
363 for (OpOperand &opOperand : op->getOpOperands()) {
364 int64_t operandNumber = opOperand.getOperandNumber();
365 if (options.subViews.count(operandNumber) != 0) {
366 if (options.useFullTileBuffers[opOperand.get()])
367 opViews.push_back(
368 (*promotedBuffersAndViews)[operandNumber].fullLocalView);
369 else
370 opViews.push_back(
371 (*promotedBuffersAndViews)[operandNumber].partialLocalView);
372 if (operandNumber >= op.getNumDpsInputs())
373 writebackViews.emplace_back(std::make_pair(
374 opOperand.get(),
375 (*promotedBuffersAndViews)[operandNumber].partialLocalView));
376 } else {
377 opViews.push_back(opOperand.get());
378 }
379 }
380 op->setOperands(0, opViews.size(), opViews);
381
383 b.setInsertionPointAfter(op);
384 // 3. Emit write-back for the promoted output views: copy the partial view.
385 for (auto viewAndPartialLocalView : writebackViews) {
386 if (failed(options.copyOutFn(b, viewAndPartialLocalView.second,
387 viewAndPartialLocalView.first)))
388 return failure();
389 }
390
391 // 4. Dealloc all local buffers.
392 for (const auto &pi : *promotedBuffersAndViews)
393 (void)options.deallocationFn(b, pi.second.fullLocalView);
394 return op;
395}
396
397LogicalResult
400 LinalgOp linalgOp = dyn_cast<LinalgOp>(op);
401 // Transformation applies to buffers only.
402 if (!linalgOp || !linalgOp.hasPureBufferSemantics())
403 return failure();
404 // Check that at least one of the requested operands is indeed a subview.
405 for (OpOperand &opOperand : linalgOp->getOpOperands()) {
406 auto sv =
407 isa_and_nonnull<memref::SubViewOp>(opOperand.get().getDefiningOp());
408 if (sv) {
409 if (!options.operandsToPromote ||
410 options.operandsToPromote->count(opOperand.getOperandNumber()))
411 return success();
412 }
413 }
414 // TODO: Check all subviews requested are bound by a static constant.
415 // TODO: Check that the total footprint fits within a given size.
416 return failure();
417}
418
419FailureOr<LinalgOp>
420mlir::linalg::promoteSubViews(OpBuilder &builder, LinalgOp linalgOp,
422 LinalgOpInstancePromotionOptions linalgOptions(linalgOp, options);
423 auto layout = DataLayout::closest(linalgOp);
424 ImplicitLocOpBuilder b(linalgOp.getLoc(), builder);
425 auto res = ::promoteSubViews(b, linalgOp, linalgOptions, layout);
426 if (failed(res))
427 return failure();
428 return res;
429}
430
431/// Allocate the given subview to a memory address space in GPU by creating a
432/// allocation operation and setting the memref type address space to desired
433/// address space.
434static std::optional<Value> allocateSubviewGPUMemoryInAddressSpace(
435 OpBuilder &builder, memref::SubViewOp subview, ArrayRef<Value> sizeBounds,
436 gpu::AddressSpace addressSpace) {
437 OpBuilder::InsertionGuard guard(builder);
438
439 func::FuncOp funcOp = subview->getParentOfType<func::FuncOp>();
440 if (!funcOp)
441 return std::nullopt;
442
443 // The subview size bounds are expected to be constant; they specify the shape
444 // of the allocation.
446 for (Value bound : sizeBounds) {
447 APInt value;
448 if (!matchPattern(bound, m_ConstantInt(&value)))
449 return std::nullopt;
450 shape.push_back(value.getSExtValue());
451 }
452
453 builder.setInsertionPointToStart(&funcOp.front());
454 auto type = MemRefType::get(
455 shape, subview.getType().getElementType(), MemRefLayoutAttrInterface{},
456 gpu::AddressSpaceAttr::get(builder.getContext(), addressSpace));
457 Value buffer;
458 if (addressSpace == gpu::GPUDialect::getWorkgroupAddressSpace()) {
459 buffer = memref::AllocOp::create(builder, funcOp.getLoc(), type);
460 } else if (addressSpace == gpu::GPUDialect::getPrivateAddressSpace()) {
461 buffer = memref::AllocaOp::create(builder, funcOp.getLoc(), type);
462 } else {
463 return std::nullopt;
464 }
465 return buffer;
466}
467
468/// Allocate the subview in the GPU workgroup memory.
470 OpBuilder &builder, memref::SubViewOp subview, ArrayRef<Value> sizeBounds,
471 DataLayout &) {
473 builder, subview, sizeBounds,
474 gpu::GPUDialect::getWorkgroupAddressSpace());
475}
476
477/// In case of GPU group memory there is no need to deallocate.
479 Value /*buffer*/) {
480 return success();
481}
482
483/// Create Memref copy operations and add gpu barrier guards before and after
484/// the copy operation to ensure data integrity.
486 Value dst) {
487 gpu::BarrierOp::create(b, src.getLoc());
488 Operation *copyOp = memref::CopyOp::create(b, src.getLoc(), src, dst);
489 gpu::BarrierOp::create(b, copyOp->getLoc());
490 return success();
491}
492
493/// Allocate the subview in the GPU private memory.
495 OpBuilder &builder, memref::SubViewOp subview, ArrayRef<Value> sizeBounds,
496 DataLayout &) {
498 builder, subview, sizeBounds, gpu::GPUDialect::getPrivateAddressSpace());
499}
500
501/// Normal copy to between src and dst.
503 Value dst) {
504 memref::CopyOp::create(b, src.getLoc(), src, dst);
505 return success();
506}
507
508/// In case of GPU private memory there is no need to deallocate since the
509/// memory is freed when going outside of the scope.
511 Value /*buffer*/) {
512 return success();
513}
return success()
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
static llvm::ManagedStatic< PassManagerOptions > options
static std::optional< Value > defaultAllocBufferCallBack(const LinalgPromotionOptions &options, OpBuilder &builder, memref::SubViewOp subView, ArrayRef< Value > boundingSubViewSize, std::optional< unsigned > alignment, DataLayout &layout)
Default allocation callback function.
Definition Promotion.cpp:86
static std::optional< Value > allocateSubviewGPUMemoryInAddressSpace(OpBuilder &builder, memref::SubViewOp subview, ArrayRef< Value > sizeBounds, gpu::AddressSpace addressSpace)
Allocate the given subview to a memory address space in GPU by creating a allocation operation and se...
static LogicalResult defaultDeallocBufferCallBack(const LinalgPromotionOptions &options, OpBuilder &b, Value fullLocalView)
Default implementation of deallocation of the buffer use for promotion.
static Value allocBuffer(ImplicitLocOpBuilder &b, const LinalgPromotionOptions &options, Type elementType, Value allocSize, DataLayout &layout, std::optional< unsigned > alignment=std::nullopt)
Alloc a new buffer of size * width i8; where width is given by the data layout for elementType.
Definition Promotion.cpp:41
#define mul(a, b)
Attributes are known-constant values of operations.
Definition Attributes.h:25
MLIRContext * getContext() const
Definition Builders.h:56
The main mechanism for performing data layout queries.
static DataLayout closest(Operation *op)
Returns the layout of the closest parent operation carrying layout info.
llvm::TypeSize getTypeSize(Type t) const
Returns the size of the given type in the current scope.
ImplicitLocOpBuilder maintains a 'current location', allowing use of the create<> method without spec...
Definition Builders.h:632
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This is a builder type that keeps local references to arguments.
Builder & setMemorySpace(Attribute newMemorySpace)
RAII guard to reset the insertion point of the builder when destroyed.
Definition Builders.h:351
This class helps build Operations.
Definition Builders.h:210
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
Definition Builders.h:434
This class represents an operand of an operation.
Definition Value.h:254
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
Location getLoc()
The source location the operation was defined or derived from.
Definition Operation.h:240
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
static FailureOr< int64_t > computeConstantBound(presburger::BoundType type, const Variable &var, const StopConditionFn &stopCondition=nullptr, ValueBoundsOptions options={})
Compute a constant bound for the given variable.
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:389
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Location getLoc() const
Return the location of this value.
Definition Value.cpp:24
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Definition Value.cpp:18
static ConstantIndexOp create(OpBuilder &builder, Location location, int64_t value)
Definition ArithOps.cpp:434
std::optional< Value > allocateWorkgroupMemory(OpBuilder &builder, memref::SubViewOp subview, ArrayRef< Value > sizeBounds, DataLayout &)
Allocate the subview in the GPU workgroup memory.
LogicalResult deallocateGPUPrivateMemory(OpBuilder &, Value)
In case of GPU private memory there is no need to deallocate since the memory is freed when going out...
FailureOr< PromotionInfo > promoteSubviewAsNewBuffer(OpBuilder &b, Location loc, memref::SubViewOp subView, bool useOriginalSubviewSize, const AllocBufferCallbackFn &allocationFn, DataLayout &layout)
std::optional< Value > allocateGPUPrivateMemory(OpBuilder &builder, memref::SubViewOp subview, ArrayRef< Value > sizeBounds, DataLayout &)
Allocate the subview in the GPU private memory.
LogicalResult copyToWorkgroupMemory(OpBuilder &b, Value src, Value dst)
Create Memref copy operations and add gpu barrier guards before and after the copy operation to ensur...
LogicalResult promoteSubviewsPrecondition(Operation *op, LinalgPromotionOptions options)
Promote memref.subviews feeding linalg-on-buffers operations.
LogicalResult copyToGPUPrivateMemory(OpBuilder &b, Value src, Value dst)
Normal copy to between src and dst.
std::function< std::optional< Value >( OpBuilder &b, memref::SubViewOp subView, ArrayRef< Value > boundingSubViewSize, DataLayout &layout)> AllocBufferCallbackFn
Callback function type used to perform the allocation for the promoted subView.
Definition Transforms.h:378
std::function< LogicalResult(OpBuilder &b, Value buffer)> DeallocBufferCallbackFn
Callback function type used to deallocate the buffers used to hold the promoted subview.
Definition Transforms.h:384
FailureOr< LinalgOp > promoteSubViews(OpBuilder &b, LinalgOp op, const LinalgPromotionOptions &options)
Promote the subViews into a new buffer allocated at the insertion point b.
LogicalResult deallocateWorkgroupMemory(OpBuilder &, Value)
In case of GPU group memory there is no need to deallocate.
std::function< LogicalResult(OpBuilder &b, Value src, Value dst)> CopyCallbackFn
Callback function type used to insert copy from original subview to subview of the promoted region fo...
Definition Transforms.h:391
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
Definition Matchers.h:490
detail::constant_int_value_binder m_ConstantInt(IntegerAttr::ValueType *bind_value)
Matches a constant holding a scalar/vector/tensor integer (splat) and writes the integer value to bin...
Definition Matchers.h:527
llvm::MapVector< KeyT, ValueT, MapType, VectorType, N > MapVector
Definition LLVM.h:133
std::optional< int64_t > getConstantIntValue(OpFoldResult ofr)
If ofr is a constant integer or an IntegerAttr, return the integer.
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
Definition Utils.cpp:114
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
Definition LLVM.h:123
Options that control value bound computation.
Create a new buffer using the allocationFn provided.
Definition Transforms.h:937