forked from davestampf/GPUTalk2014
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranspose-noncuda.cu
More file actions
61 lines (49 loc) · 1.05 KB
/
transpose-noncuda.cu
File metadata and controls
61 lines (49 loc) · 1.05 KB
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
/*
* transpose an array
*/
#include <stdio.h>
#include <stdlib.h>
void nonCudaTranspose(float* out, float *in, int size);
void startClock(char*);
void stopClock(char*);
void printClock(char*);
#define DIM 1024
int main(int argc, char** argv) {
float *h_in;
float *h_out;
h_in = (float*) malloc(DIM*DIM*sizeof(float));
h_out =(float*) malloc(DIM*DIM*sizeof(float));
int value = 1;
for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
h_in[i + j*DIM] = value++;
}
}
/* for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
printf("%10.2f ",h_in[i+j*DIM]);
}
printf("\n");
}
*/
startClock("compute");
nonCudaTranspose(h_out,h_in,DIM);
stopClock("compute");
/* for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
printf("%10.2f ",h_out[i+j*DIM]);
}
printf("\n");
}
*/
free(h_in);
free(h_out);
printClock("compute");
}
void nonCudaTranspose(float* out, float* in, int size) {
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
out[j + i*size] = in[i + j*size];
}
}
}