forked from udacity/cs344
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·73 lines (60 loc) · 2.05 KB
/
main.cpp
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
//Udacity HW4 Driver
#include <iostream>
#include "timer.h"
#include "utils.h"
#include <string>
#include <stdio.h>
void preProcess(unsigned int **inputVals,
unsigned int **inputPos,
unsigned int **outputVals,
unsigned int **outputPos,
size_t &numElems,
const std::string& filename);
void postProcess(const unsigned int* const outputVals,
const unsigned int* const outputPos,
const size_t numElems,
const std::string& output_file);
void your_sort(unsigned int* const inputVals,
unsigned int* const inputPos,
unsigned int* const outputVals,
unsigned int* const outputPos,
const size_t numElems);
int main(int argc, char **argv) {
unsigned int *inputVals;
unsigned int *inputPos;
unsigned int *outputVals;
unsigned int *outputPos;
size_t numElems;
std::string input_file;
std::string output_file;
if (argc == 3) {
input_file = std::string(argv[1]);
output_file = std::string(argv[2]);
}
else {
std::cerr << "Usage: ./hw input_file output_file" << std::endl;
exit(1);
}
//load the image and give us our input and output pointers
preProcess(&inputVals, &inputPos, &outputVals, &outputPos, numElems, input_file);
GpuTimer timer;
timer.Start();
//call the students' code
your_sort(inputVals, inputPos, outputVals, outputPos, numElems);
timer.Stop();
cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
printf("\n");
int err = printf("%f msecs.\n", timer.Elapsed());
if (err < 0) {
//Couldn't print! Probably the student closed stdout - bad news
std::cerr << "Couldn't print timing information! STDOUT Closed!" << std::endl;
exit(1);
}
//check results and output the tone-mapped image
postProcess(outputVals, outputPos, numElems, output_file);
checkCudaErrors(cudaFree(inputVals));
checkCudaErrors(cudaFree(inputPos));
checkCudaErrors(cudaFree(outputVals));
checkCudaErrors(cudaFree(outputPos));
return 0;
}