Skip to content

[flang][cuda] Lower cluster_dims values #81636

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 2 commits into from
Feb 13, 2024
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 flang/include/flang/Optimizer/Dialect/FIRAttr.td
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,16 @@ def fir_CUDALaunchBoundsAttr : fir_Attr<"CUDALaunchBounds"> {
let assemblyFormat = "`<` struct(params) `>`";
}

def fir_CUDAClusterDimsAttr : fir_Attr<"CUDAClusterDims"> {
let mnemonic = "cluster_dims";

let parameters = (ins
"mlir::IntegerAttr":$x,
"mlir::IntegerAttr":$y,
"mlir::IntegerAttr":$z
);

let assemblyFormat = "`<` struct(params) `>`";
}

#endif // FIR_DIALECT_FIR_ATTRS
5 changes: 5 additions & 0 deletions flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ static constexpr llvm::StringRef getCUDALaunchBoundsAttrName() {
return "fir.cuda_launch_bounds";
}

/// Attribute to carry CUDA cluster_dims values.
static constexpr llvm::StringRef getCUDAClusterDimsAttrName() {
return "fir.cuda_cluster_dims";
}

/// Attribute to mark that a function argument is a character dummy procedure.
/// Character dummy procedure have special ABI constraints.
static constexpr llvm::StringRef getCharacterProcedureDummyAttrName() {
Expand Down
16 changes: 15 additions & 1 deletion flang/lib/Lower/CallInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ setCUDAAttributes(mlir::func::FuncOp func,
if (auto details =
sym->GetUltimate()
.detailsIf<Fortran::semantics::SubprogramDetails>()) {
mlir::Type i64Ty = mlir::IntegerType::get(func.getContext(), 64);
if (!details->cudaLaunchBounds().empty()) {
assert(details->cudaLaunchBounds().size() >= 2 &&
"expect at least 2 values");
mlir::Type i64Ty = mlir::IntegerType::get(func.getContext(), 64);
auto maxTPBAttr =
mlir::IntegerAttr::get(i64Ty, details->cudaLaunchBounds()[0]);
auto minBPMAttr =
Expand All @@ -557,6 +557,20 @@ setCUDAAttributes(mlir::func::FuncOp func,
fir::CUDALaunchBoundsAttr::get(func.getContext(), maxTPBAttr,
minBPMAttr, ubAttr));
}

if (!details->cudaClusterDims().empty()) {
assert(details->cudaClusterDims().size() == 3 && "expect 3 values");
auto xAttr =
mlir::IntegerAttr::get(i64Ty, details->cudaClusterDims()[0]);
auto yAttr =
mlir::IntegerAttr::get(i64Ty, details->cudaClusterDims()[1]);
auto zAttr =
mlir::IntegerAttr::get(i64Ty, details->cudaClusterDims()[2]);
func.getOperation()->setAttr(
fir::getCUDAClusterDimsAttrName(),
fir::CUDAClusterDimsAttr::get(func.getContext(), xAttr, yAttr,
zAttr));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Dialect/FIRAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,5 @@ void FIROpsDialect::registerAttributes() {
addAttributes<ClosedIntervalAttr, ExactTypeAttr, FortranVariableFlagsAttr,
LowerBoundAttr, PointIntervalAttr, RealAttr, SubclassAttr,
UpperBoundAttr, CUDADataAttributeAttr, CUDAProcAttributeAttr,
CUDALaunchBoundsAttr>();
CUDALaunchBoundsAttr, CUDAClusterDimsAttr>();
}
3 changes: 3 additions & 0 deletions flang/test/Lower/CUDA/cuda-proc-attribute.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ attributes(global) launch_bounds(1, 2) subroutine sub_lbounds1(); end

attributes(global) launch_bounds(1, 2, 3) subroutine sub_lbounds2(); end
! CHECK: func.func @_QPsub_lbounds2() attributes {fir.cuda_attr = #fir.cuda_proc<global>, fir.cuda_launch_bounds = #fir.launch_bounds<maxTPB = 1 : i64, minBPM = 2 : i64, upperBoundClusterSize = 3 : i64>}

attributes(global) cluster_dims(1, 2, 3) subroutine sub_clusterdims1(); end
! CHECK: func.func @_QPsub_clusterdims1() attributes {fir.cuda_attr = #fir.cuda_proc<global>, fir.cuda_cluster_dims = #fir.cluster_dims<x = 1 : i64, y = 2 : i64, z = 3 : i64>}