2017-10-04 13 views
0

Je suis nouveau dans la programmation cuda, je veux construire mon programme et il y a une fonction .cu qui utilise cuda. Je suis associé à ce projet et le projet est énorme. Le fichier * .cpp du projet sont ajoutés au projet en utilisant un script files.cmakeErreur Cmake en utilisant la commande cuda_add_executable

SUBDIRS(
src/ThirdParty/Matrice 
) 

set(SRC_CPP_FILES 
    Operation.cpp 
    Operator.cpp 
    ThirdParty/mt97.cpp 
    Mesh.cpp 
... 
) 
... 

et le CmakeList.txt de ce projet est écrit:

project(PILOT_plugin) 


#set(CMAKE_MODULE_PATH 
# ${${MY_PROJECT_NAME}_SOURCE_DIR}/CMake 
# ${CMAKE_MODULE_PATH} 
# ) 

MACRO_CREATE_MITK_CTK_PLUGIN(
    EXPORT_DIRECTIVE PLANNING_EXPORTS 
    EXPORTED_INCLUDE_SUFFIXES src 
    #MODULE_DEPENDS QmitkExt Qmitk 
    MODULE_DEPENDS MitkQtWidgetsExt MitkQtWidgets MitkMapperExt MitkSceneSerialization 

) 

# Check the architecture and set CMAKE_LIBRARY_ARCHITECTURE accordingly 
#if(UNIX) 
# if(CMAKE_SIZEOF_VOID_P EQUAL 8) 
# set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 
# endif() 
#endif() 

function(echo_all_cmake_variable_values) 
    message(STATUS "") 
    get_cmake_property(vs VARIABLES) 
    foreach(v ${vs}) 
    message(STATUS "${v}='${${v}}'") 
    endforeach(v) 
    message(STATUS "") 
endfunction() 

#echo_all_cmake_variable_values() 

SET(QT_USE_QTSQL TRUE) 
find_package(Boost COMPONENTS serialization filesystem system REQUIRED) 
find_package(PythonLibs 2.7 REQUIRED) 
set(VTK_CMAKE_DIR ${PILOT_SUPERBUILD_BINARY_DIR}/MITK-superbuild/VTK-src/CMake) 
add_subdirectory(${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng/Build) 
add_subdirectory(${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/ompl) 

include_directories(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIR} ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/include /usr/include/libxml2 ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/ompl/src) 

add_dependencies(${PROJECT_NAME} ompl vtkBioeng) 

#find_path(CGOGN_LIB_DIR cgogn ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release) 
#message(STATUS ${CGOGN_LIB_DIR}) 

#link_directories(${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release) 
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release) 
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${CGOGN_LIB_DIR}) 
#list(APPEND ALL_LIBRARY_DIRS ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release) 


if(EXISTS ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release/libcgogn.a) 
     TARGET_LINK_LIBRARIES(${PROJECT_NAME} gsl mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} ompl vtkBioeng ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release/libcgogn.a z) 
else() 
     TARGET_LINK_LIBRARIES(${PROJECT_NAME} gsl mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} ompl vtkBioeng) 
endif() 


#TARGET_LINK_LIBRARIES(${PROJECT_NAME} mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} cgogn z) 

#echo_all_cmake_variable_values() 

add_definitions(-DBOOST_NO_CXX11_RVALUE_REFERENCES) 

Selon ma connaissance je devrais ajouter ci-dessous commande au fichier .cmake ou cmakeLists.txt!

find_package(CUDA REQUIRED) 
add_definitions(-D_FORCE_INLINES) 
set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_21 -std=c++11) 

cuda_add_executable(PILOT_plugin 
    testcuda.cu) 

le « PILOT_plugin » est le nom du projet et .cu fichier est mon fichier cuda. mais je reçois '[cmake_check_build_system] Erreur 1'. dans le fichier CmakeError.log je ne comprends rien de tout cela.

c'est le cmakeError.log

Determining if the Q_WS_WIN exist failed with the following output: 
Change Dir: /home/.../CMakeFiles/CMakeTmp 

