-
Notifications
You must be signed in to change notification settings - Fork 355
Update libcudacxx header TU testing to reuse common cmake infra #7980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jrhemstad
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
jrhemstad:libcudacxx-header-tu-layout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−208
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,6 @@ cccl_get_cudatoolkit() | |
| # Meta target for all configs' header builds: | ||
| add_custom_target(libcudacxx.test.internal_headers) | ||
|
|
||
| # We need to handle atomic headers differently as they do not compile on architectures below sm70 | ||
| set(architectures_at_least_sm70) | ||
| foreach (item IN LISTS CMAKE_CUDA_ARCHITECTURES) | ||
| if (item GREATER_EQUAL 70) | ||
| list(APPEND architectures_at_least_sm70 ${item}) | ||
| endif() | ||
| endforeach() | ||
|
|
||
| # Grep all internal headers | ||
| file( | ||
| GLOB_RECURSE internal_headers | ||
|
|
@@ -39,94 +31,94 @@ list(FILTER internal_headers EXCLUDE REGEX "__cuda/*") | |
| # generated cuda::ptx headers are not standalone | ||
| list(FILTER internal_headers EXCLUDE REGEX "__ptx/instructions/generated") | ||
|
|
||
| function(libcudacxx_create_internal_header_test header_name headertest_src) | ||
| # Create the default target for that file | ||
| add_library(internal_headertest_${header_name} SHARED "${headertest_src}.cu") | ||
| cccl_configure_target(internal_headertest_${header_name}) | ||
| target_compile_definitions( | ||
| internal_headertest_${header_name} | ||
| PRIVATE _CCCL_HEADER_TEST | ||
| function(libcudacxx_add_internal_header_test_target target_name) | ||
| if (NOT ARGN) | ||
| return() | ||
| endif() | ||
|
|
||
| cccl_generate_header_tests( | ||
| ${target_name} | ||
| libcudacxx/include | ||
| NO_METATARGETS | ||
| LANGUAGE CUDA | ||
| HEADER_TEMPLATE "${libcudacxx_SOURCE_DIR}/cmake/header_test.cpp.in" | ||
| HEADERS ${ARGN} | ||
| ) | ||
|
|
||
| target_compile_definitions(${target_name} PRIVATE _CCCL_HEADER_TEST) | ||
| target_link_libraries( | ||
| internal_headertest_${header_name} | ||
| ${target_name} | ||
| PUBLIC # | ||
| libcudacxx.compiler_interface | ||
| CUDA::cudart | ||
| ) | ||
|
|
||
| # Ensure that if this is an atomic header, we only include the right architectures | ||
| string( | ||
| REGEX MATCH | ||
| "atomic|barrier|latch|semaphore|annotated_ptr|pipeline" | ||
| match | ||
| "${header}" | ||
| ) | ||
| if (match) | ||
| # Ensure that we only compile the header when we have some architectures enabled | ||
| if (NOT architectures_at_least_sm70) | ||
| return() | ||
| endif() | ||
| set_target_properties( | ||
| internal_headertest_${header_name} | ||
| PROPERTIES CUDA_ARCHITECTURES "${architectures_at_least_sm70}" | ||
| ) | ||
| endif() | ||
|
|
||
| add_dependencies( | ||
| libcudacxx.test.internal_headers | ||
| internal_headertest_${header_name} | ||
| ) | ||
| add_dependencies(libcudacxx.test.internal_headers ${target_name}) | ||
| endfunction() | ||
|
|
||
| # We have fallbacks for some type traits that we want to explicitly test so that they do not bitrot | ||
| function( | ||
| libcudacxx_create_internal_header_fallback_test | ||
| header_name | ||
| headertest_src | ||
| libcudacxx_add_internal_header_test_target( | ||
| libcudacxx.test.internal_headers.base | ||
| ${internal_headers} | ||
| ) | ||
| # MSVC cannot handle some of the fallbacks | ||
| if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}") | ||
| if ( | ||
| "${header}" MATCHES "is_base_of" | ||
| OR "${header}" MATCHES "is_nothrow_destructible" | ||
| OR "${header}" MATCHES "is_polymorphic" | ||
| ) | ||
| return() | ||
| endif() | ||
|
|
||
| # We have fallbacks for some type traits that we want to explicitly test so that they do not bitrot. | ||
| set(internal_headers_fallback) | ||
| set(internal_headers_fallback_per_header_defines) | ||
| foreach (header IN LISTS internal_headers) | ||
| # MSVC cannot handle some of the fallbacks. | ||
| if ( | ||
| "MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}" | ||
| AND | ||
| ( | ||
| "${header}" MATCHES "is_base_of" | ||
| OR "${header}" MATCHES "is_nothrow_destructible" | ||
| OR "${header}" MATCHES "is_polymorphic" | ||
| ) | ||
| ) | ||
| continue() | ||
| endif() | ||
|
|
||
| # Search the file for a fallback definition | ||
| file(READ ${libcudacxx_SOURCE_DIR}/include/${header} header_file) | ||
| file(READ "${libcudacxx_SOURCE_DIR}/include/${header}" header_file) | ||
| string(REGEX MATCH "_LIBCUDACXX_[A-Z_]*_FALLBACK" fallback "${header_file}") | ||
| if (fallback) | ||
| # Adopt the filename for the fallback tests | ||
| set(header_name "${header_name}_fallback") | ||
| libcudacxx_create_internal_header_test(${header_name} ${headertest_src}) | ||
| target_compile_definitions( | ||
| internal_headertest_${header_name} | ||
| PRIVATE "-D${fallback}" | ||
| list(APPEND internal_headers_fallback "${header}") | ||
| string( | ||
| REGEX REPLACE | ||
| "([][+.*^$()|?\\\\])" | ||
| "\\\\\\1" | ||
| header_regex | ||
| "${header}" | ||
| ) | ||
|
Comment on lines
+84
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found the previous solution much much simpler |
||
| list( | ||
| APPEND internal_headers_fallback_per_header_defines | ||
| DEFINE | ||
| "${fallback}" | ||
| "^${header_regex}$" | ||
| ) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| function(libcudacxx_add_internal_header_test header) | ||
| # ${header} contains the "/" from the subfolder, replace by "_" for actual names | ||
| string(REPLACE "/" "_" header_name "${header}") | ||
| endforeach() | ||
|
|
||
| # Create the source file for the header target from the template and add the file to the global project | ||
| set(headertest_src "headers/${header_name}") | ||
| configure_file( | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmake/header_test.cpp.in" | ||
| "${headertest_src}.cu" | ||
| if (internal_headers_fallback) | ||
| cccl_generate_header_tests( | ||
| libcudacxx.test.internal_headers.fallback | ||
| libcudacxx/include | ||
| NO_METATARGETS | ||
| LANGUAGE CUDA | ||
| HEADER_TEMPLATE "${libcudacxx_SOURCE_DIR}/cmake/header_test.cpp.in" | ||
| HEADERS ${internal_headers_fallback} | ||
| PER_HEADER_DEFINES ${internal_headers_fallback_per_header_defines} | ||
| ) | ||
|
|
||
| # Create the default target for that file | ||
| libcudacxx_create_internal_header_test(${header_name} ${headertest_src}) | ||
|
|
||
| # Optionally create a fallback target for that file | ||
| libcudacxx_create_internal_header_fallback_test(${header_name} ${headertest_src}) | ||
| endfunction() | ||
|
|
||
| foreach (header IN LISTS internal_headers) | ||
| libcudacxx_add_internal_header_test(${header}) | ||
| endforeach() | ||
| target_compile_definitions( | ||
| libcudacxx.test.internal_headers.fallback | ||
| PRIVATE _CCCL_HEADER_TEST | ||
| ) | ||
| target_link_libraries( | ||
| libcudacxx.test.internal_headers.fallback | ||
| PUBLIC # | ||
| libcudacxx.compiler_interface | ||
| CUDA::cudart | ||
| ) | ||
| add_dependencies( | ||
| libcudacxx.test.internal_headers | ||
| libcudacxx.test.internal_headers.fallback | ||
| ) | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,82 +28,44 @@ if (CCCL_USE_LIBCXX) | |
| list(APPEND public_host_header_cxx_compile_options "-stdlib=libc++") | ||
| endif() | ||
|
|
||
| function(libcudacxx_create_public_header_test_host header_name headertest_src) | ||
| # Create the default target for that file | ||
| add_library( | ||
| public_headers_host_only_${header_name} | ||
| SHARED | ||
| "${headertest_src}.cpp" | ||
| ) | ||
| cccl_configure_target(public_headers_host_only_${header_name}) | ||
| target_compile_definitions( | ||
| public_headers_host_only_${header_name} | ||
| PRIVATE # | ||
| ${public_host_header_cxx_compile_definitions} | ||
| _CCCL_HEADER_TEST | ||
| ) | ||
| target_compile_options( | ||
| public_headers_host_only_${header_name} | ||
| PRIVATE ${public_host_header_cxx_compile_options} | ||
| ) | ||
| target_link_libraries( | ||
| public_headers_host_only_${header_name} | ||
| PUBLIC libcudacxx.compiler_interface | ||
| ) | ||
| add_dependencies( | ||
| libcudacxx.test.public_headers_host_only | ||
| public_headers_host_only_${header_name} | ||
| ) | ||
| endfunction() | ||
|
|
||
| function( | ||
| libcudacxx_create_public_header_test_host_with_ctk | ||
| header_name | ||
| headertest_src | ||
| libcudacxx_add_public_header_test_host_target | ||
| target_name | ||
| parent_target | ||
| with_ctk | ||
| ) | ||
| # Create the default target for that file | ||
| add_library( | ||
| public_headers_host_only_with_ctk_${header_name} | ||
| SHARED | ||
| "${headertest_src}.cpp" | ||
| cccl_generate_header_tests( | ||
| ${target_name} | ||
| libcudacxx/include | ||
| NO_METATARGETS | ||
| LANGUAGE CXX | ||
| HEADER_TEMPLATE "${libcudacxx_SOURCE_DIR}/cmake/header_test.cpp.in" | ||
| HEADERS ${public_headers_host_only} | ||
| ) | ||
| cccl_configure_target(public_headers_host_only_with_ctk_${header_name}) | ||
| target_compile_definitions( | ||
| public_headers_host_only_with_ctk_${header_name} | ||
| ${target_name} | ||
| PRIVATE # | ||
| ${public_host_header_cxx_compile_definitions} | ||
| _CCCL_HEADER_TEST | ||
| ) | ||
| target_compile_options( | ||
| public_headers_host_only_with_ctk_${header_name} | ||
| ${target_name} | ||
| PRIVATE ${public_host_header_cxx_compile_options} | ||
| ) | ||
| target_link_libraries( | ||
| public_headers_host_only_with_ctk_${header_name} | ||
| PUBLIC libcudacxx.compiler_interface CUDA::cudart | ||
| ) | ||
| add_dependencies( | ||
| libcudacxx.test.public_headers_host_only_with_ctk | ||
| public_headers_host_only_with_ctk_${header_name} | ||
| ) | ||
| target_link_libraries(${target_name} PUBLIC libcudacxx.compiler_interface) | ||
| if (with_ctk) | ||
| target_link_libraries(${target_name} PUBLIC CUDA::cudart) | ||
| endif() | ||
| add_dependencies(${parent_target} ${target_name}) | ||
| endfunction() | ||
|
|
||
| function(libcudacxx_add_public_headers_host_only header) | ||
| # ${header} contains the "/" from the subfolder, replace by "_" for actual names | ||
| string(REPLACE "/" "_" header_name "${header}") | ||
|
|
||
| # Create the source file for the header target from the template and add the file to the global project | ||
| set(headertest_src "headers/${header_name}") | ||
| configure_file( | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmake/header_test.cpp.in" | ||
| "${headertest_src}.cpp" | ||
| ) | ||
|
|
||
| # Create the default target for that file | ||
| libcudacxx_create_public_header_test_host(${header_name} ${headertest_src}) | ||
| libcudacxx_create_public_header_test_host_with_ctk(${header_name} ${headertest_src}) | ||
| endfunction() | ||
|
|
||
| foreach (header IN LISTS public_headers_host_only) | ||
| libcudacxx_add_public_headers_host_only(${header}) | ||
| endforeach() | ||
| libcudacxx_add_public_header_test_host_target( | ||
| libcudacxx.test.public_headers_host_only.base | ||
| libcudacxx.test.public_headers_host_only | ||
|
Comment on lines
+63
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we need those two for? Shouldnt |
||
| OFF | ||
| ) | ||
| libcudacxx_add_public_header_test_host_target( | ||
| libcudacxx.test.public_headers_host_only_with_ctk.base | ||
| libcudacxx.test.public_headers_host_only_with_ctk | ||
| ON | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: This is pretty ugly compared to the previous code, can we keep the nested ifs?