Skip to content

Commit

Permalink
[flang][cuda] Avoid generating data transfer when calling size intrin…
Browse files Browse the repository at this point in the history
…sic (#108081)

cuf.data_transfer was wrongly generated when calling the `size`
intrinsic on a device allocatable variable. Since the descriptor is
available on the host, there is no transfer needed.

Add `DescriptorInquiry` in the `CollectCudaSymbolsHelper` to filter out
symbols that are not needed for the transfer decision to be made.
  • Loading branch information
clementval authored Sep 10, 2024
1 parent 0f56ba1 commit b5ce7a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flang/lib/Evaluate/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,9 @@ struct CollectCudaSymbolsHelper : public SetTraverse<CollectCudaSymbolsHelper,
}
// Overload some of the operator() to filter out the symbols that are not
// of interest for CUDA data transfer logic.
semantics::UnorderedSymbolSet operator()(const DescriptorInquiry &) const {
return {};
}
semantics::UnorderedSymbolSet operator()(const Subscript &) const {
return {};
}
Expand Down
10 changes: 10 additions & 0 deletions flang/test/Lower/CUDA/cuda-data-transfer.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,13 @@ end subroutine
! CHECK-LABEL: func.func @_QPsub17()
! CHECK: cuf.kernel<<<*, *>>>
! CHECK-NOT: cuf.data_transfer

subroutine sub18()
integer, device, allocatable :: a(:)
integer :: isz

isz = size(a)
end subroutine

! CHECK-LABEL: func.func @_QPsub18()
! CHECK-NOT: cuf.data_transfer

0 comments on commit b5ce7a9

Please sign in to comment.