0

I am trying to use CMake to generate a Xcode project and build a CUDA library with it. The code I used for collecting & building CUDA library "caffe2_cpp_gpu" is as follows:

list(APPEND CUDA_NVCC_FLAGS "-std=c++11" "-Wno-deprecated-gpu-targets")    
file(GLOB CUDA_SOURCES "${PROJECT_SOURCE_DIR}/source/caffe2/operator/*.cu" )
  cuda_add_library(caffe2_cpp_gpu STATIC ${CUDA_SOURCES})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang++" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  list(APPEND ALL_LIBRARIES -Wl,-force_load caffe2_cpp_gpu)
else()
  list(APPEND ALL_LIBRARIES -Wl,--whole-archive caffe2_cpp_gpu -Wl,--no-whole-archive)
endif()

Note that this code can be run if Unix Makefile is used. But cannot run if Xcode is used.
In the project it shows a file is missing: missing file
And the CUDA library "caffe2_cpp_gpu" cannot be created.

Does anyone know how to solve it?

吳順成
  • 13
  • 1
  • 4

1 Answers1

1

I found the answer... If I append another kind of file (.cc, .h, etc.) into the CUDA libary, it will work. It seems like XCode cannot build single .cu file into static library (.a).
So here is what I did:

file(GLOB All_SOURCE "${PROJECT_SOURCE_DIR}/source/caffe2/operator/*.cu" "${PROJECT_SOURCE_DIR}/source/caffe2/operator/*.cc" "${PROJECT_SOURCE_DIR}/source/caffe2/operator/*.h")
cuda_add_library(caffe2_lib ${All_SOURCE})

Instead of building library seperately for CPU and GPU. I merge them into a single library file.

吳順成
  • 13
  • 1
  • 4