https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/225315
Under `-gpu=mem:pinned` an unattributed `ALLOCATABLE` is attributed as `pinned` by the compiler. The module file therefore spelled an implicitly applied `PINNED` the same as one the user wrote, and a reader treated it as a user requirement: adding `-gpu=mem:pinned` to a module's build rejected its OpenACC-only consumers over an attribute the user never wrote. Record the implicit attribution for pinned as well, so it is written as `PINNED(IMPLICIT)` and consumers can tell the two apart. >From ec0511ac05154d901fadb606ab31932372774742 Mon Sep 17 00:00:00 2001 From: ergawy <[email protected]> Date: Mon, 21 Sep 2026 22:16:07 -0700 Subject: [PATCH] [flang][cuda] Record implicit pinned attribution in module files Under -gpu=mem:pinned an unattributed ALLOCATABLE is attributed as pinned by the compiler, the same way -gpu=mem:managed attributes one as managed, but only the latter recorded that it had done so. The module file therefore spelled an implicitly applied PINNED the same as one the user wrote, and a reader treated it as a user requirement: adding -gpu=mem:pinned to a module's build rejected its OpenACC-only consumers over an attribute the user never wrote. Record the attribution for pinned as well, so it is written as PINNED(IMPLICIT) and consumers can tell the two apart. --- flang/lib/Semantics/resolve-names.cpp | 4 +- .../CUDA/cuda-pinned-implicit-modfile.cuf | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 8a2ffc1c20f1b..570c13789a097 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -11018,8 +11018,10 @@ void ResolveNamesVisitor::FinishSpecificationPart( // enabled. else if (IsAllocatable(symbol) && context().languageFeatures().IsEnabled( - common::LanguageFeature::CudaPinned)) + common::LanguageFeature::CudaPinned)) { object->set_cudaDataAttr(common::CUDADataAttr::Pinned); + object->set_cudaDataAttrIsImplicit(); + } } } } diff --git a/flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf b/flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf new file mode 100644 index 0000000000000..e9a4170c20c95 --- /dev/null +++ b/flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf @@ -0,0 +1,42 @@ +! Under -gpu=pinned the compiler attributes unattributed ALLOCATABLEs as +! pinned on the user's behalf, exactly as -gpu=managed attributes them as +! managed. A module file records that it did so, with the (IMPLICIT) +! qualifier, so that a reader can tell such an attribute from one the user +! wrote. + +! RUN: rm -rf %t && split-file %s %t +! RUN: cd %t && bbc -emit-hlfir -fcuda -gpu=pinned def.cuf -o /dev/null +! RUN: cat %t/m.mod | FileCheck %s --check-prefix=MODFILE + +! An attribute the compiler applied does not make the module a definer of CUDA +! symbols, so a consumer without CUDA Fortran enabled is not rejected. +! RUN: cd %t && bbc -emit-hlfir -fopenacc use_acc.cuf -o /dev/null + +! One the user wrote still is, and still rejects such a consumer. +! RUN: cd %t && bbc -emit-hlfir -fcuda def_explicit.cuf -o /dev/null +! RUN: cd %t && not bbc -emit-hlfir -fopenacc use_acc_explicit.cuf -o /dev/null 2>&1 \ +! RUN: | FileCheck %s --check-prefix=EXPLICIT + +!--- def.cuf +module m + real, allocatable :: implicit_var(:) +end module + +! MODFILE: real(4),allocatable,pinned(implicit)::implicit_var(:) + +!--- use_acc.cuf +subroutine acc_only() + use m +end subroutine + +!--- def_explicit.cuf +module m_explicit + real, allocatable, pinned :: explicit_var(:) +end module + +!--- use_acc_explicit.cuf +subroutine acc_only_explicit() + use m_explicit +end subroutine + +! EXPLICIT: error: Cannot use module file for module 'm_explicit': CUDA is not enabled, but '{{.*}}m_explicit.mod' defines CUDA symbols _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
