[flang-commits] [flang] b5ce7a9 - [flang][cuda] Avoid generating data transfer when calling size intrinsic (#108081)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 10 14:07:30 PDT 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-09-10T14:07:26-07:00
New Revision: b5ce7a9fbd898767d0c1fa13ef5c33bbbe67981f
URL: https://github.com/llvm/llvm-project/commit/b5ce7a9fbd898767d0c1fa13ef5c33bbbe67981f
DIFF: https://github.com/llvm/llvm-project/commit/b5ce7a9fbd898767d0c1fa13ef5c33bbbe67981f.diff
LOG: [flang][cuda] Avoid generating data transfer when calling size intrinsic (#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.
Added:
Modified:
flang/lib/Evaluate/tools.cpp
flang/test/Lower/CUDA/cuda-data-transfer.cuf
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 6b3db619c1e2f1..400f27aef98da6 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -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 {};
}
diff --git a/flang/test/Lower/CUDA/cuda-data-transfer.cuf b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
index bcbac9c3031423..11f1f33d7cb587 100644
--- a/flang/test/Lower/CUDA/cuda-data-transfer.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
@@ -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
More information about the flang-commits
mailing list