summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeCompilerCUDAArch.h
blob: dcb030ffae1237cd8d591f395a1e06b659c59ce4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}