diff options
author | Brad King <brad.king@kitware.com> | 2018-10-25 11:25:43 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-10-25 11:26:24 (GMT) |
commit | 69275d3b6a9787268f7bd80bb24d8e4cbb18710e (patch) | |
tree | 0bb53670308ea913e9b22c6471bf7fec3f1b36da /Tests | |
parent | 1c31eae65982c84d570217dd1493eb1d2ba6ee45 (diff) | |
parent | 2cc050b53b4afb1ed62621360b860e25b7c46015 (diff) | |
download | CMake-69275d3b6a9787268f7bd80bb24d8e4cbb18710e.zip CMake-69275d3b6a9787268f7bd80bb24d8e4cbb18710e.tar.gz CMake-69275d3b6a9787268f7bd80bb24d8e4cbb18710e.tar.bz2 |
Merge topic 'cuda-thread-flags'
2cc050b53b CUDA: Add test for device linking when host linking uses threads
83c13ca44f FindThreads: Pass -pthread to CUDA compiler through -Xcompiler
cf92fd9ae9 Merge branch 'cuda-filter-device-link-items' into cuda-thread-flags
e768d96c74 CUDA: Filter out host link flags during device linking
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kelly (KT) Thompson <kgt@lanl.gov>
Merge-request: !2512
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/Cuda/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/Cuda/ProperDeviceLibraries/CMakeLists.txt | 45 | ||||
-rw-r--r-- | Tests/Cuda/ProperDeviceLibraries/main.cu (renamed from Tests/CudaOnly/LinkSystemDeviceLibraries/main.cu) | 9 | ||||
-rw-r--r-- | Tests/Cuda/ProperDeviceLibraries/use_pthreads.cu | 9 | ||||
-rw-r--r-- | Tests/Cuda/ProperDeviceLibraries/use_pthreads.cxx | 9 | ||||
-rw-r--r-- | Tests/CudaOnly/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/CudaOnly/LinkSystemDeviceLibraries/CMakeLists.txt | 15 |
7 files changed, 73 insertions, 16 deletions
diff --git a/Tests/Cuda/CMakeLists.txt b/Tests/Cuda/CMakeLists.txt index 8a43df5..1b3daa6 100644 --- a/Tests/Cuda/CMakeLists.txt +++ b/Tests/Cuda/CMakeLists.txt @@ -4,5 +4,6 @@ ADD_TEST_MACRO(Cuda.ConsumeCompileFeatures CudaConsumeCompileFeatures) ADD_TEST_MACRO(Cuda.ObjectLibrary CudaObjectLibrary) ADD_TEST_MACRO(Cuda.MixedStandardLevels MixedStandardLevels) ADD_TEST_MACRO(Cuda.ToolkitInclude CudaToolkitInclude) +ADD_TEST_MACRO(Cuda.ProperDeviceLibraries ProperDeviceLibraries) ADD_TEST_MACRO(Cuda.ProperLinkFlags ProperLinkFlags) ADD_TEST_MACRO(Cuda.WithC CudaWithC) diff --git a/Tests/Cuda/ProperDeviceLibraries/CMakeLists.txt b/Tests/Cuda/ProperDeviceLibraries/CMakeLists.txt new file mode 100644 index 0000000..cb47b09 --- /dev/null +++ b/Tests/Cuda/ProperDeviceLibraries/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.13) +project(ProperDeviceLibraries CXX CUDA) + +string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_35,code=compute_35 -gencode arch=compute_35,code=sm_35") +set(CMAKE_CUDA_STANDARD 11) + +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads) + +add_executable(ProperDeviceLibraries main.cu) +set_target_properties(ProperDeviceLibraries + PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + +add_library(UseThreadsMixed SHARED use_pthreads.cxx use_pthreads.cu) +target_link_libraries(UseThreadsMixed Threads::Threads) + +add_library(UseThreadsCuda SHARED use_pthreads.cu) +target_link_libraries(UseThreadsCuda Threads::Threads) + +target_link_libraries(ProperDeviceLibraries PRIVATE UseThreadsMixed UseThreadsCuda) + +if(THREADS_HAVE_PTHREAD_ARG AND CMAKE_USE_PTHREADS_INIT) + add_library(UseExplicitPThreadsFlag SHARED use_pthreads.cu) + target_compile_options(UseExplicitPThreadsFlag PUBLIC "-Xcompiler=-pthread") + target_link_libraries(UseExplicitPThreadsFlag PUBLIC "-pthread") + + add_library(UseExplicitLThreadsFlag SHARED use_pthreads.cu) + target_compile_options(UseExplicitLThreadsFlag PUBLIC "-Xcompiler=-pthread") + target_link_libraries(UseExplicitLThreadsFlag PUBLIC "-lpthread") + + add_library(UseExplicitLongThreadsFlag SHARED use_pthreads.cu) + target_link_libraries(UseExplicitLongThreadsFlag PUBLIC "--library pthread") + + target_link_libraries(ProperDeviceLibraries PRIVATE UseExplicitPThreadsFlag UseExplicitLThreadsFlag UseExplicitLongThreadsFlag) +endif() + +if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 10.0.0) + #CUDA 10 removed the cublas_device library + target_link_libraries(ProperDeviceLibraries PRIVATE cublas_device) +endif() + +if(APPLE) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET ProperDeviceLibraries PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) +endif() diff --git a/Tests/CudaOnly/LinkSystemDeviceLibraries/main.cu b/Tests/Cuda/ProperDeviceLibraries/main.cu index 2c7c388..8ceb0cc 100644 --- a/Tests/CudaOnly/LinkSystemDeviceLibraries/main.cu +++ b/Tests/Cuda/ProperDeviceLibraries/main.cu @@ -3,6 +3,15 @@ #include <cuda_runtime.h> #include <iostream> +#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) + +# include <pthread.h> +static int verify_linking_to_pthread() +{ + return static_cast<int>(pthread_self()); +} +#endif + // this test only makes sense for versions of CUDA that ships // static libraries that have separable compilation device symbols #if __CUDACC_VER_MAJOR__ <= 9 diff --git a/Tests/Cuda/ProperDeviceLibraries/use_pthreads.cu b/Tests/Cuda/ProperDeviceLibraries/use_pthreads.cu new file mode 100644 index 0000000..c57b8a8 --- /dev/null +++ b/Tests/Cuda/ProperDeviceLibraries/use_pthreads.cu @@ -0,0 +1,9 @@ + +#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) + +# include <pthread.h> +static int verify_linking_to_pthread_cuda() +{ + return static_cast<int>(pthread_self()); +} +#endif diff --git a/Tests/Cuda/ProperDeviceLibraries/use_pthreads.cxx b/Tests/Cuda/ProperDeviceLibraries/use_pthreads.cxx new file mode 100644 index 0000000..dc7c208 --- /dev/null +++ b/Tests/Cuda/ProperDeviceLibraries/use_pthreads.cxx @@ -0,0 +1,9 @@ + +#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) + +# include <pthread.h> +static int verify_linking_to_pthread_cxx() +{ + return static_cast<int>(pthread_self()); +} +#endif diff --git a/Tests/CudaOnly/CMakeLists.txt b/Tests/CudaOnly/CMakeLists.txt index 5b7c0e6..9c4f86a 100644 --- a/Tests/CudaOnly/CMakeLists.txt +++ b/Tests/CudaOnly/CMakeLists.txt @@ -3,7 +3,6 @@ ADD_TEST_MACRO(CudaOnly.CircularLinkLine CudaOnlyCircularLinkLine) ADD_TEST_MACRO(CudaOnly.EnableStandard CudaOnlyEnableStandard) ADD_TEST_MACRO(CudaOnly.ExportPTX CudaOnlyExportPTX) ADD_TEST_MACRO(CudaOnly.GPUDebugFlag CudaOnlyGPUDebugFlag) -ADD_TEST_MACRO(CudaOnly.LinkSystemDeviceLibraries CudaOnlyLinkSystemDeviceLibraries) ADD_TEST_MACRO(CudaOnly.ResolveDeviceSymbols CudaOnlyResolveDeviceSymbols) ADD_TEST_MACRO(CudaOnly.SeparateCompilation CudaOnlySeparateCompilation) ADD_TEST_MACRO(CudaOnly.WithDefs CudaOnlyWithDefs) diff --git a/Tests/CudaOnly/LinkSystemDeviceLibraries/CMakeLists.txt b/Tests/CudaOnly/LinkSystemDeviceLibraries/CMakeLists.txt deleted file mode 100644 index 7f7f606..0000000 --- a/Tests/CudaOnly/LinkSystemDeviceLibraries/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 3.8) -project(LinkSystemDeviceLibraries CUDA) - -string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_35,code=compute_35 -gencode arch=compute_35,code=sm_35") -set(CMAKE_CUDA_STANDARD 11) - -add_executable(CudaOnlyLinkSystemDeviceLibraries main.cu) -set_target_properties( CudaOnlyLinkSystemDeviceLibraries - PROPERTIES CUDA_SEPARABLE_COMPILATION ON) -target_link_libraries( CudaOnlyLinkSystemDeviceLibraries PRIVATE cublas_device) - -if(APPLE) - # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. - set_property(TARGET CudaOnlyLinkSystemDeviceLibraries PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) -endif() |