| 1 | /*
|
|---|
| 2 | * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
|---|
| 3 | *
|
|---|
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property
|
|---|
| 5 | * and proprietary rights in and to this software, related documentation
|
|---|
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or
|
|---|
| 7 | * distribution of this software and related documentation without an express
|
|---|
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #include <stdio.h>
|
|---|
| 13 | #include <stdlib.h>
|
|---|
| 14 | #include <assert.h>
|
|---|
| 15 |
|
|---|
| 16 | int main( int argc, char* argv[] )
|
|---|
| 17 | {
|
|---|
| 18 | int n; /* size of the vector */
|
|---|
| 19 | float *a; /* the vector */
|
|---|
| 20 | float *restrict r; /* the results */
|
|---|
| 21 | float *e; /* expected results */
|
|---|
| 22 | int i, nerrors;
|
|---|
| 23 | nerrors = 0;
|
|---|
| 24 | if( argc > 1 )
|
|---|
| 25 | n = atoi( argv[1] );
|
|---|
| 26 | else
|
|---|
| 27 | n = 100000;
|
|---|
| 28 | if( n <= 0 ) n = 100000;
|
|---|
| 29 |
|
|---|
| 30 | a = (float*)malloc(n*sizeof(float));
|
|---|
| 31 | r = (float*)malloc(n*sizeof(float));
|
|---|
| 32 | e = (float*)malloc(n*sizeof(float));
|
|---|
| 33 | /* initialize */
|
|---|
| 34 | for( i = 0; i < n; ++i ) a[i] = (float)(i+1);
|
|---|
| 35 |
|
|---|
| 36 | #pragma acc kernels loop
|
|---|
| 37 | for( i = 0; i < n; ++i ) r[i] = a[i]*2.0f;
|
|---|
| 38 | /* compute on the host to compare */
|
|---|
| 39 | for( i = 0; i < n; ++i ) e[i] = a[i]*2.0f;
|
|---|
| 40 | /* check the results */
|
|---|
| 41 | for( i = 0; i < n; ++i ) {
|
|---|
| 42 | if ( r[i] != e[i] ) {
|
|---|
| 43 | nerrors++;
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | printf( "%d iterations completed\n", n );
|
|---|
| 47 | if ( nerrors != 0 ) {
|
|---|
| 48 | printf( "Test FAILED\n");
|
|---|
| 49 | } else {
|
|---|
| 50 | printf( "Test PASSED\n");
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | return 0;
|
|---|
| 54 | }
|
|---|