@@ -33,17 +33,25 @@ using namespace Fortran::runtime::cuda;
3333namespace {
3434
3535template <typename OpTy>
36- static bool isBoxGlobal (OpTy op) {
36+ static bool needDoubleDescriptor (OpTy op) {
3737 if (auto declareOp =
3838 mlir::dyn_cast_or_null<fir::DeclareOp>(op.getBox ().getDefiningOp ())) {
3939 if (mlir::isa_and_nonnull<fir::AddrOfOp>(
40- declareOp.getMemref ().getDefiningOp ()))
40+ declareOp.getMemref ().getDefiningOp ())) {
41+ if (declareOp.getDataAttr () &&
42+ *declareOp.getDataAttr () == cuf::DataAttribute::Pinned)
43+ return false ;
4144 return true ;
45+ }
4246 } else if (auto declareOp = mlir::dyn_cast_or_null<hlfir::DeclareOp>(
4347 op.getBox ().getDefiningOp ())) {
4448 if (mlir::isa_and_nonnull<fir::AddrOfOp>(
45- declareOp.getMemref ().getDefiningOp ()))
49+ declareOp.getMemref ().getDefiningOp ())) {
50+ if (declareOp.getDataAttr () &&
51+ *declareOp.getDataAttr () == cuf::DataAttribute::Pinned)
52+ return false ;
4653 return true ;
54+ }
4755 }
4856 return false ;
4957}
@@ -100,7 +108,7 @@ struct CufAllocateOpConversion
100108
101109 // TODO: Allocation of module variable will need more work as the descriptor
102110 // will be duplicated and needs to be synced after allocation.
103- if (isBoxGlobal (op))
111+ if (needDoubleDescriptor (op))
104112 return mlir::failure ();
105113
106114 // Allocation for local descriptor falls back on the standard runtime
@@ -125,7 +133,7 @@ struct CufDeallocateOpConversion
125133 mlir::PatternRewriter &rewriter) const override {
126134 // TODO: Allocation of module variable will need more work as the descriptor
127135 // will be duplicated and needs to be synced after allocation.
128- if (isBoxGlobal (op))
136+ if (needDoubleDescriptor (op))
129137 return mlir::failure ();
130138
131139 // Deallocation for local descriptor falls back on the standard runtime
@@ -274,9 +282,9 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
274282 return true ;
275283 });
276284 target.addDynamicallyLegalOp <cuf::AllocateOp>(
277- [](::cuf::AllocateOp op) { return isBoxGlobal (op); });
285+ [](::cuf::AllocateOp op) { return needDoubleDescriptor (op); });
278286 target.addDynamicallyLegalOp <cuf::DeallocateOp>(
279- [](::cuf::DeallocateOp op) { return isBoxGlobal (op); });
287+ [](::cuf::DeallocateOp op) { return needDoubleDescriptor (op); });
280288 target.addLegalDialect <fir::FIROpsDialect>();
281289 patterns.insert <CufAllocOpConversion>(ctx, &*dl, &typeConverter);
282290 patterns.insert <CufAllocateOpConversion, CufDeallocateOpConversion,
0 commit comments