Skip to content

Commit 838bbaa

Browse files
committed
Build PTX .a library
1 parent 90ae3d1 commit 838bbaa

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

flang-rt/cmake/modules/AddFlangRTOffload.cmake

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,27 @@ macro(enable_cuda_compilation name files)
4242
"${CUDA_COMPILE_OPTIONS}"
4343
)
4444

45-
if (EXISTS "${FLANG_RT_LIBCUDACXX_PATH}/include")
46-
# When using libcudacxx headers files, we have to use them
47-
# for all files of F18 runtime.
48-
include_directories(AFTER ${FLANG_RT_LIBCUDACXX_PATH}/include)
49-
add_compile_definitions(RT_USE_LIBCUDACXX=1)
50-
endif()
45+
# Create a .a library consisting of CUDA PTX.
46+
# This is different from a regular static library. The CUDA_PTX_COMPILATION
47+
# property can only be applied to object libraries and create *.ptx files
48+
# instead of *.o files. The .a will consist of those *.ptx files only.
49+
add_flangrt_library(obj.${name}PTX OBJECT ${files})
50+
set_property(TARGET obj.${name}PTX PROPERTY CUDA_PTX_COMPILATION ON)
51+
add_flangrt_library(${name}PTX STATIC "$<TARGET_OBJECTS:obj.${name}PTX>")
5152

52-
# Add an OBJECT library consisting of CUDA PTX.
53-
add_flangrt_library(${name}PTX OBJECT ${files})
54-
set_property(TARGET ${name}PTX PROPERTY CUDA_PTX_COMPILATION ON)
53+
# Apply configuration options
5554
if (FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS)
56-
target_compile_definitions(${name}PTX
55+
target_compile_definitions(obj.${name}PTX
5756
PRIVATE FLANG_RT_NO_GLOBAL_VAR_DEFS
5857
)
5958
endif()
59+
60+
# When using libcudacxx headers files, we have to use them
61+
# for all files of Flang-RT.
62+
if (EXISTS "${FLANG_RT_LIBCUDACXX_PATH}/include")
63+
target_include_directories(obj.${name}PTX AFTER PRIVATE "${FLANG_RT_LIBCUDACXX_PATH}/include")
64+
target_compile_definitions(obj.${name}PTX PRIVATE RT_USE_LIBCUDACXX=1)
65+
endif ()
6066
endif()
6167
endmacro()
6268

0 commit comments

Comments
 (0)