Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed implicit split-k while moving from conv to gemm #1527

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,14 @@ void AffixTuningParameters::affixTuningParametersImpl(
validParams.gemmKPack);
const bool requiredPadding = !(paddedGemmSize == origGemmSize);

int64_t gemmKBlocks = 1;
PopulateParamsInfo info = PopulateParamsInfo::fromOp(op);
auto maybeWrwOp = (info.kernelType == KernelType::ConvBwdWeight);
if (maybeWrwOp &&
isWrWAtomicKernel(info.gemmFeatures, info.gemmAType, requiredPadding)) {
auto res = calculateKBlockNum(
info.batchSize, paddedGemmSize, validParams.gemmMPerBlock,
validParams.gemmNPerBlock, validParams.gemmKPerBlock,
validParams.gemmKPack, info.numCu, gemmKBlocks);
validParams.gemmKPack, info.numCu, validParams.splitKFactor);

if (failed(res)) {
LLVM_DEBUG(llvm::dbgs()
Expand All @@ -164,10 +163,6 @@ void AffixTuningParameters::affixTuningParametersImpl(
}
}

// Set kblocks attribute only for backward weight convolutions.
if (auto bwdOp = dyn_cast<ConvBwdWeightOp>(op.getOperation()))
bwdOp->setAttr(bwdOp.getKBlocksAttrName(), b.getIndexAttr(gemmKBlocks));

int64_t waveSize = rock::lookupArchInfo(op.getArch()).waveSize;
RockAccelTuningParamAttrInterface gemmParams;
Attribute gemmParamsAttr =
Expand Down
16 changes: 10 additions & 6 deletions mlir/lib/Dialect/Rock/Transforms/ConvToGemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ struct MatchLayoutsToInput final
}
};

// TODO (ravil): remove
/// Lowerings for particular convolution algorithms (TODO, new file?)
LogicalResult backwardWeightAtomicAdd(ConvBwdWeightOp op, PatternRewriter &b) {
Location loc = op.getLoc();
Expand Down Expand Up @@ -1169,11 +1170,6 @@ struct ConvRewritePattern : public OpRewritePattern<T> {
maybeGemmExtraPad = GemmSize{-1, -1, -1, -1};
}

if (ConvOpType::BwdWeight == convOpType &&
isWrWAtomicKernel(features, dataType, maybeGemmExtraPad.has_value())) {
return backwardWeightAtomicAdd(cast<ConvBwdWeightOp>(op), b);
}

// Transform filter tensor.

// set layout attribute.
Expand Down Expand Up @@ -1362,8 +1358,16 @@ struct ConvRewritePattern : public OpRewritePattern<T> {
gemmB = arguments[fields.gridwiseGemmArgumentPosition[1]];
gemmC = arguments[fields.gridwiseGemmArgumentPosition[2]];

// Emit rock.gemm op.
auto storeMethod = b.getAttr<StoreMethodAttr>(StoreMethod::Set);

if (ConvOpType::BwdWeight == convOpType &&
isWrWAtomicKernel(features, dataType, maybeGemmExtraPad.has_value())) {
const int64_t splitKFactor = op.getParams()->getSplitKFactor();
if (splitKFactor == 1)
storeMethod = b.getAttr<StoreMethodAttr>(StoreMethod::AtomicAdd);
}

// Emit rock.gemm op.
b.create<GemmOp>(loc, getResultType(op, gemmC), gemmA, gemmB, gemmC,
/*aTransposed=*/b.getUnitAttr(), /*bTransposed=*/nullptr,
/*cTransposed=*/nullptr, op.getArchAttr(),
Expand Down
7 changes: 6 additions & 1 deletion mlir/lib/Dialect/Rock/utility/loweringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ bool mlir::rock::isValidBlockSize(int64_t blockSize, int64_t kPerBlock,

bool mlir::rock::isWrWAtomicKernel(GemmFeatures features, Type dataType,
bool requiredPadding) {
// TODO (ravil): do we need `!requiredPadding`?
// return isAccel(features) &&
// bitEnumContainsAll(features, GemmFeatures::atomic_add) &&
// (dataType.isF32() || dataType.isF16()) && !requiredPadding;

return isAccel(features) &&
bitEnumContainsAll(features, GemmFeatures::atomic_add) &&
(dataType.isF32() || dataType.isF16()) && !requiredPadding;
(dataType.isF32() || dataType.isF16());
}

bool mlir::rock::isAccel(GemmFeatures features) {
Expand Down