Skip to content

Conversation

@clementval
Copy link
Contributor

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.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:semantics labels Sep 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2024

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

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 --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

@clementval clementval changed the title [flang][cuf] Avoid generating data transfer when calling size intrinsic [flang][cuda] Avoid generating data transfer when calling size intrinsic Sep 10, 2024
Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@clementval clementval merged commit b5ce7a9 into llvm:main Sep 10, 2024
@clementval clementval deleted the cuf_size_data_transfer branch September 10, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants