diff --git a/cmake/NVBenchDependencies.cmake b/cmake/NVBenchDependencies.cmake index d2bdc72..8ba07fe 100644 --- a/cmake/NVBenchDependencies.cmake +++ b/cmake/NVBenchDependencies.cmake @@ -28,6 +28,12 @@ rapids_cpm_find(nlohmann_json 3.11.3 CPM_ARGS URL https://github.com/nlohmann/json/releases/download/v3.11.3/include.zip URL_HASH SHA256=a22461d13119ac5c78f205d3df1db13403e58ce1bb1794edc9313677313f4a9d + PATCH_COMMAND + ${CMAKE_COMMAND} + -D "CUDA_VERSION=${CMAKE_CUDA_COMPILER_VERSION}" + -D "CXX_VERSION=${CMAKE_CXX_COMPILER_VERSION}" + -D "CXX_ID=${CMAKE_CXX_COMPILER_ID}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/patches/json_unordered_map_ice.cmake" ) add_library(nvbench_json INTERFACE IMPORTED) diff --git a/cmake/patches/json_unordered_map_ice.cmake b/cmake/patches/json_unordered_map_ice.cmake new file mode 100644 index 0000000..44f37c3 --- /dev/null +++ b/cmake/patches/json_unordered_map_ice.cmake @@ -0,0 +1,22 @@ +# NVCC 11.1 and GCC 9 need a patch to build, otherwise: +# +# nlohmann/ordered_map.hpp(29): error #3316: +# Internal Compiler Error (codegen): "internal error during structure layout!" +# +# Usage: +# ${CMAKE_COMMAND} +# -D "CUDA_VERSION=${CMAKE_CUDA_COMPILER_VERSION}" +# -D "CXX_VERSION=${CMAKE_CXX_COMPILER_VERSION}" +# -D "CXX_ID=${CMAKE_CXX_COMPILER_ID}" +# -P "json_unordered_map_ice.cmake" + +if(CUDA_VERSION VERSION_GREATER 11.8 OR NOT CXX_ID STREQUAL "GNU" OR CXX_VERSION VERSION_LESS 9.0) + return() +endif() + +# Read the file and replace the string "JSON_NO_UNIQUE_ADDRESS" with +# "/* JSON_NO_UNIQUE_ADDRESS */". +file(READ "include/nlohmann/ordered_map.hpp" NLOHMANN_ORDERED_MAP_HPP) +string(REPLACE "JSON_NO_UNIQUE_ADDRESS" "/* [NVBench Patch] JSON_NO_UNIQUE_ADDRESS */" + NLOHMANN_ORDERED_MAP_HPP "${NLOHMANN_ORDERED_MAP_HPP}") +file(WRITE "include/nlohmann/ordered_map.hpp" "${NLOHMANN_ORDERED_MAP_HPP}")