summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Clement (バレンタイン クレメン) <clementval@gmail.com>2024-09-04 08:43:13 -0700
committerGitHub <noreply@github.com>2024-09-04 08:43:13 -0700
commitc81b43074ab010d01ad794224dd9dd22bbe8a1f7 (patch)
tree1b01417b2b49a459a5e48dfa8f101fffd2597148
parentfe454b2044aba1d808cec486a8ca7a0e202d31bf (diff)
[flang][cuda] Fix lowering of cuf kernel with unstructured nested construct (#107149)
Lowering was crashing when cuf kernels has an unstructured construct. Blocks created by PFT need to be re-created inside of the operation like it is done for OpenACC construct.
-rw-r--r--flang/lib/Lower/Bridge.cpp8
-rw-r--r--flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf20
2 files changed, 27 insertions, 1 deletions
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index e5ccf659c3f8..1f2724290b88 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "flang/Lower/Bridge.h"
+#include "DirectivesCommon.h"
#include "flang/Common/Version.h"
#include "flang/Lower/Allocatable.h"
#include "flang/Lower/CallInterface.h"
@@ -2999,6 +3000,12 @@ private:
mlir::Block &b = op.getRegion().back();
builder->setInsertionPointToStart(&b);
+ Fortran::lower::pft::Evaluation *crtEval = &getEval();
+ if (crtEval->lowerAsUnstructured())
+ Fortran::lower::createEmptyRegionBlocks<fir::FirEndOp>(
+ *builder, crtEval->getNestedEvaluations());
+ builder->setInsertionPointToStart(&b);
+
for (auto [arg, value] : llvm::zip(
op.getLoopRegions().front()->front().getArguments(), ivValues)) {
mlir::Value convArg =
@@ -3006,7 +3013,6 @@ private:
builder->create<fir::StoreOp>(loc, convArg, value);
}
- Fortran::lower::pft::Evaluation *crtEval = &getEval();
if (crtEval->lowerAsStructured()) {
crtEval = &crtEval->getFirstNestedEvaluation();
for (int64_t i = 1; i < nestedLoops; i++)
diff --git a/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf b/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
index ba5d390df478..aac569b6eb35 100644
--- a/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
+++ b/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
@@ -78,3 +78,23 @@ end
! CHECK: %[[STREAM_LOAD:.*]] = fir.load %[[STREAM]]#0 : !fir.ref<i64>
! CHECK: %[[STREAM_I32:.*]] = fir.convert %[[STREAM_LOAD]] : (i64) -> i32
! CHECK: cuf.kernel<<<*, *, stream = %[[STREAM_I32]]>>>
+
+
+! Test lowering with unstructured construct inside.
+subroutine sub2(m,a,b)
+ integer :: m
+ real, device :: a(m,m), b(m)
+ integer :: i,j
+ !$cuf kernel do<<<*,*>>>
+
+ do j = 1, m
+ i = 1
+ do while (a(i,j).eq.0)
+ i = i + 1
+ end do
+ b(j) = i
+ end do
+end subroutine
+
+! CHECK-LABEL: func.func @_QPsub2
+! CHECK: cuf.kernel