Skip to content

Commit 279b83e

Browse files
committed
merge main into amd-staging
2 parents 7ec6394 + 054f4a5 commit 279b83e

File tree

13 files changed

+106
-5
lines changed

13 files changed

+106
-5
lines changed

compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ int CollectDataFlow(const std::string &DFTBinary, const std::string &DirPath,
265265
// we then request tags in [0,Size/2) and [Size/2, Size), and so on.
266266
// Function number => DFT.
267267
auto OutPath = DirPlusFile(DirPath, Hash(FileToVector(F.File)));
268-
std::unordered_map<size_t, std::vector<uint8_t>> DFTMap;
269-
std::unordered_set<std::string> Cov;
270268
Command Cmd;
271269
Cmd.addArgument(DFTBinary);
272270
Cmd.addArgument(F.File);

flang-rt/lib/cuda/descriptor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ void RTDEF(CUFSyncGlobalDescriptor)(
5454
((Descriptor *)devAddr, (Descriptor *)hostPtr, sourceFile, sourceLine);
5555
}
5656

57+
void RTDEF(CUFDescriptorCheckSection)(
58+
const Descriptor *desc, const char *sourceFile, int sourceLine) {
59+
if (desc && !desc->IsContiguous()) {
60+
Terminator terminator{sourceFile, sourceLine};
61+
terminator.Crash("device array section argument is not contiguous");
62+
}
63+
}
64+
5765
RT_EXT_API_GROUP_END
5866
}
5967
} // namespace Fortran::runtime::cuda

flang/include/flang/Lower/LoweringOptions.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,8 @@ ENUM_LOWERINGOPT(StackRepackArrays, unsigned, 1, 0)
6363
/// in the leading dimension.
6464
ENUM_LOWERINGOPT(RepackArraysWhole, unsigned, 1, 0)
6565

66+
/// If true, CUDA Fortran runtime check is inserted.
67+
ENUM_LOWERINGOPT(CUDARuntimeCheck, unsigned, 1, 0)
68+
6669
#undef LOWERINGOPT
6770
#undef ENUM_LOWERINGOPT

flang/include/flang/Optimizer/Builder/Runtime/CUDA/Descriptor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ namespace fir::runtime::cuda {
2626
void genSyncGlobalDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
2727
mlir::Value hostPtr);
2828

29+
/// Generate runtime call to check the section of a descriptor and raise an
30+
/// error if it is not contiguous.
31+
void genDescriptorCheckSection(fir::FirOpBuilder &builder, mlir::Location loc,
32+
mlir::Value desc);
33+
2934
} // namespace fir::runtime::cuda
3035

3136
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_CUDA_DESCRIPTOR_H_

flang/include/flang/Runtime/CUDA/descriptor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ void RTDECL(CUFDescriptorSync)(Descriptor *dst, const Descriptor *src,
3737
void RTDECL(CUFSyncGlobalDescriptor)(
3838
void *hostPtr, const char *sourceFile = nullptr, int sourceLine = 0);
3939

40+
/// Check descriptor passed to a kernel.
41+
void RTDECL(CUFDescriptorCheckSection)(
42+
const Descriptor *, const char *sourceFile = nullptr, int sourceLine = 0);
43+
4044
} // extern "C"
4145

4246
} // namespace Fortran::runtime::cuda

