Skip to content

Commit ac245b1

Browse files
committed
Cleanups + testing detail headers
1 parent 012c995 commit ac245b1

File tree

7 files changed

+60
-178
lines changed

7 files changed

+60
-178
lines changed

cmake/header_testing.cmake

Lines changed: 39 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -23,204 +23,69 @@
2323
# Meta target for all header builds:
2424
add_custom_target(cuco.all.headers)
2525

26-
find_package(CUDAToolkit)
27-
28-
# Custom header test template content
29-
set(CUCO_HEADER_TEST_TEMPLATE_CONTENT
30-
"// This source file checks that:
31-
// 1) Header <@header@> compiles without error.
32-
// 2) Common macro collisions with platform/system headers are avoided.
33-
34-
// Define CUCO_HEADER_MACRO_CHECK(macro, header), which emits a diagnostic indicating
35-
// a potential macro collision and halts.
36-
//
37-
// Hacky way to build a string, but it works on all tested platforms.
38-
#define CUCO_HEADER_MACRO_CHECK(MACRO, HEADER) \\
39-
CUCO_HEADER_MACRO_CHECK_IMPL( \\
40-
Identifier MACRO should not be used from cuco headers due to conflicts with HEADER macros.)
41-
42-
// Use raw platform macros instead of the CCCL macros since we
43-
// don't want to #include any headers other than the one being tested.
44-
//
45-
// This is implemented for GCC/Clang (cuco doesn't support MSVC).
46-
#if defined(__clang__) || defined(__GNUC__)
47-
48-
// GCC/clang implementation:
49-
# define CUCO_HEADER_MACRO_CHECK_IMPL(msg) CUCO_HEADER_MACRO_CHECK_IMPL0(GCC error #msg)
50-
# define CUCO_HEADER_MACRO_CHECK_IMPL0(expr) _Pragma(#expr)
51-
52-
#else
53-
# error \"Unsupported compiler for cuco header testing\"
54-
#endif
55-
56-
// May be defined to skip macro check for certain configurations.
57-
#ifndef CUCO_IGNORE_HEADER_MACRO_CHECKS
58-
59-
// complex.h conflicts
60-
# define I CUCO_HEADER_MACRO_CHECK('I', complex.h)
61-
62-
// windows.h conflicts
63-
# define small CUCO_HEADER_MACRO_CHECK('small', windows.h)
64-
65-
# ifdef _WIN32
66-
// On Windows, make sure any include of Windows.h (e.g. via NVTX) does not define the checked macros
67-
# define WIN32_LEAN_AND_MEAN
68-
# endif // _WIN32
69-
70-
// termios.h conflicts (NVIDIA/thrust#1547)
71-
# define B0 CUCO_HEADER_MACRO_CHECK(\"B0\", termios.h)
72-
73-
#endif // CUCO_IGNORE_HEADER_MACRO_CHECKS
74-
75-
#include <@header@>
76-
77-
// No main function - this is compiled as an object file for link checking
78-
")
79-
80-
function(cuco_generate_header_tests target_name headers lang)
81-
# Configure header templates:
82-
set(header_srcs)
83-
foreach (header IN LISTS headers)
84-
if(lang STREQUAL "CUDA")
85-
set(header_src "${CMAKE_CURRENT_BINARY_DIR}/headers/${target_name}/${header}.cu")
86-
else()
87-
set(header_src "${CMAKE_CURRENT_BINARY_DIR}/headers/${target_name}/${header}.cpp")
88-
endif()
89-
90-
# Create the directory if it doesn't exist
91-
get_filename_component(header_dir "${header_src}" DIRECTORY)
92-
file(MAKE_DIRECTORY "${header_dir}")
93-
94-
# Configure the template
95-
string(CONFIGURE "${CUCO_HEADER_TEST_TEMPLATE_CONTENT}" header_content @ONLY)
96-
file(WRITE "${header_src}" "${header_content}")
97-
list(APPEND header_srcs ${header_src})
98-
endforeach()
99-
100-
# Object library that compiles each header:
101-
add_library(${target_name} OBJECT ${header_srcs})
102-
103-
# Set language-specific properties
104-
if(lang STREQUAL "CUDA")
105-
set_target_properties(${target_name} PROPERTIES
106-
CUDA_SEPARABLE_COMPILATION ON
107-
CUDA_RESOLVE_DEVICE_SYMBOLS ON
108-
)
109-
110-
# Set CUDA architectures
111-
if(CMAKE_CUDA_ARCHITECTURES)
112-
set_target_properties(${target_name} PROPERTIES
113-
CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}"
114-
)
115-
endif()
116-
117-
# Add required CUDA compiler flags for cuco
118-
target_compile_options(${target_name} PRIVATE
119-
$<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda>
120-
)
121-
endif()
122-
123-
target_link_libraries(${target_name} PUBLIC cuco::cuco)
124-
125-
# Check that all functions in headers are either template functions or inline:
126-
set(link_target ${target_name}.link_check)
127-
if(lang STREQUAL "CUDA")
128-
add_executable(${link_target} "${CMAKE_CURRENT_BINARY_DIR}/link_check_main_${target_name}.cu")
129-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/link_check_main_${target_name}.cu"
130-
"int main() { return 0; }")
131-
else()
132-
add_executable(${link_target} "${CMAKE_CURRENT_BINARY_DIR}/link_check_main_${target_name}.cpp")
133-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/link_check_main_${target_name}.cpp"
134-
"int main() { return 0; }")
135-
endif()
136-
137-
target_link_libraries(${link_target} PUBLIC cuco::cuco)
138-
139-
# Linking both ${target_name} and $<TARGET_OBJECTS:${target_name}> forces CMake to
140-
# link the same objects twice. The compiler will complain about duplicate symbols if
141-
# any functions are missing inline markup.
142-
target_link_libraries(${link_target} PRIVATE
143-
${target_name}
144-
$<TARGET_OBJECTS:${target_name}>
145-
)
146-
endfunction()
147-
14826
function(cuco_add_header_test label definitions)
14927
set(config_prefix "cuco")
15028

