summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeCompilerCUDAArch.h
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/CMakeCompilerCUDAArch.h')
-rw-r--r--Modules/CMakeCompilerCUDAArch.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/Modules/CMakeCompilerCUDAArch.h b/Modules/CMakeCompilerCUDAArch.h
new file mode 100644
index 0000000..dcb030f
--- /dev/null
+++ b/Modules/CMakeCompilerCUDAArch.h
@@ -0,0 +1,29 @@
+#include <cstdio>
+
+#include <cuda_runtime.h>
+
+static bool cmakeCompilerCUDAArch()
+{
+ int count = 0;
+ if (cudaGetDeviceCount(&count) != cudaSuccess || count == 0) {
+ std::fprintf(stderr, "No CUDA devices found.\n");
+ return -1;
+ }
+
+ bool found = false;
+ const char* sep = "";
+ for (int device = 0; device < count; ++device) {
+ cudaDeviceProp prop;
+ if (cudaGetDeviceProperties(&prop, device) == cudaSuccess) {
+ std::printf("%s%d%d", sep, prop.major, prop.minor);
+ sep = ";";
+ found = true;
+ }
+ }
+
+ if (!found) {
+ std::fprintf(stderr, "No CUDA architecture detected from any devices.\n");
+ }
+
+ return found;
+}