Unable to compile CUDA source file containing Boost header files using nvcc

I have built a simple CMake CUDA project, and the content of the CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.24 FATAL_ERROR)

if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
    set(CMAKE_CUDA_ARCHITECTURES native)
endif()

project(cuda-test LANGUAGES CXX CUDA)

set(CMAKE_CXX_STANDARD 14)

#Boost
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.80.0 REQUIRED)

add_executable(cuda-test src/main.cu)

There exists an ‘src’ directory at the same level as the CMakeLists.txt, which includes a main.cu file, the contents are as follows:

#include <boost/math/constants/constants.hpp>
int main(){
}

When compiling, the following error is reported:

**/usr/local/include/boost/math/constants/constants.hpp:** In static member function ‘**static const T& boost::math::constants::detail::constant_half<T>::get(const std::integral_constant<int, 4>&)**’:

**/usr/local/include/boost/math/constants/constants.hpp:246:1024:** **error:** template argument 2 is invalid

BOOST_DEFINE_MATH_CONSTANT(half, 5.000000000000000000000000000000000000e-01, "5.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-01")

But if the main.cu file is changed to main.cpp, the compilation does not report any errors.

OS: Ubuntu 18.04.6 LTS
Cuda Toolkit: Cuda compilation tools, release 12.1, V12.1.105, Build cuda_12.1.r12.1/compiler.32688072_0
gcc: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
boost:1.80.0

I am not sure if I have set something incorrectly or if this is a bug in CUDA.

I have found the reason for the issue. When generating the host-side code for the get function of the constant_half structure, it needs to obtain a pointer to the get_from_string function within the same structure and pass it as a template parameter to the constant_initializer structure. The original Boost code used &constant_half<T>::get_from_string to obtain the function pointer, but the CUDA compiler preprocessed it and removed the qualifier, resulting in &get_from_string . The GCC 7.5.0 version I am using does not allow obtaining function pointers in this manner and passing them as template parameters.

Can this be considered a bug and be fixed in the future to better accommodate GCC 7.5.0

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.