-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfindgpus.cu
More file actions
48 lines (40 loc) · 1.25 KB
/
findgpus.cu
File metadata and controls
48 lines (40 loc) · 1.25 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <set>
#include <utility>
void printarch(int major, int minor){
std::cout << "-gencode=arch=compute_" << major << minor << ",code=sm_" << major << minor << " ";
}
void printDefault(){
std::cout << "-gencode=arch=compute_60,code=compute_60";
}
int main(int argc, char** argv){
int numGpus = 0;
cudaError_t status = cudaSuccess;
status = cudaGetDeviceCount(&numGpus);
std::set<std::pair<int, int>> allgpusset;
if(status == cudaSuccess && numGpus > 0){
for(int d = 0; d < numGpus; d++){
int major = 0;
int minor = 0;
status = cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, d);
status = cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, d);
if(status == cudaSuccess){
allgpusset.insert(std::make_pair(major, minor));
}
}
}
std::set<std::pair<int, int>> usablegpusset;
for(const auto& p : allgpusset){
if(p.first >= 6){
usablegpusset.insert(p);
}
}
if(usablegpusset.empty()){
printDefault();
}else{
for(const auto& p : usablegpusset){
printarch(p.first, p.second);
}
}
std::cout << "\n";
}