-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathopenacc_streams.c
More file actions
41 lines (33 loc) · 775 Bytes
/
openacc_streams.c
File metadata and controls
41 lines (33 loc) · 775 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <cuda_runtime.h>
extern void saxpy(int,float,float*,float*,cudaStream_t);
int main(int argc, char **argv)
{
float *x, *y, tmp;
int n = 1<<20, i;
cudaStream_t stream;
x = (float*)malloc(n*sizeof(float));
y = (float*)malloc(n*sizeof(float));
stream = (cudaStream_t) acc_get_cuda_stream(1);
#pragma acc data create(x[0:n],y[0:n])
{
#pragma acc kernels async(1)
{
for( i = 0; i < n; i++)
{
x[i] = 1.0f;
y[i] = 0.0f;
}
}
#pragma acc host_data use_device(x,y)
{
saxpy(n, 2.0, x, y, stream);
}
#pragma acc update self(y[0:n]) async(1)
#pragma acc wait(1)
}
fprintf(stdout, "y[0] = %f\n",y[0]);
return 0;
}