-
Notifications
You must be signed in to change notification settings - Fork 4
/
nmstest.c
160 lines (123 loc) · 3.7 KB
/
nmstest.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* NMS Benchmarking Framework
*
* "Work-Efficient Parallel Non-Maximum Suppression Kernels"
* Copyright (c) 2019 David Oro et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include "nms.h"
void print_help()
{
printf("\nUsage: nmstest <detections.txt> <output.txt>\n\n");
printf(" detections.txt -> Input file containing the coordinates, width, and scores of detected objects\n");
printf(" output.txt -> Output file after performing NMS\n\n");
}
int init_cuda_runtime()
{
cudaError_t err;
int i, value, dev, seldev;
int maxsm = 0, maxmajor = 0, maxminor = 0;
struct cudaDeviceProp device;
err = cudaRuntimeGetVersion(&value);
if(err != cudaSuccess)
{
printf("Error: %s\n", cudaGetErrorString(err));
return -1;
}
printf("\nCUDA Runtime Version %d\n", value);
err = cudaGetDeviceCount(&dev);
if(err != cudaSuccess)
{
printf("Error: %s\n", cudaGetErrorString(err));
return -2;
}
/* We require at least CUDA 6.0 */
if(value < 6000)
{
printf("Error: This software requires CUDA Runtime version 6.0 or better\n");
return -3;
}
seldev = 0;
for(i=0; i<dev; i++)
{
err = cudaGetDeviceProperties(&device, i);
if(err != cudaSuccess)
{
printf("Error: %s\n", cudaGetErrorString(err));
return -4;
}
printf("Device %d# %s\t [%2.2f GHz - %d Multiprocessors - Core sm_%d%d - %ld MB]\n", i, device.name,
(float) device.clockRate / 1e6, device.multiProcessorCount, device.major, device.minor,
(long) device.totalGlobalMem / (1024*1024));
/* We select the CUDA device with the
highest number of multiprocessors and
with the newest core revision */
if((device.major >= maxmajor) && (device.minor >= maxminor))
{
maxmajor = device.major;
maxminor = device.minor;
if(device.multiProcessorCount > maxsm)
{
seldev = i;
maxsm = device.multiProcessorCount;
}
}
}
err = cudaSetDevice(seldev);
if(err != cudaSuccess)
{
printf("Error: %s\n", cudaGetErrorString(err));
return -5;
}
printf("Device %d# has been selected for CUDA computation\n\n", seldev);
return 0;
}
int main(int argc, char *argv[])
{
int res;
if(argc != 3)
{
print_help();
return 0;
}
/* CUDA runtime initialization */
if (init_cuda_runtime() < 0)
return -1;
/* Read input detection coordinates from the text file */
res = read_detections("detections.txt");
if(res < 0)
return -1;
/* Allocate GPU memory */
if (allocate_gpu_memory() < 0)
return -1;
/* Transfer detection coordinates read from the input text file to the GPU */
transfer_detections_to_gpu();
/* Execute NMS on the GPU */
res = non_maximum_suppression();
if(res < 0)
{
printf("Please update the SM_ARCH and GPU_ARCH variables in the Makefile with the parameters matching your GPU architecture, and recompile again the code.\n");
free_memory();
return -1;
}
/* Dump detections after having performed the NMS */
res = dump_merged_detections("output.txt");
if(res < 0)
return -1;
free_memory();
return 0;
}