CUDA: Add test for device linking when host linking uses threads

Convert the `CudaOnly.LinkSystemDeviceLibraries` test to a new
`Cuda.ProperDeviceLibraries` test.  The former covered only the
`cublas_device` library which is removed by CUDA 10.  Extend the new
test to also cover various cases of using threads.

Issue: #18008
This commit is contained in:
Robert Maynard
2018-10-22 10:54:44 -04:00
committed by Brad King
parent 83c13ca44f
commit 2cc050b53b
7 changed files with 73 additions and 16 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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()