-
Notifications
You must be signed in to change notification settings - Fork 13
/
GPU-ed.cu
90 lines (62 loc) · 2.81 KB
/
GPU-ed.cu
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
#include <iostream>
#include <fstream>
#include "include/ed.cuh"
#include "include/cuda_def.cuh"
int main(int argc, char* argv[]) {
if (argc != 5){
std::cout << "call" << argv[0]
<< " query.bin subject.bin M N" << std::endl;
return 1;
}
cudaSetDevice(0); CUERR
cudaDeviceReset(); CUERR
double *zquery = NULL, *subject = NULL,
*Subject = NULL, *AvgS = NULL, *StdS = NULL;
int M = atoi(argv[3]);
int N = atoi(argv[4]);
std::cout << "\n= info =====================================" << std::endl;
std::cout << "|Query| = " << M << "\t"
<< "|Subject| = " << N << "\t" << std::endl;
// host side memory
cudaMallocHost(&zquery, sizeof(double)*M); CUERR
cudaMallocHost(&subject, sizeof(double)*N); CUERR
// device side memory
cudaMalloc(&Subject, sizeof(double)*N); CUERR
cudaMalloc(&AvgS, sizeof(double)*(N-M+1)); CUERR
cudaMalloc(&StdS, sizeof(double)*(N-M+1)); CUERR
// timer events
cudaEvent_t start, stop;
float time;
cudaEventCreate(&start);
cudaEventCreate(&stop);
std::cout << "\n= loading data =============================" << std::endl;
cudaEventRecord(start, 0);
// read query from file
std::ifstream qfile(argv[1], std::ios::binary|std::ios::in);
qfile.read((char *) &zquery[0], sizeof(double)*M);
// read subject from file
std::ifstream sfile(argv[2], std::ios::binary|std::ios::in);
sfile.read((char *) &subject[0], sizeof(double)*N);
// z-normalize query and envelope
znormalize(zquery, M);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
std::cout << "Miliseconds to load data: " << time << std::endl;
cudaEventRecord(start, 0);
// copy subject to gpu
cudaMemcpy(Subject, subject, sizeof(double)*N,
cudaMemcpyHostToDevice); CUERR
// copy query to constant memory
cudaMemcpyToSymbol(::Czquery, zquery, sizeof(double)*M); CUERR
// calculate windowed average and standard deviation of Subject
avg_std<double>(Subject, AvgS, StdS, M, N);
// average not needed anymore
cudaFree(AvgS); CUERR
// calculate best z-normalized Euclidean match
calculate_ed(Subject, StdS, M, N);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
std::cout << "Miliseconds to find best match: " << time << std::endl;
}