-
Notifications
You must be signed in to change notification settings - Fork 5
/
map-noncuda.cu
55 lines (41 loc) · 952 Bytes
/
map-noncuda.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
/*
* Map the square function sqeezing all of this data through 1 CPU.
*/
#include <stdio.h>
#include <stdlib.h>
void nonCudaMap(float* out, float *in, int size);
void startClock(char*);
void stopClock(char*);
void printClock(char*);
float square(float x) {
return x*x;
}
int main(int argc, char** argv) {
if (argc < 2) {
printf("Usage: %s #-of-floats\n",argv[0]);
exit(1);
}
int size = atoi(argv[1]);
printf("size = %d\n",size);
float *h_in;
float *h_out;
h_in = (float*) malloc(size*sizeof(float));
h_out =(float*) malloc(size*sizeof(float));
for (int i = 0; i < size; i++) {
h_in[i] = i;
}
startClock("compute");
nonCudaMap(h_out,h_in,size);
stopClock("compute");
for (int i = 0; i < size; i++) {
printf("%f -> %f\n",h_in[i],h_out[i]);
}
free(h_in);
free(h_out);
printClock("compute");
}
void nonCudaMap(float* out, float* in, int size) {
for (int i = 0; i < size; i++) {
out[i] = square(in[i]);
}
}