Skip to content
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
4 changes: 2 additions & 2 deletions flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def cuf_AllocateOp : cuf_Op<"allocate", [AttrSizedOperandSegments,
Arg<Optional<AnyRefOrBoxType>, "", [MemWrite]>:$pinned,
Arg<Optional<AnyRefOrBoxType>, "", [MemRead]>:$source,
cuf_DataAttributeAttr:$data_attr, UnitAttr:$hasStat,
UnitAttr:$hasDoubleDescriptor);
UnitAttr:$hasDoubleDescriptor, UnitAttr:$pointer);

let results = (outs AnyIntegerType:$stat);

Expand Down Expand Up @@ -129,7 +129,7 @@ def cuf_DeallocateOp : cuf_Op<"deallocate",
let arguments = (ins Arg<fir_ReferenceType, "", [MemRead, MemWrite]>:$box,
Arg<Optional<AnyRefOrBoxType>, "", [MemWrite]>:$errmsg,
cuf_DataAttributeAttr:$data_attr, UnitAttr:$hasStat,
UnitAttr:$hasDoubleDescriptor);
UnitAttr:$hasDoubleDescriptor, UnitAttr:$pointer);

let results = (outs AnyIntegerType:$stat);

Expand Down
6 changes: 4 additions & 2 deletions flang/lib/Lower/Allocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ class AllocateStmtHelper {
builder, loc, retTy, box.getAddr(), errmsg, stream, pinned,
source, cudaAttr,
errorManager.hasStatSpec() ? builder.getUnitAttr() : nullptr,
doubleDescriptors ? builder.getUnitAttr() : nullptr)
doubleDescriptors ? builder.getUnitAttr() : nullptr,
box.isPointer() ? builder.getUnitAttr() : nullptr)
.getResult();
}

Expand Down Expand Up @@ -873,7 +874,8 @@ static mlir::Value genCudaDeallocate(fir::FirOpBuilder &builder,
return cuf::DeallocateOp::create(
builder, loc, retTy, box.getAddr(), errmsg, cudaAttr,
errorManager.hasStatSpec() ? builder.getUnitAttr() : nullptr,
doubleDescriptors ? builder.getUnitAttr() : nullptr)
doubleDescriptors ? builder.getUnitAttr() : nullptr,
box.isPointer() ? builder.getUnitAttr() : nullptr)
.getResult();
}

Expand Down
10 changes: 1 addition & 9 deletions flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,7 @@ struct CUFAllocateOpConversion
fir::FirOpBuilder builder(rewriter, mod);
mlir::Location loc = op.getLoc();

bool isPointer = false;

if (auto declareOp =
mlir::dyn_cast_or_null<fir::DeclareOp>(op.getBox().getDefiningOp()))
if (declareOp.getFortranAttrs() &&
bitEnumContainsAny(*declareOp.getFortranAttrs(),
fir::FortranVariableFlagsEnum::pointer))
isPointer = true;

bool isPointer = op.getPointer();
if (op.getHasDoubleDescriptor()) {
// Allocation for module variable are done with custom runtime entry point
// so the descriptors can be synchronized.
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Fir/CUDA/cuda-allocate.fir
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func.func @_QQallocate_stream() {
func.func @_QPp_alloc() {
%0 = cuf.alloc !fir.box<!fir.ptr<!fir.array<?xcomplex<f32>>>> {bindc_name = "complex_array", data_attr = #cuf.cuda<device>, uniq_name = "_QFp_allocEcomplex_array"} -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xcomplex<f32>>>>>
%4 = fir.declare %0 {data_attr = #cuf.cuda<device>, fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFp_allocEcomplex_array"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xcomplex<f32>>>>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xcomplex<f32>>>>>
%9 = cuf.allocate %4 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xcomplex<f32>>>>> {data_attr = #cuf.cuda<device>} -> i32
%9 = cuf.allocate %4 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xcomplex<f32>>>>> {data_attr = #cuf.cuda<device>, pointer} -> i32
return
}

Expand All @@ -201,7 +201,7 @@ func.func @_QPpointer_source() {
%5 = cuf.alloc !fir.box<!fir.ptr<!fir.array<?x?xf32>>> {bindc_name = "a_d", data_attr = #cuf.cuda<device>, uniq_name = "_QFpointer_sourceEa_d"} -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
%7 = fir.declare %5 {data_attr = #cuf.cuda<device>, fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFpointer_sourceEa_d"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
%8 = fir.load %4 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
%22 = cuf.allocate %7 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> source(%8 : !fir.box<!fir.ptr<!fir.array<?x?xf32>>>) {data_attr = #cuf.cuda<device>} -> i32
%22 = cuf.allocate %7 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> source(%8 : !fir.box<!fir.ptr<!fir.array<?x?xf32>>>) {data_attr = #cuf.cuda<device>, pointer} -> i32
return
}

Expand All @@ -226,7 +226,7 @@ func.func @_QQpointer_sync() attributes {fir.bindc_name = "test"} {
%3 = fir.convert %c1 : (index) -> i64
%4 = fir.convert %c10_i32 : (i32) -> i64
fir.call @_FortranAAllocatableSetBounds(%2, %c0_i32, %3, %4) fastmath<contract> : (!fir.ref<!fir.box<none>>, i32, i64, i64) -> ()
%6 = cuf.allocate %1 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>> {data_attr = #cuf.cuda<device>, hasDoubleDescriptor} -> i32
%6 = cuf.allocate %1 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>> {data_attr = #cuf.cuda<device>, hasDoubleDescriptor, pointer} -> i32
return
}

Expand All @@ -246,7 +246,7 @@ func.func @_QMmod1Ppointer_source_global() {
%2 = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?xf32>>> {bindc_name = "a", uniq_name = "_QMmod1Fallocate_source_globalEa"}
%6 = fir.declare %2 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMmod1Fallocate_source_globalEa"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
%7 = fir.load %6 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
%21 = cuf.allocate %1 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> source(%7 : !fir.box<!fir.ptr<!fir.array<?x?xf32>>>) {data_attr = #cuf.cuda<device>, hasDoubleDescriptor} -> i32
%21 = cuf.allocate %1 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> source(%7 : !fir.box<!fir.ptr<!fir.array<?x?xf32>>>) {data_attr = #cuf.cuda<device>, hasDoubleDescriptor, pointer} -> i32
return
}

Expand Down
8 changes: 8 additions & 0 deletions flang/test/Lower/CUDA/cuda-allocatable.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ end
! CHECK: %[[FLASE_CONV:.*]] = fir.convert %[[FALSE]] : (i1) -> !fir.logical<4>
! CHECK: fir.store %[[FLASE_CONV]] to %[[PLOG_DECL]]#0 : !fir.ref<!fir.logical<4>>

subroutine devicepointer()
integer, device, pointer :: i(:)
allocate(i(10))
end

! CHECK-LABEL: func.func @_QPdevicepointer()
! CHECK: cuf.allocate{{.*}}pointer

subroutine cuda_component()
use globals
type(t1), pointer, dimension(:) :: d
Expand Down
Loading