Skip to content

Commit 1ae19b9

Browse files
committed
Apply rocMLIR patches for external
1 parent d7237d5 commit 1ae19b9

File tree

5 files changed

+151
-98
lines changed

5 files changed

+151
-98
lines changed

external/llvm-project/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
6666
const BufferizationOptions &options,
6767
BufferizationState &state);
6868

69+
/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
70+
/// old (deprecated) partial, dialect conversion-based bufferization passes. A
71+
/// copy will be inserted before every buffer write.
72+
BufferizationOptions getPartialBufferizationOptions();
73+
6974
} // namespace bufferization
7075
} // namespace mlir
7176

external/llvm-project/mlir/include/mlir/Interfaces/CallInterfaces.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def CallOpInterface : OpInterface<"CallOpInterface"> {
107107
reference to a symbol, via SymbolRefAttr, or a reference to a defined
108108
SSA value. If the reference is an SSA value, the SSA value corresponds
109109
to a region of a lambda-like operation.
110-
}], "::mlir::CallInterfaceCallable", "getCallableForCallee"
110+
}],
111+
"::mlir::CallInterfaceCallable", "getCallableForCallee"
111112
>,
112113
InterfaceMethod<[{
113114
Sets the callee of this call-like operation. A `callee` is either a

external/llvm-project/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
2828
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
2929
#include "mlir/Conversion/MathToROCDL/MathToROCDL.h"
30+
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
3031
#include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h"
3132
#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
3233
#include "mlir/Dialect/Func/IR/FuncOps.h"
@@ -37,6 +38,7 @@
3738
#include "mlir/Dialect/Math/IR/Math.h"
3839
#include "mlir/Dialect/MemRef/IR/MemRef.h"
3940
#include "mlir/Dialect/Vector/IR/VectorOps.h"
41+
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
4042
#include "mlir/IR/BuiltinAttributes.h"
4143
#include "mlir/Pass/Pass.h"
4244
#include "mlir/Transforms/DialectConversion.h"
@@ -253,7 +255,8 @@ struct LowerGpuOpsToROCDLOpsPass final
253255
LowerGpuOpsToROCDLOpsPass() = default;
254256
LowerGpuOpsToROCDLOpsPass(const std::string &chipset, unsigned indexBitwidth,
255257
bool useBarePtrCallConv,
256-
gpu::amd::Runtime runtime) {
258+
gpu::amd::Runtime runtime,
259+
std::optional<llvm::SmallDenseSet<StringRef>> allowedDialects) {
257260
if (this->chipset.getNumOccurrences() == 0)
258261
this->chipset = chipset;
259262
if (this->indexBitwidth.getNumOccurrences() == 0)
@@ -262,6 +265,11 @@ struct LowerGpuOpsToROCDLOpsPass final
262265
this->useBarePtrCallConv = useBarePtrCallConv;
263266
if (this->runtime.getNumOccurrences() == 0)
264267
this->runtime = runtime;
268+
if(this->allowedDialects.getNumOccurrences() == 0 && allowedDialects.has_value()) {
269+
for (auto &str : allowedDialects.value()) {
270+
this->allowedDialects.push_back(str.str());
271+
}
272+
}
265273
}
266274

267275
void getDependentDialects(DialectRegistry &registry) const override {
@@ -369,6 +377,11 @@ struct LowerGpuOpsToROCDLOpsPass final
369377

370378
populateAMDGPUToROCDLConversionPatterns(converter, llvmPatterns,
371379
*maybeChipset);
380+
// TODO (rocmlir): remove hardcoded passes
381+
// related PR: https://github.com/llvm/llvm-project/pull/124439
382+
mlir::vector::populateVectorInsertExtractStridedSliceTransforms(
383+
llvmPatterns);
384+
// TODO: ends here
372385
populateGpuToROCDLConversionPatterns(converter, llvmPatterns, runtime,
373386
*maybeChipset);
374387
configureGpuToROCDLConversionLegality(target);
@@ -405,6 +418,9 @@ void mlir::configureGpuToROCDLConversionLegality(ConversionTarget &target) {
405418
target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
406419
target.addLegalDialect<ROCDL::ROCDLDialect>();
407420
target.addIllegalDialect<gpu::GPUDialect>();
421+
// TODO (rocmlir): remove vector::VectorDialect
422+
// related PR: https://github.com/llvm/llvm-project/pull/124439
423+
target.addIllegalDialect<gpu::GPUDialect, vector::VectorDialect>();
408424
target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::Exp2Op, LLVM::FCeilOp,
409425
LLVM::FFloorOp, LLVM::FRemOp, LLVM::LogOp, LLVM::Log10Op,
410426
LLVM::Log2Op, LLVM::PowOp, LLVM::SinOp>();
@@ -466,7 +482,8 @@ std::unique_ptr<OperationPass<gpu::GPUModuleOp>>
466482
mlir::createLowerGpuOpsToROCDLOpsPass(const std::string &chipset,
467483
unsigned indexBitwidth,
468484
bool useBarePtrCallConv,
469-
gpu::amd::Runtime runtime) {
485+
gpu::amd::Runtime runtime,
486+
const std::optional<llvm::SmallDenseSet<StringRef>>& allowedDialects) {
470487
return std::make_unique<LowerGpuOpsToROCDLOpsPass>(
471-
chipset, indexBitwidth, useBarePtrCallConv, runtime);
488+
chipset, indexBitwidth, useBarePtrCallConv, runtime, allowedDialects);
472489
}

external/llvm-project/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,16 @@ bufferization::bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
482482

483483
return success();
484484
}
485+
486+
BufferizationOptions bufferization::getPartialBufferizationOptions() {
487+
BufferizationOptions options;
488+
options.allowUnknownOps = true;
489+
options.copyBeforeWrite = true;
490+
options.unknownTypeConverterFn = [](Value value, Attribute memorySpace,
491+
const BufferizationOptions &options) {
492+
return getMemRefTypeWithStaticIdentityLayout(
493+
cast<TensorType>(value.getType()), memorySpace);
494+
};
495+
options.opFilter.allowDialect<BufferizationDialect>();
496+
return options;
497+
}

external/llvm-project/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp

Lines changed: 111 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -501,100 +501,103 @@ static LogicalResult verifyConvOpErrorIf(T op) {
501501
// Skip following checks if output is not ranked
502502
return success();
503503

504-
const RankedTensorType inputType =
505-
llvm::dyn_cast<RankedTensorType>(op.getInput().getType());
506-
const RankedTensorType weightType =
507-
llvm::dyn_cast<RankedTensorType>(op.getWeight().getType());
508-
509-
if (inputType && weightType) {
510-
const auto verifyOutputSize =
511-
[&op](const int64_t inputSize, const int64_t kernelSize,
512-
const int64_t outputSize, const int64_t padBefore,
513-
const int64_t padAfter, const int64_t stride,
514-
const int64_t dilation, const llvm::StringRef dimName,
515-
const llvm::StringRef dimAxis,
516-
const llvm::StringRef padBeforeName,
517-
const llvm::StringRef padAfterName) -> LogicalResult {
518-
if (inputSize == ShapedType::kDynamic ||
519-
kernelSize == ShapedType::kDynamic)
520-
return success();
521-
522-
// ERROR_IF: O != idiv_check(I - 1 + pa + pb - (K - 1) * d, s) + 1
523-
524-
const std::optional<int64_t> calculatedOutSizeMinusOne = idivCheck(
525-
inputSize - 1 + padBefore + padAfter - (kernelSize - 1) * dilation,
526-
stride);
527-
if (!calculatedOutSizeMinusOne.has_value())
528-
return op.emitOpError("expected input_")
529-
<< dimName << " - 1 + pad_" << padBeforeName << " + pad_"
530-
<< padAfterName << " - (kernel_" << dimName
531-
<< " - 1) * dilation_" << dimAxis
532-
<< " to be wholly divisible by stride_" << dimAxis << ", got ("
533-
<< inputSize << " - 1 + " << padBefore << " + " << padAfter
534-
<< " - (" << kernelSize << " - 1) * " << dilation << ") / "
535-
<< stride;
536-
537-
const int64_t calculatedOutSize = calculatedOutSizeMinusOne.value() + 1;
538-
if (outputSize != ShapedType::kDynamic && calculatedOutSize != outputSize)
539-
return op.emitOpError("calculated output ")
540-
<< dimName << " did not match expected: "
541-
<< "calculated=" << calculatedOutSize
542-
<< ", expected=" << outputSize;
543-
544-
return success();
545-
};
546-
547-
// input = [_,IH,IW,_], weight = [_,KH,KW,_], output = [_,OH,OW,_]
548-
if constexpr (std::is_same<T, tosa::Conv2DOp>::value) {
549-
if (failed(verifyOutputSize(
550-
inputType.getDimSize(1), weightType.getDimSize(1),
551-
outputType.getDimSize(1), padding[0], padding[1], strides[0],
552-
dilations[0], "height", "y", "top", "bottom")))
553-
return failure();
554-
555-
if (failed(verifyOutputSize(
556-
inputType.getDimSize(2), weightType.getDimSize(2),
557-
outputType.getDimSize(2), padding[2], padding[3], strides[1],
558-
dilations[1], "width", "x", "left", "right")))
559-
return failure();
560-
}
561-
562-
// input = [_,IH,IW,_], weight = [KH,KW,_,_], output = [_,OH,OW,_]
563-
if constexpr (std::is_same<T, tosa::DepthwiseConv2DOp>::value) {
564-
if (failed(verifyOutputSize(
565-
inputType.getDimSize(1), weightType.getDimSize(0),
566-
outputType.getDimSize(1), padding[0], padding[1], strides[0],
567-
dilations[0], "height", "y", "top", "bottom")))
568-
return failure();
569-
570-
if (failed(verifyOutputSize(
571-
inputType.getDimSize(2), weightType.getDimSize(1),
572-
outputType.getDimSize(2), padding[2], padding[3], strides[1],
573-
dilations[1], "width", "x", "left", "right")))
574-
return failure();
575-
}
576-
577-
// input = [_,ID,IH,IW,_], weight = [_,KD,KH,KW,_], output = [_,OD,OH,OW,_]
578-
if constexpr (std::is_same<T, tosa::Conv3DOp>::value) {
579-
if (failed(verifyOutputSize(
580-
inputType.getDimSize(1), weightType.getDimSize(1),
581-
outputType.getDimSize(1), padding[0], padding[1], strides[0],
582-
dilations[0], "depth", "d", "front", "back")))
583-
return failure();
584-
585-
if (failed(verifyOutputSize(
586-
inputType.getDimSize(2), weightType.getDimSize(2),
587-
outputType.getDimSize(2), padding[2], padding[3], strides[1],
588-
dilations[1], "height", "y", "top", "bottom")))
589-
return failure();
590-
591-
if (failed(verifyOutputSize(
592-
inputType.getDimSize(3), weightType.getDimSize(3),
593-
outputType.getDimSize(3), padding[4], padding[5], strides[2],
594-
dilations[2], "width", "x", "left", "right")))
595-
return failure();
596-
}
597-
}
504+
// TODO: fix and create upstream PR
505+
// const RankedTensorType inputType =
506+
// llvm::dyn_cast<RankedTensorType>(op.getInput().getType());
507+
// const RankedTensorType weightType =
508+
// llvm::dyn_cast<RankedTensorType>(op.getWeight().getType());
509+
510+
// if (inputType && weightType) {
511+
// const auto verifyOutputSize =
512+
// [&op](const int64_t inputSize, const int64_t kernelSize,
513+
// const int64_t outputSize, const int64_t padBefore,
514+
// const int64_t padAfter, const int64_t stride,
515+
// const int64_t dilation, const llvm::StringRef dimName,
516+
// const llvm::StringRef dimAxis,
517+
// const llvm::StringRef padBeforeName,
518+
// const llvm::StringRef padAfterName) -> LogicalResult {
519+
// if (inputSize == ShapedType::kDynamic ||
520+
// kernelSize == ShapedType::kDynamic)
521+
// return success();
522+
523+
// // ERROR_IF: O != idiv_check(I - 1 + pa + pb - (K - 1) * d, s) + 1
524+
525+
// const std::optional<int64_t> calculatedOutSizeMinusOne = idivCheck(
526+
// inputSize - 1 + padBefore + padAfter - (kernelSize - 1) * dilation,
527+
// stride);
528+
// if (!calculatedOutSizeMinusOne.has_value())
529+
// return op.emitOpError("expected input_")
530+
// << dimName << " - 1 + pad_" << padBeforeName << " + pad_"
531+
// << padAfterName << " - (kernel_" << dimName
532+
// << " - 1) * dilation_" << dimAxis
533+
// << " to be wholly divisible by stride_" << dimAxis << ", got
534+
// ("
535+
// << inputSize << " - 1 + " << padBefore << " + " << padAfter
536+
// << " - (" << kernelSize << " - 1) * " << dilation << ") / "
537+
// << stride;
538+
539+
// const int64_t calculatedOutSize = calculatedOutSizeMinusOne.value() +
540+
// 1; if (outputSize != ShapedType::kDynamic && calculatedOutSize !=
541+
// outputSize)
542+
// return op.emitOpError("calculated output ")
543+
// << dimName << " did not match expected: "
544+
// << "calculated=" << calculatedOutSize
545+
// << ", expected=" << outputSize;
546+
547+
// return success();
548+
// };
549+
550+
// // input = [_,IH,IW,_], weight = [_,KH,KW,_], output = [_,OH,OW,_]
551+
// if constexpr (std::is_same<T, tosa::Conv2DOp>::value) {
552+
// if (failed(verifyOutputSize(
553+
// inputType.getDimSize(1), weightType.getDimSize(1),
554+
// outputType.getDimSize(1), padding[0], padding[1], strides[0],
555+
// dilations[0], "height", "y", "top", "bottom")))
556+
// return failure();
557+
558+
// if (failed(verifyOutputSize(
559+
// inputType.getDimSize(2), weightType.getDimSize(2),
560+
// outputType.getDimSize(2), padding[2], padding[3], strides[1],
561+
// dilations[1], "width", "x", "left", "right")))
562+
// return failure();
563+
// }
564+
565+
// // input = [_,IH,IW,_], weight = [KH,KW,_,_], output = [_,OH,OW,_]
566+
// if constexpr (std::is_same<T, tosa::DepthwiseConv2DOp>::value) {
567+
// if (failed(verifyOutputSize(
568+
// inputType.getDimSize(1), weightType.getDimSize(0),
569+
// outputType.getDimSize(1), padding[0], padding[1], strides[0],
570+
// dilations[0], "height", "y", "top", "bottom")))
571+
// return failure();
572+
573+
// if (failed(verifyOutputSize(
574+
// inputType.getDimSize(2), weightType.getDimSize(1),
575+
// outputType.getDimSize(2), padding[2], padding[3], strides[1],
576+
// dilations[1], "width", "x", "left", "right")))
577+
// return failure();
578+
// }
579+
580+
// // input = [_,ID,IH,IW,_], weight = [_,KD,KH,KW,_], output =
581+
// [_,OD,OH,OW,_] if constexpr (std::is_same<T, tosa::Conv3DOp>::value) {
582+
// if (failed(verifyOutputSize(
583+
// inputType.getDimSize(1), weightType.getDimSize(1),
584+
// outputType.getDimSize(1), padding[0], padding[1], strides[0],
585+
// dilations[0], "depth", "d", "front", "back")))
586+
// return failure();
587+
588+
// if (failed(verifyOutputSize(
589+
// inputType.getDimSize(2), weightType.getDimSize(2),
590+
// outputType.getDimSize(2), padding[2], padding[3], strides[1],
591+
// dilations[1], "height", "y", "top", "bottom")))
592+
// return failure();
593+
594+
// if (failed(verifyOutputSize(
595+
// inputType.getDimSize(3), weightType.getDimSize(3),
596+
// outputType.getDimSize(3), padding[4], padding[5], strides[2],
597+
// dilations[2], "width", "x", "left", "right")))
598+
// return failure();
599+
// }
600+
// }
598601

599602
const RankedTensorType biasType =
600603
llvm::dyn_cast<RankedTensorType>(op.getBias().getType());
@@ -1007,6 +1010,20 @@ static void buildConvOpWithQuantInfo(OpBuilder &builder, OperationState &result,
10071010
result.addTypes(finalOutputType);
10081011
}
10091012

1013+
// Handles grouped convolution
1014+
static void buildConvOpWithQuantInfo(OpBuilder &builder, OperationState &result,
1015+
Type outputType, Value input, Value weight,
1016+
Value bias, DenseI64ArrayAttr pad,
1017+
DenseI64ArrayAttr stride,
1018+
DenseI64ArrayAttr dilation,
1019+
mlir::IntegerAttr group) {
1020+
TypeAttr accType;
1021+
buildConvOpWithQuantInfo(builder, result, outputType, input, weight, bias,
1022+
pad, stride, dilation, accType);
1023+
if (group)
1024+
result.addAttribute("group", group);
1025+
}
1026+
10101027
/// Handles tosa.transpose_conv2d which has outpad and output shape
10111028
/// attributes.
10121029
static void

0 commit comments

Comments
 (0)