OpenCVDetectCudaArch.cu 725 B

12345678910111213141516171819202122232425
  1. #include <iostream>
  2. #include <sstream>
  3. #include <list>
  4. int main()
  5. {
  6. std::ostringstream arch;
  7. std::list<std::string> archs;
  8. int count = 0;
  9. if (cudaSuccess != cudaGetDeviceCount(&count)){ return -1; }
  10. if (count == 0) { return -1; }
  11. for (int device = 0; device < count; ++device)
  12. {
  13. cudaDeviceProp prop;
  14. if (cudaSuccess != cudaGetDeviceProperties(&prop, device)){ continue; }
  15. arch << prop.major << "." << prop.minor;
  16. archs.push_back(arch.str());
  17. arch.str("");
  18. }
  19. archs.unique(); // Some devices might have the same arch
  20. for (std::list<std::string>::iterator it=archs.begin(); it!=archs.end(); ++it)
  21. std::cout << *it << " ";
  22. return 0;
  23. }