CMakeCompilerCUDAArch.h 651 B

1234567891011121314151617181920212223242526272829
  1. #include <cstdio>
  2. #include <cuda_runtime.h>
  3. static bool cmakeCompilerCUDAArch()
  4. {
  5. int count = 0;
  6. if (cudaGetDeviceCount(&count) != cudaSuccess || count == 0) {
  7. std::fprintf(stderr, "No CUDA devices found.\n");
  8. return -1;
  9. }
  10. bool found = false;
  11. char const* sep = "";
  12. for (int device = 0; device < count; ++device) {
  13. cudaDeviceProp prop;
  14. if (cudaGetDeviceProperties(&prop, device) == cudaSuccess) {
  15. std::printf("%s%d%d", sep, prop.major, prop.minor);
  16. sep = ";";
  17. found = true;
  18. }
  19. }
  20. if (!found) {
  21. std::fprintf(stderr, "No CUDA architecture detected from any devices.\n");
  22. }
  23. return found;
  24. }