Skip to content

Commit 5e3c7e3

Browse files
authored
[flang][cuda] Lower cluster_dims values (#81636)
This PR adds a new attribute to carry over the information from `cluster_dims`. The new attribute `CUDAClusterDimsAttr` holds 3 integer attributes and is added to `func.func` operation.
1 parent 7d40ea8 commit 5e3c7e3

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

flang/include/flang/Optimizer/Dialect/FIRAttr.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,16 @@ def fir_CUDALaunchBoundsAttr : fir_Attr<"CUDALaunchBounds"> {
125125
let assemblyFormat = "`<` struct(params) `>`";
126126
}
127127

128+
def fir_CUDAClusterDimsAttr : fir_Attr<"CUDAClusterDims"> {
129+
let mnemonic = "cluster_dims";
130+
131+
let parameters = (ins
132+
"mlir::IntegerAttr":$x,
133+
"mlir::IntegerAttr":$y,
134+
"mlir::IntegerAttr":$z
135+
);
136+
137+
let assemblyFormat = "`<` struct(params) `>`";
138+
}
139+
128140
#endif // FIR_DIALECT_FIR_ATTRS

flang/include/flang/Optimizer/Dialect/FIROpsSupport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ static constexpr llvm::StringRef getCUDALaunchBoundsAttrName() {
8080
return "fir.cuda_launch_bounds";
8181
}
8282

83+
/// Attribute to carry CUDA cluster_dims values.
84+
static constexpr llvm::StringRef getCUDAClusterDimsAttrName() {
85+
return "fir.cuda_cluster_dims";
86+
}
87+
8388
/// Attribute to mark that a function argument is a character dummy procedure.
8489
/// Character dummy procedure have special ABI constraints.
8590
static constexpr llvm::StringRef getCharacterProcedureDummyAttrName() {

flang/lib/Lower/CallInterface.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,10 @@ setCUDAAttributes(mlir::func::FuncOp func,
540540
if (auto details =
541541
sym->GetUltimate()
542542
.detailsIf<Fortran::semantics::SubprogramDetails>()) {
543+
mlir::Type i64Ty = mlir::IntegerType::get(func.getContext(), 64);
543544
if (!details->cudaLaunchBounds().empty()) {
544545
assert(details->cudaLaunchBounds().size() >= 2 &&
545546
"expect at least 2 values");
546-
mlir::Type i64Ty = mlir::IntegerType::get(func.getContext(), 64);
547547
auto maxTPBAttr =
548548
mlir::IntegerAttr::get(i64Ty, details->cudaLaunchBounds()[0]);
549549
auto minBPMAttr =
@@ -557,6 +557,20 @@ setCUDAAttributes(mlir::func::FuncOp func,
557557
fir::CUDALaunchBoundsAttr::get(func.getContext(), maxTPBAttr,
558558
minBPMAttr, ubAttr));
559559
}
560+
561+
if (!details->cudaClusterDims().empty()) {
562+
assert(details->cudaClusterDims().size() == 3 && "expect 3 values");
563+
auto xAttr =
564+
mlir::IntegerAttr::get(i64Ty, details->cudaClusterDims()[0]);
565+
auto yAttr =
566+
mlir::IntegerAttr::get(i64Ty, details->cudaClusterDims()[1]);
567+
auto zAttr =
568+
mlir::IntegerAttr::get(i64Ty, details->cudaClusterDims()[2]);
569+
func.getOperation()->setAttr(
570+
fir::getCUDAClusterDimsAttrName(),
571+
fir::CUDAClusterDimsAttr::get(func.getContext(), xAttr, yAttr,
572+
zAttr));
573+
}
560574
}
561575
}
562576
}

flang/lib/Optimizer/Dialect/FIRAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,5 @@ void FIROpsDialect::registerAttributes() {
299299
addAttributes<ClosedIntervalAttr, ExactTypeAttr, FortranVariableFlagsAttr,
300300
LowerBoundAttr, PointIntervalAttr, RealAttr, SubclassAttr,
301301
UpperBoundAttr, CUDADataAttributeAttr, CUDAProcAttributeAttr,
302-
CUDALaunchBoundsAttr>();
302+
CUDALaunchBoundsAttr, CUDAClusterDimsAttr>();
303303
}

flang/test/Lower/CUDA/cuda-proc-attribute.cuf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ attributes(global) launch_bounds(1, 2) subroutine sub_lbounds1(); end
3838

3939
attributes(global) launch_bounds(1, 2, 3) subroutine sub_lbounds2(); end
4040
! 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>}
41+
42+
attributes(global) cluster_dims(1, 2, 3) subroutine sub_clusterdims1(); end
43+
! 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>}

0 commit comments

Comments
 (0)