151-
# Get all .cuh and .hpp files...
152-
file(GLOB_RECURSE all_headers
29+
# GLOB ALL THE THINGS - similar to Thrust's approach, including detail headers
30+
# Use GLOB_RECURSE to find all headers recursively
31+
file(GLOB_RECURSE headers
15332
RELATIVE "${CUCO_SOURCE_DIR}/include"
15433
CONFIGURE_DEPENDS
15534
"${CUCO_SOURCE_DIR}/include/cuco/*.cuh"
15635
"${CUCO_SOURCE_DIR}/include/cuco/*.hpp"
15736
)
158-
159-
# ...and remove all the detail headers
160-
file(GLOB_RECURSE headers_exclude_details
161-
RELATIVE "${CUCO_SOURCE_DIR}/include"
162-
CONFIGURE_DEPENDS
163-
"${CUCO_SOURCE_DIR}/include/cuco/detail/*"
164-
"${CUCO_SOURCE_DIR}/include/cuco/*/detail/*"
165-
"${CUCO_SOURCE_DIR}/include/cuco/*/*/detail/*"
166-
)
16737

168-
set(headers ${all_headers})
169-
if(headers_exclude_details)
170-
list(REMOVE_ITEM headers ${headers_exclude_details})
171-
endif()
38+
# Debug: Print found headers
39+
list(LENGTH headers headers_count)
40+
message(STATUS "Found ${headers_count} headers for testing: ${headers}")
17241

17342
# List of headers that have known issues or are not meant to be included directly
17443
set(excluded_headers
175-
# Add any headers that should be excluded from testing here
176-
# Example: cuco/internal_header.cuh
44+
# Headers with circular dependencies that are not meant to be included directly
45+
cuco/detail/static_map/helpers.cuh
17746
)
17847

17948
# Remove excluded headers
18049
if(excluded_headers)
18150
list(REMOVE_ITEM headers ${excluded_headers})
51+
list(LENGTH headers headers_count_after_exclusion)
52+
message(STATUS "After exclusion: ${headers_count_after_exclusion} headers remaining")
18253
endif()
18354

184-
# Separate headers by type for different language compilation
185-
set(cuda_headers)
186-
set(cpp_headers)
187-
188-
foreach(header IN LISTS headers)
189-
if(header MATCHES "\\.cuh$")
190-
list(APPEND cuda_headers ${header})
191-
elseif(header MATCHES "\\.hpp$")
192-
list(APPEND cpp_headers ${header})
193-
list(APPEND cuda_headers ${header}) # .hpp files can also be compiled with CUDA
194-
endif()
55+
# Only test with CUDA compiler since cuco is device-only
56+
set(headertest_target ${config_prefix}.headers.${label})
57+
58+
# Generate header test sources (simple approach since CCCL utilities aren't available)
59+
set(header_srcs)
60+
foreach (header IN LISTS headers)
61+
set(header_src "${CMAKE_CURRENT_BINARY_DIR}/headers/${headertest_target}/${header}.cu")
62+
63+
# Create the directory if it doesn't exist
64+
get_filename_component(header_dir "${header_src}" DIRECTORY)
65+
file(MAKE_DIRECTORY "${header_dir}")
66+
67+
# Write simple test file that includes the header
68+
file(WRITE "${header_src}" "#include <${header}>\nint main() { return 0; }\n")
69+
list(APPEND header_srcs ${header_src})
19570
endforeach()
19671

197-
# Compile headers with both host and cuda compilers
198-
set(langs CXX CUDA)
72+
# Create object library that compiles each header
73+
add_library(${headertest_target} OBJECT ${header_srcs})
74+
target_link_libraries(${headertest_target} PUBLIC cuco::cuco)
75+
if (definitions)
76+
target_compile_definitions(${headertest_target} PRIVATE ${definitions})
77+
endif()
19978

200-
foreach (lang IN LISTS langs)
201-
set(headertest_target ${config_prefix}.headers.${label})
202-
if (lang STREQUAL "CXX")
203-
# Append .cxx to the header test target name when compiling with C++ compiler
204-
set(headertest_target ${headertest_target}.cxx)
205-
set(test_headers ${cpp_headers})
206-
else()
207-
set(test_headers ${cuda_headers})
208-
endif()
79+
# Add required CUDA compiler flags for cuco
80+
target_compile_options(${headertest_target} PRIVATE
81+
$<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda>
82+
)
20983

210-
if(test_headers)
211-
cuco_generate_header_tests(${headertest_target} "${test_headers}" ${lang})
212-
213-
if (definitions)
214-
target_compile_definitions(${headertest_target} PRIVATE ${definitions})
215-
endif()
216-
217-
# Disable macro checks for now since cuco has known issues with 'I' identifier
218-
# This should be removed once the macro collision issues are fixed
219-
target_compile_definitions(${headertest_target} PRIVATE CUCO_IGNORE_HEADER_MACRO_CHECKS)
84+
# Disable macro checks for now since cuco has known issues with 'I' identifier
85+
# This should be removed once the macro collision issues are fixed
86+
target_compile_definitions(${headertest_target} PRIVATE CUCO_IGNORE_HEADER_MACRO_CHECKS)
22087

221-
add_dependencies(cuco.all.headers ${headertest_target})
222-
endif()
223-
endforeach()
88+
add_dependencies(cuco.all.headers ${headertest_target})
22489
endfunction()
22590

22691
# Base header test - ensure all headers compile cleanly

include/cuco/detail/hash_functions/utils.cuh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include <cuda/std/cstddef>
20+
#include <cuda/std/cstdint>
2021

2122
namespace cuco::detail {
2223

@@ -29,12 +30,14 @@ constexpr __host__ __device__ T load_chunk(U const* const data, Extent index) no
2930
return chunk;
3031
}
3132

32-
constexpr __host__ __device__ std::uint32_t rotl32(std::uint32_t x, std::int8_t r) noexcept
33+
constexpr __host__ __device__ cuda::std::uint32_t rotl32(cuda::std::uint32_t x,
34+
cuda::std::int8_t r) noexcept
3335
{
3436
return (x << r) | (x >> (32 - r));
3537
}
3638

37-
constexpr __host__ __device__ std::uint64_t rotl64(std::uint64_t x, std::int8_t r) noexcept
39+
constexpr __host__ __device__ cuda::std::uint64_t rotl64(cuda::std::uint64_t x,
40+
cuda::std::int8_t r) noexcept
3841
{
3942
return (x << r) | (x >> (64 - r));
4043
}

include/cuco/detail/roaring_bitmap/util.cuh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include <cuco/detail/error.hpp>
1920
#include <cuco/utility/traits.hpp>
2021

2122
#include <cuda/std/cstddef>

include/cuco/detail/static_map/helpers.cuh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
#include <cuco/detail/static_map/kernels.cuh>
1919
#include <cuco/detail/utility/cuda.cuh>
20+
#include <cuco/detail/utility/cuda.hpp>
21+
#include <cuco/detail/utils.hpp>
22+
#include <cuco/extent.cuh>
23+
#include <cuco/static_map.cuh>
24+
#include <cuco/storage.cuh>
25+
26+
#include <cuda/stream_ref>
2027

2128
namespace cuco::detail::static_map_ns {
2229

include/cuco/detail/static_map/kernels.cuh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include <cuco/detail/bitwise_compare.cuh>
1919
#include <cuco/detail/utility/cuda.cuh>
20+
#include <cuco/operator.hpp>
21+
#include <cuco/pair.cuh>
22+
#include <cuco/types.cuh>
2023

2124
#include <cub/block/block_reduce.cuh>
2225
#include <cuda/atomic>

include/cuco/detail/static_map_kernels.cuh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
#pragma once
1717

18+
#include <cuco/detail/utility/cuda.cuh>
19+
1820
#include <cub/block/block_reduce.cuh>
1921
#include <cuda/std/atomic>
2022

include/cuco/detail/trie/dynamic_bitset/kernels.cuh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#pragma once
1919

20+
#include <cuco/detail/trie/dynamic_bitset/dynamic_bitset.cuh>
2021
#include <cuco/detail/utility/cuda.cuh>
2122
#include <cuco/detail/utility/cuda.hpp>
2223

0 commit comments

Comments
 (0)