nvlink segv w. clang as the cuda compiler

Hi All,

as the title says, I’m using clang as both C++ and CUDA compiler. However, I found that w. recent versions of clang, including mainline nightly build, my project build fails due to a segv when device linking. Cmake is using nvlink for device linking step even when clang is the cuda compiler. This seems to me potentially risky choice and creates the potential for some unnecessary complications since clang itself can be the linker. Clang devs will likely test linking with clang but they may not test linking w. nvlink as CMake is doing. In any case, does any one have advice on how to tell CMake not to use nvlink when clang is the cuda compiler and instead use clang?

Here is the output when I run make:

$make VERBOSE=1
make  -f utils/HAMR/CMakeFiles/hamr.dir/build.make utils/HAMR/CMakeFiles/hamr.dir/depend
make[2]: Entering directory '/pscratch/sd/l/loring/sensei-build-clang_cuda_omp'
cd /pscratch/sd/l/loring/sensei-build-clang_cuda_omp && /global/common/software/nersc/pm-2021q4/sw/cmake-3.22.0/bin/cmake -E cmake_depends "Unix Makefiles" /pscratch/sd/l/loring/SENSEI /pscratch/sd/l/loring/SENSEI/utils/HAMR /pscratch/sd/l/loring/sensei-build-clang_cuda_omp /pscratch/sd/l/loring/sensei-build-clang_cuda_omp/utils/HAMR /pscratch/sd/l/loring/sensei-build-clang_cuda_omp/utils/HAMR/CMakeFiles/hamr.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/pscratch/sd/l/loring/sensei-build-clang_cuda_omp'
make  -f utils/HAMR/CMakeFiles/hamr.dir/build.make utils/HAMR/CMakeFiles/hamr.dir/build
make[2]: Entering directory '/pscratch/sd/l/loring/sensei-build-clang_cuda_omp'
/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/bin/nvlink -arch=sm_80 --register-link-binaries=utils/HAMR/CMakeFiles/hamr.dir/cmake_cuda_register.h -o=utils/HAMR/CMakeFiles/hamr.dir/sm_80.cubin utils/HAMR/CMakeFiles/hamr.dir/hamr_openmp_copy.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_copy_async.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_malloc_host_allocator.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_malloc_async_allocator.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_openmp_allocator.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_malloc_allocator.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_buffer.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_malloc_allocator.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_new_allocator.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_openmp_device.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_print.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_launch.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_malloc_uva_allocator.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_cuda_device.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_host_copy.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_stream.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_env.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_openmp_print.cxx.o utils/HAMR/CMakeFiles/hamr.dir/hamr_buffer_allocator.cxx.o /opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/lib64/libcudart.so
make[2]: *** [utils/HAMR/CMakeFiles/hamr.dir/build.make:358: utils/HAMR/CMakeFiles/hamr.dir/sm_80.cubin] Segmentation fault
make[2]: *** Deleting file 'utils/HAMR/CMakeFiles/hamr.dir/sm_80.cubin'
make[2]: Leaving directory '/pscratch/sd/l/loring/sensei-build-clang_cuda_omp'
make[1]: *** [CMakeFiles/Makefile2:1618: utils/HAMR/CMakeFiles/hamr.dir/all] Error 2
make[1]: Leaving directory '/pscratch/sd/l/loring/sensei-build-clang_cuda_omp'
make: *** [Makefile:146: all] Error 2

here are cmake flags used

cmake -DCMAKE_CXX_COMPILER=`which clang++` \
    -DCMAKE_CUDA_COMPILER=`which clang++` \
    -DCMAKE_C_COMPILER=`which clang` \
    -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_CUDA_FLAGS=-std=c++17 \
    -DSENSEI_ENABLE_PYTHON=OFF \
    -DSENSEI_ENABLE_CUDA=ON -DSENSEI_ENABLE_OPENMP=ON \
    -DCMAKE_CUDA_ARCHITECTURES=80 \
    -DSENSEI_CUDA_ARCHITECTURES=80 \
    -DSENSEI_OPENMP_ARCH=sm_80 \
    -DCMAKE_INSTALL_PREFIX=/pscratch/sd/l/loring/SENSEI/sensei-install-clang_cuda_omp \
    ../SENSEI

Cc: @robert.maynard