[flang-commits] [flang] [flang][cuf] Avoid generating data transfer when calling size intrinsic (PR #108081)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 10 13:26:51 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-fir-hlfir
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/108081.diff
2 Files Affected:
- (modified) flang/lib/Evaluate/tools.cpp (+3)
- (modified) flang/test/Lower/CUDA/cuda-data-transfer.cuf (+10)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/108081
More information about the flang-commits
mailing list