summaryrefslogtreecommitdiffstats
path: root/Tests/FindOpenACC/CXXTest/main.cxx
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2019-07-30 15:01:57 (GMT)
committerBrad King <brad.king@kitware.com>2019-08-19 19:20:38 (GMT)
commitf4fc0667ae406c8f6b4c3e22a73ae4a7a075404b (patch)
treeaf34a92c3d13d3230f208b9f6f76513052e2d0b0 /Tests/FindOpenACC/CXXTest/main.cxx
parent9460501ad7353e6eecdf42d56568c1f909f64e27 (diff)
downloadCMake-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/CXXTest/main.cxx')
-rw-r--r--Tests/FindOpenACC/CXXTest/main.cxx43
1 files changed, 43 insertions, 0 deletions
diff --git a/Tests/FindOpenACC/CXXTest/main.cxx b/Tests/FindOpenACC/CXXTest/main.cxx
new file mode 100644
index 0000000..7369045
--- /dev/null
+++ b/Tests/FindOpenACC/CXXTest/main.cxx
@@ -0,0 +1,43 @@
+
+#include <vector>
+
+void vecaddgpu(float* r, float* a, float* b, std::size_t n)
+{
+#pragma acc kernels loop present(r, a, b)
+ for (std::size_t i = 0; i < n; ++i)
+ r[i] = a[i] + b[i];
+}
+
+int main(int, char* [])
+{
+ const std::size_t n = 100000; /* vector length */
+ std::vector<float> a(n); /* input vector 1 */
+ std::vector<float> b(n); /* input vector 2 */
+ std::vector<float> r(n); /* output vector */
+ std::vector<float> e(n); /* expected output values */
+
+ for (std::size_t i = 0; i < n; ++i) {
+ a[i] = static_cast<float>(i + 1);
+ b[i] = static_cast<float>(1000 * i);
+ }
+
+ /* compute on the GPU */
+ auto a_ptr = a.data();
+ auto b_ptr = b.data();
+ auto r_ptr = r.data();
+#pragma acc data copyin(a_ptr [0:n], b_ptr [0:n]) copyout(r_ptr [0:n])
+ {
+ vecaddgpu(r_ptr, a_ptr, b_ptr, n);
+ }
+ /* compute on the host to compare */
+ for (std::size_t i = 0; i < n; ++i)
+ e[i] = a[i] + b[i];
+ /* compare results */
+ int errs = 0;
+ for (std::size_t i = 0; i < n; ++i) {
+ if (r[i] != e[i]) {
+ ++errs;
+ }
+ }
+ return errs;
+}