diff options
author | Brad King <brad.king@kitware.com> | 2017-02-15 13:24:05 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2017-02-15 13:24:05 (GMT) |
commit | e853dfed6aef2dccc6bf05b6d19a5911e76f51c6 (patch) | |
tree | 417b5b341201556a0a85057c10dcf09eeba31d07 /Tests/Cuda | |
parent | 8ba5c21db774cb23d223612ba67963723010e9f3 (diff) | |
parent | 1c60231ca546597ef8b80e7340c8991b06387cbf (diff) | |
download | CMake-e853dfed6aef2dccc6bf05b6d19a5911e76f51c6.zip CMake-e853dfed6aef2dccc6bf05b6d19a5911e76f51c6.tar.gz CMake-e853dfed6aef2dccc6bf05b6d19a5911e76f51c6.tar.bz2 |
Merge topic 'cuda-with-c'
1c60231c CUDA: Link to standard system libraries when linking as CUDA
8d75d8dc Tests: Add case for CUDA with C but not C++
Diffstat (limited to 'Tests/Cuda')
-rw-r--r-- | Tests/Cuda/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/Cuda/WithC/CMakeLists.txt | 12 | ||||
-rw-r--r-- | Tests/Cuda/WithC/cuda.cu | 16 | ||||
-rw-r--r-- | Tests/Cuda/WithC/main.c | 14 |
4 files changed, 43 insertions, 0 deletions
diff --git a/Tests/Cuda/CMakeLists.txt b/Tests/Cuda/CMakeLists.txt index 42b00e1..de48501 100644 --- a/Tests/Cuda/CMakeLists.txt +++ b/Tests/Cuda/CMakeLists.txt @@ -4,3 +4,4 @@ ADD_TEST_MACRO(Cuda.ConsumeCompileFeatures CudaConsumeCompileFeatures) ADD_TEST_MACRO(Cuda.ObjectLibrary CudaObjectLibrary) ADD_TEST_MACRO(Cuda.ToolkitInclude CudaToolkitInclude) ADD_TEST_MACRO(Cuda.ProperLinkFlags ProperLinkFlags) +ADD_TEST_MACRO(Cuda.WithC CudaWithC) diff --git a/Tests/Cuda/WithC/CMakeLists.txt b/Tests/Cuda/WithC/CMakeLists.txt new file mode 100644 index 0000000..7596804 --- /dev/null +++ b/Tests/Cuda/WithC/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.7) +project(CudaComplex CUDA C) + +set(CMAKE_CUDA_FLAGS "-gencode arch=compute_30,code=compute_30") + +add_executable(CudaWithC main.c cuda.cu) + +if(APPLE) + # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that + # the static cuda runtime can find it at runtime. + target_link_libraries(CudaWithC PRIVATE -Wl,-rpath,/usr/local/cuda/lib) +endif() diff --git a/Tests/Cuda/WithC/cuda.cu b/Tests/Cuda/WithC/cuda.cu new file mode 100644 index 0000000..06bd7b9 --- /dev/null +++ b/Tests/Cuda/WithC/cuda.cu @@ -0,0 +1,16 @@ +#include <cuda.h> + +#include <iostream> + +extern "C" int use_cuda(void) +{ + int nDevices = 0; + cudaError_t err = cudaGetDeviceCount(&nDevices); + if (err != cudaSuccess) { + std::cerr << "Failed to retrieve the number of CUDA enabled devices" + << std::endl; + return 1; + } + std::cout << "Found " << nDevices << " CUDA enabled devices" << std::endl; + return 0; +} diff --git a/Tests/Cuda/WithC/main.c b/Tests/Cuda/WithC/main.c new file mode 100644 index 0000000..cb5fddc --- /dev/null +++ b/Tests/Cuda/WithC/main.c @@ -0,0 +1,14 @@ +extern int use_cuda(void); + +#ifdef _WIN32 +#include <windows.h> +#endif + +int main() +{ +#ifdef _WIN32 + /* Use an API that requires CMake's "standard" C libraries. */ + GetOpenFileName(NULL); +#endif + return use_cuda(); +} |