@@ -457,6 +457,10 @@ static constexpr IntrinsicHandler cudaHandlers[]{
457457 static_cast <CUDAIntrinsicLibrary::SubroutineGenerator>(&CI::genSyncWarp),
458458 {},
459459 /* isElemental=*/ false },
460+ {" this_cluster" ,
461+ static_cast <CUDAIntrinsicLibrary::ElementalGenerator>(&CI::genThisCluster),
462+ {},
463+ /* isElemental=*/ false },
460464 {" this_grid" ,
461465 static_cast <CUDAIntrinsicLibrary::ElementalGenerator>(&CI::genThisGrid),
462466 {},
@@ -1122,6 +1126,44 @@ void CUDAIntrinsicLibrary::genSyncWarp(
11221126 mlir::NVVM::SyncWarpOp::create (builder, loc, fir::getBase (args[0 ]));
11231127}
11241128
1129+ // THIS_CLUSTER
1130+ mlir::Value
1131+ CUDAIntrinsicLibrary::genThisCluster (mlir::Type resultType,
1132+ llvm::ArrayRef<mlir::Value> args) {
1133+ assert (args.size () == 0 );
1134+ auto recTy = mlir::cast<fir::RecordType>(resultType);
1135+ assert (recTy && " RecordType expepected" );
1136+ mlir::Value res = fir::AllocaOp::create (builder, loc, resultType);
1137+ mlir::Type i32Ty = builder.getI32Type ();
1138+
1139+ // SIZE
1140+ mlir::Value size = mlir::NVVM::ClusterDim::create (builder, loc, i32Ty);
1141+ auto sizeFieldName = recTy.getTypeList ()[1 ].first ;
1142+ mlir::Type sizeFieldTy = recTy.getTypeList ()[1 ].second ;
1143+ mlir::Type fieldIndexType = fir::FieldType::get (resultType.getContext ());
1144+ mlir::Value sizeFieldIndex = fir::FieldIndexOp::create (
1145+ builder, loc, fieldIndexType, sizeFieldName, recTy,
1146+ /* typeParams=*/ mlir::ValueRange{});
1147+ mlir::Value sizeCoord = fir::CoordinateOp::create (
1148+ builder, loc, builder.getRefType (sizeFieldTy), res, sizeFieldIndex);
1149+ fir::StoreOp::create (builder, loc, size, sizeCoord);
1150+
1151+ // RANK
1152+ mlir::Value rank = mlir::NVVM::ClusterId::create (builder, loc, i32Ty);
1153+ mlir::Value one = builder.createIntegerConstant (loc, i32Ty, 1 );
1154+ rank = mlir::arith::AddIOp::create (builder, loc, rank, one);
1155+ auto rankFieldName = recTy.getTypeList ()[2 ].first ;
1156+ mlir::Type rankFieldTy = recTy.getTypeList ()[2 ].second ;
1157+ mlir::Value rankFieldIndex = fir::FieldIndexOp::create (
1158+ builder, loc, fieldIndexType, rankFieldName, recTy,
1159+ /* typeParams=*/ mlir::ValueRange{});
1160+ mlir::Value rankCoord = fir::CoordinateOp::create (
1161+ builder, loc, builder.getRefType (rankFieldTy), res, rankFieldIndex);
1162+ fir::StoreOp::create (builder, loc, rank, rankCoord);
1163+
1164+ return res;
1165+ }
1166+
11251167// THIS_GRID
11261168mlir::Value
11271169CUDAIntrinsicLibrary::genThisGrid (mlir::Type resultType,
0 commit comments