Skip to content

Commit

Permalink
Add option to send skinny matmuls to the gpu vector reduction pipeline (
Browse files Browse the repository at this point in the history
iree-org#16818)

This can be enabled with the flag:
`--iree-codegen-llvmgpu-reduce-skinny-matmuls`

which is **off** by default.

Note that this may lead to precision loss.
  • Loading branch information
kuhar authored Mar 18, 2024
1 parent 0e55278 commit eb3dcb5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/src/iree/compiler/Codegen/LLVMGPU/KernelConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ llvm::cl::opt<bool> clGPUUseConvVectorDistributePipeline(
llvm::cl::desc("enable the usage of the conv vector distribution pipeline"),
llvm::cl::init(false));

llvm::cl::opt<bool> clGPUReduceSkinnyMatmuls(
"iree-codegen-llvmgpu-reduce-skinny-matmuls",
llvm::cl::desc("Use vector reduction pipeline for skinny matmul. This may "
"lead to precission loss."),
llvm::cl::init(false));

llvm::cl::opt<bool> clGPUEnableTransformDialectJit(
"iree-codegen-llvmgpu-enable-transform-dialect-jit",
llvm::cl::desc("enable the usage of the transform dialect JIT"),
Expand Down Expand Up @@ -689,6 +695,18 @@ static LogicalResult setContractConfig(mlir::FunctionOpInterface entryPoint,
if (staticNonUnitParallelDimCount <= 1)
return failure();

if (clGPUReduceSkinnyMatmuls) {
// Send 2xNxK matmuls to the vector reduction pipeline, similar to matvec.
// Note: Because of reassociation in the vector reduction pipeline, this may
// lead to precission loss.
if (llvm::all_equal({contractionDims->m.size(), contractionDims->n.size(),
contractionDims->k.size(), size_t{1}}) &&
(bounds[contractionDims->m.front()] <= 2 ||
bounds[contractionDims->n.front()] <= 2)) {
return failure();
}
}

// Don't consider operations that don't have a broadcast, those should go
// through reductions.
if (llvm::any_of(op.getIndexingMapsArray(),
Expand Down

0 comments on commit eb3dcb5

Please sign in to comment.