Skip to content

Commit 1563a87

Browse files
authored
[flang][runtime] Allow building CUDA PTX library without global vars definitions. (llvm#90280)
1 parent 3ba0791 commit 1563a87

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

flang/cmake/modules/AddFlangOffloadRuntime.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ option(FLANG_EXPERIMENTAL_CUDA_RUNTIME
22
"Compile Fortran runtime as CUDA sources (experimental)" OFF
33
)
44

5+
option(FLANG_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS
6+
"Do not compile global variables' definitions when producing PTX library" OFF
7+
)
8+
59
set(FLANG_LIBCUDACXX_PATH "" CACHE PATH "Path to libcu++ package installation")
610

711
set(FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD "off" CACHE STRING
@@ -56,6 +60,11 @@ macro(enable_cuda_compilation name files)
5660
# Add an OBJECT library consisting of CUDA PTX.
5761
llvm_add_library(${name}PTX OBJECT PARTIAL_SOURCES_INTENDED ${files})
5862
set_property(TARGET obj.${name}PTX PROPERTY CUDA_PTX_COMPILATION ON)
63+
if (FLANG_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS)
64+
target_compile_definitions(obj.${name}PTX
65+
PRIVATE FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
66+
)
67+
endif()
5968
endif()
6069
endmacro()
6170

flang/runtime/environment.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ extern char **environ;
2323

2424
namespace Fortran::runtime {
2525

26+
#ifndef FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
2627
RT_OFFLOAD_VAR_GROUP_BEGIN
2728
RT_VAR_ATTRS ExecutionEnvironment executionEnvironment;
2829
RT_OFFLOAD_VAR_GROUP_END
30+
#endif // FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
2931

3032
static void SetEnvironmentDefaults(const EnvironmentDefaultList *envDefaults) {
3133
if (!envDefaults) {

flang/runtime/unit.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
namespace Fortran::runtime::io {
2121

22+
#ifndef FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
2223
RT_OFFLOAD_VAR_GROUP_BEGIN
2324
RT_VAR_ATTRS ExternalFileUnit *defaultInput{nullptr}; // unit 5
2425
RT_VAR_ATTRS ExternalFileUnit *defaultOutput{nullptr}; // unit 6
2526
RT_VAR_ATTRS ExternalFileUnit *errorOutput{nullptr}; // unit 0 extension
2627
RT_OFFLOAD_VAR_GROUP_END
28+
#endif // FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
2729

2830
RT_OFFLOAD_API_GROUP_BEGIN
2931

flang/runtime/utf.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Fortran::runtime {
1212

13+
#ifndef FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
1314
// clang-format off
1415
RT_OFFLOAD_VAR_GROUP_BEGIN
1516
const RT_CONST_VAR_ATTRS std::uint8_t UTF8FirstByteTable[256]{
@@ -40,6 +41,7 @@ const RT_CONST_VAR_ATTRS std::uint8_t UTF8FirstByteTable[256]{
4041
};
4142
RT_OFFLOAD_VAR_GROUP_END
4243
// clang-format on
44+
#endif // FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
4345

4446
RT_OFFLOAD_API_GROUP_BEGIN
4547
// Non-minimal encodings are accepted.

0 commit comments

Comments
 (0)