[llvm] [flang-rt][cuda] Build io-stmt-minimal.cpp as CUDA in the thin I/O PTX target (PR #219250)
Zhen Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 10:46:29 PDT 2026
https://github.com/wangzpgi created https://github.com/llvm/llvm-project/pull/219250
In enable_cuda_compilation(), LANGUAGE CUDA and the CUDA compile options are set on ${files}. The thin I/O PTX target appends io-stmt-minimal.cpp to the source list, but that file is not part of ${files}, so it never receives those properties. It is compiled as plain C++, produces no PTX in a target with CUDA_PTX_COMPILATION enabled, and none of its definitions reach the device library.
Since thin I/O also drops io-stmt.cpp and io-error.cpp, the symbols they provided end up undefined, and device-side list-directed output fails at link time, e.g.:
```
ptxas fatal : Unresolved extern function
'_ZN7Fortran7runtime2io24ExternalIoStatementStateILNS1_9DirectionE0EEC2ERNS1_16ExternalFileUnitEPKci'
```
Set LANGUAGE CUDA and the CUDA compile options on io-stmt-minimal.cpp so it is`compiled as device code.
>From b648052afb4ff11871e2294fa92e8b5c061a92ab Mon Sep 17 00:00:00 2001
From: Zhen Wang <zhenw at nvidia.com>
Date: Thu, 27 Aug 2026 10:39:02 -0700
Subject: [PATCH] Build io-stmt-minimal.cpp as CUDA in the thin I/O PTX target
---
flang-rt/cmake/modules/AddFlangRTOffload.cmake | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/flang-rt/cmake/modules/AddFlangRTOffload.cmake b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
index 1506c53a5b55c..374b6e82d5dfa 100644
--- a/flang-rt/cmake/modules/AddFlangRTOffload.cmake
+++ b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
@@ -51,6 +51,13 @@ macro(enable_cuda_compilation name files)
list(REMOVE_ITEM sources
io-api.cpp io-error.cpp io-stmt.cpp descriptor-io.cpp namelist.cpp)
list(APPEND sources io-stmt-minimal.cpp)
+ # io-stmt-minimal.cpp is not part of ${files}, so it did not get the CUDA
+ # language and compile options set above. Without them it is compiled as
+ # plain C++ and contributes no PTX, leaving its definitions out of the
+ # device library.
+ set_source_files_properties(io-stmt-minimal.cpp PROPERTIES
+ LANGUAGE CUDA
+ COMPILE_OPTIONS "${CUDA_COMPILE_OPTIONS}")
add_flangrt_library(obj.${name}PTX OBJECT ${sources})
set_target_properties(obj.${name}PTX PROPERTIES
CUDA_PTX_COMPILATION ON
More information about the llvm-commits
mailing list