Run Build Command:"/usr/bin/make" "cmTryCompileExec2072448143/fast" 
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/make -f CMakeFiles/cmTryCompileExec2072448143.dir/build.make CMakeFiles/cmTryCompileExec2072448143.dir/build 
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1 
Building CXX object CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o 
/usr/bin/c++ -I/usr/include/qt4 -o CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx 
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’: 
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_WIN’ was not declared in this scope 
    return ((int*)(&Q_WS_WIN))[argc]; 
       ^
CMakeFiles/cmTryCompileExec2072448143.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o' failed 
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[4]: *** [CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o] Error 1 
Makefile:118: recipe for target 'cmTryCompileExec2072448143/fast' failed 
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[3]: *** [cmTryCompileExec2072448143/fast] Error 2 

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: 
/* */ 
#include <QtCore/qglobal.h> 

int main(int argc, char** argv) 
{ 
    (void)argv; 
#ifndef Q_WS_WIN 
    return ((int*)(&Q_WS_WIN))[argc]; 
#else 
    (void)argc; 
    return 0; 
#endif 
} 

Determining if the Q_WS_QWS exist failed with the following output: 
Change Dir: /home/.../CMakeFiles/CMakeTmp 

Run Build Command:"/usr/bin/make" "cmTryCompileExec3895328539/fast" 
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/make -f CMakeFiles/cmTryCompileExec3895328539.dir/build.make CMakeFiles/cmTryCompileExec3895328539.dir/build 
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1 
Building CXX object CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o 
/usr/bin/c++ -I/usr/include/qt4 -o CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx 
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’: 
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_QWS’ was not declared in this scope 
    return ((int*)(&Q_WS_QWS))[argc]; 
       ^
CMakeFiles/cmTryCompileExec3895328539.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o' failed 
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[4]: *** [CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o] Error 1 
Makefile:118: recipe for target 'cmTryCompileExec3895328539/fast' failed 
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[3]: *** [cmTryCompileExec3895328539/fast] Error 2 

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: 
/* */ 
#include <QtCore/qglobal.h> 

int main(int argc, char** argv) 
{ 
    (void)argv; 
#ifndef Q_WS_QWS 
    return ((int*)(&Q_WS_QWS))[argc]; 
#else 
    (void)argc; 
    return 0; 
#endif 
} 

Determining if the Q_WS_MAC exist failed with the following output: 
Change Dir: /home/.../CMakeFiles/CMakeTmp 

Run Build Command:"/usr/bin/make" "cmTryCompileExec816771383/fast" 
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/make -f CMakeFiles/cmTryCompileExec816771383.dir/build.make CMakeFiles/cmTryCompileExec816771383.dir/build 
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1 
Building CXX object CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o 
/usr/bin/c++ -I/usr/include/qt4 -o CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx 
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’: 
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_MAC’ was not declared in this scope 
    return ((int*)(&Q_WS_MAC))[argc]; 
       ^
CMakeFiles/cmTryCompileExec816771383.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o' failed 
make[4]: *** [CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o] Error 1 
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
Makefile:118: recipe for target 'cmTryCompileExec816771383/fast' failed 
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[3]: *** [cmTryCompileExec816771383/fast] Error 2 

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: 
/* */ 
#include <QtCore/qglobal.h> 

int main(int argc, char** argv) 
{ 
    (void)argv; 
#ifndef Q_WS_MAC 
    return ((int*)(&Q_WS_MAC))[argc]; 
#else 
    (void)argc; 
    return 0; 
#endif 
} 

Determining if the pthread_create exist failed with the following output: 
Change Dir: /home/.../CMakeFiles/CMakeTmp 

