diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2019-07-30 15:01:57 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-08-19 19:20:38 (GMT) |
commit | f4fc0667ae406c8f6b4c3e22a73ae4a7a075404b (patch) | |
tree | af34a92c3d13d3230f208b9f6f76513052e2d0b0 /Tests/FindOpenACC/CTest/main.c | |
parent | 9460501ad7353e6eecdf42d56568c1f909f64e27 (diff) | |
download | CMake-f4fc0667ae406c8f6b4c3e22a73ae4a7a075404b.zip CMake-f4fc0667ae406c8f6b4c3e22a73ae4a7a075404b.tar.gz CMake-f4fc0667ae406c8f6b4c3e22a73ae4a7a075404b.tar.bz2 |
FindOpenACC: Provide import targets and OpenACC_<lang>_OPTIONS variable
Previously the FindOpenACC module had issues where the contents of
OpenACC_<lang>_FLAGS could not be used with target_compile_options
when it contained multiple compiler flags.
Diffstat (limited to 'Tests/FindOpenACC/CTest/main.c')
-rw-r--r-- | Tests/FindOpenACC/CTest/main.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Tests/FindOpenACC/CTest/main.c b/Tests/FindOpenACC/CTest/main.c new file mode 100644 index 0000000..53b6cae --- /dev/null +++ b/Tests/FindOpenACC/CTest/main.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> + +void vecaddgpu(float* r, float* a, float* b, int n) +{ +#pragma acc kernels loop present(r, a, b) + for (int i = 0; i < n; ++i) + r[i] = a[i] + b[i]; +} + +int main() +{ + int n = 100000; /* vector length */ + float* a; /* input vector 1 */ + float* b; /* input vector 2 */ + float* r; /* output vector */ + float* e; /* expected output values */ + int i, errs; + + a = (float*)malloc(n * sizeof(float)); + b = (float*)malloc(n * sizeof(float)); + r = (float*)malloc(n * sizeof(float)); + e = (float*)malloc(n * sizeof(float)); + for (i = 0; i < n; ++i) { + a[i] = (float)(i + 1); + b[i] = (float)(1000 * i); + } +/* compute on the GPU */ +#pragma acc data copyin(a [0:n], b [0:n]) copyout(r [0:n]) + { + vecaddgpu(r, a, b, n); + } + /* compute on the host to compare */ + for (i = 0; i < n; ++i) + e[i] = a[i] + b[i]; + /* compare results */ + errs = 0; + for (i = 0; i < n; ++i) { + if (r[i] != e[i]) { + ++errs; + } + } + return errs; +} |