[CMake] CMake for CUDA with MPICC still using gcc to link?

Quang Ha quang.t.ha.20 at gmail.com
Tue Jul 31 13:43:36 EDT 2018


Hi all,

Currently using cmake/3.11.1, I want to try and compile MPI/CUDA
application with cmake. I kept running into problems of 'undefined
MPI_Init', so I take a look at `make VERBOSE=1`. The output looks something
like this

===============================================================================
/projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_link_script
CMakeFiles/tangram.dir/link.txt --verbose=1
*/projects/opt/centos7/openmpi/2.1.2-gcc_6.4.0/bin/mpicc* -fPIC -fopenmp
-O3 -DNDEBUG  -shared -Wl,-soname,libtangram.so -o libtangram.so
CMakeFiles/tangram.dir/tangram/intersect/r3d.c.o
make[2]: Leaving directory `/home/qth20/develop/tangram/build'
[ 40%] Built target tangram
make -f app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/build.make
app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/depend
make[2]: Entering directory `/home/qth20/develop/tangram/build'
cd /home/qth20/develop/tangram/build &&
/projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_depends "Unix
Makefiles" /home/qth20/develop/tangram
/home/qth20/develop/tangram/app/vfgen-cuda
/home/qth20/develop/tangram/build
/home/qth20/develop/tangram/build/app/vfgen-cud$
 /home/qth20/develop/tangram/build/app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/DependInfo.cmake
--color=
make[2]: Leaving directory `/home/qth20/develop/tangram/build'
make -f app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/build.make
app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/build
make[2]: Entering directory `/home/qth20/develop/tangram/build'
[ 60%] Building CUDA object
app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o
cd /home/qth20/develop/tangram/build/app/vfgen-cuda &&
/projects/opt/centos7/cuda/9.0/bin/nvcc  -DCUDA_CALLABLE="\"__host__
__device__\"" -DENABLE_MPI -DHAVE_LAPACKE -DMPICH_SKIP_MPICXX
-DOMPI_SKIP_MPICXX -DTHRUST
-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA -DTHRUST$
HOST_SYSTEM=THRUST_HOST_SYSTEM_CPP -I/home/qth20/develop/tangram
-I/home/qth20/develop/tangram/build
-I/home/qth20/develop/tangram/cinch/logging
-I/home/qth20/installed/jali-gcc_6.4.0-openmpi-2.1.2/include
-I/home/qth20/installed/jali-tpls-gcc_6.4.0-openmpi-2.1.2/include
-I/home/qth20/installed/jali-tpls-gcc_6.4.0-openmpi-2.1.2/trilinos-12-10-1/include
-I/projects/opt/centos7/openmpi/2.1.2-gcc_6.4.0/include
-I/home/qth20/installed/jali-tpls-gcc_6.4.0-openmpi-2.1.2/trilinos-12-10-1/lib/cmake/Zoltan/../../../include
-I/home/qth20/installed$
jali-tpls-gcc_6.4.0-openmpi-2.1.2/include/UnitTest++ -I/usr/include/lapacke
-I/home/qth20/installed/xmof2d-gcc_6.4.0-openmpi_2.1.2/include
-I/projects/opt/centos7/cuda/9.0/include  --expt-relaxed-constexpr
--std=c++11 -Xcompiler -fPIC -lmpi  -O3 -DNDEBUG   -x cu -c /home$
qth20/develop/tangram/app/vfgen-cuda/vfgen-cuda.cu -o
CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o
/home/qth20/develop/tangram/tangram/wrappers/mesh/AuxMeshTopology.h(1708):
warning: variable "nnodes" was declared but never referenced

/home/qth20/develop/tangram/tangram/wrappers/mesh/AuxMeshTopology.h(1993):
warning: variable "ncells" was declared but never referenced

/home/qth20/develop/tangram/tangram/wrappers/mesh/AuxMeshTopology.h(2070):
warning: variable "ibndry" was declared but never referenced

[ 80%] Linking CUDA device code
CMakeFiles/vfgen-cuda.dir/cmake_device_link.o
cd /home/qth20/develop/tangram/build/app/vfgen-cuda &&
/projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_link_script
CMakeFiles/vfgen-cuda.dir/dlink.txt --verbose=1
/projects/opt/centos7/cuda/9.0/bin/nvcc  --expt-relaxed-constexpr
--std=c++11 -Xcompiler -fPIC -lmpi  -O3 -DNDEBUG  -Xcompiler=-fPIC
-Wno-deprecated-gpu-targets -shared -dlink
CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o -o
CMakeFiles/vfgen-cuda.dir/cmake_device_link.o
[100%] Linking CUDA executable vfgen-cuda
cd /home/qth20/develop/tangram/build/app/vfgen-cuda &&
/projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_link_script
CMakeFiles/vfgen-cuda.dir/link.txt --verbose=1
*/projects/opt/centos7/gcc/6.4.0/bin/g++*
CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o
CMakeFiles/vfgen-cuda.dir/cmake_device_link.o -o vfgen-cuda
/projects/opt/centos7/cuda/9.0/lib64/libcudart_static.a -ldl
/usr/lib64/librt.so  -L"/projects/opt/centos7/cuda/9.0/lib64/stubs"
 -L"/projects/opt/centos7/cuda/9.0/lib64" -lcudadevrt -lcudart_static -lrt
-lpthread -ldl
===============================================================================

so apparently, mpicc is used other parts of the project, but when linking
extension between object codes it snaps back to g++(!). I have already
specified CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to be mpicc and mpic++,
respectively. Inside the CMakeLists for this CUDA:

===============================================================================
project(tangram LANGUAGES CXX CUDA)
[...]
if (CUDA_FOUND)
   string(APPEND CMAKE_CUDA_FLAGS "--expt-relaxed-constexpr --std=c++11 ")
   # Other CUDA flags
endif(CUDA_FOUND)

[... Inside CUDA app directory...]
add_executable(vfgen-cuda vfgen-cuda.cu)
target_link_libraries(vfgen-cuda ${EXTRA_LIBS} ${MPI_LIBRARIES})
===============================================================================

Is something missed out?

Thanks,
Quang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180731/8cdab47c/attachment-0001.html>


More information about the CMake mailing list