diff options
| author | agozillon <Andrew.Gozillon@amd.com> | 2024-10-24 06:14:52 -0500 |
|---|---|---|
| committer | agozillon <Andrew.Gozillon@amd.com> | 2024-10-24 06:14:52 -0500 |
| commit | ab2b7d046e51f997d9f3bd23183d8139e2371542 (patch) | |
| tree | a65c5e58428cde025e2db2d68e9798cd0beb4298 | |
| parent | ea3534b385a713639953fb5dfd287af87b52bead (diff) | |
| parent | 8f16f9f1d0919b8642d5bd93268deb5c10b40b7a (diff) | |
[𝘀𝗽𝗿] initial versionusers/agozillon/openmpmlir-descriptor-explicit-member-map-lowering-changes-2
Created using spr 1.3.4
89 files changed, 1630 insertions, 323 deletions
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 626539cb7bde..348c1b9c2b8b 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -895,7 +895,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { TypeAttr:$var_type, Optional<OpenMP_PointerLikeType>:$var_ptr_ptr, Variadic<OpenMP_PointerLikeType>:$members, - OptionalAttr<AnyIntElementsAttr>:$members_index, + OptionalAttr<IndexListArrayAttr>:$members_index, Variadic<OpenMP_MapBoundsType>:$bounds, /* rank-0 to rank-{n-1} */ OptionalAttr<UI64Attr>:$map_type, OptionalAttr<VariableCaptureKindAttr>:$map_capture_type, diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index e1df647d6a3c..8d31cda3a33e 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -1395,16 +1395,15 @@ static void printMapClause(OpAsmPrinter &p, Operation *op, } static ParseResult parseMembersIndex(OpAsmParser &parser, - DenseIntElementsAttr &membersIdx) { - SmallVector<APInt> values; - int64_t value; - int64_t shape[2] = {0, 0}; - unsigned shapeTmp = 0; + ArrayAttr &membersIdx) { + SmallVector<Attribute> values, memberIdxs; + auto parseIndices = [&]() -> ParseResult { + int64_t value; if (parser.parseInteger(value)) return failure(); - shapeTmp++; - values.push_back(APInt(32, value, /*isSigned=*/true)); + values.push_back(IntegerAttr::get(parser.getBuilder().getIntegerType(64), + APInt(64, value, /*isSigned=*/false))); return success(); }; @@ -1418,52 +1417,29 @@ static ParseResult parseMembersIndex(OpAsmParser &parser, if (failed(parser.parseRSquare())) return failure(); - // Only set once, if any indices are not the same size - // we error out in the next check as that's unsupported - if (shape[1] == 0) - shape[1] = shapeTmp; - - // Verify that the recently parsed list is equal to the - // first one we parsed, they must be equal lengths to - // keep the rectangular shape DenseIntElementsAttr - // requires - if (shapeTmp != shape[1]) - return failure(); - - shapeTmp = 0; - shape[0]++; + memberIdxs.push_back(ArrayAttr::get(parser.getContext(), values)); + values.clear(); } while (succeeded(parser.parseOptionalComma())); - if (!values.empty()) { - ShapedType valueType = - VectorType::get(shape, IntegerType::get(parser.getContext(), 32)); - membersIdx = DenseIntElementsAttr::get(valueType, values); - } + if (!memberIdxs.empty()) + membersIdx = ArrayAttr::get(parser.getContext(), memberIdxs); return success(); } static void printMembersIndex(OpAsmPrinter &p, MapInfoOp op, - DenseIntElementsAttr membersIdx) { - llvm::ArrayRef<int64_t> shape = membersIdx.getShapedType().getShape(); - assert(shape.size() <= 2); - + ArrayAttr membersIdx) { if (!membersIdx) return; - for (int i = 0; i < shape[0]; ++i) { + llvm::interleaveComma(membersIdx, p, [&p](Attribute v) { p << "["; - int rowOffset = i * shape[1]; - for (int j = 0; j < shape[1]; ++j) { - p << membersIdx.getValues<int32_t>()[rowOffset + j]; - if ((j + 1) < shape[1]) - p << ","; - } + auto memberIdx = cast<ArrayAttr>(v); + llvm::interleaveComma(memberIdx.getValue(), p, [&p](Attribute v2) { + p << cast<IntegerAttr>(v2).getInt(); + }); p << "]"; - - if ((i + 1) < shape[0]) - p << ", "; - } + }); } static void printCaptureType(OpAsmPrinter &p, Operation *op, diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index 27cd38dc3c62..8b932d966b4d 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -2386,46 +2386,36 @@ static int getMapDataMemberIdx(MapInfoData &mapData, omp::MapInfoOp memberOp) { static omp::MapInfoOp getFirstOrLastMappedMemberPtr(omp::MapInfoOp mapInfo, bool first) { - DenseIntElementsAttr indexAttr = mapInfo.getMembersIndexAttr(); - + ArrayAttr indexAttr = mapInfo.getMembersIndexAttr(); // Only 1 member has been mapped, we can return it. if (indexAttr.size() == 1) - if (auto mapOp = - dyn_cast<omp::MapInfoOp>(mapInfo.getMembers()[0].getDefiningOp())) - return mapOp; + return cast<omp::MapInfoOp>(mapInfo.getMembers()[0].getDefiningOp()); - llvm::ArrayRef<int64_t> shape = indexAttr.getShapedType().getShape(); - llvm::SmallVector<size_t> indices(shape[0]); + llvm::SmallVector<size_t> indices(indexAttr.size()); std::iota(indices.begin(), indices.end(), 0); llvm::sort(indices.begin(), indices.end(), [&](const size_t a, const size_t b) { - auto indexValues = indexAttr.getValues<int32_t>(); - for (int i = 0; i < shape[1]; ++i) { - int aIndex = indexValues[a * shape[1] + i]; - int bIndex = indexValues[b * shape[1] + i]; + auto memberIndicesA = cast<ArrayAttr>(indexAttr[a]); + auto memberIndicesB = cast<ArrayAttr>(indexAttr[b]); + for (const auto it : llvm::zip(memberIndicesA, memberIndicesB)) { + int64_t aIndex = cast<IntegerAttr>(std::get<0>(it)).getInt(); + int64_t bIndex = cast<IntegerAttr>(std::get<1>(it)).getInt(); if (aIndex == bIndex) continue; - if (aIndex != -1 && bIndex == -1) - return false; - - if (aIndex == -1 && bIndex != -1) - return true; - - // A is earlier in the record type layout than B if (aIndex < bIndex) return first; - if (bIndex < aIndex) + if (aIndex > bIndex) return !first; } - // Iterated the entire list and couldn't make a decision, all - // elements were likely the same. Return false, since the sort - // comparator should return false for equal elements. - return false; + // Iterated the up until the end of the smallest member and + // they were found to be equal up to that point, so select + // the member with the lowest index count, so the "parent" + return memberIndicesA.size() < memberIndicesB.size(); }); return llvm::cast<omp::MapInfoOp>( @@ -2596,17 +2586,8 @@ static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers( /*isSigned=*/false); combinedInfo.Sizes.push_back(size); - // TODO: This will need to be expanded to include the whole host of logic for - // the map flags that Clang currently supports (e.g. it should take the map - // flag of the parent map flag, remove the OMP_MAP_TARGET_PARAM and do some - // further case specific flag modifications). For the moment, it handles what - // we support as expected. - llvm::omp::OpenMPOffloadMappingFlags mapFlag = - llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO; - llvm::omp::OpenMPOffloadMappingFlags memberOfFlag = ompBuilder.getMemberOfFlag(combinedInfo.BasePointers.size() - 1); - ompBuilder.setCorrectMemberOfFlag(mapFlag, memberOfFlag); // This creates the initial MEMBER_OF mapping that consists of // the parent/top level container (same as above effectively, except @@ -2615,6 +2596,12 @@ static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers( // only relevant if the structure in its totality is being mapped, // otherwise the above suffices. if (!parentClause.getPartialMap()) { + // TODO: This will need to be expanded to include the whole host of logic + // for the map flags that Clang currently supports (e.g. it should do some + // further case specific flag modifications). For the moment, it handles + // what we support as expected. + llvm::omp::OpenMPOffloadMappingFlags mapFlag = mapData.Types[mapDataIndex]; + ompBuilder.setCorrectMemberOfFlag(mapFlag, memberOfFlag); combinedInfo.Types.emplace_back(mapFlag); combinedInfo.DevicePointers.emplace_back( llvm::OpenMPIRBuilder::DeviceInfoTy::None); @@ -2665,6 +2652,31 @@ static void processMapMembersWithParent( assert(memberDataIdx >= 0 && "could not find mapped member of structure"); + // If we're currently mapping a pointer to a block of data, we must + // initially map the pointer, and then attatch/bind the data with a + // subsequent map to the pointer. This segment of code generates the + // pointer mapping, which can in certain cases be optimised out as Clang + // currently does in its lowering. However, for the moment we do not do so, + // in part as we currently have substantially less information on the data + // being mapped at this stage. + if (checkIfPointerMap(memberClause)) { + auto mapFlag = llvm::omp::OpenMPOffloadMappingFlags( + memberClause.getMapType().value()); + mapFlag &= ~llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM; + mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF; + ompBuilder.setCorrectMemberOfFlag(mapFlag, memberOfFlag); + combinedInfo.Types.emplace_back(mapFlag); + combinedInfo.DevicePointers.emplace_back( + llvm::OpenMPIRBuilder::DeviceInfoTy::None); + combinedInfo.Names.emplace_back( + LLVM::createMappingInformation(memberClause.getLoc(), ompBuilder)); + combinedInfo.BasePointers.emplace_back( + mapData.BasePointers[mapDataIndex]); + combinedInfo.Pointers.emplace_back(mapData.BasePointers[memberDataIdx]); + combinedInfo.Sizes.emplace_back(builder.getInt64( + moduleTranslation.getLLVMModule()->getDataLayout().getPointerSize())); + } + // Same MemberOfFlag to indicate its link with parent and other members // of. auto mapFlag = @@ -2680,7 +2692,10 @@ static void processMapMembersWithParent( mapData.DevicePointers[memberDataIdx]); combinedInfo.Names.emplace_back( LLVM::createMappingInformation(memberClause.getLoc(), ompBuilder)); - combinedInfo.BasePointers.emplace_back(mapData.BasePointers[mapDataIndex]); + uint64_t basePointerIndex = + checkIfPointerMap(memberClause) ? memberDataIdx : mapDataIndex; + combinedInfo.BasePointers.emplace_back( + mapData.BasePointers[basePointerIndex]); combinedInfo.Pointers.emplace_back(mapData.Pointers[memberDataIdx]); combinedInfo.Sizes.emplace_back(mapData.Sizes[memberDataIdx]); } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index 6f11b451fa00..63e53ee2e261 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -2633,8 +2633,8 @@ func.func @omp_map_with_members(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm // CHECK: %[[MAP4:.*]] = omp.map.info var_ptr(%[[ARG4]] : !llvm.ptr, f32) map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""} %mapv5 = omp.map.info var_ptr(%arg4 : !llvm.ptr, f32) map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""} - // CHECK: %[[MAP5:.*]] = omp.map.info var_ptr(%[[ARG5]] : !llvm.ptr, !llvm.struct<(i32, struct<(i32, f32)>)>) map_clauses(from) capture(ByRef) members(%[[MAP3]], %[[MAP4]] : [1,0], [1,1] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "", partial_map = true} - %mapv6 = omp.map.info var_ptr(%arg5 : !llvm.ptr, !llvm.struct<(i32, struct<(i32, f32)>)>) map_clauses(from) capture(ByRef) members(%mapv4, %mapv5 : [1,0], [1,1] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "", partial_map = true} + // CHECK: %[[MAP5:.*]] = omp.map.info var_ptr(%[[ARG5]] : !llvm.ptr, !llvm.struct<(i32, struct<(i32, f32)>)>) map_clauses(from) capture(ByRef) members(%[[MAP3]], %[[MAP4]] : [1, 0], [1, 1] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "", partial_map = true} + %mapv6 = omp.map.info var_ptr(%arg5 : !llvm.ptr, !llvm.struct<(i32, struct<(i32, f32)>)>) map_clauses(from) capture(ByRef) members(%mapv4, %mapv5 : [1, 0], [1, 1] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "", partial_map = true} // CHECK: omp.target_exit_data map_entries(%[[MAP3]], %[[MAP4]], %[[MAP5]] : !llvm.ptr, !llvm.ptr, !llvm.ptr) omp.target_exit_data map_entries(%mapv4, %mapv5, %mapv6 : !llvm.ptr, !llvm.ptr, !llvm.ptr){} diff --git a/mlir/test/Target/LLVMIR/omptarget-nested-ptr-record-type-mapping-host.mlir b/mlir/test/Target/LLVMIR/omptarget-nested-ptr-record-type-mapping-host.mlir new file mode 100644 index 000000000000..5d772a13fe57 --- /dev/null +++ b/mlir/test/Target/LLVMIR/omptarget-nested-ptr-record-type-mapping-host.mlir @@ -0,0 +1,66 @@ +// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s + +// This test checks the offload sizes, map types and base pointers and pointers +// provided to the OpenMP kernel argument structure are correct when lowering +// to LLVM-IR from MLIR when performing explicit member mapping of a record type +// that includes records with pointer members in various locations of the record +// types hierarchy. + +module attributes {omp.is_target_device = false, omp.target_triples = ["amdgcn-amd-amdhsa"]} { + llvm.func @omp_nested_derived_type_alloca_map(%arg0: !llvm.ptr) { + %0 = llvm.mlir.constant(4 : index) : i64 + %1 = llvm.mlir.constant(1 : index) : i64 + %2 = llvm.mlir.constant(2 : index) : i64 + %3 = llvm.mlir.constant(0 : index) : i64 + %4 = llvm.mlir.constant(6 : index) : i64 + %5 = omp.map.bounds lower_bound(%3 : i64) upper_bound(%0 : i64) extent(%0 : i64) stride(%1 : i64) start_idx(%3 : i64) {stride_in_bytes = true} + %6 = llvm.getelementptr %arg0[0, 6] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(f32, struct<(ptr, i64, i32, i8, i8, i8, i8)>, array<10 x i32>, f32, struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>, i32, struct<(f32, array<10 x i32>, struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>, i32)>)> + %7 = llvm.getelementptr %6[0, 2] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(f32, array<10 x i32>, struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>, i32)> + %8 = llvm.getelementptr %7[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> + %9 = omp.map.info var_ptr(%7 : !llvm.ptr, i32) var_ptr_ptr(%8 : !llvm.ptr) map_clauses(tofrom) capture(ByRef) bounds(%5) -> !llvm.ptr {name = ""} + %10 = omp.map.info var_ptr(%7 : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "one_l%nest%array_k"} + %11 = omp.map.info var_ptr(%arg0 : !llvm.ptr, !llvm.struct<(f32, struct<(ptr, i64, i32, i8, i8, i8, i8)>, array<10 x i32>, f32, struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>, i32, struct<(f32, array<10 x i32>, struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>, i32)>)>) map_clauses(tofrom) capture(ByRef) members(%10, %9 : [6,2], [6,2,0] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "one_l", partial_map = true} + omp.target map_entries(%10 -> %arg1, %9 -> %arg2, %11 -> %arg3 : !llvm.ptr, !llvm.ptr, !llvm.ptr) { + omp.terminator + } + llvm.return + } +} + +// CHECK: @.offload_sizes{{.*}} = private unnamed_addr constant [4 x i64] [i64 0, i64 48, i64 8, i64 20] +// CHECK: @.offload_maptypes{{.*}} = private unnamed_addr constant [4 x i64] [i64 32, i64 281474976710659, i64 281474976710659, i64 281474976710675] + +// CHECK: define void @omp_nested_derived_type_alloca_map(ptr %[[ARG:.*]]) { + +// CHECK: %[[NESTED_DTYPE_MEMBER_GEP:.*]] = getelementptr { float, { ptr, i64, i32, i8, i8, i8, i8 }, [10 x i32], float, { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, i32, { float, [10 x i32], { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, i32 } }, ptr %[[ARG]], i32 0, i32 6 +// CHECK: %[[NESTED_STRUCT_PTR_MEMBER_GEP:.*]] = getelementptr { float, [10 x i32], { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, i32 }, ptr %[[NESTED_DTYPE_MEMBER_GEP]], i32 0, i32 2 +// CHECK: %[[NESTED_STRUCT_PTR_MEMBER_BADDR_GEP:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[NESTED_STRUCT_PTR_MEMBER_GEP]], i32 0, i32 0 +// CHECK: %[[NESTED_STRUCT_PTR_MEMBER_BADDR_LOAD:.*]] = load ptr, ptr %[[NESTED_STRUCT_PTR_MEMBER_BADDR_GEP]], align 8 +// CHECK: %[[ARR_OFFSET:.*]] = getelementptr inbounds i32, ptr %[[NESTED_STRUCT_PTR_MEMBER_BADDR_LOAD]], i64 0 +// CHECK: %[[DTYPE_SIZE_SEGMENT_CALC_1:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[NESTED_STRUCT_PTR_MEMBER_GEP]], i64 1 +// CHECK: %[[DTYPE_SIZE_SEGMENT_CALC_2:.*]] = ptrtoint ptr %[[DTYPE_SIZE_SEGMENT_CALC_1]] to i64 +// CHECK: %[[DTYPE_SIZE_SEGMENT_CALC_3:.*]] = ptrtoint ptr %[[NESTED_STRUCT_PTR_MEMBER_GEP]] to i64 +// CHECK: %[[DTYPE_SIZE_SEGMENT_CALC_4:.*]] = sub i64 %[[DTYPE_SIZE_SEGMENT_CALC_2]], %[[DTYPE_SIZE_SEGMENT_CALC_3]] +// CHECK: %[[DTYPE_SIZE_SEGMENT_CALC_5:.*]] = sdiv exact i64 %[[DTYPE_SIZE_SEGMENT_CALC_4]], ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64) + +// CHECK: %[[BASE_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_baseptrs, i32 0, i32 0 +// CHECK: store ptr %[[ARG]], ptr %[[BASE_PTRS]], align 8 +// CHECK: %[[OFFLOAD_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_ptrs, i32 0, i32 0 +// CHECK: store ptr %[[NESTED_STRUCT_PTR_MEMBER_GEP]], ptr %[[OFFLOAD_PTRS]], align 8 +// CHECK: %[[OFFLOAD_SIZES:.*]] = getelementptr inbounds [4 x i64], ptr %.offload_sizes, i32 0, i32 0 +// CHECK: store i64 %[[DTYPE_SIZE_SEGMENT_CALC_5]], ptr %[[OFFLOAD_SIZES]], align 8 + +// CHECK: %[[BASE_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_baseptrs, i32 0, i32 1 +// CHECK: store ptr %[[ARG]], ptr %[[BASE_PTRS]], align 8 +// CHECK: %[[OFFLOAD_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_ptrs, i32 0, i32 1 +// CHECK: store ptr %[[NESTED_STRUCT_PTR_MEMBER_GEP]], ptr %[[OFFLOAD_PTRS]], align 8 + +// CHECK: %[[BASE_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_baseptrs, i32 0, i32 2 +// CHECK: store ptr %[[ARG]], ptr %[[BASE_PTRS]], align 8 +// CHECK: %[[OFFLOAD_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_ptrs, i32 0, i32 2 +// CHECK: store ptr %[[NESTED_STRUCT_PTR_MEMBER_BADDR_GEP]], ptr %[[OFFLOAD_PTRS]], align 8 + +// CHECK: %[[BASE_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_baseptrs, i32 0, i32 3 +// CHECK: store ptr %[[NESTED_STRUCT_PTR_MEMBER_BADDR_GEP]], ptr %[[BASE_PTRS]], align 8 +// CHECK: %[[OFFLOAD_PTRS:.*]] = getelementptr inbounds [4 x ptr], ptr %.offload_ptrs, i32 0, i32 3 +// CHECK: store ptr %[[ARR_OFFSET]], ptr %[[OFFLOAD_PTRS]], align 8 diff --git a/mlir/test/Target/LLVMIR/omptarget-nested-record-type-mapping-host.mlir b/mlir/test/Target/LLVMIR/omptarget-nested-record-type-mapping-host.mlir index 8c1182c839a2..8837b42f70a4 100644 --- a/mlir/test/Target/LLVMIR/omptarget-nested-record-type-mapping-host.mlir +++ b/mlir/test/Target/LLVMIR/omptarget-nested-record-type-mapping-host.mlir @@ -21,7 +21,7 @@ llvm.func @_QQmain() { %9 = llvm.getelementptr %4[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(f32, array<10 x i32>, struct<(f32, i32)>, i32)> %10 = omp.map.bounds lower_bound(%2 : i64) upper_bound(%1 : i64) extent(%0 : i64) stride(%2 : i64) start_idx(%2 : i64) %11 = omp.map.info var_ptr(%9 : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(tofrom) capture(ByRef) bounds(%10) -> !llvm.ptr - %12 = omp.map.info var_ptr(%4 : !llvm.ptr, !llvm.struct<(f32, array<10 x i32>, struct<(f32, i32)>, i32)>) map_clauses(tofrom) capture(ByRef) members(%6, %8, %11 : [3, -1], [2, 1], [1, -1] : !llvm.ptr, !llvm.ptr, !llvm.ptr) -> !llvm.ptr {partial_map = true} + %12 = omp.map.info var_ptr(%4 : !llvm.ptr, !llvm.struct<(f32, array<10 x i32>, struct<(f32, i32)>, i32)>) map_clauses(tofrom) capture(ByRef) members(%6, %8, %11 : [3], [2, 1], [1] : !llvm.ptr, !llvm.ptr, !llvm.ptr) -> !llvm.ptr {partial_map = true} omp.target map_entries(%6 -> %arg0, %8 -> %arg1, %11 -> %arg2, %12 -> %arg3 : !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) { omp.terminator } diff --git a/mlir/test/Target/LLVMIR/omptarget-fortran-allocatable-types-host.mlir b/mlir/test/Target/LLVMIR/omptarget-record-type-with-ptr-member-host.mlir index 6fe77bd228ef..d5ca33fb38f3 100644 --- a/mlir/test/Target/LLVMIR/omptarget-fortran-allocatable-types-host.mlir +++ b/mlir/test/Target/LLVMIR/omptarget-record-type-with-ptr-member-host.mlir @@ -1,20 +1,20 @@ // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s // This test checks the offload sizes, map types and base pointers and pointers -// provided to the OpenMP kernel argument structure are correct when lowering -// to LLVM-IR from MLIR when a fortran allocatable descriptor type is provided -// alongside the omp.map.info, the test utilises mapping of array sections, +// provided to the OpenMP kernel argument structure are correct when lowering +// to LLVM-IR from MLIR when a structure with a pointer member type is provided +// alongside the omp.map.info, the test utilises mapping of array sections, // full arrays and individual allocated scalars. module attributes {omp.is_target_device = false, omp.target_triples = ["amdgcn-amd-amdhsa"]} { - llvm.func @_QQmain() { + llvm.func @main() { %0 = llvm.mlir.constant(5 : index) : i64 %1 = llvm.mlir.constant(2 : index) : i64 %2 = llvm.mlir.constant(1 : index) : i64 - %3 = llvm.mlir.addressof @_QFEfull_arr : !llvm.ptr + %3 = llvm.mlir.addressof @full_arr : !llvm.ptr %4 = llvm.mlir.constant(1 : i64) : i64 - %5 = llvm.alloca %4 x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> {bindc_name = "scalar"} : (i64) -> !llvm.ptr - %6 = llvm.mlir.addressof @_QFEsect_arr : !llvm.ptr + %5 = llvm.alloca %4 x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> : (i64) -> !llvm.ptr + %6 = llvm.mlir.addressof @sect_arr : !llvm.ptr %7 = llvm.mlir.constant(0 : i64) : i64 %8 = llvm.getelementptr %3[0, 7, %7, 0] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> %9 = llvm.load %8 : !llvm.ptr -> i64 @@ -47,11 +47,11 @@ module attributes {omp.is_target_device = false, omp.target_triples = ["amdgcn-a } llvm.return } - llvm.mlir.global internal @_QFEfull_arr() {addr_space = 0 : i32} : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> { + llvm.mlir.global internal @full_arr() {addr_space = 0 : i32} : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> { %0 = llvm.mlir.undef : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> llvm.return %0 : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> } - llvm.mlir.global internal @_QFEsect_arr() {addr_space = 0 : i32} : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> { + llvm.mlir.global internal @sect_arr() {addr_space = 0 : i32} : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> { %0 = llvm.mlir.undef : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> llvm.return %0 : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> } @@ -59,11 +59,11 @@ module attributes {omp.is_target_device = false, omp.target_triples = ["amdgcn-a // CHECK: @[[FULL_ARR_GLOB:.*]] = internal global { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] } undef // CHECK: @[[ARR_SECT_GLOB:.*]] = internal global { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] } undef -// CHECK: @.offload_sizes = private unnamed_addr constant [9 x i64] [i64 0, i64 48, i64 0, i64 0, i64 48, i64 0, i64 0, i64 24, i64 4] -// CHECK: @.offload_maptypes = private unnamed_addr constant [9 x i64] [i64 32, i64 281474976710657, i64 281474976710675, i64 32, i64 1125899906842625, i64 1125899906842643, i64 32, i64 1970324836974593, i64 1970324836974611] -// CHECK: @.offload_mapnames = private constant [9 x ptr] [ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}] +// CHECK: @.offload_sizes = private unnamed_addr constant [12 x i64] [i64 0, i64 48, i64 8, i64 0, i64 0, i64 48, i64 8, i64 0, i64 0, i64 24, i64 8, i64 4] +// CHECK: @.offload_maptypes = private unnamed_addr constant [12 x i64] [i64 32, i64 281474976710659, i64 281474976710659, i64 281474976710675, i64 32, i64 1407374883553283, i64 1407374883553283, i64 1407374883553299, i64 32, i64 2533274790395907, i64 2533274790395907, i64 2533274790395923] +// CHECK: @.offload_mapnames = private constant [12 x ptr] [ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}, ptr @{{.*}}] -// CHECK: define void @_QQmain() +// CHECK: define void @main() // CHECK: %[[SCALAR_ALLOCA:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8 // CHECK: %[[FULL_ARR_SIZE5:.*]] = load i64, ptr getelementptr ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @[[FULL_ARR_GLOB]], i32 0, i32 7, i64 0, i32 1), align 4 // CHECK: %[[FULL_ARR_SIZE4:.*]] = sub i64 %[[FULL_ARR_SIZE5]], 1 @@ -79,67 +79,77 @@ module attributes {omp.is_target_device = false, omp.target_triples = ["amdgcn-a // CHECK: %[[ARR_SECT_SIZE2:.*]] = add i64 %[[ARR_SECT_SIZE3]], 1 // CHECK: %[[ARR_SECT_SIZE1:.*]] = mul i64 1, %[[ARR_SECT_SIZE2]] // CHECK: %[[ARR_SECT_SIZE:.*]] = mul i64 %[[ARR_SECT_SIZE1]], 4 -// CHECK: %[[LFULL_ARR:.*]] = load ptr, ptr @_QFEfull_arr, align 8 +// CHECK: %[[LFULL_ARR:.*]] = load ptr, ptr @full_arr, align 8 // CHECK: %[[FULL_ARR_PTR:.*]] = getelementptr inbounds float, ptr %[[LFULL_ARR]], i64 0 // CHECK: %[[ARR_SECT_OFFSET1:.*]] = mul i64 %[[ARR_SECT_OFFSET2]], 1 -// CHECK: %[[LARR_SECT:.*]] = load ptr, ptr @_QFEsect_arr, align 8 +// CHECK: %[[LARR_SECT:.*]] = load ptr, ptr @sect_arr, align 8 // CHECK: %[[ARR_SECT_PTR:.*]] = getelementptr inbounds i32, ptr %[[LARR_SECT]], i64 %[[ARR_SECT_OFFSET1]] // CHECK: %[[SCALAR_PTR_LOAD:.*]] = load ptr, ptr %[[SCALAR_BASE]], align 8 -// CHECK: %[[FULL_ARR_DESC_SIZE:.*]] = sdiv exact i64 sub (i64 ptrtoint (ptr getelementptr ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEfull_arr, i32 1) to i64), i64 ptrtoint (ptr @_QFEfull_arr to i64)), ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64) -// CHECK: %[[ARR_SECT_DESC_SIZE:.*]] = sdiv exact i64 sub (i64 ptrtoint (ptr getelementptr ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsect_arr, i32 1) to i64), i64 ptrtoint (ptr @_QFEsect_arr to i64)), ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64) +// CHECK: %[[FULL_ARR_DESC_SIZE:.*]] = sdiv exact i64 sub (i64 ptrtoint (ptr getelementptr ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @full_arr, i32 1) to i64), i64 ptrtoint (ptr @full_arr to i64)), ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64) +// CHECK: %[[ARR_SECT_DESC_SIZE:.*]] = sdiv exact i64 sub (i64 ptrtoint (ptr getelementptr ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @sect_arr, i32 1) to i64), i64 ptrtoint (ptr @sect_arr to i64)), ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64) // CHECK: %[[SCALAR_DESC_SZ4:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8 }, ptr %[[SCALAR_ALLOCA]], i32 1 // CHECK: %[[SCALAR_DESC_SZ3:.*]] = ptrtoint ptr %[[SCALAR_DESC_SZ4]] to i64 // CHECK: %[[SCALAR_DESC_SZ2:.*]] = ptrtoint ptr %[[SCALAR_ALLOCA]] to i64 // CHECK: %[[SCALAR_DESC_SZ1:.*]] = sub i64 %[[SCALAR_DESC_SZ3]], %[[SCALAR_DESC_SZ2]] // CHECK: %[[SCALAR_DESC_SZ:.*]] = sdiv exact i64 %[[SCALAR_DESC_SZ1]], ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64) -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 0 -// CHECK: store ptr @_QFEfull_arr, ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 0 -// CHECK: store ptr @_QFEfull_arr, ptr %[[OFFLOADPTRS]], align 8 - -// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [9 x i64], ptr %.offload_sizes, i32 0, i32 0 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 0 +// CHECK: store ptr @full_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 0 +// CHECK: store ptr @full_arr, ptr %[[OFFLOADPTRS]], align 8 +// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [12 x i64], ptr %.offload_sizes, i32 0, i32 0 // CHECK: store i64 %[[FULL_ARR_DESC_SIZE]], ptr %[[OFFLOADSIZES]], align 8 - -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 1 -// CHECK: store ptr @_QFEfull_arr, ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 1 -// CHECK: store ptr @_QFEfull_arr, ptr %[[OFFLOADPTRS]], align 8 -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 2 -// CHECK: store ptr @_QFEfull_arr, ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 2 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 1 +// CHECK: store ptr @full_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 1 +// CHECK: store ptr @full_arr, ptr %[[OFFLOADPTRS]], align 8 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 2 +// CHECK: store ptr @full_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 2 +// CHECK: store ptr @full_arr, ptr %[[OFFLOADPTRS]], align 8 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 3 +// CHECK: store ptr @full_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 3 // CHECK: store ptr %[[FULL_ARR_PTR]], ptr %[[OFFLOADPTRS]], align 8 -// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [9 x i64], ptr %.offload_sizes, i32 0, i32 2 +// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [12 x i64], ptr %.offload_sizes, i32 0, i32 3 // CHECK: store i64 %[[FULL_ARR_SIZE]], ptr %[[OFFLOADSIZES]], align 8 -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 3 -// CHECK: store ptr @_QFEsect_arr, ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 3 -// CHECK: store ptr @_QFEsect_arr, ptr %[[OFFLOADPTRS]], align 8 -// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [9 x i64], ptr %.offload_sizes, i32 0, i32 3 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 4 +// CHECK: store ptr @sect_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 4 +// CHECK: store ptr @sect_arr, ptr %[[OFFLOADPTRS]], align 8 +// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [12 x i64], ptr %.offload_sizes, i32 0, i32 4 // CHECK: store i64 %[[ARR_SECT_DESC_SIZE]], ptr %[[OFFLOADSIZES]], align 8 -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 4 -// CHECK: store ptr @_QFEsect_arr, ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 4 -// CHECK: store ptr @_QFEsect_arr, ptr %[[OFFLOADPTRS]], align 8 -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 5 -// CHECK: store ptr @_QFEsect_arr, ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 5 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 5 +// CHECK: store ptr @sect_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 5 +// CHECK: store ptr @sect_arr, ptr %[[OFFLOADPTRS]], align 8 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 6 +// CHECK: store ptr @sect_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 6 +// CHECK: store ptr @sect_arr, ptr %[[OFFLOADPTRS]], align 8 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 7 +// CHECK: store ptr @sect_arr, ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 7 // CHECK: store ptr %[[ARR_SECT_PTR]], ptr %[[OFFLOADPTRS]], align 8 -// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [9 x i64], ptr %.offload_sizes, i32 0, i32 5 +// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [12 x i64], ptr %.offload_sizes, i32 0, i32 7 // CHECK: store i64 %[[ARR_SECT_SIZE]], ptr %[[OFFLOADSIZES]], align 8 -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 6 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 8 // CHECK: store ptr %[[SCALAR_ALLOCA]], ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 6 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 8 // CHECK: store ptr %[[SCALAR_ALLOCA]], ptr %[[OFFLOADPTRS]], align 8 -// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [9 x i64], ptr %.offload_sizes, i32 0, i32 6 +// CHECK: %[[OFFLOADSIZES:.*]] = getelementptr inbounds [12 x i64], ptr %.offload_sizes, i32 0, i32 8 // CHECK: store i64 %[[SCALAR_DESC_SZ]], ptr %[[OFFLOADSIZES]], align 8 -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 7 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 9 // CHECK: store ptr %[[SCALAR_ALLOCA]], ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 7 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 9 // CHECK: store ptr %[[SCALAR_ALLOCA]], ptr %[[OFFLOADPTRS]], align 8 -// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_baseptrs, i32 0, i32 8 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 10 // CHECK: store ptr %[[SCALAR_ALLOCA]], ptr %[[OFFLOADBASEPTRS]], align 8 -// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [9 x ptr], ptr %.offload_ptrs, i32 0, i32 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 10 +// CHECK: store ptr %[[SCALAR_BASE]], ptr %[[OFFLOADPTRS]], align 8 +// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_baseptrs, i32 0, i32 11 +// CHECK: store ptr %[[SCALAR_BASE]], ptr %[[OFFLOADBASEPTRS]], align 8 +// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [12 x ptr], ptr %.offload_ptrs, i32 0, i32 11 // CHECK: store ptr %[[SCALAR_PTR_LOAD]], ptr %[[OFFLOADPTRS]], align 8 diff --git a/offload/test/offloading/fortran/basic-target-region-1D-array-section.f90 b/offload/test/offloading/fortran/basic-target-region-1D-array-section.f90 index 15795fbcf7f3..61244a965a1b 100644 --- a/offload/test/offloading/fortran/basic-target-region-1D-array-section.f90 +++ b/offload/test/offloading/fortran/basic-target-region-1D-array-section.f90 @@ -1,5 +1,5 @@ -! Basic offloading test of arrays with provided lower -! and upper bounds as specified by OpenMP's sectioning +! Basic offloading test of arrays with provided lower and upper bounds as +! specified by OpenMP's sectioning ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/basic-target-region-3D-array-section.f90 b/offload/test/offloading/fortran/basic-target-region-3D-array-section.f90 index ca0364543c20..2e1c6a61379c 100644 --- a/offload/test/offloading/fortran/basic-target-region-3D-array-section.f90 +++ b/offload/test/offloading/fortran/basic-target-region-3D-array-section.f90 @@ -1,5 +1,5 @@ -! Basic offloading test of a regular array explicitly -! passed within a target region +! Basic offloading test of a regular array explicitly passed within a target +! region ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/basic-target-region-3D-array.f90 b/offload/test/offloading/fortran/basic-target-region-3D-array.f90 index d57581071389..61fced35980f 100644 --- a/offload/test/offloading/fortran/basic-target-region-3D-array.f90 +++ b/offload/test/offloading/fortran/basic-target-region-3D-array.f90 @@ -1,5 +1,5 @@ -! Basic offloading test of a regular array explicitly -! passed within a target region +! Basic offloading test of a regular array explicitly passed within a target +! region ! REQUIRES: flang ! REQUIRES: gpu ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/constant-arr-index.f90 b/offload/test/offloading/fortran/constant-arr-index.f90 index 80440b6836ac..f819f1f0d994 100644 --- a/offload/test/offloading/fortran/constant-arr-index.f90 +++ b/offload/test/offloading/fortran/constant-arr-index.f90 @@ -1,7 +1,5 @@ -! Basic offloading test with a target region -! that checks constant indexing on device -! correctly works (regression test for prior -! bug). +! Basic offloading test with a target region that checks constant indexing on +! device correctly works (regression test for prior bug). ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/declare-target-vars-in-target-region.f90 b/offload/test/offloading/fortran/declare-target-vars-in-target-region.f90 index c0bc9304b303..5410a0681e8e 100644 --- a/offload/test/offloading/fortran/declare-target-vars-in-target-region.f90 +++ b/offload/test/offloading/fortran/declare-target-vars-in-target-region.f90 @@ -1,6 +1,6 @@ -! Offloading test with a target region mapping a declare target -! Fortran array writing some values to it and checking the host -! correctly receives the updates made on the device. +! Offloading test with a target region mapping a declare target Fortran array +! writing some values to it and checking the host correctly receives the +! updates made on the device. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/double-target-call-with-declare-target.f90 b/offload/test/offloading/fortran/double-target-call-with-declare-target.f90 index fa909815757f..f7fef9583214 100644 --- a/offload/test/offloading/fortran/double-target-call-with-declare-target.f90 +++ b/offload/test/offloading/fortran/double-target-call-with-declare-target.f90 @@ -1,7 +1,6 @@ -! Offloading test with two target regions mapping the same -! declare target Fortran array and writing some values to -! it before checking the host correctly receives the -! correct updates made on the device. +! Offloading test with two target regions mapping the same declare target +! Fortran array and writing some values to it before checking the host +! correctly receives the correct updates made on the device. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/dtype-array-constant-index-map.f90 b/offload/test/offloading/fortran/dtype-array-constant-index-map.f90 index 7e168b846f85..e120c95019c6 100644 --- a/offload/test/offloading/fortran/dtype-array-constant-index-map.f90 +++ b/offload/test/offloading/fortran/dtype-array-constant-index-map.f90 @@ -1,17 +1,9 @@ -! Offloading test which maps a specific element of a -! derived type to the device and then accesses the -! element alongside an individual element of an array -! that the derived type contains. In particular, this -! test helps to check that we can replace the constants -! within the kernel with instructions and then replace -! these instructions with the kernel parameters. -! REQUIRES: flang -! UNSUPPORTED: nvptx64-nvidia-cuda -! UNSUPPORTED: nvptx64-nvidia-cuda-LTO -! UNSUPPORTED: aarch64-unknown-linux-gnu -! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO -! UNSUPPORTED: x86_64-unknown-linux-gnu -! UNSUPPORTED: x86_64-unknown-linux-gnu-LTO +! Offloading test which maps a specific element of a derived type to the device +! and then accesses the element alongside an individual element of an array +! that the derived type contains. In particular, this test helps to check that +! we can replace the constants within the kernel with instructions and then +! replace these instructions with the kernel parameters. +! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic module test_0 diff --git a/offload/test/offloading/fortran/dtype-member-map-syntax-1.f90 b/offload/test/offloading/fortran/dtype-member-map-syntax-1.f90 new file mode 100644 index 000000000000..fa4f20149c01 --- /dev/null +++ b/offload/test/offloading/fortran/dtype-member-map-syntax-1.f90 @@ -0,0 +1,109 @@ +! This test checks a number of more complex derived type member mapping +! syntaxes utilising a non-allocatable parent derived type. + +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type dtype2 + integer int + real float + real float_elements(10) + end type dtype2 + + type dtype1 + character (LEN=30) characters + character (LEN=1) character + type(dtype2) number + end type dtype1 + + type nonallocatabledtype + integer elements(20) + type(dtype1) num_chars + integer value + type(dtype2) internal_dtypes(5) + end type nonallocatabledtype + + type (nonallocatabledtype) array_dtype(5) + + !$omp target map(tofrom: array_dtype(5)) + do i = 1, 20 + array_dtype(5)%elements(i) = 20 + i + end do + + array_dtype(5)%num_chars%number%float_elements(5) = 10 + array_dtype(5)%value = 40 + !$omp end target + + print *, array_dtype(5)%elements + print *, array_dtype(5)%num_chars%number%float_elements(5) + print *, array_dtype(5)%value + + !$omp target map(tofrom: array_dtype(4)%elements(3)) + array_dtype(4)%elements(3) = 74 + !$omp end target + + print *, array_dtype(4)%elements(3) + + !$omp target map(tofrom: array_dtype(5)%elements(3:5)) + do i = 3, 5 + array_dtype(5)%elements(i) = i + 1 + end do + !$omp end target + + do i = 3, 5 + print *, array_dtype(5)%elements(i) + end do + + !$omp target map(tofrom: array_dtype(3:5)) + do i = 3, 5 + array_dtype(i)%value = i + 2 + end do + !$omp end target + + do i = 3, 5 + print *, array_dtype(i)%value + end do + + !$omp target map(tofrom: array_dtype(4)%num_chars%number%float_elements(8)) + array_dtype(4)%num_chars%number%float_elements(8) = 250 + !$omp end target + + print *, array_dtype(4)%num_chars%number%float_elements(8) + + !$omp target map(tofrom: array_dtype(4)%num_chars%number%float_elements(5:10)) + do i = 5, 10 + array_dtype(4)%num_chars%number%float_elements(i) = i + 3 + end do + !$omp end target + + do i = 5, 10 + print *, array_dtype(4)%num_chars%number%float_elements(i) + end do + + !$omp target map(tofrom: array_dtype(4)%internal_dtypes(3)%float_elements(4)) + array_dtype(4)%internal_dtypes(3)%float_elements(4) = 200 + !$omp end target + + print *, array_dtype(4)%internal_dtypes(3)%float_elements(4) + +end program main + +! CHECK: 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 +! CHECK: 10. +! CHECK: 40 +! CHECK: 74 +! CHECK: 4 +! CHECK: 5 +! CHECK: 6 +! CHECK: 5 +! CHECK: 6 +! CHECK: 7 +! CHECK: 250. +! CHECK: 8. +! CHECK: 9. +! CHECK: 10. +! CHECK: 11. +! CHECK: 12. +! CHECK: 13. +! CHECK: 200 diff --git a/offload/test/offloading/fortran/dtype-member-map-syntax-2.f90 b/offload/test/offloading/fortran/dtype-member-map-syntax-2.f90 new file mode 100644 index 000000000000..8d666360066d --- /dev/null +++ b/offload/test/offloading/fortran/dtype-member-map-syntax-2.f90 @@ -0,0 +1,176 @@ +! This test checks a number of more complex derived type member mapping +! syntaxes utilising an allocatable parent derived type and mixed +! allocatable members. + +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + implicit none + + integer :: i + integer :: N1, N2 + + type :: vertexes + integer :: test + integer :: testarray(10) + integer(4), allocatable :: vertexx(:) + integer(4), allocatable :: vertexy(:) + end type vertexes + + type testing_tile_type + TYPE(vertexes) :: field + end type testing_tile_type + + type :: dtype + real(4) :: i + type(vertexes), allocatable :: vertexes(:) + TYPE(testing_tile_type), DIMENSION(:), allocatable :: test_tile + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type dtype + + type(dtype) :: alloca_dtype + type(dtype), DIMENSION(:), allocatable :: alloca_dtype_arr + + allocate(alloca_dtype%vertexes(4)) + allocate(alloca_dtype%vertexes(1)%vertexx(10)) + allocate(alloca_dtype%vertexes(1)%vertexy(10)) + allocate(alloca_dtype%vertexes(2)%vertexx(10)) + allocate(alloca_dtype%vertexes(2)%vertexy(10)) + allocate(alloca_dtype%vertexes(3)%vertexx(10)) + allocate(alloca_dtype%vertexes(3)%vertexy(10)) + allocate(alloca_dtype%vertexes(4)%vertexx(10)) + allocate(alloca_dtype%vertexes(4)%vertexy(10)) + allocate(alloca_dtype%test_tile(4)) + allocate(alloca_dtype%test_tile(1)%field%vertexx(10)) + allocate(alloca_dtype%test_tile(1)%field%vertexy(10)) + allocate(alloca_dtype%test_tile(2)%field%vertexx(10)) + allocate(alloca_dtype%test_tile(2)%field%vertexy(10)) + allocate(alloca_dtype%test_tile(3)%field%vertexx(10)) + allocate(alloca_dtype%test_tile(3)%field%vertexy(10)) + allocate(alloca_dtype%test_tile(4)%field%vertexx(10)) + allocate(alloca_dtype%test_tile(4)%field%vertexy(10)) + + allocate(alloca_dtype_arr(3)) + + N1 = 1 + N2 = 2 + +!$omp target map(tofrom: alloca_dtype%vertexes(N1)%test) + alloca_dtype%vertexes(N1)%test = 3 +!$omp end target + +print *, alloca_dtype%vertexes(N1)%test + +!$omp target map(tofrom: alloca_dtype%vertexes(N1)%test, alloca_dtype%vertexes(N2)%test) + alloca_dtype%vertexes(N1)%test = 5 + alloca_dtype%vertexes(N2)%test = 10 +!$omp end target + +print *, alloca_dtype%vertexes(N1)%test +print *, alloca_dtype%vertexes(N2)%test + +!$omp target map(tofrom: alloca_dtype%test_tile(N1)%field%vertexx, & +!$omp alloca_dtype%test_tile(N1)%field%vertexy) + do i = 1, 10 + alloca_dtype%test_tile(N1)%field%vertexx(i) = i + 4 + alloca_dtype%test_tile(N1)%field%vertexy(i) = i + 4 + end do +!$omp end target + +print *, alloca_dtype%test_tile(N1)%field%vertexx +print *, alloca_dtype%test_tile(N1)%field%vertexy + +!$omp target map(tofrom: alloca_dtype%test_tile(N1)%field%test, & +!$omp alloca_dtype%test_tile(N2)%field%test, & +!$omp alloca_dtype%test_tile(N1)%field%vertexy, & +!$omp alloca_dtype%test_tile(N2)%field%vertexy) + alloca_dtype%test_tile(N2)%field%test = 9999 + alloca_dtype%test_tile(N2)%field%vertexy(2) = 9998 + alloca_dtype%test_tile(N1)%field%test = 9997 + alloca_dtype%test_tile(N1)%field%vertexy(2) = 9996 +!$omp end target + +print *, alloca_dtype%test_tile(N1)%field%test +print *, alloca_dtype%test_tile(N2)%field%test +print *, alloca_dtype%test_tile(N1)%field%vertexy(2) +print *, alloca_dtype%test_tile(N2)%field%vertexy(2) + +!$omp target map(tofrom: alloca_dtype%test_tile(N2)%field%vertexy) + alloca_dtype%test_tile(N2)%field%vertexy(2) = 2000 +!$omp end target + +!$omp target map(tofrom: alloca_dtype%vertexes(N1)%vertexx, & +!$omp alloca_dtype%vertexes(N1)%vertexy, & +!$omp alloca_dtype%vertexes(N2)%vertexx, & +!$omp alloca_dtype%vertexes(N2)%vertexy) + do i = 1, 10 + alloca_dtype%vertexes(N1)%vertexx(i) = i * 2 + alloca_dtype%vertexes(N1)%vertexy(i) = i * 2 + alloca_dtype%vertexes(N2)%vertexx(i) = i * 2 + alloca_dtype%vertexes(N2)%vertexy(i) = i * 2 + end do +!$omp end target + +print *, alloca_dtype%vertexes(N1)%vertexx +print *, alloca_dtype%vertexes(N1)%vertexy +print *, alloca_dtype%vertexes(N2)%vertexx +print *, alloca_dtype%vertexes(N2)%vertexy + +!$omp target map(tofrom: alloca_dtype%vertexes(N1)%vertexx, & +!$omp alloca_dtype%vertexes(N1)%vertexy, & +!$omp alloca_dtype%vertexes(4)%vertexy, & +!$omp alloca_dtype%vertexes(4)%vertexx, & +!$omp alloca_dtype%vertexes(N2)%vertexx, & +!$omp alloca_dtype%vertexes(N2)%vertexy) + do i = 1, 10 + alloca_dtype%vertexes(N1)%vertexx(i) = i * 3 + alloca_dtype%vertexes(N1)%vertexy(i) = i * 3 + alloca_dtype%vertexes(4)%vertexx(i) = i * 3 + alloca_dtype%vertexes(4)%vertexy(i) = i * 3 + alloca_dtype%vertexes(N2)%vertexx(i) = i * 3 + alloca_dtype%vertexes(N2)%vertexy(i) = i * 3 + end do +!$omp end target + + + print *, alloca_dtype%vertexes(1)%vertexx + print *, alloca_dtype%vertexes(1)%vertexy + print *, alloca_dtype%vertexes(4)%vertexx + print *, alloca_dtype%vertexes(4)%vertexy + print *, alloca_dtype%vertexes(2)%vertexx + print *, alloca_dtype%vertexes(2)%vertexy + +!$omp target map(tofrom: alloca_dtype_arr(N2)%array_i) + do i = 1, 10 + alloca_dtype_arr(N2)%array_i(i) = i + 2 + end do +!$omp end target + +print *, alloca_dtype_arr(N2)%array_i + +end program main + +! CHECK: 3 +! CHECK: 5 +! CHECK: 10 +! CHECK: 5 6 7 8 9 10 11 12 13 14 +! CHECK: 5 6 7 8 9 10 11 12 13 14 +! CHECK: 9997 +! CHECK: 9999 +! CHECK: 9996 +! CHECK: 9998 +! CHECK: 2 4 6 8 10 12 14 16 18 20 +! CHECK: 2 4 6 8 10 12 14 16 18 20 +! CHECK: 2 4 6 8 10 12 14 16 18 20 +! CHECK: 2 4 6 8 10 12 14 16 18 20 +! CHECK: 3 6 9 12 15 18 21 24 27 30 +! CHECK: 3 6 9 12 15 18 21 24 27 30 +! CHECK: 3 6 9 12 15 18 21 24 27 30 +! CHECK: 3 6 9 12 15 18 21 24 27 30 +! CHECK: 3 6 9 12 15 18 21 24 27 30 +! CHECK: 3 6 9 12 15 18 21 24 27 30 +! CHECK: 3 4 5 6 7 8 9 10 11 12 diff --git a/offload/test/offloading/fortran/dump_map_tables.f90 b/offload/test/offloading/fortran/dump_map_tables.f90 index e25b05b9e04d..efde4ee56ca1 100644 --- a/offload/test/offloading/fortran/dump_map_tables.f90 +++ b/offload/test/offloading/fortran/dump_map_tables.f90 @@ -1,6 +1,6 @@ -! Offloading test with runtine call to ompx_dump_mapping_tables -! Fortran array writing some values and printing the variable mapped to device -! correctly receives the updates made on the device. +! Offloading test with runtine call to ompx_dump_mapping_tables Fortran array +! writing some values and printing the variable mapped to device correctly +! receives the updates made on the device. ! REQUIRES: flang ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO ! UNSUPPORTED: aarch64-unknown-linux-gnu diff --git a/offload/test/offloading/fortran/local-descriptor-map-regress.f90 b/offload/test/offloading/fortran/local-descriptor-map-regress.f90 index 5f628b8ad8c7..e6afc4a6fb9b 100644 --- a/offload/test/offloading/fortran/local-descriptor-map-regress.f90 +++ b/offload/test/offloading/fortran/local-descriptor-map-regress.f90 @@ -1,17 +1,13 @@ -! Small regression test that checks that we do not cause -! a runtime map error in cases where we are required to -! allocate a local variable for the fortran descriptor -! to store into and then load from it, done so by -! re-using the temporary local variable across all -! maps related to the mapped variable and associated -! local variable to make sure that each map does as -! it's intended to do with the original data. This -! prevents blobs of local descriptor data remaining -! attatched on device long after it's supposed to, -! which can cause weird map issues later in susbequent -! function invocations. However, it doesn't avoid a user -! shooting themselves in the foot by mapping data via enter -! and then not providing a corresponding exit. +! Small regression test that checks that we do not cause a runtime map error in +! cases where we are required to allocate a local variable for the fortran +! descriptor to store into and then load from it, done so by re-using the +! temporary local variable across all maps related to the mapped variable and +! associated local variable to make sure that each map does as it is intended +! to do with the original data. This prevents blobs of local descriptor data +! remaining attatched on device long after it's supposed to, which can cause +! weird map issues later in susbequent function invocations. However, it +! doesn't avoid a user shooting themselves in the foot by mapping data via +! enter and then not providing a corresponding exit. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-depend.f90 b/offload/test/offloading/fortran/target-depend.f90 index 1bb320d6bd93..dc9351dd8c20 100644 --- a/offload/test/offloading/fortran/target-depend.f90 +++ b/offload/test/offloading/fortran/target-depend.f90 @@ -1,5 +1,4 @@ -! Offloading test checking the use of the depend clause on -! the target construct +! Offloading test checking the use of the depend clause on the target construct ! REQUIRES: flang, amdgcn-amd-amdhsa ! UNSUPPORTED: nvptx64-nvidia-cuda ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/target-map-all-common-block-members.f90 b/offload/test/offloading/fortran/target-map-all-common-block-members.f90 index f92e5818a764..4e78ed1accf3 100644 --- a/offload/test/offloading/fortran/target-map-all-common-block-members.f90 +++ b/offload/test/offloading/fortran/target-map-all-common-block-members.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of -! mapping all the members of a common block -! to a target region +! Offloading test checking interaction of mapping all the members of a common +! block to a target region ! REQUIRES: flang, amdgcn-amd-amdhsa ! UNSUPPORTED: nvptx64-nvidia-cuda ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array-of-dtype.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array-of-dtype.f90 new file mode 100644 index 000000000000..c430726cfbe9 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array-of-dtype.f90 @@ -0,0 +1,36 @@ +! Offloading test checking interaction of explicit member mapping of an +! allocatable array of derived types contained within an allocatable +! derived type +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: nested_dtype + real(4) :: i + real(4) :: j + integer(4) :: array_i(10) + integer(4) :: k + end type nested_dtype + + type :: dtype + real(4) :: i + integer(4) :: array_i(10) + real(4) :: j + type(nested_dtype), allocatable :: array_dtype(:) + integer(4) :: k + end type dtype + + type(dtype), allocatable :: dtyped + allocate(dtyped) + allocate(dtyped%array_dtype(10)) + +!$omp target map(tofrom: dtyped%array_dtype) + do i = 1, 10 + dtyped%array_dtype(i)%k = i + end do +!$omp end target + + print *, dtyped%array_dtype%k +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array.f90 new file mode 100644 index 000000000000..df51128fc5b7 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array.f90 @@ -0,0 +1,29 @@ +! Offload test that checks an allocatable array within an allocatable derived +! type can be mapped explicitly using member mapping. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: dtype + real(4) :: i + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type dtype + + type(dtype), allocatable :: alloca_dtype + allocate(alloca_dtype) + allocate(alloca_dtype%array_j(10)) + +!$omp target map(tofrom: alloca_dtype%array_j) + do i = 1, 10 + alloca_dtype%array_j(i) = i + end do +!$omp end target + +print *, alloca_dtype%array_j + +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array-v2.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array-v2.f90 new file mode 100644 index 000000000000..54a32160c7a6 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array-v2.f90 @@ -0,0 +1,34 @@ +! Offload test that checks an allocatable derived type can be mapped alongside +! one of its own allocatable components without disrupting either mapping, +! different from original as the argument ordering is reversed (similar to C++ +! mapping of a struct and a pointer, in concept at least). +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: dtype + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type dtype + + type(dtype), allocatable :: alloca_dtype + allocate(alloca_dtype) + allocate(alloca_dtype%array_j(10)) + +!$omp target map(tofrom: alloca_dtype%array_j, alloca_dtype) + do i = 1, 10 + alloca_dtype%array_j(i) = i + end do + alloca_dtype%k = 50 +!$omp end target + +print *, alloca_dtype%array_j +print *, alloca_dtype%k +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 50 diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array.f90 new file mode 100644 index 000000000000..2b1957a8451c --- /dev/null +++ b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array.f90 @@ -0,0 +1,33 @@ +! Offload test that checks an allocatable derived type can be mapped alongside +! one of its own allocatable components without disrupting either mapping +! (similar to C++ mapping of a struct and a pointer, in concept at least). +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: dtype + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type dtype + + type(dtype), allocatable :: alloca_dtype + allocate(alloca_dtype) + allocate(alloca_dtype%array_j(10)) + +!$omp target map(tofrom: alloca_dtype, alloca_dtype%array_j) + do i = 1, 10 + alloca_dtype%array_j(i) = i + end do + alloca_dtype%k = 50 +!$omp end target + +print *, alloca_dtype%array_j +print *, alloca_dtype%k +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 50 diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-array-and-scalar.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-array-and-scalar.f90 new file mode 100644 index 000000000000..30f35be98af6 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-alloca-dtype-array-and-scalar.f90 @@ -0,0 +1,39 @@ +! Offloading test checking interaction of explicit member mapping of +! non-allocatable members of an allocatable derived type. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: nested_dtype + real(4) :: i + real(4) :: j + integer(4) :: array_i(10) + integer(4) :: k + end type nested_dtype + + type :: dtype + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + type(nested_dtype) :: nested_dtype + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type dtype + + type(dtype), allocatable :: alloca_dtype + allocate(alloca_dtype) + +!$omp target map(tofrom: alloca_dtype%nested_dtype%array_i, alloca_dtype%k) + do i = 1, 10 + alloca_dtype%nested_dtype%array_i(i) = i + end do + alloca_dtype%k = 50 +!$omp end target + +print *, alloca_dtype%k +print *, alloca_dtype%nested_dtype%array_i +end program main + +!CHECK: 50 +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-array-of-dtype.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-array-of-dtype.f90 new file mode 100644 index 000000000000..bad8ff55e638 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-alloca-dtype-array-of-dtype.f90 @@ -0,0 +1,35 @@ +! Offloading test checking interaction of explicit member mapping of an array +! of derived types contained within an allocatable derived type +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: nested_dtype + real(4) :: i + real(4) :: j + integer(4) :: array_i(10) + integer(4) :: k + end type nested_dtype + + type :: dtype + real(4) :: i + integer(4) :: array_i(10) + real(4) :: j + type(nested_dtype) :: array_dtype(10) + integer(4) :: k + end type dtype + + type(dtype), allocatable :: dtyped + allocate(dtyped) + +!$omp target map(tofrom: dtyped%array_dtype) + do i = 1, 10 + dtyped%array_dtype(i)%k = i + end do +!$omp end target + +print *, dtyped%array_dtype%k + +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-allocatable-array-section-1d-bounds.f90 b/offload/test/offloading/fortran/target-map-allocatable-array-section-1d-bounds.f90 index 3e981116ab42..7734ca9d0cf0 100644 --- a/offload/test/offloading/fortran/target-map-allocatable-array-section-1d-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-allocatable-array-section-1d-bounds.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of a -! two 1-D allocatable arrays with a target region -! while providing the map upper and lower bounds +! Offloading test checking interaction of a two 1-D allocatable arrays with a +! target region while providing the map upper and lower bounds ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-allocatable-array-section-3d-bounds.f90 b/offload/test/offloading/fortran/target-map-allocatable-array-section-3d-bounds.f90 index 31b6daa35ca5..7dba860a4a83 100644 --- a/offload/test/offloading/fortran/target-map-allocatable-array-section-3d-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-allocatable-array-section-3d-bounds.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of allocatables -! with multi-dimensional bounds (3-D in this case) and -! a target region +! Offloading test checking interaction of allocatables with multi-dimensional +! bounds (3-D in this case) and a target region ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-allocatable-dtype.f90 b/offload/test/offloading/fortran/target-map-allocatable-dtype.f90 new file mode 100644 index 000000000000..13b8890eee9a --- /dev/null +++ b/offload/test/offloading/fortran/target-map-allocatable-dtype.f90 @@ -0,0 +1,31 @@ +! Offload test that checks an allocatable derived type can be mapped and at the +! least non-allocatable components can be accessed. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: dtype + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type dtype + + type(dtype), allocatable :: alloca_dtype + allocate(alloca_dtype) + +!$omp target map(tofrom: alloca_dtype) + do i = 1, 10 + alloca_dtype%array_i(i) = i + end do + alloca_dtype%k = 50 +!$omp end target + +print *, alloca_dtype%k +print *, alloca_dtype%array_i +end program main + +!CHECK: 50 +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-allocatable-map-scopes.f90 b/offload/test/offloading/fortran/target-map-allocatable-map-scopes.f90 index 4a97a9ade91c..fe9c70900fef 100644 --- a/offload/test/offloading/fortran/target-map-allocatable-map-scopes.f90 +++ b/offload/test/offloading/fortran/target-map-allocatable-map-scopes.f90 @@ -1,5 +1,5 @@ -! Offloading test checking interaction of allocatables -! with target in different scopes +! Offloading test checking interaction of allocatables with target in different +! scopes ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-common-block.f90 b/offload/test/offloading/fortran/target-map-common-block.f90 index d2705db5d6ff..f368762b46d4 100644 --- a/offload/test/offloading/fortran/target-map-common-block.f90 +++ b/offload/test/offloading/fortran/target-map-common-block.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of -! mapping a full common block in a target -! region +! Offloading test checking interaction of mapping a full common block in a +! target region ! REQUIRES: flang, amdgcn-amd-amdhsa ! UNSUPPORTED: nvptx64-nvidia-cuda ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/target-map-declare-target-link-common-block.f90 b/offload/test/offloading/fortran/target-map-declare-target-link-common-block.f90 index 857e79c5fa6e..697365709d21 100644 --- a/offload/test/offloading/fortran/target-map-declare-target-link-common-block.f90 +++ b/offload/test/offloading/fortran/target-map-declare-target-link-common-block.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of -! mapping a declare target link common -! block with device_type any to a target -! region +! Offloading test checking interaction of mapping a declare target link common +! block with device_type any to a target region ! REQUIRES: flang, amdgcn-amd-amdhsa ! UNSUPPORTED: nvptx64-nvidia-cuda ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/target-map-derived-type-full-1.f90 b/offload/test/offloading/fortran/target-map-derived-type-full-1.f90 index fe3b84398eaf..9f2aeb4bf9fc 100644 --- a/offload/test/offloading/fortran/target-map-derived-type-full-1.f90 +++ b/offload/test/offloading/fortran/target-map-derived-type-full-1.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of an -! explicit derived type mapping when mapped -! to target and assinging one derived type -! to another +! Offloading test checking interaction of an explicit derived type mapping when +! mapped to target and assinging one derived type to another ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-derived-type-full-2.f90 b/offload/test/offloading/fortran/target-map-derived-type-full-2.f90 index 302af23a3c7e..f4f63f233cc0 100644 --- a/offload/test/offloading/fortran/target-map-derived-type-full-2.f90 +++ b/offload/test/offloading/fortran/target-map-derived-type-full-2.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! explicit derived type mapping when mapped to -! target and assigning to individual members +! Offloading test checking interaction of an explicit derived type mapping when +! mapped to target and assigning to individual members ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-derived-type-full-implicit-1.f90 b/offload/test/offloading/fortran/target-map-derived-type-full-implicit-1.f90 index f43fa3cc6905..8632b951d6fb 100644 --- a/offload/test/offloading/fortran/target-map-derived-type-full-implicit-1.f90 +++ b/offload/test/offloading/fortran/target-map-derived-type-full-implicit-1.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of an -! implicit derived type mapping when mapped -! to target and assinging one derived type -! to another +! Offloading test checking interaction of an implicit derived type mapping when +! mapped to target and assinging one derived type to another ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-derived-type-full-implicit-2.f90 b/offload/test/offloading/fortran/target-map-derived-type-full-implicit-2.f90 index f6c8f9812b14..9331a48c3eb7 100644 --- a/offload/test/offloading/fortran/target-map-derived-type-full-implicit-2.f90 +++ b/offload/test/offloading/fortran/target-map-derived-type-full-implicit-2.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of an -! explicit derived type mapping when mapped -! to target and assinging one derived type -! to another +! Offloading test checking interaction of an explicit derived type mapping when +! mapped to target and assinging one derived type to another ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-double-large-nested-dtype-multi-member.f90 b/offload/test/offloading/fortran/target-map-double-large-nested-dtype-multi-member.f90 index e390481bbaba..ef27ad387ea8 100644 --- a/offload/test/offloading/fortran/target-map-double-large-nested-dtype-multi-member.f90 +++ b/offload/test/offloading/fortran/target-map-double-large-nested-dtype-multi-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! explicit member map from two large nested -! derived types +! Offloading test checking interaction of an explicit member map from two large +! nested derived types ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90 b/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90 index 7f260ac4cdc1..b90fbd05fb2e 100644 --- a/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of two -! explicit arrau member maps with bounds from -! two nested derived types +! Offloading test checking interaction of two explicit array member maps with +! bounds from two nested derived types ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-double-nested-dtype-double-array-bounds.f90 b/offload/test/offloading/fortran/target-map-double-nested-dtype-double-array-bounds.f90 index bd9bbb1b7eed..f637dbed470c 100644 --- a/offload/test/offloading/fortran/target-map-double-nested-dtype-double-array-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-double-nested-dtype-double-array-bounds.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of two -! explicit array member maps with array bounds -! from two nested derived types +! Offloading test checking interaction of two explicit array member maps with +! array bounds from two nested derived types ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-double-nested-dtype-single-member.f90 b/offload/test/offloading/fortran/target-map-double-nested-dtype-single-member.f90 index 3c3b5e4b91e2..cbf1c6877bde 100644 --- a/offload/test/offloading/fortran/target-map-double-nested-dtype-single-member.f90 +++ b/offload/test/offloading/fortran/target-map-double-nested-dtype-single-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! explicit derived type member mapping of two -! derived types for a single array member each +! Offloading test checking interaction of an explicit derived type member +! mapping of two derived types for a single array member each ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-dtype-3d-alloca-array-with-bounds.f90 b/offload/test/offloading/fortran/target-map-dtype-3d-alloca-array-with-bounds.f90 new file mode 100644 index 000000000000..9fa13339aadd --- /dev/null +++ b/offload/test/offloading/fortran/target-map-dtype-3d-alloca-array-with-bounds.f90 @@ -0,0 +1,41 @@ +! Offload test that checks an allocatable array can be mapped with a specified +! 3-D bounds when contained within a derived type and mapped via member mapping. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:,:,:) + integer(4) :: k + end type top_layer + + type(top_layer) :: one_l + integer :: inArray(3,3,3) + + allocate(one_l%array_j(3,3,3)) + + do i = 1, 3 + do j = 1, 3 + do k = 1, 3 + inArray(i, j, k) = 42 + one_l%array_j(i, j, k) = 0 + end do + end do + end do + +!$omp target map(tofrom: one_l%array_j(1:3, 1:3, 2:2)) map(to: inArray(1:3, 1:3, 1:3)) + do j = 1, 3 + do k = 1, 3 + one_l%array_j(k, j, 2) = inArray(k, j, 2) + end do + end do +!$omp end target + + print *, one_l%array_j +end program main + +!CHECK: 0 0 0 0 0 0 0 0 0 42 42 42 42 42 42 42 42 42 0 0 0 0 0 0 0 0 0 diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-and-non-alloca-array.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-and-non-alloca-array.f90 new file mode 100644 index 000000000000..c72f82a80673 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-dtype-alloca-and-non-alloca-array.f90 @@ -0,0 +1,36 @@ +! Offload test that checks an allocatable array can be mapped alongside a +! non-allocatable array when both are contained within a derived type can be +! mapped correctly via member mapping and then written to. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: one_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type one_layer + + type(one_layer) :: one_l + + allocate(one_l%array_j(10)) + + do i = 1, 10 + one_l%array_i(i) = i + end do + +!$omp target map(tofrom: one_l%array_i, one_l%array_j) + do i = 1, 10 + one_l%array_j(i) = one_l%array_i(i) + i + end do +!$omp end target + + print *, one_l%array_i + print *, one_l%array_j +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 2 4 6 8 10 12 14 16 18 20 diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-array-and-non-alloca-dtype.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-array-and-non-alloca-dtype.f90 new file mode 100644 index 000000000000..172b3c4683f8 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-dtype-alloca-array-and-non-alloca-dtype.f90 @@ -0,0 +1,44 @@ +! Offload test that checks an allocatable array can be mapped alongside a +! non-allocatable derived type when both are contained within a derived type +! can be mapped correctly via member mapping and then written to. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer(4) :: array_i(10) + integer(4) :: k + end type bottom_layer + + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(bottom_layer) :: nest + end type top_layer + + type(top_layer) :: one_l + + allocate(one_l%array_j(10)) + allocate(one_l%scalar) + + do i = 1, 10 + one_l%nest%array_i(i) = i + end do + +!$omp target map(tofrom: one_l%nest, one_l%array_j) + do i = 1, 10 + one_l%array_j(i) = one_l%nest%array_i(i) + i + end do +!$omp end target + + print *, one_l%nest%array_i + print *, one_l%array_j +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 2 4 6 8 10 12 14 16 18 20 diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-array-of-dtype.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-array-of-dtype.f90 new file mode 100644 index 000000000000..f56a72843e6d --- /dev/null +++ b/offload/test/offloading/fortran/target-map-dtype-alloca-array-of-dtype.f90 @@ -0,0 +1,34 @@ +! Offload test that checks it is possible to member map an allocatable array of +! derived types nested within a non-allocatable derived type. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: nested_dtype + real(4) :: i + real(4) :: j + integer(4) :: array_i(10) + integer(4) :: k + end type nested_dtype + + type :: dtype + real(4) :: i + integer(4) :: array_i(10) + real(4) :: j + type(nested_dtype), allocatable :: array_dtype(:) + integer(4) :: k + end type dtype + + type(dtype) :: dtyped + allocate(dtyped%array_dtype(10)) + +!$omp target map(tofrom: dtyped%array_dtype) + do i = 1, 10 + dtyped%array_dtype(i)%k = i + end do +!$omp end target + +print *, dtyped%array_dtype%k +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-array-with-bounds.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-array-with-bounds.f90 new file mode 100644 index 000000000000..53480d1d5699 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-dtype-alloca-array-with-bounds.f90 @@ -0,0 +1,29 @@ +! Offload test that checks an allocatable array can be mapped with a specified +! 1-D bounds when contained within a derived type and mapped via member mapping +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type top_layer + + type(top_layer) :: one_l + + allocate(one_l%array_j(10)) + +!$omp target map(tofrom: one_l%array_j(2:6)) + do index = 1, 10 + one_l%array_j(index) = index + end do +!$omp end target + + print *, one_l%array_j(2:6) +end program main + +!CHECK: 2 3 4 5 6 diff --git a/offload/test/offloading/fortran/target-map-dtype-allocatable-array.f90 b/offload/test/offloading/fortran/target-map-dtype-allocatable-array.f90 new file mode 100644 index 000000000000..dbd839637f28 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-dtype-allocatable-array.f90 @@ -0,0 +1,28 @@ +! Offload test that checks an allocatable array contained within a derived type +! can be mapped correctly via member mapping and then written to. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: one_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type one_layer + + type(one_layer) :: one_l + allocate(one_l%array_j(10)) + + !$omp target map(tofrom: one_l%array_j) + do i = 1, 10 + one_l%array_j(i) = i + end do + !$omp end target + + print *, one_l%array_j +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-dtype-allocatable-scalar-and-array.f90 b/offload/test/offloading/fortran/target-map-dtype-allocatable-scalar-and-array.f90 new file mode 100644 index 000000000000..352d02e34cac --- /dev/null +++ b/offload/test/offloading/fortran/target-map-dtype-allocatable-scalar-and-array.f90 @@ -0,0 +1,34 @@ +! Offload test that checks an allocatable array alongside an allocatable scalar +! contained within a derived type can be mapped correctly via member mapping +! and then written to. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: one_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + end type one_layer + + type(one_layer) :: one_l + + allocate(one_l%array_j(10)) + allocate(one_l%scalar) + + !$omp target map(tofrom: one_l%array_j, one_l%j) + do i = 1, 10 + one_l%array_j(i) = i + end do + one_l%j = 50 + !$omp end target + + print *, one_l%j + print *, one_l%array_j +end program main + +!CHECK: 50 +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit-update.f90 b/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit-update.f90 index e3c28062687c..74bbdc0a6810 100644 --- a/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit-update.f90 +++ b/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit-update.f90 @@ -1,8 +1,6 @@ -! Offloading test checking interaction of an -! explicit derived type member mapping of -! an array with bounds when mapped to -! target using a combination of update, -! enter and exit directives. +! Offloading test checking interaction of an explicit derived type member +! mapping of an array with bounds when mapped to target using a combination of +! update, enter and exit directives. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit.f90 b/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit.f90 index fd56142c5cbf..8dcd7b5f39f3 100644 --- a/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit.f90 +++ b/offload/test/offloading/fortran/target-map-dtype-arr-bounds-member-enter-exit.f90 @@ -1,8 +1,6 @@ -! Offloading test checking interaction of an -! explicit derived type member mapping of -! an array with bounds when mapped to -! target using a combination of enter and -! exit directives. +! Offloading test checking interaction of an explicit derived type member +! mapping of an array with bounds when mapped to target using a combination of +! enter and exit directives. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-dtype-explicit-individual-array-member.f90 b/offload/test/offloading/fortran/target-map-dtype-explicit-individual-array-member.f90 index ce8a1b2ba84b..c4496a3e411a 100644 --- a/offload/test/offloading/fortran/target-map-dtype-explicit-individual-array-member.f90 +++ b/offload/test/offloading/fortran/target-map-dtype-explicit-individual-array-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! explicit derived type member mapping of -! an array when mapped to target +! Offloading test checking interaction of an explicit derived type member +! mapping of an array when mapped to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-3D-member-bounds.f90 b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-3D-member-bounds.f90 index c72bb8537809..145818fd4111 100644 --- a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-3D-member-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-3D-member-bounds.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of an -! explicit derived type member mapping of -! two arrays with explicit bounds when -! mapped to target +! Offloading test checking interaction of an explicit derived type member +! mapping of two arrays with explicit bounds when mapped to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member-bounds.f90 b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member-bounds.f90 index b8defce2abc7..1a4742461f8c 100644 --- a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member-bounds.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of an -! explicit derived type member mapping of -! two arrays with explicit bounds when -! mapped to target +! Offloading test checking interaction of an explicit derived type member +! mapping of two arrays with explicit bounds when mapped to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member.f90 b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member.f90 index 5816598b5b50..d05b2dafebb1 100644 --- a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member.f90 +++ b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-array-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! derived type mapping of two explicit array -! members to target +! Offloading test checking interaction of an derived type mapping of two +! explicit array members to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-member.f90 b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-member.f90 index e86980447016..1bda6d67f2b2 100644 --- a/offload/test/offloading/fortran/target-map-dtype-multi-explicit-member.f90 +++ b/offload/test/offloading/fortran/target-map-dtype-multi-explicit-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! derived type mapping of two explicit -! members to target +! Offloading test checking interaction of an derived type mapping of two +! explicit members to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-enter-exit-allocatables.f90 b/offload/test/offloading/fortran/target-map-enter-exit-allocatables.f90 index 60806feb7a19..497b824b4fc7 100644 --- a/offload/test/offloading/fortran/target-map-enter-exit-allocatables.f90 +++ b/offload/test/offloading/fortran/target-map-enter-exit-allocatables.f90 @@ -1,5 +1,5 @@ -! Offloading test checking interaction of allocatables -! with enter, exit and target +! Offloading test checking interaction of allocatables with enter, exit and +! target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-enter-exit-array-2.f90 b/offload/test/offloading/fortran/target-map-enter-exit-array-2.f90 index 320b76fcdb46..b6005e037e83 100644 --- a/offload/test/offloading/fortran/target-map-enter-exit-array-2.f90 +++ b/offload/test/offloading/fortran/target-map-enter-exit-array-2.f90 @@ -1,5 +1,5 @@ -! Offloading test checking interaction of an -! enter and exit map of an array of scalars +! Offloading test checking interaction of an enter and exit map of an array of +! scalars ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-enter-exit-array-bounds.f90 b/offload/test/offloading/fortran/target-map-enter-exit-array-bounds.f90 index cae1d47013f6..d6264c60ba30 100644 --- a/offload/test/offloading/fortran/target-map-enter-exit-array-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-enter-exit-array-bounds.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! enter and exit map of an array of scalars -! with specified bounds +! Offloading test checking interaction of an enter and exit map of an array of +! scalars with specified bounds ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-enter-exit-array.f90 b/offload/test/offloading/fortran/target-map-enter-exit-array.f90 index 67946ba66cd9..51de70f092ef 100644 --- a/offload/test/offloading/fortran/target-map-enter-exit-array.f90 +++ b/offload/test/offloading/fortran/target-map-enter-exit-array.f90 @@ -1,5 +1,5 @@ -! Offloading test checking interaction of fixed size -! arrays with enter, exit and target +! Offloading test checking interaction of fixed size arrays with enter, exit +! and target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-enter-exit-scalar.f90 b/offload/test/offloading/fortran/target-map-enter-exit-scalar.f90 index 046a906dd524..7e252259007f 100644 --- a/offload/test/offloading/fortran/target-map-enter-exit-scalar.f90 +++ b/offload/test/offloading/fortran/target-map-enter-exit-scalar.f90 @@ -1,5 +1,4 @@ -! Offloading test checking interaction of an -! enter and exit map of an scalar +! Offloading test checking interaction of an enter and exit map of an scalar ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-first-common-block-member.f90 b/offload/test/offloading/fortran/target-map-first-common-block-member.f90 index 57a7380221ad..4f72f30cd51d 100644 --- a/offload/test/offloading/fortran/target-map-first-common-block-member.f90 +++ b/offload/test/offloading/fortran/target-map-first-common-block-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of -! mapping a member of a common block to a -! target region +! Offloading test checking interaction of mapping a member of a common block to +! a target region ! REQUIRES: flang, amdgcn-amd-amdhsa ! UNSUPPORTED: nvptx64-nvidia-cuda ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/target-map-individual-dtype-member-map.f90 b/offload/test/offloading/fortran/target-map-individual-dtype-member-map.f90 index 42a094996910..081718e0448c 100644 --- a/offload/test/offloading/fortran/target-map-individual-dtype-member-map.f90 +++ b/offload/test/offloading/fortran/target-map-individual-dtype-member-map.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! single explicit member map from a single -! derived type. +! Offloading test checking interaction of an single explicit member map from a +! single derived type. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-large-nested-dtype-multi-member.f90 b/offload/test/offloading/fortran/target-map-large-nested-dtype-multi-member.f90 index 2e345fd49cfa..0b9fcea4422f 100644 --- a/offload/test/offloading/fortran/target-map-large-nested-dtype-multi-member.f90 +++ b/offload/test/offloading/fortran/target-map-large-nested-dtype-multi-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! explicit member map a large nested derived -! type +! Offloading test checking interaction of an explicit member map a large nested +! derived type ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-mix-imp-exp-common-block-members.f90 b/offload/test/offloading/fortran/target-map-mix-imp-exp-common-block-members.f90 index a634cd023c57..8c2907a87721 100644 --- a/offload/test/offloading/fortran/target-map-mix-imp-exp-common-block-members.f90 +++ b/offload/test/offloading/fortran/target-map-mix-imp-exp-common-block-members.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of -! mapping all the members of a common block -! with a mix of explicit and implicit -! mapping to a target region +! Offloading test checking interaction of mapping all the members of a common +! block with a mix of explicit and implicit mapping to a target region ! REQUIRES: flang, amdgcn-amd-amdhsa ! UNSUPPORTED: nvptx64-nvidia-cuda ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-alloca-members.f90 b/offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-alloca-members.f90 new file mode 100644 index 000000000000..7880069881ac --- /dev/null +++ b/offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-alloca-members.f90 @@ -0,0 +1,90 @@ +! Offloading test checking interaction of an explicit member map allocatable +! components of two large nested derived types. NOTE: Unfortunately this test +! loses a bit of its bite as we do not currently support linking against an +! offload compiled fortran runtime library which means allocatable scalar +! assignment isn't going to work in target regions. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer1 + real(4), allocatable :: i4 + real(4), allocatable :: j4 + integer, pointer :: array_ptr(:) + real(4), allocatable :: k4 + end type bottom_layer1 + + type :: bottom_layer2 + integer(4), allocatable :: i3 + integer(4), allocatable :: j3 + integer, allocatable :: scalar + real, allocatable :: array_j(:) + integer(4), allocatable :: k3 + end type bottom_layer2 + + type :: middle_layer + real(4) :: array_i2(10) + real(4), allocatable :: i2 + integer, pointer :: scalar_ptr + real(4) :: array_j2(10) + type(bottom_layer1), allocatable :: nest + type(bottom_layer2), allocatable :: nest2 + end type middle_layer + + type :: top_layer + real(4) :: i + integer(4), allocatable :: array_i(:) + real(4) :: j + integer(4) :: k + type(middle_layer), allocatable :: nested + end type top_layer + + type(top_layer), allocatable :: top_dtype + type(top_layer), allocatable :: top_dtype2 + integer, target :: array_target(10) + integer, target :: array_target2(10) + + allocate(top_dtype) + allocate(top_dtype2) + allocate(top_dtype%nested) + allocate(top_dtype2%nested) + allocate(top_dtype%nested%nest) + allocate(top_dtype2%nested%nest) + allocate(top_dtype%nested%nest2) + allocate(top_dtype2%nested%nest2) + allocate(top_dtype%array_i(10)) + allocate(top_dtype2%array_i(10)) + + top_dtype%nested%nest%array_ptr => array_target + allocate(top_dtype%nested%nest2%array_j(10)) + + top_dtype2%nested%nest%array_ptr => array_target2 + allocate(top_dtype2%nested%nest2%array_j(10)) + +!$omp target map(tofrom: top_dtype%array_i, top_dtype%nested%nest2%array_j, top_dtype%nested%nest%array_ptr) & +!$omp map(tofrom: top_dtype2%array_i, top_dtype2%nested%nest2%array_j, top_dtype2%nested%nest%array_ptr) + do i = 1, 10 + top_dtype%nested%nest%array_ptr(i) = i + top_dtype%nested%nest2%array_j(i) = i + top_dtype%array_i(i) = i + top_dtype2%nested%nest%array_ptr(i) = i + top_dtype2%nested%nest2%array_j(i) = i + top_dtype2%array_i(i) = i + end do +!$omp end target + + print *, top_dtype%nested%nest%array_ptr + print *, top_dtype%nested%nest2%array_j + print *, top_dtype%array_i + + print *, top_dtype2%nested%nest%array_ptr + print *, top_dtype2%nested%nest2%array_j + print *, top_dtype2%array_i +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-mixed-members.f90 b/offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-mixed-members.f90 new file mode 100644 index 000000000000..7f1eda63d9d4 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-mixed-members.f90 @@ -0,0 +1,82 @@ +! Offloading test checking interaction of an explicit member map of mixed +! allocatable and non-allocatable components of a nested derived types. +! +! NOTE: Unfortunately this test loses a bit of its bite as we do not currently +! support linking against an offload compiled fortran runtime library which +! means allocatable scalar assignment isn't going to work in target regions. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer1 + real(4) :: i4 + real(4), allocatable :: j4 + real(4) :: k4 + end type bottom_layer1 + + type :: bottom_layer2 + integer(4) :: i3 + integer(4) :: j3 + integer(4), allocatable :: k3 + end type bottom_layer2 + + type :: middle_layer + real(4) :: array_i2(10) + real(4) :: i2 + real(4), allocatable :: array_j2(:) + type(bottom_layer1) :: nest + type(bottom_layer2), allocatable :: nest2 + end type middle_layer + + type :: top_layer + real(4) :: i + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(middle_layer) :: nested + end type top_layer + + type(top_layer), allocatable :: top_dtype + + allocate(top_dtype) + allocate(top_dtype%array_j(10)) + allocate(top_dtype%nested%nest2) + allocate(top_dtype%nested%array_j2(10)) + +!$omp target map(tofrom: top_dtype%nested%nest%i4, top_dtype%nested%array_j2) & +!$omp map(tofrom: top_dtype%nested%nest%k4, top_dtype%array_i, top_dtype%nested%nest2%i3) & +!$omp map(tofrom: top_dtype%nested%i2, top_dtype%nested%nest2%j3, top_dtype%array_j) + top_dtype%nested%nest%i4 = 10 + top_dtype%nested%nest%k4 = 10 + top_dtype%nested%nest2%i3 = 20 + top_dtype%nested%nest2%j3 = 40 + + top_dtype%nested%i2 = 200 + + do i = 1, 10 + top_dtype%array_j(i) = i + top_dtype%array_i(i) = i + top_dtype%nested%array_j2(i) = i + end do +!$omp end target + + print *, top_dtype%nested%nest%i4 + print *, top_dtype%nested%nest%k4 + print *, top_dtype%nested%nest2%i3 + print *, top_dtype%nested%nest2%j3 + + print *, top_dtype%nested%i2 + print *, top_dtype%array_i + print *, top_dtype%array_j + print *, top_dtype%nested%array_j2 +end program main + +!CHECK: 10. +!CHECK: 10. +!CHECK: 20 +!CHECK: 40 +!CHECK: 200. +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. diff --git a/offload/test/offloading/fortran/target-map-nested-alloca-dtype-3d-alloca-array-bounds.f90 b/offload/test/offloading/fortran/target-map-nested-alloca-dtype-3d-alloca-array-bounds.f90 new file mode 100644 index 000000000000..a03e8d137ce8 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-nested-alloca-dtype-3d-alloca-array-bounds.f90 @@ -0,0 +1,51 @@ +! Offloading test checking interaction of an explicit member map of an +! allocatable 3d array within a nested allocatable derived type with +! specified bounds +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer(4) :: array_i(10) + integer, allocatable :: array_k(:,:,:) + integer(4) :: k + end type bottom_layer + + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(bottom_layer), allocatable :: nest + end type top_layer + + type(top_layer), allocatable :: one_l + integer :: inArray(3,3,3) + allocate(one_l) + allocate(one_l%nest) + allocate(one_l%nest%array_k(3,3,3)) + + do i = 1, 3 + do j = 1, 3 + do k = 1, 3 + inArray(i, j, k) = 42 + one_l%nest%array_k(i, j, k) = 0 + end do + end do + end do + +!$omp target map(tofrom: one_l%nest%array_k(1:3, 1:3, 2:2)) map(to: inArray(1:3, 1:3, 1:3)) + do j = 1, 3 + do k = 1, 3 + one_l%nest%array_k(k, j, 2) = inArray(k, j, 2) + end do + end do +!$omp end target + + print *, one_l%nest%array_k +end program main + +!CHECK: 0 0 0 0 0 0 0 0 0 42 42 42 42 42 42 42 42 42 0 0 0 0 0 0 0 0 0 diff --git a/offload/test/offloading/fortran/target-map-nested-alloca-dtype-alloca-array-bounds.f90 b/offload/test/offloading/fortran/target-map-nested-alloca-dtype-alloca-array-bounds.f90 new file mode 100644 index 000000000000..35b487370d1a --- /dev/null +++ b/offload/test/offloading/fortran/target-map-nested-alloca-dtype-alloca-array-bounds.f90 @@ -0,0 +1,43 @@ +! Offloading test checking interaction of an explicit member map of an +! allocatable array within a nested allocatable derived type with specified +! bounds +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer(4) :: array_i(10) + integer, allocatable :: array_k(:) + integer(4) :: k + end type bottom_layer + + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(bottom_layer), allocatable :: nest + end type top_layer + + type(top_layer), allocatable :: one_l + allocate(one_l) + allocate(one_l%nest) + allocate(one_l%nest%array_k(10)) + + do index = 1, 10 + one_l%nest%array_k(index) = 0 + end do + +!$omp target map(tofrom: one_l%nest%array_k(2:6)) + do index = 2, 6 + one_l%nest%array_k(index) = index + end do +!$omp end target + + print *, one_l%nest%array_k +end program main + +!CHECK: 0 2 3 4 5 6 0 0 0 0 diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-3d-alloca-array-with-bounds.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-3d-alloca-array-with-bounds.f90 new file mode 100644 index 000000000000..5aa5a094824a --- /dev/null +++ b/offload/test/offloading/fortran/target-map-nested-dtype-3d-alloca-array-with-bounds.f90 @@ -0,0 +1,50 @@ +! Offload test that checks an allocatable array can be mapped with a specified +! 3-D bounds when contained within a nested derived type and mapped via member +! mapping. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer(4) :: array_i(10) + integer, allocatable :: array_k(:,:,:) + integer(4) :: k + end type bottom_layer + + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(bottom_layer) :: nest + end type top_layer + + type(top_layer) :: one_l + integer :: inArray(3,3,3) + + allocate(one_l%nest%array_k(3,3,3)) + + do i = 1, 3 + do j = 1, 3 + do k = 1, 3 + inArray(i, j, k) = 42 + one_l%nest%array_k(i, j, k) = 0 + end do + end do + end do + +!$omp target map(tofrom: one_l%nest%array_k(1:3, 1:3, 2:2)) map(to: inArray(1:3, 1:3, 1:3)) + do j = 1, 3 + do k = 1, 3 + one_l%nest%array_k(k, j, 2) = inArray(k, j, 2) + end do + end do +!$omp end target + + print *, one_l%nest%array_k +end program main + +!CHECK: 0 0 0 0 0 0 0 0 0 42 42 42 42 42 42 42 42 42 0 0 0 0 0 0 0 0 0 diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-alloca-and-non-alloca-array.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-and-non-alloca-array.f90 new file mode 100644 index 000000000000..1bbf25e0b0aa --- /dev/null +++ b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-and-non-alloca-array.f90 @@ -0,0 +1,47 @@ +! Offload test that checks an allocatable array can be mapped via member +! mapping alongside a non-allocatable array when both are contained within a +! nested derived type. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer, allocatable :: scalar_i + integer(4) :: array_i(10) + integer, allocatable :: array_k(:) + integer(4) :: k + end type bottom_layer + + type :: one_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(bottom_layer) :: nest + end type one_layer + + type(one_layer) :: one_l + + allocate(one_l%nest%array_k(10)) + allocate(one_l%nest%scalar_i) + + do i = 1, 10 + one_l%nest%array_i(i) = i + end do + + !$omp target map(tofrom: one_l%nest%array_i, one_l%nest%array_k) + do i = 1, 10 + one_l%nest%array_k(i) = one_l%nest%array_i(i) + i + end do + !$omp end target + + print *, one_l%nest%array_k + print *, one_l%nest%array_i +end program main + +!CHECK: 2 4 6 8 10 12 14 16 18 20 +!CHECK: 1 2 3 4 5 6 7 8 9 10 + diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-and-non-alloca-dtype.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-and-non-alloca-dtype.f90 new file mode 100644 index 000000000000..f278c37e9990 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-and-non-alloca-dtype.f90 @@ -0,0 +1,51 @@ +! Offload test that checks an allocatable array can be mapped alongside a +! non-allocatable derived type when both are contained within a nested derived +! type. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer(4) :: array_i(10) + integer(4) :: k + end type bottom_layer + + type :: middle_layer + real(4) :: i + integer(4) :: array_i(10) + type(bottom_layer) :: nest2 + integer, allocatable :: array_k(:) + integer(4) :: k + end type middle_layer + + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(middle_layer) :: nest + end type top_layer + + type(top_layer) :: one_l + + allocate(one_l%nest%array_k(10)) + + do i = 1, 10 + one_l%nest%nest2%array_i(i) = i + end do + + !$omp target map(tofrom: one_l%nest%nest2, one_l%nest%array_k) + do i = 1, 10 + one_l%nest%array_k(i) = one_l%nest%nest2%array_i(i) + i + end do + !$omp end target + + print *, one_l%nest%nest2%array_i + print *, one_l%nest%array_k +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 +!CHECK: 2 4 6 8 10 12 14 16 18 20 diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-with-bounds.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-with-bounds.f90 new file mode 100644 index 000000000000..84328f79ef1c --- /dev/null +++ b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-with-bounds.f90 @@ -0,0 +1,43 @@ +! Offload test that checks an allocatable array can be mapped with a specified +! 1-D bounds when contained within a nested derived type and mapped via member +! mapping. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer(4) :: array_i(10) + integer, allocatable :: array_k(:) + integer(4) :: k + end type bottom_layer + + type :: top_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(bottom_layer) :: nest + end type top_layer + + type(top_layer) :: one_l + + allocate(one_l%nest%array_k(10)) + + do index = 1, 10 + one_l%nest%array_k(index) = 0 + end do + +!$omp target map(tofrom: one_l%nest%array_k(2:6)) + do index = 2, 6 + one_l%nest%array_k(index) = index + end do +!$omp end target + +print *, one_l%nest%array_k + +end program main + +!CHECK: 0 2 3 4 5 6 0 0 0 0 diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array.f90 new file mode 100644 index 000000000000..7d0b06dd67f0 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-nested-dtype-alloca-array.f90 @@ -0,0 +1,37 @@ +! Offload test that checks an allocatable array contained within a nested +! derived type can be mapped correctly via member mapping and then written to. +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +program main + type :: bottom_layer + real(4) :: i + integer(4) :: array_i(10) + integer, allocatable :: array_k(:) + integer(4) :: k + end type bottom_layer + + type :: one_layer + real(4) :: i + integer, allocatable :: scalar + integer(4) :: array_i(10) + real(4) :: j + integer, allocatable :: array_j(:) + integer(4) :: k + type(bottom_layer) :: nest + end type one_layer + + type(one_layer) :: one_l + + allocate(one_l%nest%array_k(10)) + +!$omp target map(tofrom: one_l%nest%array_k) + do i = 1, 10 + one_l%nest%array_k(i) = i + end do +!$omp end target + + print *, one_l%nest%array_k +end program main + +!CHECK: 1 2 3 4 5 6 7 8 9 10 diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-complex-member.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-complex-member.f90 index becc88d3157c..e1c5fbba5387 100644 --- a/offload/test/offloading/fortran/target-map-nested-dtype-complex-member.f90 +++ b/offload/test/offloading/fortran/target-map-nested-dtype-complex-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! nested derived type member map of a complex -! number member +! Offloading test checking interaction of an nested derived type member map of +! a complex number member ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-derived-member.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-derived-member.f90 index c5f79de22b29..3d5cb95a78c8 100644 --- a/offload/test/offloading/fortran/target-map-nested-dtype-derived-member.f90 +++ b/offload/test/offloading/fortran/target-map-nested-dtype-derived-member.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of an -! nested derived type member map with the -! inclusion of an entire nested derived -! type being mapped +! Offloading test checking interaction of an nested derived type member map +! with the inclusion of an entire nested derived type being mapped ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-multi-member.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-multi-member.f90 index b3579c39f7f6..b8153940fbaa 100644 --- a/offload/test/offloading/fortran/target-map-nested-dtype-multi-member.f90 +++ b/offload/test/offloading/fortran/target-map-nested-dtype-multi-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! explicit member map from a small nested -! derived type +! Offloading test checking interaction of an explicit member map from a small +! nested derived type ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-nested-dtype-single-member.f90 b/offload/test/offloading/fortran/target-map-nested-dtype-single-member.f90 index 20c245a5877c..498b461ca25f 100644 --- a/offload/test/offloading/fortran/target-map-nested-dtype-single-member.f90 +++ b/offload/test/offloading/fortran/target-map-nested-dtype-single-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of an -! single explicit member map from a nested -! derived type. +! Offloading test checking interaction of an single explicit member map from a +! nested derived type. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-pointer-scopes-enter-exit.f90 b/offload/test/offloading/fortran/target-map-pointer-scopes-enter-exit.f90 index 2dc03641f8a6..f5f284caed64 100644 --- a/offload/test/offloading/fortran/target-map-pointer-scopes-enter-exit.f90 +++ b/offload/test/offloading/fortran/target-map-pointer-scopes-enter-exit.f90 @@ -1,5 +1,5 @@ -! Offloading test checking interaction of pointers -! with target in different scopes +! Offloading test checking interaction of pointers with target in different +! scopes ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-pointer-target-array-section-3d-bounds.f90 b/offload/test/offloading/fortran/target-map-pointer-target-array-section-3d-bounds.f90 index 2b2c60f5d4b5..6d9c497134ff 100644 --- a/offload/test/offloading/fortran/target-map-pointer-target-array-section-3d-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-pointer-target-array-section-3d-bounds.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of pointer -! and target with target where 3-D bounds have -! been specified +! Offloading test checking interaction of pointer and target with target where +! 3-D bounds have been specified ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-pointer-target-scopes.f90 b/offload/test/offloading/fortran/target-map-pointer-target-scopes.f90 index fcbcf024d9c9..323f0e055fb5 100644 --- a/offload/test/offloading/fortran/target-map-pointer-target-scopes.f90 +++ b/offload/test/offloading/fortran/target-map-pointer-target-scopes.f90 @@ -1,5 +1,5 @@ -! Offloading test checking interaction of pointer -! and target with target across multiple scopes +! Offloading test checking interaction of pointer and target with target across +! multiple scopes ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-pointer-to-dtype-allocatable-member.f90 b/offload/test/offloading/fortran/target-map-pointer-to-dtype-allocatable-member.f90 new file mode 100644 index 000000000000..8e1e68528943 --- /dev/null +++ b/offload/test/offloading/fortran/target-map-pointer-to-dtype-allocatable-member.f90 @@ -0,0 +1,45 @@ +! Offloading test checking interaction of implicit captured of a pointer +! targeting an allocatable member of a derived type, alongside the explicit +! map of the derived type and allocatable data via target enter and exit +! directives +! REQUIRES: flang, amdgpu + +! RUN: %libomptarget-compile-fortran-run-and-check-generic +module dtype + type :: my_dtype + integer :: s, e + integer,dimension(:),allocatable :: values + end type +end module + +program offload_types + use dtype + + type(my_dtype),target :: my_instance + integer,dimension(:),pointer :: values_ptr + integer :: i + + allocate(my_instance%values(20)) + my_instance%s=1 + my_instance%e=20 + + values_ptr => my_instance%values + + !$omp target enter data map(to:my_instance, my_instance%values) + + !$omp target + do i = 1,20 + values_ptr(i) = i + end do + !$omp end target + + !$omp target exit data map(from:my_instance%values) + + write(*,*) my_instance%values + + !$omp target exit data map(release:my_instance) + + deallocate(my_instance%values) +end program + +!CHECK: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 diff --git a/offload/test/offloading/fortran/target-map-second-common-block-member.f90 b/offload/test/offloading/fortran/target-map-second-common-block-member.f90 index fce876cfb021..432c6e1f82b9 100644 --- a/offload/test/offloading/fortran/target-map-second-common-block-member.f90 +++ b/offload/test/offloading/fortran/target-map-second-common-block-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of -! mapping a member of a common block to a -! target region +! Offloading test checking interaction of mapping a member of a common block to +! a target region ! REQUIRES: flang, amdgcn-amd-amdhsa ! UNSUPPORTED: nvptx64-nvidia-cuda ! UNSUPPORTED: nvptx64-nvidia-cuda-LTO diff --git a/offload/test/offloading/fortran/target-map-two-dtype-explicit-member.f90 b/offload/test/offloading/fortran/target-map-two-dtype-explicit-member.f90 index 2d9f3cdfccc9..0fe153189f1b 100644 --- a/offload/test/offloading/fortran/target-map-two-dtype-explicit-member.f90 +++ b/offload/test/offloading/fortran/target-map-two-dtype-explicit-member.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of two -! derived type's with one explicit member -! each being mapped with bounds to target +! Offloading test checking interaction of two derived type's with one explicit +! member each being mapped with bounds to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-two-dtype-individual-member-array-1D-bounds.f90 b/offload/test/offloading/fortran/target-map-two-dtype-individual-member-array-1D-bounds.f90 index 26d030c2f042..261443a4e4e9 100644 --- a/offload/test/offloading/fortran/target-map-two-dtype-individual-member-array-1D-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-two-dtype-individual-member-array-1D-bounds.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of two -! derived type's with a single explicit array -! member each being mapped with bounds to -! target +! Offloading test checking interaction of two derived type's with a single +! explicit array member each being mapped with bounds to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-1.f90 b/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-1.f90 index 43cdf0497c57..7d3a3eca3405 100644 --- a/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-1.f90 +++ b/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-1.f90 @@ -1,6 +1,5 @@ -! Offloading test checking interaction of two -! derived type's with a mix of explicit and -! implicit member mapping to target +! Offloading test checking interaction of two derived type's with a mix of +! explicit and implicit member mapping to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-2.f90 b/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-2.f90 index 336e182f8a16..8f0bae32709b 100644 --- a/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-2.f90 +++ b/offload/test/offloading/fortran/target-map-two-dtype-mixed-implicit-explicit-capture-2.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of two -! derived type's with a mix of explicit and -! implicit member mapping of arrays to target -! one with bounds. +! Offloading test checking interaction of two derived type's with a mix of +! explicit and implicit member mapping of arrays to target one with bounds. ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-two-dtype-multi-member-array-1D-bounds.f90 b/offload/test/offloading/fortran/target-map-two-dtype-multi-member-array-1D-bounds.f90 index 308d6a0c3610..4726093c3657 100644 --- a/offload/test/offloading/fortran/target-map-two-dtype-multi-member-array-1D-bounds.f90 +++ b/offload/test/offloading/fortran/target-map-two-dtype-multi-member-array-1D-bounds.f90 @@ -1,7 +1,5 @@ -! Offloading test checking interaction of two -! derived type's with two explicit array -! members each being mapped with bounds to -! target +! Offloading test checking interaction of two derived type's with two explicit +! array members each being mapped with bounds to target ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-map-two-nested-dtype-member-array-map.f90 b/offload/test/offloading/fortran/target-map-two-nested-dtype-member-array-map.f90 index 1a59a7c95b9c..ef105839a7e4 100644 --- a/offload/test/offloading/fortran/target-map-two-nested-dtype-member-array-map.f90 +++ b/offload/test/offloading/fortran/target-map-two-nested-dtype-member-array-map.f90 @@ -1,5 +1,5 @@ -! Offloading test checking interaction of an -! explicit member map utilising array bounds +! Offloading test checking interaction of an explicit member map utilising +! array bounds ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-nested-target-data.f90 b/offload/test/offloading/fortran/target-nested-target-data.f90 index 6041433afbdc..1eb52caf278b 100644 --- a/offload/test/offloading/fortran/target-nested-target-data.f90 +++ b/offload/test/offloading/fortran/target-nested-target-data.f90 @@ -1,5 +1,4 @@ -! Offloading test for target nested inside -! a target data region +! Offloading test for target nested inside a target data region ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic diff --git a/offload/test/offloading/fortran/target-region-implicit-array.f90 b/offload/test/offloading/fortran/target-region-implicit-array.f90 index 22d0c5ea655f..e3852569a5a8 100644 --- a/offload/test/offloading/fortran/target-region-implicit-array.f90 +++ b/offload/test/offloading/fortran/target-region-implicit-array.f90 @@ -1,5 +1,5 @@ -! Basic offloading test of a regular array explicitly -! passed within a target region +! Basic offloading test of a regular array explicitly passed within a target +! region ! REQUIRES: flang, amdgpu ! RUN: %libomptarget-compile-fortran-run-and-check-generic |
