From e1cda95ac772b4b223dab24216f54201f9c31fec Mon Sep 17 00:00:00 2001 From: a-hirota Date: Sun, 14 Sep 2025 11:46:37 +0000 Subject: [PATCH] Fix CCCL/Jitify compatibility issues for NVRTC compilation This commit addresses build failures caused by type redeclaration conflicts between CCCL 3.0.2 and Jitify when compiling with NVRTC. Issues fixed: 1. stdint type redeclarations: CCCL's cstdint header conflicted with system stdint.h types (int_fast16_t, intptr_t, etc.) - Added _STDINT_H guards to prevent duplicate definitions 2. char limits narrowing conversion: numeric_limits template instantiation failed with narrowing conversion error - Added explicit casts to CHAR_MIN and CHAR_MAX Implementation: - Added CCCL patch to guard type definitions and fix char limits - Added Jitify patch to fix numeric_limits instantiation - Integrated patches into CMake build system via rapids-cmake - Patches are applied automatically during build process Testing: - Successfully builds with ./build.sh on Ubuntu with CUDA 13.0 - JIT preprocessing completes without errors --- cpp/cmake/thirdparty/get_cccl.cmake | 3 + cpp/cmake/thirdparty/get_jitify.cmake | 4 ++ .../patches/cccl_jitify_compatibility.patch | 65 +++++++++++++++++++ .../thirdparty/patches/cccl_override.json | 16 +++++ .../patches/jitify_char_limits.patch | 23 +++++++ .../thirdparty/patches/jitify_override.json | 16 +++++ 6 files changed, 127 insertions(+) create mode 100644 cpp/cmake/thirdparty/patches/cccl_jitify_compatibility.patch create mode 100644 cpp/cmake/thirdparty/patches/cccl_override.json create mode 100644 cpp/cmake/thirdparty/patches/jitify_char_limits.patch create mode 100644 cpp/cmake/thirdparty/patches/jitify_override.json diff --git a/cpp/cmake/thirdparty/get_cccl.cmake b/cpp/cmake/thirdparty/get_cccl.cmake index ba5419eae7b..77cdbb6d578 100644 --- a/cpp/cmake/thirdparty/get_cccl.cmake +++ b/cpp/cmake/thirdparty/get_cccl.cmake @@ -14,6 +14,9 @@ # Use CPM to find or clone CCCL function(find_and_configure_cccl) + include(${rapids-cmake-dir}/cpm/package_override.cmake) + rapids_cpm_package_override("${CMAKE_CURRENT_LIST_DIR}/patches/cccl_override.json") + include(${rapids-cmake-dir}/cpm/cccl.cmake) rapids_cpm_cccl(BUILD_EXPORT_SET cudf-exports INSTALL_EXPORT_SET cudf-exports) endfunction() diff --git a/cpp/cmake/thirdparty/get_jitify.cmake b/cpp/cmake/thirdparty/get_jitify.cmake index 5db4e3e907f..a375e61f77d 100644 --- a/cpp/cmake/thirdparty/get_jitify.cmake +++ b/cpp/cmake/thirdparty/get_jitify.cmake @@ -16,12 +16,16 @@ # This function finds Jitify and sets any additional necessary environment variables. function(find_and_configure_jitify) + include(${rapids-cmake-dir}/cpm/package_override.cmake) + rapids_cpm_package_override("${CMAKE_CURRENT_LIST_DIR}/patches/jitify_override.json") + rapids_cpm_find( jitify 2.0.0 GIT_REPOSITORY https://github.com/NVIDIA/jitify.git GIT_TAG 44e978b21fc8bdb6b2d7d8d179523c8350db72e5 # jitify2 branch as of 23rd Aug 2025 GIT_SHALLOW FALSE DOWNLOAD_ONLY TRUE + PATCH_COMMAND git apply --reject --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/patches/jitify_char_limits.patch || true ) set(JITIFY_INCLUDE_DIR "${jitify_SOURCE_DIR}" diff --git a/cpp/cmake/thirdparty/patches/cccl_jitify_compatibility.patch b/cpp/cmake/thirdparty/patches/cccl_jitify_compatibility.patch new file mode 100644 index 00000000000..31c4efddac9 --- /dev/null +++ b/cpp/cmake/thirdparty/patches/cccl_jitify_compatibility.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Claude +Date: Sat, 14 Sep 2025 00:00:00 +0000 +Subject: [PATCH] Fix CCCL/Jitify compatibility for NVRTC + +This patch fixes type redeclaration conflicts between CCCL and Jitify +when compiling with NVRTC by: +1. Adding guards to prevent duplicate type definitions when stdint.h is included +2. Fixing CHAR_MIN/MAX with explicit casts to avoid narrowing conversions + +diff --git a/libcudacxx/include/cuda/std/cstdint b/libcudacxx/include/cuda/std/cstdint +index ae444b9bd..3ad5e955b 100644 +--- a/libcudacxx/include/cuda/std/cstdint ++++ b/libcudacxx/include/cuda/std/cstdint +@@ -30,6 +30,9 @@ _CCCL_PUSH_MACROS + #else // ^^^ !_CCCL_COMPILER(NVRTC) ^^^ / vvv _CCCL_COMPILER(NVRTC) vvv + # include + ++// Only define types if stdint.h hasn't been included ++#ifndef _STDINT_H ++ + using int8_t = signed char; + using int16_t = signed short; + using int32_t = signed int; +@@ -63,6 +66,11 @@ using uintptr_t = uint64_t; + using intmax_t = int64_t; + using uintmax_t = uint64_t; + ++#endif // _STDINT_H ++ ++// Only define macros if stdint.h hasn't been included ++#ifndef _STDINT_H ++ + # define INT8_MIN SCHAR_MIN + # define INT16_MIN SHRT_MIN + # define INT32_MIN INT_MIN +@@ -126,6 +134,8 @@ using uintmax_t = uint64_t; + + # define INTMAX_C(X) ((::intmax_t)(X)) + # define UINTMAX_C(X) ((::uintmax_t)(X)) ++ ++#endif // _STDINT_H + #endif // ^^^ _CCCL_COMPILER(NVRTC) + + _LIBCUDACXX_BEGIN_NAMESPACE_STD +diff --git a/libcudacxx/include/cuda/std/climits b/libcudacxx/include/cuda/std/climits +index a605f2dc5..085205322 100644 +--- a/libcudacxx/include/cuda/std/climits ++++ b/libcudacxx/include/cuda/std/climits +@@ -34,10 +34,10 @@ _CCCL_PUSH_MACROS + # define __CHAR_UNSIGNED__ ('\xff' > 0) // CURSED + # if __CHAR_UNSIGNED__ + # define CHAR_MIN 0 +-# define CHAR_MAX UCHAR_MAX ++# define CHAR_MAX ((char)UCHAR_MAX) + # else +-# define CHAR_MIN SCHAR_MIN +-# define CHAR_MAX SCHAR_MAX ++# define CHAR_MIN ((char)SCHAR_MIN) ++# define CHAR_MAX ((char)SCHAR_MAX) + # endif + # define SHRT_MIN (-SHRT_MAX - 1) + # define SHRT_MAX 0x7fff +-- +2.34.1 \ No newline at end of file diff --git a/cpp/cmake/thirdparty/patches/cccl_override.json b/cpp/cmake/thirdparty/patches/cccl_override.json new file mode 100644 index 00000000000..f66e43e47fd --- /dev/null +++ b/cpp/cmake/thirdparty/patches/cccl_override.json @@ -0,0 +1,16 @@ +{ + "packages": { + "CCCL": { + "version": "3.0.2", + "git_url": "https://github.com/NVIDIA/cccl.git", + "git_tag": "9c40ed11560fa8ffd21abe4cdc8dc3ce875e48e3", + "patches": [ + { + "file": "${current_json_dir}/cccl_jitify_compatibility.patch", + "issue": "Fix CCCL/Jitify compatibility issues with stdint types and char limits", + "fixed_in": "" + } + ] + } + } +} \ No newline at end of file diff --git a/cpp/cmake/thirdparty/patches/jitify_char_limits.patch b/cpp/cmake/thirdparty/patches/jitify_char_limits.patch new file mode 100644 index 00000000000..1957a050888 --- /dev/null +++ b/cpp/cmake/thirdparty/patches/jitify_char_limits.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Claude +Date: Sat, 14 Sep 2025 00:00:00 +0000 +Subject: [PATCH] Fix char limits narrowing conversion in numeric_limits + +This patch fixes the narrowing conversion error when instantiating +numeric_limits by adding explicit casts to CHAR_MIN and CHAR_MAX. + +diff --git a/jitify2.hpp b/jitify2.hpp +index 1234567..2345678 100644 +--- a/jitify2.hpp ++++ b/jitify2.hpp +@@ -6080,7 +6080,7 @@ struct numeric_limits + : public __jitify_detail::IntegerLimits {}; + template <> + struct numeric_limits +- : public __jitify_detail::IntegerLimits {}; ++ : public __jitify_detail::IntegerLimits {}; + template <> + struct numeric_limits + : public __jitify_detail::IntegerLimits { +-- +2.34.1 \ No newline at end of file diff --git a/cpp/cmake/thirdparty/patches/jitify_override.json b/cpp/cmake/thirdparty/patches/jitify_override.json new file mode 100644 index 00000000000..162deb52cb4 --- /dev/null +++ b/cpp/cmake/thirdparty/patches/jitify_override.json @@ -0,0 +1,16 @@ +{ + "packages": { + "jitify": { + "version": "2.0.0", + "git_url": "https://github.com/NVIDIA/jitify.git", + "git_tag": "44e978b21fc8bdb6b2d7d8d179523c8350db72e5", + "patches": [ + { + "file": "${current_json_dir}/jitify_char_limits.patch", + "issue": "Fix char limits narrowing conversion in numeric_limits template", + "fixed_in": "" + } + ] + } + } +} \ No newline at end of file