summaryrefslogtreecommitdiffstats
path: root/Tests/CudaOnly/WithDefs
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2016-11-01 20:11:51 (GMT)
committerBrad King <brad.king@kitware.com>2016-11-14 21:40:50 (GMT)
commit7b9131da64b4b569e10ec145fab0c8e22fa69761 (patch)
treebf3cf32fa6515c1d197e7950262094290b797e6e /Tests/CudaOnly/WithDefs
parent9cf5b98d54497b425fe341e4ad5bc188d9fa5445 (diff)
downloadCMake-7b9131da64b4b569e10ec145fab0c8e22fa69761.zip
CMake-7b9131da64b4b569e10ec145fab0c8e22fa69761.tar.gz
CMake-7b9131da64b4b569e10ec145fab0c8e22fa69761.tar.bz2
CUDA: Add tests to verify CUDA compiler works properly.
Diffstat (limited to 'Tests/CudaOnly/WithDefs')
-rw-r--r--Tests/CudaOnly/WithDefs/CMakeLists.txt31
-rw-r--r--Tests/CudaOnly/WithDefs/main.notcu46
2 files changed, 77 insertions, 0 deletions
diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt
new file mode 100644
index 0000000..c4ca8b9
--- /dev/null
+++ b/Tests/CudaOnly/WithDefs/CMakeLists.txt
@@ -0,0 +1,31 @@
+
+cmake_minimum_required(VERSION 3.7)
+project (CudaOnlyWithDefs CUDA)
+
+#verify that we can pass explicit cuda arch flags
+set(CMAKE_CUDA_FLAGS "-gencode arch=compute_30,code=compute_30")
+set(debug_compile_flags --generate-code arch=compute_20,code=sm_20 -Xcompiler=-Werror)
+set(release_compile_defs DEFREL)
+
+#Goal for this example:
+#build a executable that needs to be passed a complex define through add_defintions
+#this verifies we can pass things such as '_','(' to nvcc
+add_definitions("-DPACKED_DEFINE=__attribute__((packed))")
+set_source_files_properties(main.notcu PROPERTIES LANGUAGE CUDA)
+add_executable(CudaOnlyWithDefs main.notcu)
+
+target_compile_options(CudaOnlyWithDefs
+ PRIVATE
+ $<$<CONFIG:DEBUG>:$<BUILD_INTERFACE:${debug_compile_flags}>>
+ )
+
+target_compile_definitions(CudaOnlyWithDefs
+ PRIVATE
+ $<$<CONFIG:RELEASE>:$<BUILD_INTERFACE:${release_compile_defs}>>
+ )
+
+#we need to add an rpath for the cuda library so that everything
+#loads properly on the mac
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ set_target_properties(CudaOnlyWithDefs PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}")
+endif()
diff --git a/Tests/CudaOnly/WithDefs/main.notcu b/Tests/CudaOnly/WithDefs/main.notcu
new file mode 100644
index 0000000..6b02bbc
--- /dev/null
+++ b/Tests/CudaOnly/WithDefs/main.notcu
@@ -0,0 +1,46 @@
+#include <cuda.h>
+#include <cuda_runtime.h>
+#include <iostream>
+
+static
+__global__
+void DetermineIfValidCudaDevice()
+{
+}
+
+struct PACKED_DEFINE result_type
+{
+ bool valid;
+ int value;
+#if defined(NDEBUG) && !defined(DEFREL)
+#error missing DEFREL flag
+#endif
+};
+
+result_type can_launch_kernel()
+{
+ result_type r;
+ DetermineIfValidCudaDevice <<<1,1>>> ();
+ r.valid = (cudaSuccess == cudaGetLastError());
+ if(r.valid)
+ {
+ r.value = 1;
+ }
+ else
+ {
+ r.value = -1;
+ }
+ return r;
+}
+
+int main(int argc, char **argv)
+{
+ cudaError_t err;
+ int nDevices = 0;
+ err = cudaGetDeviceCount(&nDevices);
+ if(err != cudaSuccess)
+ {
+ return 1;
+ }
+ return 0;
+}