Skip to content

Commit cfc0951

Browse files
authored
[flang][cuda] Do not check assignment semantic in cuf kernel (#107512)
1 parent 37086ea commit cfc0951

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,18 @@ void CUDAChecker::Enter(const parser::CUFKernelDoConstruct &x) {
565565
std::get<std::list<parser::CUFReduction>>(directive.t)) {
566566
CheckReduce(context_, reduce);
567567
}
568+
inCUFKernelDoConstruct_ = true;
569+
}
570+
571+
void CUDAChecker::Leave(const parser::CUFKernelDoConstruct &) {
572+
inCUFKernelDoConstruct_ = false;
568573
}
569574

570575
void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
571576
auto lhsLoc{std::get<parser::Variable>(x.t).GetSource()};
572577
const auto &scope{context_.FindScope(lhsLoc)};
573578
const Scope &progUnit{GetProgramUnitContaining(scope)};
574-
if (IsCUDADeviceContext(&progUnit)) {
579+
if (IsCUDADeviceContext(&progUnit) || inCUFKernelDoConstruct_) {
575580
return; // Data transfer with assignment is only perform on host.
576581
}
577582

flang/lib/Semantics/check-cuda.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ class CUDAChecker : public virtual BaseChecker {
3939
void Enter(const parser::FunctionSubprogram &);
4040
void Enter(const parser::SeparateModuleSubprogram &);
4141
void Enter(const parser::CUFKernelDoConstruct &);
42+
void Leave(const parser::CUFKernelDoConstruct &);
4243
void Enter(const parser::AssignmentStmt &);
4344

4445
private:
4546
SemanticsContext &context_;
47+
bool inCUFKernelDoConstruct_ = false;
4648
};
4749

4850
bool CanonicalizeCUDA(parser::Program &);

flang/test/Lower/CUDA/cuda-data-transfer.cuf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,24 @@ end subroutine
332332
! CHECK: acc.serial
333333
! CHECK-NOT: cuf.data_transfer
334334
! CHECK: hlfir.assign
335+
336+
! Check that cuf.data_transfer are not generated within cuf kernel and do not
337+
! trigger semantic error.
338+
subroutine sub17()
339+
integer, parameter :: n = 10
340+
real, device :: adev(n)
341+
real, device :: bdev(n)
342+
real :: ahost
343+
real, managed :: b
344+
integer :: i
345+
346+
adev = ahost
347+
!$cuf kernel do <<<*,*>>>
348+
do i = 1, n
349+
ahost = adev(i) * bdev(i) + b
350+
enddo
351+
end subroutine
352+
353+
! CHECK-LABEL: func.func @_QPsub17()
354+
! CHECK: cuf.kernel<<<*, *>>>
355+
! CHECK-NOT: cuf.data_transfer

0 commit comments

Comments
 (0)