Add 'libgomp.oacc-c-c++-common/map-data-1.c'
diff mbox series

Message ID 87immp3eb1.fsf@euler.schwinge.homeip.net
State New
Headers show
Series
  • Add 'libgomp.oacc-c-c++-common/map-data-1.c'
Related show

Commit Message

Thomas Schwinge Dec. 9, 2019, 11:53 a.m. UTC
Hi!

See attached "Add 'libgomp.oacc-c-c++-common/map-data-1.c'", committed to
trunk in r279121.


Grüße
 Thomas

Patch
diff mbox series

From 524aec42ea4d0a98fd6a0815e7573bf94fa70ee3 Mon Sep 17 00:00:00 2001
From: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 9 Dec 2019 11:40:27 +0000
Subject: [PATCH] Add 'libgomp.oacc-c-c++-common/map-data-1.c'

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/map-data-1.c: New file.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@279121 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog                             |  2 +
 .../libgomp.oacc-c-c++-common/map-data-1.c    | 53 +++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/map-data-1.c

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index aac3b1887b0..51a00a3a46c 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,5 +1,7 @@ 
 2019-12-09  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* testsuite/libgomp.oacc-c-c++-common/map-data-1.c: New file.
+
 	PR libgomp/92854
 	* testsuite/libgomp.oacc-c-c++-common/pr92854-1.c: New file.
 
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/map-data-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/map-data-1.c
new file mode 100644
index 00000000000..d0781dd7f56
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/map-data-1.c
@@ -0,0 +1,53 @@ 
+/* Verify that 'acc_map_data' does not copy data to, and 'acc_unmap_data' does
+   not copy data from the device.  */
+
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+#include <stdlib.h>
+#include <string.h>
+#include <openacc.h>
+
+int
+main ()
+{
+  const int c0 = 9;
+  const int c1 = 40;
+  const int c2 = 47;
+
+  const size_t N = 256;
+
+  unsigned char *h = (unsigned char *) malloc (N);
+
+  void *d = acc_malloc (N);
+
+  memset (h, c0, N); // H <- c0
+  acc_memcpy_to_device (d, h, N); // D <- H = c0
+
+  memset (h, c1, N); // H <- c1
+  acc_map_data (h, d, N);
+  for (size_t i = 0; i < N; ++i)
+    if (h[i] != c1)
+      abort ();
+
+  acc_memcpy_from_device (h, d, N); // H <- D = c0
+  for (size_t i = 0; i < N; ++i)
+    if (h[i] != c0)
+      abort ();
+
+  memset (h, c2, N); // H <- c2
+  acc_unmap_data (h);
+  for (size_t i = 0; i < N; ++i)
+    if (h[i] != c2)
+      abort ();
+
+  acc_memcpy_from_device (h, d, N); // H <- D = c0
+  for (size_t i = 0; i < N; ++i)
+    if (h[i] != c0)
+      abort ();
+
+  acc_free (d);
+
+  free (h);
+
+  return 0;
+}
-- 
2.17.1