forked from jefflarkin/openacc-interoperability
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4be2a4c
commit 497826b
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
extern void saxpy(int,float,float*,float*); | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
float *x, *y, tmp; | ||
int n = 1<<20, i; | ||
|
||
x = (float*)malloc(n*sizeof(float)); | ||
y = (float*)malloc(n*sizeof(float)); | ||
|
||
#pragma acc data create(x[0:n]) copyout(y[0:n]) | ||
{ | ||
#pragma acc kernels | ||
{ | ||
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); | ||
} | ||
} | ||
|
||
fprintf(stdout, "y[0] = %f\n",y[0]); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
__global__ | ||
void saxpy_kernel(int n, float a, float *x, float *y) | ||
{ | ||
int i = blockDim.x * blockIdx.x + threadIdx.x; | ||
|
||
if ( i < n ) | ||
y[i] += a * x[i]; | ||
} | ||
extern "C" void saxpy(int n ,float a, float *x, float *y) | ||
{ | ||
dim3 griddim, blockdim; | ||
|
||
blockdim = dim3(128,1,1); | ||
griddim = dim3(n/blockdim.x,1,1); | ||
|
||
saxpy_kernel<<<griddim,blockdim>>>(n,a,x,y); | ||
} |