Run Build Command:"/usr/bin/make" "cmTryCompileExec3000733177/fast" 
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/make -f CMakeFiles/cmTryCompileExec3000733177.dir/build.make CMakeFiles/cmTryCompileExec3000733177.dir/build 
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1 
Building C object CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o 
/usr/bin/cc -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all  -o CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.c 
Linking C executable cmTryCompileExec3000733177 
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3000733177.dir/link.txt --verbose=1 
/usr/bin/cc  -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all  CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o -o cmTryCompileExec3000733177 -rdynamic 
CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o: In function `main': 
CheckSymbolExists.c:(.text+0x29): undefined reference to `pthread_create' 
collect2: error: ld returned 1 exit status 
CMakeFiles/cmTryCompileExec3000733177.dir/build.make:88: recipe for target 'cmTryCompileExec3000733177' failed 
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[4]: *** [cmTryCompileExec3000733177] Error 1 
Makefile:118: recipe for target 'cmTryCompileExec3000733177/fast' failed 
make[3]: *** [cmTryCompileExec3000733177/fast] Error 2 
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.c: 
/* */ 
#include <pthread.h> 

int main(int argc, char** argv) 
{ 
    (void)argv; 
#ifndef pthread_create 
    return ((int*)(&pthread_create))[argc]; 
#else 
    (void)argc; 
    return 0; 
#endif 
} 

Determining if the function pthread_create exists in the pthreads failed with the following output: 
Change Dir: /home/.../CMakeFiles/CMakeTmp 

Run Build Command:"/usr/bin/make" "cmTryCompileExec2524936657/fast" 
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/make -f CMakeFiles/cmTryCompileExec2524936657.dir/build.make CMakeFiles/cmTryCompileExec2524936657.dir/build 
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp' 
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1 
Building C object CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o 
/usr/bin/cc -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.0/Modules/CheckFunctionExists.c 
Linking C executable cmTryCompileExec2524936657 
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec2524936657.dir/link.txt --verbose=1 
/usr/bin/cc  -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o -o cmTryCompileExec2524936657 -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads 
collect2: error: ld returned 1 exit status 
CMakeFiles/cmTryCompileExec2524936657.dir/build.make:88: recipe for target 'cmTryCompileExec2524936657' failed 
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[4]: *** [cmTryCompileExec2524936657] Error 1 
Makefile:118: recipe for target 'cmTryCompileExec2524936657/fast' failed 
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp' 
make[3]: *** [cmTryCompileExec2524936657/fast] Error 2 

Pourquoi je ne peux pas ajouter le fichier .cu au projet? le projet principal utilise gcc pour compiler. Y at-il un autre moyen que je peux ajouter le fichier .cu au projet principal et compiler en utilisant nvcc?

PS: si je fais un projet simple et faire la même chose que ci-dessus CMakeLists.txt fonctionne bien, mais je ne comprends pas pourquoi je ne peux pas ajouter .cu à ce grand projet toute aide est très appréciée

Répondre

1

Si vous utilisez une version récente de cmake, vous ne devez pas utiliser l'extension cuda_add_executable et utiliser la fonctionnalité intégrée pour prendre en charge CUDA (voir https://devblogs.nvidia.com/parallelforall/building-cuda-applications-cmake/).

Donc ce que vous devez faire est de modifier vos cmakelists comme ceci:

projet (PILOT_plugin C LANGUE CXX CUDA)

L'utilisation des ADD_EXECUTABLE normales/macros add_library.

Cependant, je ne pense pas que ce soit votre problème: je pense que votre installation de Qt4 n'est pas configuré correctement.

+0

vous avez raison, j'utilise la dernière version de Cmake et la nouvelle fonction ci-dessus semble cool aussi; cependant en le changeant en nouvelles commandes ne fonctionne pas!. Le programme fonctionne bien sans fichier .cu; par conséquent, je ne pense pas que le problème vient de Qt4. et comme je l'ai déjà dit, avec la même version de Cmake, un programme simple fonctionne bien. merci – Ehsan

+4

Aucune des erreurs dans le fichier journal CMake publié n'est liée à cuda. Notez que vous devez passer les drapeaux CUDA en utilisant CMAKE_CUDA_FLAGS au lieu de CUDA_NVCC_FLAGS avec le style décrit ci-dessus. Sans les messages d'erreur réels de la console, nous ne pouvons pas vraiment vous aider plus que cela. –