Hello everyone! I want to use a third party library called stdgpu in DGL to implement some custom function in CUDA/C++ for experimental purpose.
So I clone the repository to the dgl/third_party
directory and add
add_subdirectory(third_party/stdgpu)
list(APPEND DGL_LINKER_LIBS stdgpu::stdgpu)
in CMakeList.
However, this library depends on c++17 and Thrust. When I just simply include the library like:
#include <stdgpu/queue.cuh>
and try to rebuild DGL from source, there will be a lot of errors…
So I changed c++14 to c++17 in CMakeList and CUDA.cmake, for example in CMakeLists:
# change to c++17
# set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++14 ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++17 ${CMAKE_CXX_FLAGS}")
# change to c++17
# set_property(TARGET dgl PROPERTY CXX_STANDARD 14)
set_property(TARGET dgl PROPERTY CXX_STANDARD 17)
and in CUDA.cmake:
# change to c++17
# list(APPEND CUDA_NVCC_FLAGS "-std=c++14")
list(APPEND CUDA_NVCC_FLAGS "-std=c++17")
Now, when I rebuild DGL from source, the number of errors has decreased and the main error include:
namespace stdgpu
{
template <typename T1, typename T2>
# error: identifier "thrust" is undefined
using pair = thrust::pair<T1, T2>;
// ... ...
}
I guess the reason is in CMakeList:
# see https://github.com/NVIDIA/thrust/issues/1401
add_definitions(-DTHRUST_CUB_WRAPPED_NAMESPACE=dgl)
include(cmake/modules/CUDA.cmake)
message(STATUS "Use external CUB/Thrust library for a consistent API and performance.")
cuda_include_directories(BEFORE "${CMAKE_SOURCE_DIR}/third_party/thrust")
cuda_include_directories(BEFORE "${CMAKE_SOURCE_DIR}/third_party/thrust/dependencies/cub")
Because if I chage the code above like:
namespace dgl{
namespace stdgpu
{
template <typename T1, typename T2>
# error: identifier "thrust" is undefined
using pair = thrust::pair<T1, T2>;
// ... ...
}
}
The error of this file is resolved. But the library is strongly depends on Thrust, so it is hard for me to do such kind of change everywhere the library uses Thrust…
What should I do so I can use this library without change too much? Thanks in advance!