main
test-branch
|
Last change
on this file since beab7f2 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [33534bb] | 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | void vecaddgpu( float *restrict r, float *a, float *b, int n ){
|
|---|
| 4 | #pragma acc kernels loop copyin(a[0:n],b[0:n]) copyout(r[0:n])
|
|---|
| 5 | for( int i = 0; i < n; ++i ) r[i] = a[i] + b[i];
|
|---|
| 6 | }
|
|---|
| 7 |
|
|---|
| 8 | int main( int argc, char* argv[] ){
|
|---|
| 9 | int n; /* vector length */
|
|---|
| 10 | float * a; /* input vector 1 */
|
|---|
| 11 | float * b; /* input vector 2 */
|
|---|
| 12 | float * r; /* output vector */
|
|---|
| 13 | float * e; /* expected output values */
|
|---|
| 14 | int i, errs;
|
|---|
| 15 | if( argc > 1 ) n = atoi( argv[1] );
|
|---|
| 16 | else n = 100000; /* default vector length */
|
|---|
| 17 | if( n <= 0 ) n = 100000;
|
|---|
| 18 | a = (float*)malloc( n*sizeof(float) );
|
|---|
| 19 | b = (float*)malloc( n*sizeof(float) );
|
|---|
| 20 | r = (float*)malloc( n*sizeof(float) );
|
|---|
| 21 | e = (float*)malloc( n*sizeof(float) );
|
|---|
| 22 | for( i = 0; i < n; ++i ){
|
|---|
| 23 | a[i] = (float)(i+1);
|
|---|
| 24 | } b[i] = (float)(1000*i);
|
|---|
| 25 | /* compute on the GPU */
|
|---|
| 26 | vecaddgpu( r, a, b, n );
|
|---|
| 27 | /* compute on the host to compare */
|
|---|
| 28 | for( i = 0; i < n; ++i ) e[i] = a[i] + b[i];
|
|---|
| 29 | /* compare results */
|
|---|
| 30 | errs = 0;
|
|---|
| 31 | for( i = 0; i < n; ++i ){
|
|---|
| 32 | if( r[i] != e[i] ){
|
|---|
| 33 | ++errs;
|
|---|
| 34 | }}
|
|---|
| 35 | printf("%d errors found\n", errs );
|
|---|
| 36 | return errs;
|
|---|
| 37 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.