-
Notifications
You must be signed in to change notification settings - Fork 23
/
cuda_map.cu
30 lines (24 loc) · 707 Bytes
/
cuda_map.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <cuda_runtime.h>
extern "C" void saxpy(int,float,float*,float*);
extern "C" void set(int,float,float*);
extern "C" void map(float*, float*, int);
int main(int argc, char **argv)
{
float *x, *y, *dx, *dy, tmp;
int n = 1<<20;
x = (float*) malloc(n*sizeof(float));
y = (float*) malloc(n*sizeof(float));
cudaMalloc((void**)&dx,(size_t)n*sizeof(float));
cudaMalloc((void**)&dy,(size_t)n*sizeof(float));
map(x, dx, n*sizeof(float));
map(y, dy, n*sizeof(float));
set(n,1.0f,x);
set(n,0.0f,y);
saxpy(n, 2.0, x, y);
cudaMemcpy(&tmp,dy,(size_t)sizeof(float),cudaMemcpyDeviceToHost);
printf("%f\n",tmp);
return 0;
}