Skip to content

Extend mma dimension and layout checking to support strided batched matmul and tensor contractions #1761

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

Merged
merged 9 commits into from
Jun 27, 2022
Merged
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
12 changes: 12 additions & 0 deletions torch/csrc/jit/codegen/cuda/mma_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ MmaBuilder& MmaBuilder::operand(MmaOptions::Operand a_or_b) {

// TODO: validate op config
MmaOptions MmaBuilder::build() const {
TORCH_CHECK(
option_.mma_op != nullptr,
"Please configure accumulator tv before using swizzle options.")
return option_;
}

Expand All @@ -53,6 +56,15 @@ void MmaBuilder::configureMma(TensorView* mma_output) const {
mma->configureOptions(option_);
}

void MmaBuilder::accumulatorTv(TensorView* tv) {
TORCH_CHECK(
tv->getMemoryType() == MemoryType::Local, "Mma only outputs to register");
TORCH_CHECK(tv->definition(), "Input cannot be accumulator tv");
auto mma = dynamic_cast<MmaOp*>(tv->definition());
TORCH_CHECK(mma, "Requires mma op output for reduction tv");
option_.mma_op = mma;
}

namespace {

// Utility to get ldmatrix direction a mma layout and operand
Expand Down
7 changes: 7 additions & 0 deletions torch/csrc/jit/codegen/cuda/mma_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ struct MmaOptions {
operand == other.operand &&
accumulator_stride == other.accumulator_stride;
}

// To be inferred by mma builder interface.
MmaOp* mma_op = nullptr;
};

//! User interface for configuring the mma and mma related
Expand Down Expand Up @@ -127,6 +130,10 @@ class TORCH_CUDA_CU_API MmaBuilder {
//! specified mma option.
LoadStoreOpType ldMatrix() const;

//! Store the accumulator tv register reference in mma builder
//! to avoid automatic matching of which mma ops.
void accumulatorTv(TensorView* tv);

//! Fill in mma options in scheduling time.
//! Each mma op in Fusion IR must be configured once before lowering.
//! Mma options are configuration parameters used in lowering to mma
Expand Down
Loading