-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuda_cardz.c
77 lines (70 loc) · 1.22 KB
/
cuda_cardz.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// This program is part of ppcg_polybench_test-benchmark
// Copyright Денис Крыськов 2014
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime_api.h>
int card_found=0;
int cards_count=-1;
void dump(int x,int check_KERNEL_EXEC_TIMEOUT)
{
struct cudaDeviceProp p;
cudaGetDeviceProperties(&p, x);
if(check_KERNEL_EXEC_TIMEOUT && p.kernelExecTimeoutEnabled)
return;
printf("%d %d%d\n", x, p.major, p.minor);
card_found=1;
}
void all(int u)
{
int i;
if(cards_count==-1)
cudaGetDeviceCount(&cards_count);
if(u==-1)
for(i=0; i<cards_count; i++)
dump(i,0);
else
if(u<cards_count)
dump(u,0);
}
void free_cards()
{
int i;
cudaGetDeviceCount(&cards_count);
for(i=0; i<cards_count; i++)
dump(i,1);
}
void free_or_all()
{
free_cards();
if(card_found)
return;
all(-1);
}
int main(int ac,char** av)
{
if(ac==1)
{
free_or_all();
return 0;
}
char* e;
int u=strtol(av[1], &e, 0);
if(*e)
{
//should be "all" or "free"
if(!strcmp(av[1],"all"))
{
all(-1);
return 0;
}
if(!strcmp(av[1],"free"))
{
free_or_all();
return 0;
}
// garbage, ingored
return 0;
}
all(u);
return 0;
}