flang/lib/Lower/ConvertCall.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "flang/Optimizer/Builder/IntrinsicCall.h"
2727
#include "flang/Optimizer/Builder/LowLevelIntrinsics.h"
2828
#include "flang/Optimizer/Builder/MutableBox.h"
29+
#include "flang/Optimizer/Builder/Runtime/CUDA/Descriptor.h"
2930
#include "flang/Optimizer/Builder/Runtime/Derived.h"
3031
#include "flang/Optimizer/Builder/Todo.h"
3132
#include "flang/Optimizer/Dialect/CUF/CUFOps.h"
@@ -543,6 +544,19 @@ Fortran::lower::genCallOpAndResult(
543544
fir::FortranProcedureFlagsEnumAttr procAttrs =
544545
caller.getProcedureAttrs(builder.getContext());
545546

547+
if (converter.getLoweringOptions().getCUDARuntimeCheck()) {
548+
if (caller.getCallDescription().chevrons().empty()) {
549+
for (auto [oper, arg] :
550+
llvm::zip(operands, caller.getPassedArguments())) {
551+
if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(oper.getType())) {
552+
const Fortran::semantics::Symbol *sym = caller.getDummySymbol(arg);
553+
if (sym && Fortran::evaluate::IsCUDADeviceSymbol(*sym))
554+
fir::runtime::cuda::genDescriptorCheckSection(builder, loc, oper);
555+
}
556+
}
557+
}
558+
}
559+
546560
if (!caller.getCallDescription().chevrons().empty()) {
547561
// A call to a CUDA kernel with the chevron syntax.
548562

flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,18 @@ void fir::runtime::cuda::genSyncGlobalDescriptor(fir::FirOpBuilder &builder,
3232
builder, loc, fTy, hostPtr, sourceFile, sourceLine)};
3333
builder.create<fir::CallOp>(loc, callee, args);
3434
}
35+
36+
void fir::runtime::cuda::genDescriptorCheckSection(fir::FirOpBuilder &builder,
37+
mlir::Location loc,
38+
mlir::Value desc) {
39+
mlir::func::FuncOp func =
40+
fir::runtime::getRuntimeFunc<mkRTKey(CUFDescriptorCheckSection)>(loc,
41+
builder);
42+
auto fTy = func.getFunctionType();
43+
mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc);
44+
mlir::Value sourceLine =
45+
fir::factory::locationToLineNo(builder, loc, fTy.getInput(2));
46+
llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments(
47+
builder, loc, fTy, desc, sourceFile, sourceLine)};
48+
builder.create<fir::CallOp>(loc, func, args);
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
2+
3+
! Check insertion of runtime checks
4+
5+
interface
6+
subroutine foo(a)
7+
real, device, dimension(:,:) :: a
8+
end subroutine
9+
end interface
10+
11+
real, device, allocatable, dimension(:,:) :: a
12+
allocate(a(10,10))
13+
call foo(a(1:10,1:10:2))
14+
end
15+
16+
subroutine foo(a)
17+
real, device, dimension(:,:) :: a
18+
end subroutine
19+
20+
! CHECK-LABEL: func.func @_QQmain()
21+
! CHECK: fir.call @_FortranACUFDescriptorCheckSection
22+
! CHECK: fir.call @_QPfoo

flang/test/Lower/OpenMP/flush02.f90

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! This test checks lowering of OpenMP Flush Directive.
2+
3+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
4+
5+
module flush02_mod
6+
type t1
7+
integer(kind=4) :: x = 4
8+
end type t1
9+
10+
type :: t2
11+
type(t1) :: y = t1(2)
12+
end type t2
13+
14+
15+
contains
16+
17+
subroutine sub01(pt)
18+
class(t1), intent(inout) :: pt
19+
type(t2) :: dt
20+
integer, allocatable :: a(:)
21+
integer, pointer :: b(:)
22+
23+
! CHECK: omp.flush({{.*}} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
24+
! CHECK: omp.flush({{.*}} : !fir.ref<f32>)
25+
! CHECK: omp.flush({{.*}} : !fir.ref<!fir.type<_QMflush02_modTt2{y:!fir.type<_QMflush02_modTt1{x:i32}>}>>)
26+
! CHECK: omp.flush({{.*}} : !fir.class<!fir.type<_QMflush02_modTt1{x:i32}>>)
27+
!$omp flush(a)
28+
!$omp flush(p)
29+
!$omp flush(dt)
30+
!$omp flush(pt)
31+
end subroutine
32+
end module flush02_mod

flang/tools/bbc/bbc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
441441
loweringOptions.setStackRepackArrays(stackRepackArrays);
442442
loweringOptions.setRepackArrays(repackArrays);
443443
loweringOptions.setRepackArraysWhole(repackArraysWhole);
444+
if (enableCUDA)
445+
loweringOptions.setCUDARuntimeCheck(true);
444446
std::vector<Fortran::lower::EnvironmentDefault> envDefaults = {};
445447
Fortran::frontend::TargetOptions targetOpts;
446448
Fortran::frontend::CodeGenOptions cgOpts;

llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,6 @@ static void mergePdbs() {
13751375
}
13761376

13771377
static void explain() {
1378-
std::unique_ptr<IPDBSession> Session;
13791378
InputFile IF =
13801379
ExitOnErr(InputFile::open(opts::explain::InputFilename.front(), true));
13811380

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def FlushOp : OpenMP_Op<"flush", clauses = [
889889
specified or implied.
890890
}] # clausesDescription;
891891

892-
let arguments = !con((ins Variadic<OpenMP_PointerLikeType>:$varList),
892+
let arguments = !con((ins Variadic<AnyType>:$varList),
893893
clausesArgs);
894894

895895
// Override inherited assembly format to include `varList`.

polly/lib/Support/RegisterPasses.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ static bool
541541
parseTopLevelPipeline(llvm::ModulePassManager &MPM,
542542
PassInstrumentationCallbacks *PIC,
543543
ArrayRef<PassBuilder::PipelineElement> Pipeline) {
544-
std::vector<PassBuilder::PipelineElement> FullPipeline;
545544
StringRef FirstName = Pipeline.front().Name;
546545

547546
if (!isScopPassName(FirstName))

0 commit comments

Comments
 (0)