@@ -33,17 +33,25 @@ using namespace Fortran::runtime::cuda;
33
33
namespace {
34
34
35
35
template <typename OpTy>
36
- static bool isBoxGlobal (OpTy op) {
36
+ static bool needDoubleDescriptor (OpTy op) {
37
37
if (auto declareOp =
38
38
mlir::dyn_cast_or_null<fir::DeclareOp>(op.getBox ().getDefiningOp ())) {
39
39
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 ;
41
44
return true ;
45
+ }
42
46
} else if (auto declareOp = mlir::dyn_cast_or_null<hlfir::DeclareOp>(
43
47
op.getBox ().getDefiningOp ())) {
44
48
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 ;
46
53
return true ;
54
+ }
47
55
}
48
56
return false ;
49
57
}
@@ -100,7 +108,7 @@ struct CufAllocateOpConversion
100
108
101
109
// TODO: Allocation of module variable will need more work as the descriptor
102
110
// will be duplicated and needs to be synced after allocation.
103
- if (isBoxGlobal (op))
111
+ if (needDoubleDescriptor (op))
104
112
return mlir::failure ();
105
113
106
114
// Allocation for local descriptor falls back on the standard runtime
@@ -125,7 +133,7 @@ struct CufDeallocateOpConversion
125
133
mlir::PatternRewriter &rewriter) const override {
126
134
// TODO: Allocation of module variable will need more work as the descriptor
127
135
// will be duplicated and needs to be synced after allocation.
128
- if (isBoxGlobal (op))
136
+ if (needDoubleDescriptor (op))
129
137
return mlir::failure ();
130
138
131
139
// Deallocation for local descriptor falls back on the standard runtime
@@ -274,9 +282,9 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
274
282
return true ;
275
283
});
276
284
target.addDynamicallyLegalOp <cuf::AllocateOp>(
277
- [](::cuf::AllocateOp op) { return isBoxGlobal (op); });
285
+ [](::cuf::AllocateOp op) { return needDoubleDescriptor (op); });
278
286
target.addDynamicallyLegalOp <cuf::DeallocateOp>(
279
- [](::cuf::DeallocateOp op) { return isBoxGlobal (op); });
287
+ [](::cuf::DeallocateOp op) { return needDoubleDescriptor (op); });
280
288
target.addLegalDialect <fir::FIROpsDialect>();
281
289
patterns.insert <CufAllocOpConversion>(ctx, &*dl, &typeConverter);
282
290
patterns.insert <CufAllocateOpConversion, CufDeallocateOpConversion,
0 commit comments